2015-12-25 22:42:32 +00:00
|
|
|
#!/bin/bash
|
2016-02-25 11:22:02 +00:00
|
|
|
set +o posix
|
|
|
|
|
2018-05-26 05:30:35 -04:00
|
|
|
# Fail fast with concise message when cwd does not exist
|
|
|
|
if ! [[ -d "$PWD" ]]; then
|
|
|
|
echo "Error: The current working directory doesn't exist, cannot proceed." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-06-28 21:32:45 +02:00
|
|
|
quiet_cd() {
|
2018-10-04 09:31:37 +01:00
|
|
|
cd "$@" >/dev/null || return
|
2014-11-25 22:27:03 -05:00
|
|
|
}
|
|
|
|
|
2016-08-24 10:55:46 +01:00
|
|
|
symlink_target_directory() {
|
2018-10-04 09:31:37 +01:00
|
|
|
local target target_dirname
|
|
|
|
target="$(readlink "$1")"
|
|
|
|
target_dirname="$(dirname "$target")"
|
2016-08-24 10:55:46 +01:00
|
|
|
local directory="$2"
|
|
|
|
quiet_cd "$directory" && quiet_cd "$target_dirname" && pwd -P
|
|
|
|
}
|
|
|
|
|
2019-11-04 10:18:53 -06:00
|
|
|
# Unset functions that override Bash builtins
|
|
|
|
# Enable all Bash builtins
|
2019-11-04 09:56:03 -06:00
|
|
|
for cmd in $(compgen -A builtin)
|
|
|
|
do
|
2019-11-04 10:18:53 -06:00
|
|
|
unset -f $cmd
|
|
|
|
enable $cmd
|
2019-11-04 09:56:03 -06:00
|
|
|
done
|
|
|
|
unset cmd
|
|
|
|
|
2016-06-29 16:20:47 +02:00
|
|
|
BREW_FILE_DIRECTORY="$(quiet_cd "${0%/*}/" && pwd -P)"
|
|
|
|
HOMEBREW_BREW_FILE="${BREW_FILE_DIRECTORY%/}/${0##*/}"
|
2016-02-13 11:31:00 -08:00
|
|
|
HOMEBREW_PREFIX="${HOMEBREW_BREW_FILE%/*/*}"
|
2016-08-24 10:55:19 +01:00
|
|
|
|
|
|
|
# Default to / prefix if unset or the bin/brew file.
|
|
|
|
if [[ -z "$HOMEBREW_PREFIX" || "$HOMEBREW_PREFIX" = "$HOMEBREW_BREW_FILE" ]]
|
|
|
|
then
|
|
|
|
HOMEBREW_PREFIX="/"
|
|
|
|
fi
|
2016-06-29 16:20:47 +02:00
|
|
|
|
2016-02-13 11:31:00 -08:00
|
|
|
HOMEBREW_REPOSITORY="$HOMEBREW_PREFIX"
|
|
|
|
|
2016-08-24 10:55:46 +01:00
|
|
|
# Resolve the bin/brew symlink to find Homebrew's repository
|
2016-01-18 11:40:00 +08:00
|
|
|
if [[ -L "$HOMEBREW_BREW_FILE" ]]
|
2013-02-08 08:55:42 -08:00
|
|
|
then
|
2016-08-24 10:55:46 +01:00
|
|
|
BREW_FILE_DIRECTORY="$(symlink_target_directory "$HOMEBREW_BREW_FILE" "$BREW_FILE_DIRECTORY")"
|
2016-02-13 11:31:00 -08:00
|
|
|
HOMEBREW_REPOSITORY="${BREW_FILE_DIRECTORY%/*}"
|
2013-02-08 08:55:42 -08:00
|
|
|
fi
|
|
|
|
|
2016-08-24 10:56:23 +01:00
|
|
|
# Try to find a /usr/local HOMEBREW_PREFIX where possible (for bottles)
|
2019-02-05 06:44:04 +01:00
|
|
|
if [[ -L "/usr/local/bin/brew" && ! -L "$HOMEBREW_PREFIX/Cellar" ]]
|
2016-08-24 10:56:23 +01:00
|
|
|
then
|
|
|
|
USR_LOCAL_BREW_FILE_DIRECTORY="$(symlink_target_directory "/usr/local/bin/brew" "/usr/local/bin")"
|
|
|
|
USR_LOCAL_HOMEBREW_REPOSITORY="${USR_LOCAL_BREW_FILE_DIRECTORY%/*}"
|
|
|
|
if [[ "$HOMEBREW_REPOSITORY" = "$USR_LOCAL_HOMEBREW_REPOSITORY" ]]
|
|
|
|
then
|
|
|
|
HOMEBREW_PREFIX="/usr/local"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-02-13 11:18:33 -08:00
|
|
|
HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
|
2015-12-25 22:42:00 +00:00
|
|
|
|
2017-05-13 11:42:01 +01:00
|
|
|
# Whitelist and copy to HOMEBREW_* all variables previously mentioned in
|
|
|
|
# manpage or used elsewhere by Homebrew.
|
|
|
|
for VAR in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY BINTRAY_USER BINTRAY_KEY \
|
2019-02-10 23:30:54 -08:00
|
|
|
BROWSER DISPLAY EDITOR GIT NO_COLOR PATH VISUAL
|
2017-04-19 10:49:20 +01:00
|
|
|
do
|
2017-05-14 20:05:26 +01:00
|
|
|
# Skip if variable value is empty.
|
|
|
|
[[ -z "${!VAR}" ]] && continue
|
|
|
|
|
2017-04-19 10:49:20 +01:00
|
|
|
VAR_NEW="HOMEBREW_${VAR}"
|
2017-05-14 20:05:26 +01:00
|
|
|
# Skip if existing HOMEBREW_* variable is set.
|
2017-04-23 15:10:18 +01:00
|
|
|
[[ -n "${!VAR_NEW}" ]] && continue
|
2017-04-19 10:49:20 +01:00
|
|
|
export "$VAR_NEW"="${!VAR}"
|
|
|
|
done
|
|
|
|
|
2019-08-20 08:28:25 +01:00
|
|
|
# Set CI variable for GitHub Actions, Azure Pipelines, Jenkins
|
|
|
|
# (Set by default on Circle and Travis CI)
|
|
|
|
if [[ -n "$GITHUB_ACTIONS" || -n "$TF_BUILD" || -n "$JENKINS_HOME" ]]
|
2019-01-17 09:22:50 +00:00
|
|
|
then
|
|
|
|
export CI="1"
|
|
|
|
fi
|
|
|
|
|
2017-12-05 14:07:28 +00:00
|
|
|
# test-bot does environment filtering itself
|
|
|
|
if [[ -z "$HOMEBREW_NO_ENV_FILTERING" && "$1" != "test-bot" ]]
|
2017-01-09 12:31:28 +00:00
|
|
|
then
|
2017-02-23 15:21:46 +00:00
|
|
|
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
2017-02-19 02:12:46 +00:00
|
|
|
|
2017-02-26 20:42:24 +00:00
|
|
|
FILTERED_ENV=()
|
2017-12-05 14:07:28 +00:00
|
|
|
# Filter all but the specific variables.
|
2018-12-30 21:13:24 +00:00
|
|
|
for VAR in HOME SHELL PATH TERM TERMINFO COLUMNS LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS \
|
2018-02-01 18:11:29 +08:00
|
|
|
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY \
|
2018-03-07 15:09:08 +00:00
|
|
|
"${!HOMEBREW_@}" "${!TRAVIS_@}"
|
2017-02-23 15:21:46 +00:00
|
|
|
do
|
2017-11-27 14:43:24 +00:00
|
|
|
# Skip if variable value is empty.
|
|
|
|
[[ -z "${!VAR}" ]] && continue
|
|
|
|
|
2017-02-26 20:42:24 +00:00
|
|
|
FILTERED_ENV+=( "${VAR}=${!VAR}" )
|
2017-02-23 15:21:46 +00:00
|
|
|
done
|
|
|
|
|
2017-11-28 21:05:51 +01:00
|
|
|
exec /usr/bin/env -i "${FILTERED_ENV[@]}" /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@"
|
2017-01-09 12:31:28 +00:00
|
|
|
else
|
2018-10-04 09:31:37 +01:00
|
|
|
# Don't need shellcheck to follow this `source`.
|
|
|
|
# shellcheck disable=SC1090
|
2017-01-09 12:31:28 +00:00
|
|
|
source "$HOMEBREW_LIBRARY/Homebrew/brew.sh"
|
|
|
|
fi
|