diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 8b729da6ad..a1b4392fc5 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -44,6 +44,26 @@ else HOMEBREW_DEFAULT_TEMP="/tmp" fi +realpath() { + (cd "$1" &>/dev/null && pwd -P) +} + +# Support systems where HOMEBREW_PREFIX is the default, +# but a parent directory is a symlink. +# Example: Fedora Silverblue symlinks /home -> var/home +if [[ "${HOMEBREW_PREFIX}" != "${HOMEBREW_DEFAULT_PREFIX}" && "$(realpath "${HOMEBREW_DEFAULT_PREFIX}")" == "${HOMEBREW_PREFIX}" ]] +then + HOMEBREW_PREFIX="${HOMEBREW_DEFAULT_PREFIX}" +fi + +# Support systems where HOMEBREW_REPOSITORY is the default, +# but a parent directory is a symlink. +# Example: Fedora Silverblue symlinks /home -> var/home +if [[ "${HOMEBREW_REPOSITORY}" != "${HOMEBREW_DEFAULT_REPOSITORY}" && "$(realpath "${HOMEBREW_DEFAULT_REPOSITORY}")" == "${HOMEBREW_REPOSITORY}" ]] +then + HOMEBREW_REPOSITORY="${HOMEBREW_DEFAULT_REPOSITORY}" +fi + # Where we store built products; a Cellar in HOMEBREW_PREFIX (often /usr/local # for bottles) unless there's already a Cellar in HOMEBREW_REPOSITORY. # These variables are set by bin/brew diff --git a/bin/brew b/bin/brew index 3732948067..afc02e9eb8 100755 --- a/bin/brew +++ b/bin/brew @@ -40,7 +40,7 @@ do done unset cmd -BREW_FILE_DIRECTORY="$(quiet_cd "${0%/*}/" && pwd)" +BREW_FILE_DIRECTORY="$(quiet_cd "${0%/*}/" && pwd -P)" HOMEBREW_BREW_FILE="${BREW_FILE_DIRECTORY%/}/${0##*/}" HOMEBREW_PREFIX="${HOMEBREW_BREW_FILE%/*/*}"