-
Notifications
You must be signed in to change notification settings - Fork 0
Fix sudo execution error, add Xcode Command Line Tools check, and improve Docker detection #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sudo execution error, add Xcode Command Line Tools check, and improve Docker detection #1
Conversation
Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
|
@copilot Good, now we have a problem. What's gonna happen when we get to the dnsmasq step since we're pretty much need sudo access lol |
Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
Good catch! I've updated the script to clarify this (commit a2b680f). The key distinction:
The script now:
When you run it normally, the script will prompt for your password at lines 139, 144, and 151 for:
This is the standard approach for setup scripts - run as regular user, prompt for sudo only when needed. |
|
@copilot getting this error now 📦 Installing Homebrew... |
Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
... This error occurs because Homebrew needs sudo access to install, but when running via I've added a warning that will appear before Homebrew installation (commit 7114af1). The script will now:
To avoid this issue, run the script interactively: curl -fsSL https://raw.githubusercontent.com/munezaclovis/setup/refs/heads/main/install.sh -o setup.sh
bash setup.shThis way, Homebrew can properly prompt for your sudo password when needed. |
|
@copilot It is possible that docker might already be installed from another place. not only from homebrew, Please edit the code that check if docker is install to account for that situation |
Co-authored-by: munezaclovis <51137458+munezaclovis@users.noreply.github.com>
Updated the Docker installation check (commit 97a35d4). The script now:
This properly handles Docker Desktop installed directly from Docker's website or other sources, not just Homebrew. |
Problem
When running the installation script on macOS, users encountered critical issues:
Homebrew installation fails with sudo: Running the script with
sudocauses Homebrew to fail with the error "Don't run this as root!" because Homebrew explicitly forbids root execution for security reasons.Missing Xcode Command Line Tools: Homebrew requires Xcode Command Line Tools as a prerequisite, but the script attempted to install Homebrew without verifying this dependency was present, leading to installation failures.
Non-interactive mode sudo issues: When running via
curl | bash, Homebrew installation fails because it can't prompt for sudo password in non-interactive mode (stdin is not a TTY).Docker detection only checks Homebrew: The script only checked if Docker was installed via Homebrew, ignoring Docker installations from other sources (e.g., direct download from Docker's website).
Solution
This PR adds essential checks and warnings to prevent these failures and provide clear user guidance:
1. Root/Sudo Execution Check
Added an early check that detects if the script is run with
sudoor as root:This provides immediate, actionable feedback to users before any installation attempts.
2. Xcode Command Line Tools Check
Added a new
ensure_xcode_tools()function that runs before any other installation steps:This function:
xcode-select -p3. Non-Interactive Mode Warning
Added detection and warning when Homebrew is being installed in non-interactive mode:
This warns users that the Homebrew installation may fail due to inability to prompt for sudo password, and provides clear instructions to run the script interactively instead.
4. Improved Docker Detection
Updated Docker installation check to detect Docker from any installation source:
This ensures the script respects existing Docker installations from any source (direct download, other package managers, etc.) and avoids unnecessary reinstallation attempts.
5. Updated Installation Order
Modified the
main()function to ensure proper order of operations:Changes Made
Root/Sudo Check (Lines 20-29): Prevents running the entire script with sudo, which causes Homebrew installation to fail. Includes clarification that sudo will be prompted for specific tasks.
ensure_xcode_tools Function (Lines 44-70): Checks if Xcode Command Line Tools are installed, triggers installation if missing, and provides clear user instructions.
main() Function (Lines 236-237): Calls
ensure_xcode_tools()before attempting any other installations, ensuring proper order of operations.setup_dnsmasq Function (Line 137): Informs users that the dnsmasq setup step will require sudo access for system configuration.
install_homebrew Function (Lines 101-112): Detects non-interactive mode and warns that Homebrew installation may fail due to inability to prompt for sudo password. Provides alternative interactive installation steps.
Docker Installation Check (Lines 277-286): Now checks if Docker is available from any source first using
command_exists docker, not just Homebrew. Only attempts Homebrew installation if Docker is not found on the system.clone_setup_repo Function: Improved error messaging for clarity.
Impact
Before:
sudo→ Homebrew installation fails silently or with confusing errorcurl | bash→ Homebrew fails with sudo access error in non-interactive modeAfter:
sudo→ Clear error message with correct usage instructionscurl | bash→ Warning displayed with instructions to run interactively if neededKey Points About Sudo and Interactive Mode
sudo bash install.sh), as this causes Homebrew installation to fail/etc/resolverdirectorycurl | bash(non-interactive mode), Homebrew's sudo prompts may failTesting
These minimal, surgical changes directly address the reported issues while maintaining full backward compatibility and providing clear guidance for different execution scenarios.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.