Merge pull request #15827 from MikeMcQuaid/bin_brew_home_set

bin/brew: require HOME to be set.
This commit is contained in:
Mike McQuaid 2023-08-05 14:32:49 +01:00 committed by GitHub
commit b0da6e58c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,13 @@ then
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() {
cd "$@" &>/dev/null || return
}
@ -107,28 +114,8 @@ export_homebrew_env_file "${HOMEBREW_PREFIX}/etc/homebrew/brew.env"
if [[ -n "${XDG_CONFIG_HOME-}" ]]
then
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew"
elif [[ -n "${HOME-}" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew"
elif [[ -n "${USER-}" ]]
then
if [[ "${OSTYPE}" == "darwin"* ]]
then
HOMEBREW_USER_CONFIG_HOME="/Users/${USER}/.homebrew"
else
HOMEBREW_USER_CONFIG_HOME="/home/${USER}/.homebrew"
fi
elif [[ -n "${LOGNAME-}" ]]
then
if [[ "${OSTYPE}" == "darwin"* ]]
then
HOMEBREW_USER_CONFIG_HOME="/Users/${LOGNAME}/.homebrew"
else
HOMEBREW_USER_CONFIG_HOME="/home/${LOGNAME}/.homebrew"
fi
else
echo "Error: \$HOME or \$USER or \$LOGNAME must be set to run brew." >&2
exit 1
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew"
fi
export_homebrew_env_file "${HOMEBREW_USER_CONFIG_HOME}/brew.env"