-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·440 lines (402 loc) · 7.83 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/usr/bin/env bash
# Main script.
# Check and download dependencies
# Interactive menu to execute playbooks.
# Global constants
readonly CURRENT_PLATFORM="$(uname -s)"
readonly REPO_NAME="macos_configurator"
readonly REPO_LINK="https://github.com/ggragham/${REPO_NAME}.git"
readonly DEFAULT_REPO_PATH="$HOME/.local/opt/$REPO_NAME"
# Global vars
TEMP_DIR="$(mktemp -d)"
USER_PASSWORD="${USER_PASSWORD:-}"
REPO_ROOT_PATH="${REPO_ROOT_PATH:-$HOME/.local/opt/$REPO_NAME}"
SCRIPT_PATH="$(dirname "$0")"
if [[ -d "$SCRIPT_PATH/.git" ]]; then
REPO_ROOT_PATH="$SCRIPT_PATH"
else
REPO_ROOT_PATH="${REPO_ROOT_PATH:-"$DEFAULT_REPO_PATH"}"
fi
ANSIBLE_PLAYBOOK_PATH="$REPO_ROOT_PATH/ansible"
# Text formating
readonly NORMAL='\033[0m'
readonly BOLD='\033[1m'
readonly LONG_TAB='\033[40G'
readonly LIGHTBLUE='\033[1;34m'
# readonly BLINK='\033[5m'
# readonly RED='\033[0;31m'
# readonly GREEN='\033[0;32m'
cleanup() {
local exitStatus="$?"
unset USER_PASSWORD
rm -rf "$TEMP_DIR"
exit "$exitStatus"
}
trap cleanup TERM EXIT
checkSudo() {
if [ "$EUID" -eq 0 ]; then
echo "Error: Running this script with sudo is not allowed."
exit 1
fi
}
installInitDeps() {
if [[ "$CURRENT_PLATFORM" != "Darwin" ]]; then
echo -e "Platform ${BOLD}$CURRENT_PLATFORM${NORMAL} is not supported"
exit 1
fi
if ! brew --version 2>/dev/null 1>&2; then
local brewInstallPath="$TEMP_DIR/brew_install.sh"
(
set -e
echo "Installing Homebrew..."
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh -o "$brewInstallPath"
/bin/bash "$brewInstallPath"
) || {
echo "Failed to install Homebrew. Exiting..."
exit 2
}
echo "Brew installation complete"
fi
if ! ansible --version 2>/dev/null 1>&2; then
(
set -e
echo "Installing Ansible..."
brew update
brew install ansible
) || {
echo "Failed to install Ansible. Exiting..."
exit 2
}
echo "Ansible installation complete"
fi
}
cloneRepo() {
(
set -eu
mkdir -p "$REPO_ROOT_PATH"
git clone "$REPO_LINK" "$REPO_ROOT_PATH"
)
}
init() {
installInitDeps
if [ "$PWD/$0" != "$REPO_ROOT_PATH/$0" ]; then
cloneRepo
fi
cd "$REPO_ROOT_PATH" || exit "$?"
}
enterUserPassword() {
sudo -K
checkPassword() {
if echo "$USER_PASSWORD" | sudo -S true >/dev/null 2>&1; then
sudo -K
return 0
else
echo -e "\nSorry, try again."
return 1
fi
}
if [ -n "$USER_PASSWORD" ]; then
if checkPassword; then
return 0
fi
exit $?
fi
while :; do
read -rsp "Password: " USER_PASSWORD
if checkPassword; then
break
fi
done
return 0
}
pressAnyKeyToContinue() {
read -n 1 -s -r -p "Press any key to continue"
echo
}
asciiLogo() {
cat <<'EOF'
___ ___ _____ _____ _____ __ _
| \/ | | _ / ___| / __ \ / _(_)
| . . | __ _ ___| | | \ `--. | / \/ ___ _ __ | |_ _ __ _
| |\/| |/ _` |/ __| | | |`--. \ | | / _ \| '_ \| _| |/ _` |
| | | | (_| | (__\ \_/ /\__/ / | \__/\ (_) | | | | | | | (_| |
\_| |_/\__,_|\___|\___/\____/ \____/\___/|_| |_|_| |_|\__, |
__/ |
|___/
EOF
}
printHeader() {
clear
echo -e "${LIGHTBLUE}${BOLD}"
asciiLogo
echo -e "${NORMAL}"
echo -e "${LONG_TAB} By ${BOLD}ggragham${NORMAL}"
echo
echo -e "${LIGHTBLUE}Choose an option:${NORMAL}"
echo
}
menuItem() {
local number="$1"
local text="$2"
echo -e "${LIGHTBLUE}$number.${NORMAL} $text"
}
runAnsiblePlaybook() {
local playbookName="$1"
shift
local tagsList="$*"
ansible-playbook "$ANSIBLE_PLAYBOOK_PATH/$playbookName.yml" --tags "prepare,$tagsList" --extra-vars "ansible_become_password=$USER_PASSWORD"
}
# PKGs
installPackages() {
local select="*"
while :; do
printHeader
menuItem "1" "Install Base pkgs"
menuItem "2" "Install Dev pkgs"
echo
menuItem "0" "Back"
echo
case $select in
1)
installBasePackages
select="*"
;;
2)
installDevPackages
select="*"
;;
0)
return 0
;;
*)
read -rp "> " select
continue
;;
esac
done
}
installBasePackages() {
local select="*"
while :; do
printHeader
menuItem "1" "Install Homebrew PKGs"
menuItem "2" "Install Oh My ZSH"
menuItem "3" "Install Scripts"
menuItem "4" "Install lporg"
echo
menuItem "0" "Back"
echo
case $select in
1)
runAnsiblePlaybook "install_pkgs" "brew"
pressAnyKeyToContinue
select="*"
;;
2)
runAnsiblePlaybook "install_pkgs" "omz"
pressAnyKeyToContinue
select="*"
;;
3)
runAnsiblePlaybook "install_pkgs" "script"
pressAnyKeyToContinue
select="*"
;;
4)
runAnsiblePlaybook "install_pkgs" "lporg"
pressAnyKeyToContinue
select="*"
;;
0)
return 0
;;
*)
read -rp "> " select
continue
;;
esac
done
}
installDevPackages() {
local select="*"
while :; do
printHeader
menuItem "1" "Install Base DevOps PKGs"
menuItem "2" "Install VSCodium"
menuItem "3" "Install Virtualization PKGs"
menuItem "4" "Install Docker"
menuItem "5" "Install Kubernetes PKGs"
menuItem "6" "Install PyEnv"
menuItem "7" "Install Node Version Manager"
echo
menuItem "0" "Back"
echo
case $select in
1)
runAnsiblePlaybook "install_dev_pkgs" "devops"
pressAnyKeyToContinue
select="*"
;;
2)
runAnsiblePlaybook "install_dev_pkgs" "vscodium"
pressAnyKeyToContinue
select="*"
;;
3)
runAnsiblePlaybook "install_dev_pkgs" "virtualization"
pressAnyKeyToContinue
select="*"
;;
4)
runAnsiblePlaybook "install_dev_pkgs" "docker"
pressAnyKeyToContinue
select="*"
;;
5)
runAnsiblePlaybook "install_dev_pkgs" "kubernetes"
pressAnyKeyToContinue
select="*"
;;
6)
runAnsiblePlaybook "install_dev_pkgs" "pyenv"
pressAnyKeyToContinue
select="*"
;;
7)
runAnsiblePlaybook "install_dev_pkgs" "nvm"
pressAnyKeyToContinue
select="*"
;;
0)
return 0
;;
*)
read -rp "> " select
continue
;;
esac
done
}
# Config
applyConfig() {
local select="*"
while :; do
printHeader
menuItem "1" "Apply Settings"
menuItem "2" "Apply Configs"
menuItem "3" "Configure Apps"
menuItem "4" "Organize Launchpad"
echo
menuItem "0" "Back"
echo
case $select in
1)
runAnsiblePlaybook "apply_config" "config_script"
pressAnyKeyToContinue
select="*"
;;
2)
runAnsiblePlaybook "apply_config" "local_config_files"
pressAnyKeyToContinue
select="*"
;;
3)
runAnsiblePlaybook "apply_config" "app_config"
pressAnyKeyToContinue
select="*"
;;
4)
runAnsiblePlaybook "apply_config" "lporg"
pressAnyKeyToContinue
select="*"
;;
0)
return 0
;;
*)
read -rp "> " select
continue
;;
esac
done
}
# Privacy & Security
privacyAndSecurity() {
local select="*"
while :; do
printHeader
menuItem "1" "Apply Hosts"
menuItem "2" "Apply Security Settings"
menuItem "3" "Apply Privacy Settings"
menuItem "4" "Cleanup"
echo
menuItem "0" "Back"
echo
case $select in
1)
runAnsiblePlaybook "privacy_and_security" "hosts"
pressAnyKeyToContinue
select="*"
;;
2)
runAnsiblePlaybook "privacy_and_security" "security"
pressAnyKeyToContinue
select="*"
;;
3)
runAnsiblePlaybook "privacy_and_security" "privacy"
pressAnyKeyToContinue
select="*"
;;
4)
runAnsiblePlaybook "privacy_and_security" "cleanup"
pressAnyKeyToContinue
select="*"
;;
0)
return 0
;;
*)
read -rp "> " select
continue
;;
esac
done
}
main() {
checkSudo
enterUserPassword
init
local select="*"
while :; do
printHeader
menuItem "1" "Install PKGs"
menuItem "2" "Apply configs"
menuItem "3" "Privacy & Security"
echo
menuItem "0" "Exit"
echo
case $select in
1)
installPackages
select="*"
;;
2)
applyConfig
select="*"
;;
3)
privacyAndSecurity
select="*"
;;
0)
return 0
;;
*)
read -rp "> " select
continue
;;
esac
done
}
main