[macOS] Fix the issue with brew install (#2354)

* Update azure-cli installation

* Update curl installation

* Update git-lfs installation

* Add utils

* Update gnupg installation

* Add brew_install function

* Revert jq installation

* Add condition for the aws-sam-cli

* Add return to function, revert aws-sam-cli changes, rename brew_install function

* Fix typo

Co-authored-by: MaksimZhukov <v-mazhuk@microsoft.com>
This commit is contained in:
MaksimZhukov
2020-12-28 10:54:25 +03:00
committed by GitHub
parent 64c9751269
commit 310f692ea5
19 changed files with 103 additions and 32 deletions

View File

@@ -108,4 +108,63 @@ brew_cask_install_ignoring_sha256() {
pushd $CASK_DIR
git checkout HEAD -- "$TOOL_NAME.rb"
popd
}
}
get_brew_os_keyword() {
if is_HighSierra; then
echo "high_sierra"
elif is_Mojave; then
echo "mojave"
elif is_Catalina; then
echo "catalina"
elif is_BigSur; then
echo "big_sur"
else
echo "null"
fi
}
should_build_from_source() {
local tool_name=$1
local os_name=$2
local tool_info=$(brew info --json=v1 $tool_name)
local bottle_disabled=$(echo "$tool_info" | jq ".[0].bottle_disabled")
# No need to build from source if a bottle is disabled
# Use the simple 'brew install' command to download a package
if $bottle_disabled; then
echo "false"
return
fi
local tool_bottle=$(echo "$tool_info" | jq ".[0].bottle.stable.files.$os_name")
if [[ "$tool_bottle" == "null" ]]; then
echo "true"
return
else
echo "false"
return
fi
}
# brew provides package bottles for different macOS versions
# The 'brew install' command will fail if a package bottle does not exist
# Use the '--build-from-source' option to build from source in this case
brew_smart_install() {
local tool_name=$1
local os_name=$(get_brew_os_keyword)
if [[ "$os_name" == "null" ]]; then
echo "$OSTYPE is unknown operating system"
exit 1
fi
local build_from_source=$(should_build_from_source "$tool_name" "$os_name")
if $build_from_source; then
echo "Bottle of the $tool_name for the $os_name was not found. Building $tool_name from source..."
brew install --build-from-source $tool_name
else
echo "Downloading $tool_name..."
brew install $tool_name
fi
}