bin/brew: require HOME to be set.

Rather than having increasingly involved workarounds that require
other variables to be set.

Closes #15822
This commit is contained in:
Mike McQuaid 2023-08-05 13:41:50 +01:00
parent 22afefce8e
commit 4184546067
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

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
else
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
fi
export_homebrew_env_file "${HOMEBREW_USER_CONFIG_HOME}/brew.env"