diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 558f818a55..d950b9f8c3 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -348,31 +348,38 @@ export USER="${USER:-$(id -un)}" # Higher depths mean this command was invoked by another Homebrew command. export HOMEBREW_COMMAND_DEPTH="$((HOMEBREW_COMMAND_DEPTH + 1))" -# This is set by the user environment. -# shellcheck disable=SC2154 -if [[ -n "${HOMEBREW_FORCE_BREWED_CURL}" && -x "${HOMEBREW_PREFIX}/opt/curl/bin/curl" ]] && - "${HOMEBREW_PREFIX}/opt/curl/bin/curl" --version &>/dev/null -then - HOMEBREW_CURL="${HOMEBREW_PREFIX}/opt/curl/bin/curl" -elif [[ -n "${HOMEBREW_DEVELOPER}" && -x "${HOMEBREW_CURL_PATH}" ]] -then - HOMEBREW_CURL="${HOMEBREW_CURL_PATH}" -else - HOMEBREW_CURL="curl" -fi +setup_curl() { + # This is set by the user environment. + # shellcheck disable=SC2154 + if [[ -n "${HOMEBREW_FORCE_BREWED_CURL}" && -x "${HOMEBREW_PREFIX}/opt/curl/bin/curl" ]] && + "${HOMEBREW_PREFIX}/opt/curl/bin/curl" --version &>/dev/null + then + HOMEBREW_CURL="${HOMEBREW_PREFIX}/opt/curl/bin/curl" + elif [[ -n "${HOMEBREW_DEVELOPER}" && -x "${HOMEBREW_CURL_PATH}" ]] + then + HOMEBREW_CURL="${HOMEBREW_CURL_PATH}" + else + HOMEBREW_CURL="curl" + fi +} -# This is set by the user environment. -# shellcheck disable=SC2154 -if [[ -n "${HOMEBREW_FORCE_BREWED_GIT}" && -x "${HOMEBREW_PREFIX}/opt/git/bin/git" ]] && - "${HOMEBREW_PREFIX}/opt/git/bin/git" --version &>/dev/null -then - HOMEBREW_GIT="${HOMEBREW_PREFIX}/opt/git/bin/git" -elif [[ -n "${HOMEBREW_DEVELOPER}" && -x "${HOMEBREW_GIT_PATH}" ]] -then - HOMEBREW_GIT="${HOMEBREW_GIT_PATH}" -else - HOMEBREW_GIT="git" -fi +setup_git() { + # This is set by the user environment. + # shellcheck disable=SC2154 + if [[ -n "${HOMEBREW_FORCE_BREWED_GIT}" && -x "${HOMEBREW_PREFIX}/opt/git/bin/git" ]] && + "${HOMEBREW_PREFIX}/opt/git/bin/git" --version &>/dev/null + then + HOMEBREW_GIT="${HOMEBREW_PREFIX}/opt/git/bin/git" + elif [[ -n "${HOMEBREW_DEVELOPER}" && -x "${HOMEBREW_GIT_PATH}" ]] + then + HOMEBREW_GIT="${HOMEBREW_GIT_PATH}" + else + HOMEBREW_GIT="git" + fi +} + +setup_curl +setup_git HOMEBREW_VERSION="$("${HOMEBREW_GIT}" -C "${HOMEBREW_REPOSITORY}" describe --tags --dirty --abbrev=7 2>/dev/null)" HOMEBREW_USER_AGENT_VERSION="${HOMEBREW_VERSION}" @@ -548,11 +555,18 @@ Your Git executable: $(unset git && type -p ${HOMEBREW_GIT})" fi fi -if [[ -n "${HOMEBREW_FORCE_BREWED_CA_CERTIFICATES}" && -f "${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" ]] -then - export SSL_CERT_FILE="${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" - export GIT_SSL_CAINFO="${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" -fi +setup_ca_certificates() { + if [[ -n "${HOMEBREW_FORCE_BREWED_CA_CERTIFICATES}" && -f "${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" ]] + then + export SSL_CERT_FILE="${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" + export GIT_SSL_CAINFO="${HOMEBREW_PREFIX}/etc/ca-certificates/cert.pem" + fi +} +setup_ca_certificates + +# Redetermine curl and git paths as we may have forced some options above. +setup_curl +setup_git # A bug in the auto-update process prior to 3.1.2 means $HOMEBREW_BOTTLE_DOMAIN # could be passed down with the default domain. diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 389871816c..a42bf47a97 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -390,6 +390,7 @@ EOS if [[ -d "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" || -n "${HOMEBREW_INSTALL_FROM_API}" ]] then brew install ca-certificates + setup_ca_certificates fi fi @@ -401,6 +402,8 @@ EOS then odie "'curl' must be installed and in your PATH!" fi + + setup_curl fi if ! git --version &>/dev/null || @@ -411,6 +414,8 @@ EOS then odie "'git' must be installed and in your PATH!" fi + + setup_git fi [[ -f "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/.git/shallow" ]] && HOMEBREW_CORE_SHALLOW=1