Describe the bug
When running the script using the recommended sudo elevation (e.g., curl ... | sudo bash), the script fails to detect or update Homebrew (brew).
This happens due to a dual conflict:
- PATH Reset:
sudo strips out the user's custom environment variables, meaning /home/linuxbrew/.linuxbrew/bin is missing from the root $PATH. This causes check_command brew to report that Homebrew is not installed.
- Root Restrictions: Homebrew explicitly blocks or misbehaves when executed directly as the
root user, which could corrupt file permissions in the user's home directory.
To Reproduce
Run the update script inside a modern Linux distribution (especially those using sudo-rs or strict secure_path defaults):
curl -fsSL "https://raw.githubusercontent.com/gvatsal60/Linux-All-In-One-Update-Script/HEAD/.update.sh" | sudo bash
Expected behavior
The script should be able to safely locate the Homebrew binary and drop privileges back down to the local user account (NON_ROOT_USER) to perform the brew update routines securely.
Proposed Solution / Code Fix
We can resolve this by updating check_command to explicitly look for the standard Linux Homebrew installation path, and updating update_brew to execute the commands via su - "${NON_ROOT_USER}".
1. Update check_command to handle brew paths under sudo:
check_command() {
command_name="$1"
# Explicit handling for brew when run under a stripped sudo PATH
if [ "${command_name}" = "brew" ] && [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
return 0
fi
if ! command -v "${command_name}" >/dev/null 2>&1; then
print_err "${command_name} is not installed."
return 1
fi
return 0
}
2. Update update_brew to safely run as the non-root user:
update_brew() {
println "Update Brew Formula's"
if ! check_command brew; then
return
fi
# Safely drop privileges back to the normal user to run brew commands
if [ "\({NON_ROOT_USER}" != "nobody" ] && [ "\){NON_ROOT_USER}" != "root" ]; then
su - "\${NON_ROOT_USER}" -c '
eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew update && brew upgrade && brew cleanup -s
echo "\nBrew Diagnostics"
brew doctor && brew missing
'
else
# Fallback if no valid non-root user was resolved
eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew update && brew upgrade && brew cleanup -s
println "Brew Diagnostics"
brew doctor && brew missing
fi
}
Describe the bug
When running the script using the recommended
sudoelevation (e.g.,curl ... | sudo bash), the script fails to detect or update Homebrew (brew).This happens due to a dual conflict:
sudostrips out the user's custom environment variables, meaning/home/linuxbrew/.linuxbrew/binis missing from the root$PATH. This causescheck_command brewto report that Homebrew is not installed.rootuser, which could corrupt file permissions in the user's home directory.To Reproduce
Run the update script inside a modern Linux distribution (especially those using
sudo-rsor strictsecure_pathdefaults):Expected behavior
The script should be able to safely locate the Homebrew binary and drop privileges back down to the local user account (
NON_ROOT_USER) to perform thebrew updateroutines securely.Proposed Solution / Code Fix
We can resolve this by updating
check_commandto explicitly look for the standard Linux Homebrew installation path, and updatingupdate_brewto execute the commands viasu - "${NON_ROOT_USER}".1. Update
check_commandto handlebrewpaths under sudo:2. Update
update_brewto safely run as the non-root user: