fix(brew): Prevent loading Homebrew if user is root (thanks to @HastD)

This commit is contained in:
fiftydinar 2025-03-10 08:32:01 +01:00 committed by GitHub
parent 92f4d285ab
commit e66445df32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View file

@ -3,7 +3,7 @@
# Completion is in sh to account for the zsh syntax & when zsh tries to source scripts from /etc/profiles
# Check for interactive bash and that we haven't already been sourced.
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BREW_BASH_COMPLETION-}" = x ]; then
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BREW_BASH_COMPLETION-}" = x -a "$(/usr/bin/id -u)" != 0 ]; then
# Check for recent enough version of bash.
if [ "${BASH_VERSINFO[0]}" -gt 4 ] ||

View file

@ -1,6 +1,6 @@
#!/usr/bin/env fish
#shellcheck disable=all
if status --is-interactive
if status --is-interactive and if test $(/usr/bin/id -u) -ne 0
if [ -d /home/linuxbrew/.linuxbrew ]
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
if test -d (brew --prefix)/share/fish/completions

View file

@ -215,7 +215,9 @@ if [[ ! -f "/etc/profile.d/brew.sh" ]]; then
echo "Apply brew path export fix, to solve path conflicts between system & brew programs with same name"
cat > /etc/profile.d/brew.sh <<EOF
#!/usr/bin/env bash
[[ -d /home/linuxbrew/.linuxbrew && \$- == *i* ]] && eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
if [[ -d /home/linuxbrew/.linuxbrew && \$- == *i* && "\$(/usr/bin/id -u)" != 0 ]]; then
eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
EOF
fi