From 22bc5a94e71ba76d0ffb5ce3d959912e42d8dce5 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 18 Nov 2020 16:38:08 -0600 Subject: [PATCH 1/8] Properly handle outdated cURL `HOMEBREW_CURL_PATH` has an effect only when `HOMEBREW_DEVELOPER` is set. However, the part of `brew.sh` that prints a message about outdated cURL disregards the value of `HOMEBREW_DEVELOPER`, which leads to a misleadnig message telling the user that `HOMEBREW_CURL_PATH` is outdated even though another cURL was used/tested. This PR fixes it and instructs Homebrew to: 1. Display a warning message when system cURL is outdated and either `HOMEBREW_CURL_PATH` **or `HOMEBREW_DEVELOPER`** are not set. New `HOMEBREW_CURL_WARNING` variable is set to display the above warning only once (useful when `brew` calls itself internally). 2. Display `Installing Homebrew cURL` before auto-installing cURL in `update.sh` (due to `HOMEBREW_FORCE_BREWED_CURL`) and stop/exit if this step fails. 3. Display `Installing Homebrew Git` before auto-installing Git in `update.sh` (due to `HOMEBREW_FORCE_BREWED_GIT`) and stop/exit if this step fails. --- Library/Homebrew/brew.sh | 23 +++++++++++++++-------- Library/Homebrew/cmd/update.sh | 9 +++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index d0b15e080f..16df41f478 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -350,17 +350,23 @@ else curl_name_and_version="${curl_version_output%% (*}" if [[ $(numeric "${curl_name_and_version##* }") -lt $(numeric "$HOMEBREW_MINIMUM_CURL_VERSION") ]] then - if [[ -z $HOMEBREW_CURL_PATH ]]; then + message="Your cURL version is too old. +Minimum required version: ${HOMEBREW_MINIMUM_CURL_VERSION} +Your cURL version: ${curl_name_and_version##* } +Your cURL executable: $(type -p $HOMEBREW_CURL) +To point Homebrew to cURL ${HOMEBREW_MINIMUM_CURL_VERSION} or newer, +enable developer mode by setting HOMEBREW_DEVELOPER to 1, +then set HOMEBREW_CURL_PATH to the location of cURL executable." + + if [[ -z $HOMEBREW_CURL_PATH || -z $HOMEBREW_DEVELOPER ]]; then HOMEBREW_SYSTEM_CURL_TOO_OLD=1 HOMEBREW_FORCE_BREWED_CURL=1 + if [[ -z $HOMEBREW_CURL_WARNING ]]; then + onoe "$message" + HOMEBREW_CURL_WARNING=1 + fi else - odie </dev/null || @@ -380,7 +381,11 @@ EOS ! -x "$HOMEBREW_PREFIX/opt/git/bin/git" ]] then # we cannot install brewed git if homebrew/core is unavailable. - [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && brew install git + if [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] + then + ohai "Installing Homebrew Git" + brew install git || odie "Failed to install Git" + fi unset GIT_EXECUTABLE if ! git --version &>/dev/null then From 7c4b1841bca92c989cd5b0d6bea5c832494ba404 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 20 Nov 2020 18:02:22 -0600 Subject: [PATCH 2/8] Use set -e/set +e instead of odie --- Library/Homebrew/cmd/update.sh | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index d1ebdec412..b39e3840cf 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -368,30 +368,27 @@ user account: EOS fi - # we may want to use a Homebrew curl + set -e if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && ! -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] then ohai "Installing Homebrew cURL" - brew install curl || odie "Failed to install cURL" + brew install curl fi if ! git --version &>/dev/null || [[ -n "$HOMEBREW_FORCE_BREWED_GIT" && ! -x "$HOMEBREW_PREFIX/opt/git/bin/git" ]] then - # we cannot install brewed git if homebrew/core is unavailable. - if [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] - then - ohai "Installing Homebrew Git" - brew install git || odie "Failed to install Git" - fi + ohai "Installing Homebrew Git" + brew install git unset GIT_EXECUTABLE if ! git --version &>/dev/null then odie "Git must be installed and in your PATH!" fi fi + set +e export GIT_TERMINAL_PROMPT="0" export GIT_SSH_COMMAND="ssh -oBatchMode=yes" From 2b6c1e220d967b3377611dd8dad475ca8e9a8043 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 24 Nov 2020 20:51:49 -0600 Subject: [PATCH 3/8] brew.sh: don't mention HOMEBREW_DEVELOPER --- Library/Homebrew/brew.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 16df41f478..0b0cf52409 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -350,13 +350,10 @@ else curl_name_and_version="${curl_version_output%% (*}" if [[ $(numeric "${curl_name_and_version##* }") -lt $(numeric "$HOMEBREW_MINIMUM_CURL_VERSION") ]] then - message="Your cURL version is too old. -Minimum required version: ${HOMEBREW_MINIMUM_CURL_VERSION} + message="Please update your system cURL. +Minimum required version: ${HOMEBREW_MINIMUM_CURL_VERSION}. Your cURL version: ${curl_name_and_version##* } -Your cURL executable: $(type -p $HOMEBREW_CURL) -To point Homebrew to cURL ${HOMEBREW_MINIMUM_CURL_VERSION} or newer, -enable developer mode by setting HOMEBREW_DEVELOPER to 1, -then set HOMEBREW_CURL_PATH to the location of cURL executable." +Your cURL executable: $(type -p $HOMEBREW_CURL)" if [[ -z $HOMEBREW_CURL_PATH || -z $HOMEBREW_DEVELOPER ]]; then HOMEBREW_SYSTEM_CURL_TOO_OLD=1 From 82ad6a56e9bb6d0966029f9da60383d45ec474f9 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 24 Nov 2020 20:59:46 -0600 Subject: [PATCH 4/8] Address review comments. --- Library/Homebrew/cmd/update.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index b39e3840cf..f1f64adc5f 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -368,12 +368,14 @@ user account: EOS fi - set -e if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && ! -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] then ohai "Installing Homebrew cURL" - brew install curl + if [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && ! brew install curl + then + odie "Curl must be installed and in your PATH!" + fi fi if ! git --version &>/dev/null || @@ -381,14 +383,14 @@ EOS ! -x "$HOMEBREW_PREFIX/opt/git/bin/git" ]] then ohai "Installing Homebrew Git" - brew install git + [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && brew install git unset GIT_EXECUTABLE if ! git --version &>/dev/null then odie "Git must be installed and in your PATH!" fi fi - set +e + export GIT_TERMINAL_PROMPT="0" export GIT_SSH_COMMAND="ssh -oBatchMode=yes" From fd08ffdd67691b99bf3d6fd598ed40ef433d4c8b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 25 Nov 2020 08:44:40 +0000 Subject: [PATCH 5/8] cmd/update.sh: update Git logic. Co-authored-by: Maxim Belkin --- Library/Homebrew/cmd/update.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index f1f64adc5f..581ba6a0e7 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -383,9 +383,7 @@ EOS ! -x "$HOMEBREW_PREFIX/opt/git/bin/git" ]] then ohai "Installing Homebrew Git" - [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && brew install git - unset GIT_EXECUTABLE - if ! git --version &>/dev/null + if [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && ! brew install git then odie "Git must be installed and in your PATH!" fi From c3231a40953290cfc32037fcfb315cf8cc56fa93 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 25 Nov 2020 12:54:18 -0600 Subject: [PATCH 6/8] Apply Mike's suggestions Co-authored-by: Mike McQuaid --- Library/Homebrew/cmd/update.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 581ba6a0e7..3068452a16 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -368,10 +368,11 @@ user account: EOS fi + # we may want to use a Homebrew curl if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && ! -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] then - ohai "Installing Homebrew cURL" + # we cannot install a Homebrew cURL if homebrew/core is unavailable. if [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && ! brew install curl then odie "Curl must be installed and in your PATH!" @@ -382,7 +383,7 @@ EOS [[ -n "$HOMEBREW_FORCE_BREWED_GIT" && ! -x "$HOMEBREW_PREFIX/opt/git/bin/git" ]] then - ohai "Installing Homebrew Git" + # we cannot install a Homebrew Git if homebrew/core is unavailable. if [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && ! brew install git then odie "Git must be installed and in your PATH!" From 2aecfe60fc8fd42c01a0b46b3ad15246b740a131 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Wed, 25 Nov 2020 16:08:57 -0600 Subject: [PATCH 7/8] Update logic that handles HOMEBREW_GIT_PATH. --- Library/Homebrew/brew.sh | 23 +++++++++++++---------- Library/Homebrew/cmd/update.sh | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 0b0cf52409..e753515c51 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -351,7 +351,7 @@ else if [[ $(numeric "${curl_name_and_version##* }") -lt $(numeric "$HOMEBREW_MINIMUM_CURL_VERSION") ]] then message="Please update your system cURL. -Minimum required version: ${HOMEBREW_MINIMUM_CURL_VERSION}. +Minimum required version: ${HOMEBREW_MINIMUM_CURL_VERSION} Your cURL version: ${curl_name_and_version##* } Your cURL executable: $(type -p $HOMEBREW_CURL)" @@ -376,16 +376,18 @@ Your cURL executable: $(type -p $HOMEBREW_CURL)" IFS=. read -r major minor micro build extra <<< "${git_version_output##* }" if [[ $(numeric "$major.$minor.$micro.$build") -lt $(numeric "$HOMEBREW_MINIMUM_GIT_VERSION") ]] then - if [[ -z $HOMEBREW_GIT_PATH ]]; then - HOMEBREW_FORCE_BREWED_GIT="1" - else - odie < Date: Thu, 26 Nov 2020 08:35:42 +0000 Subject: [PATCH 8/8] brew.sh: remove trailing period. --- Library/Homebrew/brew.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index e753515c51..24235954b9 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -377,7 +377,7 @@ Your cURL executable: $(type -p $HOMEBREW_CURL)" if [[ $(numeric "$major.$minor.$micro.$build") -lt $(numeric "$HOMEBREW_MINIMUM_GIT_VERSION") ]] then message="Please update your system Git. -Minimum required version: ${HOMEBREW_MINIMUM_GIT_VERSION}. +Minimum required version: ${HOMEBREW_MINIMUM_GIT_VERSION} Your Git version: $major.$minor.$micro.$build Your Git executable: $(unset git && type -p $HOMEBREW_GIT)" if [[ -z $HOMEBREW_GIT_PATH || -z $HOMEBREW_DEVELOPER ]]; then