-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bin/brew: handle missing $HOME
.
#15818
Conversation
Try to build it using `$USER` or `$LOGNAME` and, if both are missing, just give up.
I have a comment. Although this is not the common case, the echo "$USER"
carlos.alvaro
pwd
/Users/Carlos However, this way for getting the eval echo -n "~$USER"
/Users/Carlos |
@cdalvaro Not interested in making it more involved than it currently is or using |
@cdalvaro However, literally the only thing it's being used for in this file is for these user-specific environment files. |
I'm sorry. After this change, I've checked if the
Finally, I've found the issue. def _homebrew_bin():
"""
Returns the full path to the homebrew binary in the PATH
"""
ret = __salt__["cmd.run"]("brew --prefix", output_loglevel="trace")
ret += "/bin/brew"
return ret Apparently, the environment in this situation is very limited: LC_PAPER=C
LC_ADDRESS=C
LC_MONETARY=C
LC_NUMERIC=C
LC_TELEPHONE=C
PATH=/opt/homebrew/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LC_MESSAGES=C
LC_IDENTIFICATION=C
LC_COLLATE=C
PWD=/private/var/root
LC_MEASUREMENT=C
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
SHLVL=1
LANGUAGE=C
HOMEBREW_PREFIX=/opt/homebrew
LC_CTYPE=C
LC_TIME=C
LC_NAME=C
_=/usr/bin/env (I have added So as you can see, no I'm preparing a fix for def _homebrew_bin():
"""
Returns the full path to the homebrew binary in the PATH
"""
bin_brew = "/bin/brew"
try:
ret = __salt__["cmd.run"]("brew --prefix", output_loglevel="trace", raise_err=True)
except CommandExecutionError:
log.warn("Unable to find homebrew prefix by running 'brew --prefix'. Trying with HOMEBREW_PREFIX env variable.")
ret = os.getenv("HOMEBREW_PREFIX")
if ret is not None:
log.debug("Found homebrew prefix: {}".format(ret))
return ret + bin_brew
ret = "/opt/homebrew" if __grains__["cpuarch"] == "arm64" else "/usr/local"
ret += bin_brew
if not os.path.exists(ret):
log.error("Command {} does not exist. Unable to find brew command".format(ret))
raise CommandExecutionError("Failed to get guess homebrew prefix. Please, set HOMEBREW_PREFIX env variable", info={"result": {}})
return ret Please, let me know if you consider there is a better approach for this situation. |
Ignoring this user config code completely for a moment, how has a missing Lines 35 to 45 in 3f49592
? If you can skip the user config stuff and see how the above code works for you, that would be useful information. |
Salt only runs Once it has find the This is how Salt runs def _call_brew(*cmd, failhard=True):
"""
Calls the brew command with the user account of brew
"""
user = __salt__["file.get_user"](_homebrew_bin())
runas = user if user != __opts__["user"] else None
_cmd = []
if runas:
_cmd = ["sudo -i -n -H -u {} -- ".format(runas)]
_cmd = _cmd + [salt.utils.path.which("brew")] + list(cmd)
_cmd = " ".join(_cmd)
runas = None
result = __salt__["cmd.run_all"](
cmd=_cmd,
runas=runas,
output_loglevel="trace",
python_shell=False,
)
if failhard and result["retcode"] != 0:
raise CommandExecutionError("Brew command failed", info={"result": result})
return result It tries to figure out brew's owner and then runs the command as this user ( |
It's likely it just doesn't and puts these files into the wrong place. |
Try to build it using
$USER
or$LOGNAME
and, if both are missing, just give up.See #15787 (comment)