-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathhomebrew.sh
executable file
·119 lines (80 loc) · 2.52 KB
/
homebrew.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../../utils.sh" \
&& . "./utils.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
add_to_path() {
# Check if `brew` is available.
if command -v brew &> /dev/null; then
return
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# If not, add it to the PATH.
HARDWARE="$(uname -m)"
prefix=""
if [ "$HARDWARE" == "arm64" ]; then
prefix="/opt/homebrew"
elif [ "$HARDWARE" == "x86_64" ]; then
prefix="/usr/local"
else
print_error "Homebrew is only supported on Intel and ARM processors!"
fi
PATH="$prefix/bin:$PATH"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Inform the user about the availability of `brew`.
command -v brew &> /dev/null
print_result $? "Add to PATH"
}
get_git_config_file_path() {
local path=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if path="$(brew --repository 2> /dev/null)/.git/config"; then
printf "%s" "$path"
return 0
else
print_error "Get config file path"
return 1
fi
}
install() {
if ! cmd_exists "brew"; then
ask_for_sudo
printf "\n" | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" &> /dev/null
# └─ simulate the ENTER keypress
fi
print_result $? "Install"
}
opt_out_of_analytics() {
local path=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Try to get the path of the `Homebrew` git config file.
path="$(get_git_config_file_path)" \
|| return 1
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Opt-out of Homebrew's analytics.
# https://github.com/Homebrew/brew/blob/0c95c60511cc4d85d28f66b58d51d85f8186d941/share/doc/homebrew/Analytics.md#opting-out
if [ "$(git config --file="$path" --get homebrew.analyticsdisabled)" != "true" ]; then
git config --file="$path" --replace-all homebrew.analyticsdisabled true &> /dev/null
print_result $? "Opt-out of analytics"
fi
}
update() {
execute \
"brew update" \
"Update"
}
upgrade() {
execute \
"brew upgrade" \
"Upgrade"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main() {
print_in_purple "\n Homebrew\n\n"
install
add_to_path
opt_out_of_analytics
update
upgrade
}
main