-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpack.sh
executable file
·203 lines (175 loc) · 6.58 KB
/
unpack.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
#!/usr/bin/env bash
################################################################
# unpack.sh - All-in-One Install and Setup Script for Unix #
################################################################
# Prompt the user to check system compatibility, install #
# packages and apps, symlink dotfiles, and configure system. #
# #
# OPTIONS: #
# --auto-yes: Skip all prompts, and auto-accept all changes #
# --no-clear: Don't clear the screen before running #
# #
# IMPORTANT: Read and understand contents before running. #
################################################################
# set variables
PARAMS=$* # user provided parameters
SYSTEM_TYPE=$(uname -s) # system type - Linux / MacOS (Darwin)
export PROMPT_TIMEOUT=15 # when user is prompted for input, skip after x seconds
export DOTFILES=~/Setup/dotfiles
export GITHUB_USER="boldandbrad"
export GITHUB_REPO_DIR=~/Developer/github
if [ "$SYSTEM_TYPE" = "Darwin" ]; then
export HOMEBREW_BUNDLE_FILE="$DOTFILES/util/macos/brew/Brewfile"
fi
# color ansi escape codes
export RESET='\033[0m'
export RED_B='\033[1;31m'
export GREEN_B='\033[1;32m'
export BLUE_B='\033[1;34m'
export PURPLE_B='\033[1;35m'
export PLAIN_B='\033[1;37m'
export YELLOW_B='\033[1;93m'
GREEN='\033[0;32m'
# clear screen
if [[ ! $PARAMS == *"--no-clear"* ]] && [[ ! $PARAMS == *"--help"* ]] ; then
clear
fi
# print help
if [[ $PARAMS == *"--help"* ]] ; then
echo -e "usage: ./unpack.sh [--help] [--auto-yes] [--no-clear]\n\n"\
"Prompt the user to check system compatibility, install packages and apps, symlink dotfiles, and configure system.\n\n"\
"OPTIONS:\n"\
"\t--auto-yes\tSkip all prompts, and auto accept all changes\n"\
"\t--no-clear\tDon't clear the screen before running\n"\
"\t--help\t\tPrint this message and exit"
exit 0
fi
# if auto-yes set, then don't wait for user reply
if [[ $PARAMS == *"--auto-yes"* ]]; then
export PROMPT_TIMEOUT=1
export AUTO_YES=true
fi
function make_banner () {
bannerText=$1
lineColor="${2:-$BLUE_B}"
textColor="${3:-$PLAIN_B}"
padding="${4:-0}"
titleLen=$(expr ${#bannerText} + 2 + $padding);
lineChar="─"; line=""
for (( i = 0; i < "$titleLen"; ++i )); do line="${line}${lineChar}"; done
banner="${lineColor}╭${line}╮\n│ ${textColor}${bannerText}${lineColor} │\n╰${line}╯"
echo -e "\n${banner}\n${RESET}"
}
function pre_setup () {
# welcome banner
make_banner "${GITHUB_USER}/dotfiles - Install" "${BLUE_B}" "${BLUE_B}"
# explain to the user what changes will be made
echo -e "${BLUE_B}This install script will do the following:${RESET}\n"\
"(1) Pre-setup\n"\
" - Check system compatibility\n"\
"(2) Install packages\n"\
" - Check that system is up-to-date\n"\
" - On macOS, install/update packages listed in Brewfile\n"\
"(3) Setup dotfiles\n"\
" - Symlink dotfiles to correct locations\n"\
"(4) Configure system\n"\
"(5) Clone user repos\n\n"\
"${PURPLE_B}You will be prompted at each stage, before any changes are made.${RESET}\n"\
"${PURPLE_B}For more info, see GitHub: \033[4;35mhttps://github.com/${GITHUB_USER}/dotfiles${RESET}"
# confirm the user would like to proceed
echo -en "\n${BLUE_B}Would you like to continue? (y/N):${RESET} "
read -t $PROMPT_TIMEOUT -n 1 -r ans_start && echo
if [[ ! $ans_start =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
echo -e "\nInstallation canceled. Terminating..."
exit 0
fi
# verify compatibility
if [ "$SYSTEM_TYPE" != "Darwin" ]; then
echo -e "\n${RED_B}${SYSTEM_TYPE} not supported. Terminating...${RESET}"
exit 1
fi
}
function update_system () {
# confirm the user would like to update the system
echo -en "\n${BLUE_B}Would you like to update the system? (y/N):${RESET} "
read -t $PROMPT_TIMEOUT -n 1 -r ans_sysupdate && echo
if [[ ! $ans_sysupdate =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
echo -e "\nSkipping system updates."
return
fi
# check if running in CI
if [ -z "${CI}" ]; then
# update macOS system software
if [ "$SYSTEM_TYPE" = "Darwin" ]; then
$DOTFILES/util/macos/update_system.sh
fi
else
echo -e "\nSkipping system updates. Running in CI."
fi
}
function install_packages () {
# confirm the user would like to install packages
echo -en "\n${BLUE_B}Would you like to install/update packages and apps? (y/N):${RESET} "
read -t $PROMPT_TIMEOUT -n 1 -r ans_syspackages && echo
if [[ ! $ans_syspackages =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
echo -e "\nSkipping package installs."
return
fi
# install macOS packages
if [ "$SYSTEM_TYPE" = "Darwin" ]; then
# install macOS packages and apps with homebrew
$DOTFILES/util/macos/install_packages.sh
fi
}
function setup_dotfiles () {
# confirm the user would like to symlink dotfiles
echo -en "\n${BLUE_B}Would you like to install dotfiles? (y/N):${RESET} "
read -t $PROMPT_TIMEOUT -n 1 -r ans_symlinks && echo
if [[ ! $ans_symlinks =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
echo -e "\nSkipping dotfile symlinks."
return
fi
# symlink dotfiles
echo -e "\nInstalling dotfiles..."
eval "$(aliae init zsh --config $DOTFILES/config/aliae/aliae.yaml)"
}
function config_system () {
# confirm the user would like to perform system configuration
echo -en "\n${BLUE_B}Would you like to perform system-specific configuration? (y/N):${RESET} "
read -t $PROMPT_TIMEOUT -n 1 -r ans_sysconfig && echo
if [[ ! $ans_sysconfig =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
echo -e "\nSkipping system-specific configuration."
return
fi
# perform macOS configuration
if [ "$SYSTEM_TYPE" = "Darwin" ]; then
$DOTFILES/util/macos/config_system.sh
fi
}
function clone_repos () {
# confirm the user would like to clone repos
echo -en "\n${BLUE_B}Would you like to clone ${GITHUB_USER}'s GitHub repos? (y/N):${RESET} "
read -t $PROMPT_TIMEOUT -n 1 -r ans_clone_repos && echo
if [[ ! $ans_clone_repos =~ ^[Yy]$ ]] && [[ $AUTO_YES != true ]] ; then
echo -e "\nSkipping GitHub repo clones."
return
fi
# clone repos
$DOTFILES/util/tools/github/clone_repos.sh
}
# terminate on first failure
set -e
# start!
pre_setup
update_system
install_packages
setup_dotfiles
config_system
clone_repos
# TODO: change default shell to homebrew zsh on macOS
# TODO: vscodium extensions
# TODO: debian linux support
set +e
echo
echo -e "${GREEN_B}Installation and setup complete!${RESET}"
echo -e "${PURPLE_B}Restart for all changes to take effect:${RESET} sudo shutdown -r now"