Skip to content

Commit

Permalink
If running under sudo, run brew as the original sudo user (issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Oct 19, 2023
1 parent 4971a1f commit 60976bb
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions share/ruby-install/package_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ function install_packages()
run $sudo pkg install -y "$@" || return $?
;;
brew)
local brew_owner="$(/usr/bin/stat -f %Su "$(command -v brew)")"
local brew_sudo=""

if [[ "$brew_owner" != "$(id -un)" ]]; then
brew_sudo="sudo -u $brew_owner"
if (( UID == 0 )) && [[ -n "$SUDO_USER" ]]; then
brew_sudo="sudo -u \"$SUDO_USER\""
fi

run $brew_sudo brew install "$@" ||
Expand Down

0 comments on commit 60976bb

Please sign in to comment.