brew.sh: make sudo-checker cross-platform

This commit is contained in:
Xu Cheng 2016-07-17 02:07:06 +08:00
parent 356018501b
commit 177d988917
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE

View File

@ -195,19 +195,30 @@ then
HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh"
fi fi
if [[ "$(id -u)" = "0" && "$(/usr/bin/stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ]] check-run-command-as-root() {
then
case "$HOMEBREW_COMMAND" in 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 odie <<EOS
Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND' Cowardly refusing to 'sudo brew $HOMEBREW_COMMAND'
You can use brew with sudo, but only if the brew executable is owned by root. 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 However, this is both not recommended and completely unsupported so do so at
your own risk. your own risk.
EOS EOS
;; fi
esac }
fi check-run-command-as-root
# Hide shellcheck complaint: # Hide shellcheck complaint:
# shellcheck source=/dev/null # shellcheck source=/dev/null