Move all wrapper checks to utils/wrapper.sh
This commit is contained in:
parent
ead3af9feb
commit
83d8a4118b
@ -187,54 +187,10 @@ case "$@" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Include some helper functions.
|
# Check `HOMEBREW_FORCE_BREW_WRAPPER` for all non-trivial commands
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/helpers.sh"
|
# (i.e. not defined above this line e.g. formulae or --cellar).
|
||||||
|
source "${HOMEBREW_LIBRARY}/Homebrew/utils/wrapper.sh"
|
||||||
# Require HOMEBREW_BREW_WRAPPER to be set if HOMEBREW_FORCE_BREW_WRAPPER is set
|
check-brew-wrapper
|
||||||
# (and HOMEBREW_NO_FORCE_BREW_WRAPPER and HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER are not set)
|
|
||||||
# for all non-trivial commands (i.e. not defined above this line e.g. formulae or --cellar).
|
|
||||||
if [[ -z "${HOMEBREW_NO_FORCE_BREW_WRAPPER:-}" && -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" &&
|
|
||||||
-z "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" ]]
|
|
||||||
then
|
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/wrapper.sh"
|
|
||||||
if [[ -z "${HOMEBREW_BREW_WRAPPER:-}" ]]
|
|
||||||
then
|
|
||||||
odie-with-wrapper-message "but HOMEBREW_BREW_WRAPPER was unset."
|
|
||||||
elif [[ "${HOMEBREW_FORCE_BREW_WRAPPER}" != "${HOMEBREW_BREW_WRAPPER}" ]]
|
|
||||||
then
|
|
||||||
odie-with-wrapper-message "but HOMEBREW_BREW_WRAPPER was set to ${HOMEBREW_BREW_WRAPPER}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If HOMEBREW_FORCE_BREW_WRAPPER and HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER are set,
|
|
||||||
# verify that the path to our parent process is the same as the value of HOMEBREW_FORCE_BREW_WRAPPER for all
|
|
||||||
# non-trivial commands (i.e. not defined above this line e.g. formulae or --cellar).
|
|
||||||
if [[ -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" && -n "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" ]]
|
|
||||||
then
|
|
||||||
if [[ -n "${HOMEBREW_MACOS:-}" ]]
|
|
||||||
then
|
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/ruby.sh"
|
|
||||||
setup-ruby-path
|
|
||||||
HOMEBREW_BREW_CALLER="$("${HOMEBREW_RUBY_PATH}" "${HOMEBREW_LIBRARY}/Homebrew/utils/pid_path.rb" "${PPID}")"
|
|
||||||
else
|
|
||||||
HOMEBREW_BREW_CALLER="$(readlink -f "/proc/${PPID}/exe")"
|
|
||||||
fi
|
|
||||||
HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE="$?"
|
|
||||||
|
|
||||||
if ((HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE != 0))
|
|
||||||
then
|
|
||||||
# Error message already printed above when populating `HOMEBREW_BREW_CALLER`.
|
|
||||||
odie "failed to check the path to the parent process!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${HOMEBREW_BREW_CALLER:-}" != "${HOMEBREW_FORCE_BREW_WRAPPER}" ]]
|
|
||||||
then
|
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/wrapper.sh"
|
|
||||||
odie-with-wrapper-message "but \`brew\` was invoked by ${HOMEBREW_BREW_CALLER}."
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset HOMEBREW_BREW_CALLER HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE
|
|
||||||
fi
|
|
||||||
|
|
||||||
# commands that take a single or no arguments and need to write to HOMEBREW_PREFIX.
|
# commands that take a single or no arguments and need to write to HOMEBREW_PREFIX.
|
||||||
# HOMEBREW_LIBRARY set by bin/brew
|
# HOMEBREW_LIBRARY set by bin/brew
|
||||||
@ -254,6 +210,8 @@ esac
|
|||||||
##### Next, define all other helper functions.
|
##### Next, define all other helper functions.
|
||||||
#####
|
#####
|
||||||
|
|
||||||
|
source "${HOMEBREW_LIBRARY}/Homebrew/utils/helpers.sh"
|
||||||
|
|
||||||
check-run-command-as-root() {
|
check-run-command-as-root() {
|
||||||
[[ "${EUID}" == 0 || "${UID}" == 0 ]] || return
|
[[ "${EUID}" == 0 || "${UID}" == 0 ]] || return
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
# HOMEBREW_LIBRARY, HOMEBREW_BREW_FILE, HOMEBREW_ORIGINAL_BREW_FILE, HOMEBREW_PREFIX are set by bin/brew.
|
# HOMEBREW_LIBRARY, HOMEBREW_BREW_FILE, HOMEBREW_ORIGINAL_BREW_FILE, HOMEBREW_PREFIX are set by bin/brew.
|
||||||
# HOMEBREW_FORCE_BREW_WRAPPER is set by the user environment.
|
# HOMEBREW_FORCE_BREW_WRAPPER is set by the user environment.
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/utils/helpers.sh"
|
|
||||||
|
|
||||||
odie-with-wrapper-message() {
|
odie-with-wrapper-message() {
|
||||||
|
source "${HOMEBREW_LIBRARY}/Homebrew/utils/helpers.sh"
|
||||||
|
|
||||||
local CUSTOM_MESSAGE="${1}"
|
local CUSTOM_MESSAGE="${1}"
|
||||||
local HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW="${HOMEBREW_FORCE_BREW_WRAPPER%/brew}"
|
local HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW="${HOMEBREW_FORCE_BREW_WRAPPER%/brew}"
|
||||||
|
|
||||||
@ -23,3 +23,52 @@ or that ${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW} comes before ${HOMEBREW_PREF
|
|||||||
export PATH="${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW}:${HOMEBREW_PREFIX}/bin:\$PATH"
|
export PATH="${HOMEBREW_FORCE_BREW_WRAPPER_WITHOUT_BREW}:${HOMEBREW_PREFIX}/bin:\$PATH"
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check-brew-wrapper() {
|
||||||
|
[[ -z "${HOMEBREW_FORCE_BREW_WRAPPER:-}" ]] && return
|
||||||
|
[[ -z "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" && -n "${HOMEBREW_NO_FORCE_BREW_WRAPPER:-}" ]] && return
|
||||||
|
|
||||||
|
# Require HOMEBREW_BREW_WRAPPER to be set if HOMEBREW_FORCE_BREW_WRAPPER is set
|
||||||
|
# (and HOMEBREW_NO_FORCE_BREW_WRAPPER and HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER are not set).
|
||||||
|
if [[ -z "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" && -z "${HOMEBREW_NO_FORCE_BREW_WRAPPER:-}" ]]
|
||||||
|
then
|
||||||
|
if [[ -z "${HOMEBREW_BREW_WRAPPER:-}" ]]
|
||||||
|
then
|
||||||
|
odie-with-wrapper-message "but HOMEBREW_BREW_WRAPPER was unset."
|
||||||
|
elif [[ "${HOMEBREW_FORCE_BREW_WRAPPER}" != "${HOMEBREW_BREW_WRAPPER}" ]]
|
||||||
|
then
|
||||||
|
odie-with-wrapper-message "but HOMEBREW_BREW_WRAPPER was set to ${HOMEBREW_BREW_WRAPPER}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If HOMEBREW_FORCE_BREW_WRAPPER and HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER are set,
|
||||||
|
# verify that the path to our parent process is the same as the value of HOMEBREW_FORCE_BREW_WRAPPER,
|
||||||
|
if [[ -n "${HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER:-}" ]]
|
||||||
|
then
|
||||||
|
local HOMEBREW_BREW_CALLER HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE
|
||||||
|
|
||||||
|
if [[ -n "${HOMEBREW_MACOS:-}" ]]
|
||||||
|
then
|
||||||
|
source "${HOMEBREW_LIBRARY}/Homebrew/utils/ruby.sh"
|
||||||
|
setup-ruby-path
|
||||||
|
HOMEBREW_BREW_CALLER="$("${HOMEBREW_RUBY_PATH}" "${HOMEBREW_LIBRARY}/Homebrew/utils/pid_path.rb" "${PPID}")"
|
||||||
|
else
|
||||||
|
HOMEBREW_BREW_CALLER="$(readlink -f "/proc/${PPID}/exe")"
|
||||||
|
fi
|
||||||
|
HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE="$?"
|
||||||
|
|
||||||
|
if ((HOMEBREW_BREW_CALLER_CHECK_EXIT_CODE != 0))
|
||||||
|
then
|
||||||
|
# Error message already printed above when populating `HOMEBREW_BREW_CALLER`.
|
||||||
|
odie "failed to check the path to the parent process!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${HOMEBREW_BREW_CALLER:-}" != "${HOMEBREW_FORCE_BREW_WRAPPER}" ]]
|
||||||
|
then
|
||||||
|
source "${HOMEBREW_LIBRARY}/Homebrew/utils/wrapper.sh"
|
||||||
|
odie-with-wrapper-message "but \`brew\` was invoked by ${HOMEBREW_BREW_CALLER}."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user