Files
brew/package/scripts/preinstall
T
Mike McQuaid af3538d54d Add as-console-user command
- Support MDM/Munki/Jamf runs where the parent process is root but
  Homebrew must execute as the logged-in macOS console user.
- Keep the nested operation constrained to `HOMEBREW_BREW_FILE` so this
  helper cannot become a general-purpose root command launcher.
- Share `macos_user.sh` with installer scripts so no-user and package
  plist fallback behaviour cannot drift between install paths.
- Stage `macos_user.sh` for `pkgbuild` because `preinstall` needs the
  resolver before the Homebrew payload has been installed.
2026-05-20 19:35:06 +01:00

23 lines
626 B
Bash
Executable File

#!/bin/bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)"
if [[ -f "${script_dir}/macos_user.sh" ]]
then
# `pkgbuild` stages this helper beside the package scripts.
# shellcheck disable=SC1091
source "${script_dir}/macos_user.sh"
else
# This fallback keeps direct local execution from the repository working.
# shellcheck disable=SC1091
source "${script_dir}/../../Library/Homebrew/utils/macos_user.sh"
fi
if homebrew-package-user &>/dev/null
then
exit 0
fi
echo "No valid user for Homebrew installation. Log in before install or specify an install user."
exit 1