Skip to content

Commit

Permalink
brew.sh: make sudo-checker cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-cheng committed Jul 16, 2016
1 parent 3560185 commit 177d988
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,30 @@ then
HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh"
fi

if [[ "$(id -u)" = "0" && "$(/usr/bin/stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ]]
then
check-run-command-as-root() {
case "$HOMEBREW_COMMAND" in
analytics|install|reinstall|postinstall|link|pin|update|upgrade|vendor-install|create|migrate|tap|tap-pin|switch)
analytics|create|install|link|migrate|pin|postinstall|reinstall|switch|tap|tap-pin|\
update|upgrade|vendor-install)
;;
*)
return
;;
esac

[[ "$(id -u)" = 0 ]] || return

local brew_file_ls_info=($(ls -nd "$HOMEBREW_BREW_FILE"))
if [[ "${brew_file_ls_info[2]}" != 0 ]]
then
odie <<EOS
Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND'
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.
EOS
;;
esac
fi
fi
}
check-run-command-as-root

# Hide shellcheck complaint:
# shellcheck source=/dev/null
Expand Down

0 comments on commit 177d988

Please sign in to comment.