brew.sh: avoid shelling out when possible.
This commit is contained in:
parent
0d1c7b9367
commit
41bf51e211
@ -3,16 +3,33 @@
|
|||||||
##### to be able to `source` in shell configurations run quickly.
|
##### to be able to `source` in shell configurations run quickly.
|
||||||
#####
|
#####
|
||||||
|
|
||||||
# Doesn't need a default case because we don't support other OSs
|
case "${MACHTYPE}" in
|
||||||
# shellcheck disable=SC2249
|
arm64-*)
|
||||||
|
HOMEBREW_PROCESSOR="arm64"
|
||||||
|
;;
|
||||||
|
x86_64-*)
|
||||||
|
HOMEBREW_PROCESSOR="x86_64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
HOMEBREW_PROCESSOR="$(uname -m)"
|
HOMEBREW_PROCESSOR="$(uname -m)"
|
||||||
HOMEBREW_PHYSICAL_PROCESSOR="${HOMEBREW_PROCESSOR}"
|
;;
|
||||||
HOMEBREW_SYSTEM="$(uname -s)"
|
|
||||||
case "${HOMEBREW_SYSTEM}" in
|
|
||||||
Darwin) HOMEBREW_MACOS="1" ;;
|
|
||||||
Linux) HOMEBREW_LINUX="1" ;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case "${OSTYPE}" in
|
||||||
|
darwin*)
|
||||||
|
HOMEBREW_SYSTEM="Darwin"
|
||||||
|
HOMEBREW_MACOS="1"
|
||||||
|
;;
|
||||||
|
linux*)
|
||||||
|
HOMEBREW_SYSTEM="Linux"
|
||||||
|
HOMEBREW_LINUX="1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
HOMEBREW_SYSTEM="$(uname -s)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
HOMEBREW_PHYSICAL_PROCESSOR="${HOMEBREW_PROCESSOR}"
|
||||||
|
|
||||||
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
|
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX="/opt/homebrew"
|
||||||
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
|
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY="${HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}"
|
||||||
HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"
|
HOMEBREW_LINUX_DEFAULT_PREFIX="/home/linuxbrew/.linuxbrew"
|
||||||
@ -79,11 +96,11 @@ HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}"
|
|||||||
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
|
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
|
||||||
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
|
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
|
||||||
|
|
||||||
# Don't need to handle a default case.
|
|
||||||
# HOMEBREW_LIBRARY set by bin/brew
|
|
||||||
# shellcheck disable=SC2249,SC2154
|
|
||||||
#
|
|
||||||
# commands that take a single or no arguments.
|
# commands that take a single or no arguments.
|
||||||
|
# HOMEBREW_LIBRARY set by bin/brew
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "$1" in
|
case "$1" in
|
||||||
formulae)
|
formulae)
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/formulae.sh"
|
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/formulae.sh"
|
||||||
@ -109,6 +126,8 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# functions that take multiple arguments or handle multiple commands.
|
# functions that take multiple arguments or handle multiple commands.
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "$@" in
|
case "$@" in
|
||||||
--cellar)
|
--cellar)
|
||||||
echo "${HOMEBREW_CELLAR}"
|
echo "${HOMEBREW_CELLAR}"
|
||||||
@ -232,7 +251,7 @@ numeric() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check-run-command-as-root() {
|
check-run-command-as-root() {
|
||||||
[[ "$(id -u)" == 0 || "$(id -ur)" == 0 ]] || return
|
[[ "${EUID}" == 0 || "${UID}" == 0 ]] || return
|
||||||
|
|
||||||
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
|
||||||
[[ -f /.dockerenv ]] && return
|
[[ -f /.dockerenv ]] && return
|
||||||
@ -429,11 +448,11 @@ fi
|
|||||||
|
|
||||||
# Many Pathname operations use getwd when they shouldn't, and then throw
|
# Many Pathname operations use getwd when they shouldn't, and then throw
|
||||||
# odd exceptions. Reduce our support burden by showing a user-friendly error.
|
# odd exceptions. Reduce our support burden by showing a user-friendly error.
|
||||||
if ! [[ -d "$(pwd)" ]]
|
if ! [[ -d "${PWD}" ]]
|
||||||
then
|
then
|
||||||
odie "The current working directory must exist to run brew."
|
odie "The current working directory must exist to run brew."
|
||||||
fi
|
fi
|
||||||
if ! [[ -r "$(pwd)" ]]
|
if ! [[ -r "${PWD}" ]]
|
||||||
then
|
then
|
||||||
odie "The current working directory must be readable to ${USER} to run brew."
|
odie "The current working directory must be readable to ${USER} to run brew."
|
||||||
fi
|
fi
|
||||||
@ -536,6 +555,8 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# commands that take a single or no arguments.
|
# commands that take a single or no arguments.
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--version | -v)
|
--version | -v)
|
||||||
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/--version.sh"
|
source "${HOMEBREW_LIBRARY}/Homebrew/cmd/--version.sh"
|
||||||
@ -807,6 +828,7 @@ EOS
|
|||||||
# a popup window asking the user to install the CLT
|
# a popup window asking the user to install the CLT
|
||||||
if [[ -n "${XCODE_SELECT_PATH}" ]]
|
if [[ -n "${XCODE_SELECT_PATH}" ]]
|
||||||
then
|
then
|
||||||
|
# TODO: this is fairly slow, figure out if there's a faster way.
|
||||||
XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
|
XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
|
||||||
XCRUN_STATUS="$?"
|
XCRUN_STATUS="$?"
|
||||||
|
|
||||||
@ -836,6 +858,8 @@ HOMEBREW_COMMAND="$1"
|
|||||||
shift
|
shift
|
||||||
# If you are going to change anything in below case statement,
|
# If you are going to change anything in below case statement,
|
||||||
# be sure to also update HOMEBREW_INTERNAL_COMMAND_ALIASES hash in commands.rb
|
# be sure to also update HOMEBREW_INTERNAL_COMMAND_ALIASES hash in commands.rb
|
||||||
|
# doesn't need a default case as other arguments handled elsewhere.
|
||||||
|
# shellcheck disable=SC2249
|
||||||
case "${HOMEBREW_COMMAND}" in
|
case "${HOMEBREW_COMMAND}" in
|
||||||
ls) HOMEBREW_COMMAND="list" ;;
|
ls) HOMEBREW_COMMAND="list" ;;
|
||||||
homepage) HOMEBREW_COMMAND="home" ;;
|
homepage) HOMEBREW_COMMAND="home" ;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user