forked from sambacha/solc-osx-aarch64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brew_fn.sh
executable file
·72 lines (62 loc) · 1.96 KB
/
brew_fn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
brew_cask_install_ignoring_sha256() {
local TOOL_NAME=$1
CASK_DIR="$(brew --repo homebrew/cask)/Casks"
chmod a+w "$CASK_DIR/$TOOL_NAME.rb"
SHA=$(grep "sha256" "$CASK_DIR/$TOOL_NAME.rb" | awk '{print $2}')
sed -i '' "s/$SHA/:no_check/" "$CASK_DIR/$TOOL_NAME.rb"
brew install --cask $TOOL_NAME
pushd $CASK_DIR
git checkout HEAD -- "$TOOL_NAME.rb"
popd
}
get_brew_os_keyword() {
if is_Catalina; then
echo "catalina"
elif is_BigSur; then
echo "big_sur"
elif is_Monterey; then
echo "monterey"
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
}