bin/brew: handle missing $HOME.

Try to build it using `$USER` or `$LOGNAME` and, if both are missing,
just give up.
This commit is contained in:
Mike McQuaid 2023-08-04 08:30:37 +01:00
parent 24b6b3494d
commit 59ea118991
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

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