-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·294 lines (269 loc) · 7.12 KB
/
install.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env bash
# install.sh
#
# ----------------------------------------------------------------------------------------
# Help
# ----------------------------------------------------------------------------------------
show_help() {
cat << EOF
This scrit checks for and installs dev dependencies on a MacOS computer.
NOTEs:
- You can optionally use macgnu or linuxify.
- This script installs gnu versions, but DOES NOT setup aliases for them.
Use: ${0##*/} -e {-r}
-r REPORT Check for dependencies and report without installing.
-h HELP Show this help menu.
Examples:
Run the script.
./${0##*/}
Generate a dependnecy report.
./${0##*/} -r
EOF
exit 1
}
# ----------------------------------------------------------------------------------------
# Arguments
# ----------------------------------------------------------------------------------------
ts='date -u +'%FT%H-%M-%S''
OPTIND=1
while getopts "hrf" opt; do
case "$opt" in
h)
show_help
;;
r)
arg_r='set'
;;
f)
arg_f='set'
# This is a hidden arg for the developer.
# This arg permits the script to run on non-macos systems.
;;
:)
echo "ERROR: Option -$OPTARG requires an argument."
show_help
;;
*)
echo "ERROR: Unknown option!"
show_help
;;
esac
done
shift "$((OPTIND-1))"
[ "$1" = "--" ] && shift
# ----------------------------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------------------------
case "$OSTYPE" in
darwin*) export OS_TYPE="OSX" ;;
linux*) export OS_TYPE="LINUX" ;;
*)
echo -e "\e[01;31mERROR\e[0m: $OSTYPE not supported!"
exit 1
;;
esac
function printHeading() {
txt="$@"
printf "\n\e[01;39M${txt}\e[0m "
printf '\n%*s' "$((${COLUMNS}-$((${COLUMNS}-$(wc -c<<<$txt)+1))))" | tr ' ' -
printf '\n'
}
function ask {
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
elif [ "${2:-}" = "Range" ]; then
prompt="${3:-}"
default=0
else
prompt="y/n"
default=
fi
# Ask the question
read -p $"$1 [$prompt]: " reply
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*|[1-99]) return 0 ;;
N*|n*|0*) return 1 ;;
esac
done
}
function log() {
case $1 in
0|emerg)
level='\e[01;30;41mEMERGENCY\e[0m'
;;
1|alert)
level='\e[01;31;43mALERT\e[0m'
;;
2|crit)
level='\e[01;97;41mCRITICAL\e[0m'
;;
3|err)
level='\e[01;31mERROR\e[0m'
;;
4|warn)
level='\e[01;33mWARNING\e[0m'
;;
5|notice)
level='\e[01;30;107mNOTICE\e[0m'
;;
6|info)
level='\e[01;39mINFO\e[0m'
;;
7|debug)
level='\e[01;97;46mDEBUG\e[0m'
;;
77|succ)
level='\e[01;32mSUCCESS\e[0m'
# Not a real severity level under RFC5425. Purely for display purposes.
;;
*)
echo -e "\e[01;31mERROR\e[00m: Invalid level argument!"
exit 1
;;
esac
msg=${@:2}
echo -e "$($ts) - $level: $msg" | tee -a ~/${0##*/}.log
}
function checkIsInstalled() {
package=$(cut -d_ -f2- <<< $package)
if [[ ! $(command -v $package) ]]; then
confirmInstall $package
else
log 6 "$package - OK"
fi
}
function verifyInstall() {
package=$(cut -d_ -f2- <<< $package)
if [[ $(command -v $package) ]]; then
log 77 "$package installed."
else
log 3 "$package failed to install!"
fi
}
function confirmInstall() {
if [[ -z ${arg_r+x} ]]; then
if ask "Confirm: Install $package?" Y; then
answer="yes"
else
answer="no"
fi
else
log 6 "$package is NOT installed."
fi
}
function doInstall() {
if [[ $answer == "yes" ]]; then
log 5 "Installing $package..."
install$package
verifyInstall
unset answer
fi
}
function doBrewInstall() {
if [[ $answer == "yes" ]]; then
log 5 "Installing $package..."
brew install $package
verifyInstall
unset answer
fi
}
function installbrew() {
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
function installdocker() {
if [[ $(uname -m) == 'arm64' ]]; then
log 6 "Installing for Apple M1 CPU."
log 5 "Installing Rosetta 2..."
softwareupdate --install-rosetta
wget https://desktop.docker.com/mac/main/arm64/Docker.dmg
else
log 6 "Installing for Intel CPU."
wget https://desktop.docker.com/mac/main/amd64/Docker.dmg
fi
sudo hdiutil attach Docker.dmg
sudo /Volumes/Docker/Docker.app/Contents/MacOS/install --accept-license
sudo hdiutil detach /Volumes/Docker
}
installasdf() {
# https://www.wiserfirst.com/blog/how-to-use-asdf-on-macos/
# https://www.youtube.com/watch?v=RTaqWRj-6Lg
artifact='v0.10.2.zip'
md5sum='ebb76713bf2388d096d603d21f0f6de3'
wget https://github.com/asdf-vm/asdf/archive/refs/tags/"$artifact"
# Update resources/checkmd5.md5 with: 'md5sum vX.X.X.zip > resources/checkmd5.md5' as needed.
if [[ $(md5sum --quiet -c resources/checkmd5.md5) ]]; then
rm -rf ~/.asdf/ /tmp/asdf/
unzip -q "$artifact" -d /tmp/asdf
rm -f "$artifact"
mkdir ~/.asdf
mv /tmp/asdf/"$artifact"/* ~/.asdf/
rm -rf /tmp/asdf/
else
log 4 "asdf NOT installed!"
log 4 "MD5 checksum for $artifact FAILED!"
}
# ----------------------------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------------------------
# brew must be first.
# coreutils contents: http://www.maizure.org/projects/decoded-gnu-coreutils/
packages=()
packages+=( brew
brew_bash
brew_coreutils
brew_vim
brew_bc
brew_less
brew_git
brew_mutagen
brew_wget
brew_curl
brew_gnu-sed
brew_gawk
brew_gnu-tar
brew_gzip
brew_unzip
brew_jq
brew_yq
brew_gnu-getopt
brew_findutils
brew_gnu-which
brew_grep
brew_md5sha1sum
brew_glibc
brew_glib
brew_gcc
brew_binutils
brew_openssl
brew_gnutls
brew_ca-certificates
docker
asdf
)
# ----------------------------------------------------------------------------------------
# Main Operations
# ----------------------------------------------------------------------------------------
if [[ -n ${arg_r+x} ]]; then
printHeading "Generating dependencies report..."
else
l printHeading "Checking for dependencies..."
fi
for package in ${packages[@]}; do
if [[ ! $package =~ "brew_" ]]; then
checkIsInstalled
[[ ! -n ${arg_r+x} ]] && doInstall
else
checkIsInstalled
[[ ! -n ${arg_r+x} ]] && doBrewInstall
fi
done