Skip to content

Commit e66445d

Browse files
authored
fix(brew): Prevent loading Homebrew if user is root (thanks to @HastD)
1 parent 92f4d28 commit e66445d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

modules/brew/brew-bash-completions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Completion is in sh to account for the zsh syntax & when zsh tries to source scripts from /etc/profiles
44

55
# Check for interactive bash and that we haven't already been sourced.
6-
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BREW_BASH_COMPLETION-}" = x ]; then
6+
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BREW_BASH_COMPLETION-}" = x -a "$(/usr/bin/id -u)" != 0 ]; then
77

88
# Check for recent enough version of bash.
99
if [ "${BASH_VERSINFO[0]}" -gt 4 ] ||

modules/brew/brew-fish-completions.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env fish
22
#shellcheck disable=all
3-
if status --is-interactive
3+
if status --is-interactive and if test $(/usr/bin/id -u) -ne 0
44
if [ -d /home/linuxbrew/.linuxbrew ]
55
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
66
if test -d (brew --prefix)/share/fish/completions

modules/brew/brew.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ if [[ ! -f "/etc/profile.d/brew.sh" ]]; then
215215
echo "Apply brew path export fix, to solve path conflicts between system & brew programs with same name"
216216
cat > /etc/profile.d/brew.sh <<EOF
217217
#!/usr/bin/env bash
218-
[[ -d /home/linuxbrew/.linuxbrew && \$- == *i* ]] && eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
218+
if [[ -d /home/linuxbrew/.linuxbrew && \$- == *i* && "\$(/usr/bin/id -u)" != 0 ]]; then
219+
eval "\$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
220+
fi
219221
EOF
220222
fi
221223

0 commit comments

Comments
 (0)