mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
bin/brew: improve sudo
handling
- prioritise `/usr/bin/sudo` instead of any random `sudo` in `PATH`
This commit is contained in:
parent
36a0e539e4
commit
cd4f6eb2c0
22
bin/brew
22
bin/brew
@ -36,12 +36,6 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Reset sudo timestamp to avoid running unauthorized sudo commands
|
|
||||||
if command -v sudo >/dev/null
|
|
||||||
then
|
|
||||||
sudo --reset-timestamp 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
quiet_cd() {
|
quiet_cd() {
|
||||||
CDPATH='' cd -- "$@" &>/dev/null || return
|
CDPATH='' cd -- "$@" &>/dev/null || return
|
||||||
}
|
}
|
||||||
@ -63,6 +57,22 @@ do
|
|||||||
done
|
done
|
||||||
unset cmd
|
unset cmd
|
||||||
|
|
||||||
|
# Avoid picking up any random `sudo` in `PATH`.
|
||||||
|
if [[ -x /usr/bin/sudo ]]
|
||||||
|
then
|
||||||
|
SUDO=/usr/bin/sudo
|
||||||
|
else
|
||||||
|
# Do this after ensuring we're using default Bash builtins.
|
||||||
|
SUDO="$(command -v sudo 2>/dev/null)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Reset sudo timestamp to avoid running unauthorized sudo commands
|
||||||
|
if [[ -n "${SUDO}" ]]
|
||||||
|
then
|
||||||
|
"${SUDO}" --reset-timestamp 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
unset SUDO
|
||||||
|
|
||||||
# Take the HOMEBREW_PATH if we are running brew within brew, otherwise we would lose the original path.
|
# Take the HOMEBREW_PATH if we are running brew within brew, otherwise we would lose the original path.
|
||||||
if [[ -n "${HOMEBREW_BREW_FILE:-}" && -n "${HOMEBREW_PATH:-}" ]]
|
if [[ -n "${HOMEBREW_BREW_FILE:-}" && -n "${HOMEBREW_PATH:-}" ]]
|
||||||
then
|
then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user