From 59ea1189915f5c1207832448d17ed7bc5e282243 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 4 Aug 2023 08:30:37 +0100 Subject: [PATCH] bin/brew: handle missing `$HOME`. Try to build it using `$USER` or `$LOGNAME` and, if both are missing, just give up. --- bin/brew | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bin/brew b/bin/brew index 60d67b29d88e9..ea08128845ff2 100755 --- a/bin/brew +++ b/bin/brew @@ -105,9 +105,30 @@ fi if [[ -n "${XDG_CONFIG_HOME-}" ]] then HOMEBREW_USER_CONFIG_HOME="${XDG_CONFIG_HOME}/homebrew" -else +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 fi + if [[ -f "${HOMEBREW_USER_CONFIG_HOME}/brew.env" ]] then # only load HOMEBREW_*=* lines