brew/bin/brew

309 lines
7.9 KiB
Plaintext
Raw Normal View History

#!/bin/bash -pu
2022-11-28 19:31:28 +01:00
set -u
2021-09-16 21:18:48 +08:00
# Fail fast with concise message when not using bash
# Single brackets is needed here for POSIX compatibility
2021-11-07 21:21:42 +08:00
# shellcheck disable=SC2292
2021-09-16 21:18:48 +08:00
if [ -z "${BASH_VERSION:-}" ]
then
2021-09-16 21:18:48 +08:00
echo "Error: Bash is required to run brew." >&2
exit 1
fi
2021-09-16 21:18:48 +08:00
set +o posix # as we are using bash now
# Fail fast with concise messages when PWD has issues
if [[ -z "${PWD-}" ]]
then
echo "Error: \$PWD must be set to run brew." >&2
exit 1
fi
2021-09-16 21:18:48 +08:00
if ! [[ -d "${PWD}" ]]
then
echo "Error: The current working directory must exist to run brew." >&2
exit 1
fi
if ! [[ -r "${PWD}" ]]
then
echo "Error: The current working directory must be readable to ${USER} to run brew." >&2
2021-09-15 17:10:05 +08:00
exit 1
fi
# Fail fast with concise message when HOME is unset
if [[ -z "${HOME:-}" ]]
then
echo "Error: \$HOME must be set to run brew." >&2
exit 1
fi
quiet_cd() {
CDPATH='' cd -- "$@" &>/dev/null || return
}
symlink_target_directory() {
2018-10-04 09:31:37 +01:00
local target target_dirname
target="$(readlink "$1")"
2021-04-16 00:02:13 +09:00
target_dirname="$(dirname "${target}")"
local directory="$2"
2021-04-16 00:02:13 +09:00
quiet_cd "${directory}" && quiet_cd "${target_dirname}" && pwd -P
}
# Enable and use default Bash builtins rather than user-defined functions
builtin enable compgen unset
for cmd in $(builtin compgen -A builtin)
do
2021-04-16 00:02:13 +09:00
builtin unset -f "${cmd}"
builtin enable "${cmd}"
done
unset cmd
# 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:-}" ]]
then
PATH="${HOMEBREW_PATH}"
fi
BREW_FILE_DIRECTORY="$(quiet_cd "${0%/*}/" && pwd -P)"
HOMEBREW_BREW_FILE="${BREW_FILE_DIRECTORY%/}/${0##*/}"
HOMEBREW_PREFIX="${HOMEBREW_BREW_FILE%/*/*}"
# Default to / prefix if unset or the bin/brew file.
2021-04-16 00:02:13 +09:00
if [[ -z "${HOMEBREW_PREFIX}" || "${HOMEBREW_PREFIX}" = "${HOMEBREW_BREW_FILE}" ]]
then
HOMEBREW_PREFIX="/"
fi
2021-04-16 00:02:13 +09:00
HOMEBREW_REPOSITORY="${HOMEBREW_PREFIX}"
# Resolve the bin/brew symlink to find Homebrew's repository
2021-04-16 00:02:13 +09:00
if [[ -L "${HOMEBREW_BREW_FILE}" ]]
then
2021-04-16 00:02:13 +09:00
BREW_FILE_DIRECTORY="$(symlink_target_directory "${HOMEBREW_BREW_FILE}" "${BREW_FILE_DIRECTORY}")"
HOMEBREW_REPOSITORY="${BREW_FILE_DIRECTORY%/*}"
fi
2024-05-14 00:20:30 +01:00
# Try to find a /usr/local HOMEBREW_PREFIX where possible (for macOS x86_64 bottles)
2021-04-16 00:02:13 +09:00
if [[ -L "/usr/local/bin/brew" && ! -L "${HOMEBREW_PREFIX}/Cellar" ]]
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%/*}"
2021-04-16 00:02:13 +09:00
if [[ "${HOMEBREW_REPOSITORY}" = "${USR_LOCAL_HOMEBREW_REPOSITORY}" ]]
then
HOMEBREW_PREFIX="/usr/local"
fi
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
unset USR_LOCAL_BREW_FILE_DIRECTORY USR_LOCAL_HOMEBREW_REPOSITORY
fi
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
unset BREW_FILE_DIRECTORY
# If the location of HOMEBREW_LIBRARY changes
# keg_relocate.rb, formula_cellar_checks.rb, and test/global_spec.rb need to change.
2021-04-16 00:02:13 +09:00
HOMEBREW_LIBRARY="${HOMEBREW_REPOSITORY}/Library"
# These variables are exported in this file and are not allowed to be overridden by the user.
BIN_BREW_EXPORTED_VARS=(
HOMEBREW_BREW_FILE
HOMEBREW_PREFIX
HOMEBREW_REPOSITORY
HOMEBREW_LIBRARY
HOMEBREW_USER_CONFIG_HOME
HOMEBREW_ORIGINAL_BREW_FILE
)
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
# Load Homebrew's variable configuration files from disk.
export_homebrew_env_file() {
local env_file
env_file="${1}"
[[ -r "${env_file}" ]] || return 0
while read -r line
do
# only load variables defined in env_config.rb
[[ "${line}" =~ ^(HOMEBREW_|SUDO_ASKPASS=|(all|no|ftp|https?)_proxy=) ]] || continue
# forbid overriding variables that are set in this file
local invalid_variable
for VAR in "${BIN_BREW_EXPORTED_VARS[@]}"
do
[[ "${line}" = "${VAR}"* ]] && invalid_variable="${VAR}"
done
[[ -n "${invalid_variable:-}" ]] && continue
export "${line?}"
done <"${env_file}"
}
# We only want to be able to set this in `brew.env` files.
unset HOMEBREW_DISABLE_NO_FORCE_BREW_WRAPPER
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
# First, load the system-wide configuration.
export_homebrew_env_file "/etc/homebrew/brew.env"
unset SYSTEM_ENV_TAKES_PRIORITY
if [[ -n "${HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY-}" ]]
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
then
SYSTEM_ENV_TAKES_PRIORITY="1"
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
fi
# Next, load the prefix configuration
export_homebrew_env_file "${HOMEBREW_PREFIX}/etc/homebrew/brew.env"
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
# Finally, load the user configuration
if [[ -n "${XDG_CONFIG_HOME-}" ]]
then
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew"
else
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew"
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
fi
export_homebrew_env_file "${HOMEBREW_USER_CONFIG_HOME}/brew.env"
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
# If the system configuration takes priority, load it again to override any previous settings.
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
if [[ -n "${SYSTEM_ENV_TAKES_PRIORITY-}" ]]
then
export_homebrew_env_file "/etc/homebrew/brew.env"
Allow configuring Homebrew with `.env` files For a long time people have requested some sort of configuration files for Homebrew. Now: here's the first version of that. Similarly to how you can configure Git for a system, a repository or a user: you can configure Homebrew for a system, a prefix or a user. The system-wide configuration file is `/etc/homebrew/brew.env`, the prefix-specific configuration file is `$HOMEBREW_PREFIX/etc/homebrew/brew.env` and the user-specific configuration file is `~/.homebrew/brew.env`. As we need to read these files from Bash in `bin/brew` (so they can) influence functionality ASAP: they are in a simple format that Bash can read. It may be that we have more complex array or hash data in future that's configured through JSON or YAML (most likely JSON as we use it more) and stored in a `brew.json`/`brew.yaml` file in the same directory. As this is relying on `eval` in Bash which is fairly dangerous: we filter the lines with a regex to ensure we're only permitting setting `HOMEBREW_*` variables and nothing more. To give a bit of power to system administrators, the `HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in `/etc/homebrew/brew.env` to ensure that the system-wide configuration file is loaded last and overrides any prefix or user settings. Now that we have an actual location for configuration files, let's also change the `brew livecheck` watchlist configuration file to be in this directory and deprecate the existing location. As this is a developer command and the mitigation is to just move the file: we don't need to follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
fi
# Use HOMEBREW_FORCE_BREW_WRAPPER if set.
export HOMEBREW_ORIGINAL_BREW_FILE="${HOMEBREW_BREW_FILE}"
if [[ -n "${HOMEBREW_FORCE_BREW_WRAPPER:-}" ]]
then
HOMEBREW_BREW_FILE="${HOMEBREW_FORCE_BREW_WRAPPER}"
fi
2020-09-09 11:49:26 -07:00
# Copy and export all HOMEBREW_* variables previously mentioned in
# manpage or used elsewhere by Homebrew.
# These variables are allowed to be set by the user as, e.g., `HOMEBREW_BROWSER`.
MANPAGE_VARS=(
BAT_CONFIG_PATH
BAT_THEME
BROWSER
BUNDLE_USER_CACHE
DISPLAY
EDITOR
NO_COLOR
)
for VAR in "${MANPAGE_VARS[@]}"
do
# Skip if variable value is empty or set to 0.
[[ -z "${!VAR:-}" || "${!VAR:-}" = "0" ]] && continue
VAR_NEW="HOMEBREW_${VAR}"
# Skip if existing HOMEBREW_* variable is set.
2022-11-28 19:31:28 +01:00
[[ -n "${!VAR_NEW:-}" ]] && continue
2021-04-16 00:02:13 +09:00
export "${VAR_NEW}"="${!VAR}"
done
# We don't want to take the user's value for, e.g., `HOMEBREW_PATH` here!
USED_BY_HOMEBREW_VARS=(
CODESPACES
COLORTERM
DBUS_SESSION_BUS_ADDRESS
NODENV_ROOT
PATH
PYENV_ROOT
RBENV_ROOT
SSH_TTY
SUDO_USER
2024-09-05 15:49:11 +08:00
TMPDIR
TMUX
XDG_CACHE_HOME
XDG_DATA_DIRS
XDG_RUNTIME_DIR
2024-06-12 16:24:45 +02:00
ZDOTDIR
)
for VAR in "${USED_BY_HOMEBREW_VARS[@]}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
# We unconditionally override `HOMEBREW_*` here.
VAR_NEW="HOMEBREW_${VAR}"
export "${VAR_NEW}"="${!VAR}"
done
unset VAR VAR_NEW MANPAGE_VARS USED_BY_HOMEBREW_VARS
for VAR in "${BIN_BREW_EXPORTED_VARS[@]}"
do
export "${VAR?}"
done
2021-03-02 16:59:57 +00:00
2021-04-15 17:24:17 +01:00
# set from user environment
2021-04-16 00:02:13 +09:00
# shellcheck disable=SC2154
2020-04-05 15:44:50 +01:00
# Use VISUAL if HOMEBREW_EDITOR and EDITOR are unset.
2022-11-28 19:36:03 +01:00
if [[ -z "${HOMEBREW_EDITOR:-}" && -n "${VISUAL:-}" ]]
2020-04-05 15:44:50 +01:00
then
2021-04-16 00:02:13 +09:00
export HOMEBREW_EDITOR="${VISUAL}"
2020-04-05 15:44:50 +01:00
fi
2021-04-15 17:24:17 +01:00
# set from user environment
2021-04-16 00:02:13 +09:00
# shellcheck disable=SC2154
# Set CI variable for Azure Pipelines and Jenkins
2021-04-12 22:47:33 +09:00
# (Set by default on GitHub Actions, Circle and Travis CI)
2022-11-28 19:31:28 +01:00
if [[ -z "${CI:-}" ]] && [[ -n "${TF_BUILD:-}" || -n "${JENKINS_HOME:-}" ]]
then
export CI="1"
fi
if [[ -n "${GITHUB_ACTIONS:-}" && -n "${ImageOS:-}" && -n "${ImageVersion:-}" ]]
then
export HOMEBREW_GITHUB_HOSTED_RUNNER=1
fi
# don't filter the environment for `brew bundle (exec|env|sh)`
if [[ "${1:-}" == "bundle" ]]
then
if [[ "${2:-}" == "exec" || "${2:-}" == "env" || "${2:-}" == "sh" ]]
then
exec /bin/bash -p "${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"
exit $?
fi
fi
# filter the user environment
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
FILTERED_ENV=()
ENV_VAR_NAMES=(
HOME SHELL PATH TERM TERMINFO TERMINFO_DIRS COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY
)
# Filter all but the specific variables.
for VAR in "${ENV_VAR_NAMES[@]}" "${!HOMEBREW_@}"
do
# Skip if variable value is empty.
2022-11-28 19:31:28 +01:00
[[ -z "${!VAR:-}" ]] && continue
FILTERED_ENV+=("${VAR}=${!VAR}")
done
if [[ -n "${CI:-}" ]]
then
for VAR in "${!GITHUB_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
# Skip variables that look like tokens.
[[ "${VAR}" = *TOKEN* ]] && continue
FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi
2024-08-15 11:40:36 -04:00
if [[ -n "${HOMEBREW_RDBG:-}" ]]
then
for VAR in "${!RUBY_DEBUG_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue
FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi
unset VAR ENV_VAR_NAMES
2024-03-21 03:25:49 +00:00
exec /usr/bin/env -i "${FILTERED_ENV[@]}" /bin/bash -p "${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"