Merge pull request #15818 from MikeMcQuaid/brew_env_home

bin/brew: handle missing `$HOME`.
This commit is contained in:
Mike McQuaid 2023-08-04 09:21:36 +01:00 committed by GitHub
commit ef4731d67a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -105,9 +105,30 @@ fi
if [[ -n "${XDG_CONFIG_HOME-}" ]] if [[ -n "${XDG_CONFIG_HOME-}" ]]
then then
HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew" HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew"
else elif [[ -n "${HOME-}" ]]
then
HOMEBREW_USER_CONFIG_HOME="${HOME}/.homebrew" 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 fi
if [[ -f "${HOMEBREW_USER_CONFIG_HOME}/brew.env" ]] if [[ -f "${HOMEBREW_USER_CONFIG_HOME}/brew.env" ]]
then then
# only load HOMEBREW_*=* lines # only load HOMEBREW_*=* lines