brew/bin/brew

68 lines
1.8 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set +o posix
quiet_cd() {
cd "$@" >/dev/null
}
symlink_target_directory() {
local target="$(readlink "$1")"
local target_dirname="$(dirname "$target")"
local directory="$2"
quiet_cd "$directory" && quiet_cd "$target_dirname" && pwd -P
}
BREW_FILE_DIRECTORY="$(quiet_cd "${0%/*}/" && pwd -P)"
HOMEBREW_BREW_FILE="${BREW_FILE_DIRECTORY%/}/${0##*/}"
HOMEBREW_PREFIX="${HOMEBREW_BREW_FILE%/*/*}"
# Default to / prefix if unset or the bin/brew file.
if [[ -z "$HOMEBREW_PREFIX" || "$HOMEBREW_PREFIX" = "$HOMEBREW_BREW_FILE" ]]
then
HOMEBREW_PREFIX="/"
fi
HOMEBREW_REPOSITORY="$HOMEBREW_PREFIX"
# Resolve the bin/brew symlink to find Homebrew's repository
if [[ -L "$HOMEBREW_BREW_FILE" ]]
then
BREW_FILE_DIRECTORY="$(symlink_target_directory "$HOMEBREW_BREW_FILE" "$BREW_FILE_DIRECTORY")"
HOMEBREW_REPOSITORY="${BREW_FILE_DIRECTORY%/*}"
fi
# Try to find a /usr/local HOMEBREW_PREFIX where possible (for bottles)
if [[ -L "/usr/local/bin/brew" ]]
then
USR_LOCAL_BREW_FILE_DIRECTORY="$(symlink_target_directory "/usr/local/bin/brew" "/usr/local/bin")"
USR_LOCAL_HOMEBREW_REPOSITORY="${USR_LOCAL_BREW_FILE_DIRECTORY%/*}"
if [[ "$HOMEBREW_REPOSITORY" = "$USR_LOCAL_HOMEBREW_REPOSITORY" ]]
then
HOMEBREW_PREFIX="/usr/local"
fi
fi
HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
2017-01-09 12:31:28 +00:00
if [[ -n "$HOMEBREW_ENV_FILTERING" ]]
then
homebrew_vars=$("$HOMEBREW_LIBRARY/Homebrew/utils/homebrew_vars.rb")
cmd_str="/usr/bin/env -i \
HOME=$HOME \
PATH=/usr/bin:/bin:/usr/sbin:/sbin \
TERM=$TERM \
HOMEBREW_BREW_FILE=$HOMEBREW_BREW_FILE \
HOMEBREW_PREFIX=$HOMEBREW_PREFIX \
HOMEBREW_REPOSITORY=$HOMEBREW_REPOSITORY \
HOMEBREW_LIBRARY=$HOMEBREW_LIBRARY \
$homebrew_vars \
/bin/bash $HOMEBREW_LIBRARY/Homebrew/brew.sh $@"
command $cmd_str
2017-01-09 12:31:28 +00:00
else
source "$HOMEBREW_LIBRARY/Homebrew/brew.sh"
fi