-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·260 lines (222 loc) · 5.54 KB
/
setup.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
#!/usr/bin/env zsh
# vim: tabstop=2:shiftwidth=2
####
# set color variables, simply because i like when shell scripts
# look nice
YLW="$(echo -e "\e[1;93m")"
GRN="$(echo -e "\e[1;92m")"
BLU="$(echo -e "\e[1;94m")"
RED="$(echo -e "\e[1;91m")"
END="$(echo -e "\e[0m")"
####
# i'm also quite fond of consistency and
# reusable variables
S="${GRN}*${END}"
Q="${YLW}?${END}"
X="${RED}X${END}"
YESNO="(${GRN}y${END}/${RED}N${END}): "
DOT=${DOT:-~/.dot}
SETUP=${SETUP:-$DOT/.setup}
INSTALL=${INSTALL:-$SETUP/install}
SETTINGS=${SETTINGS:-$SETUP/settings}
function get_os() {
case "$OSTYPE" in
[Dd]arwin*)
echo "${S} Let's set up this ${BLU}Mac${END}! ${S}"
echo ""
echo ""
OS="mac"
;;
[Ll]inux*)
echo "${S} WOO! ${BLU}Linux${END}! ${S}"
echo ""
echo ""
OS="linux"
;;
[Ww]indows*)
echo "${S} huh? ${S}"
echo ""
echo ""
OS="windows"
;;
*)
echo "${S} I have ${RED}no idea${END} what ${RED}this is ${END}. ${S} "
echo " But let's give it a shot!"
echo ""
echo ""
OS="NULL"
;;
esac
}
function quit_preferences() {
if [[ "$OS" == "mac" ]]; then
echo "${S} Quitting System Preferences..."
echo ""
osascript -e 'tell application "System Preferences" to quit'
fi
}
function source_files() {
for ((i = 0; i < ${#sources[@]}; i++)); do
source "${sources[$i]}"
done
}
function reply() {
local response="$*"
echo " ${response}" 1>&2
}
function ask() {
local question="$*"
echo "? ${Q} ${question} ${YESNO}"
}
function invalid_answer() {
echo " ${X} Invalid answer. Enter \"y/yes\" or \"N/no\"" >&2
echo " $((max_retries - ++retries)) attempts remaining."
echo ""
}
# Installing Brew & Xcode's Command Line Tools
function check_brew() {
echo "${S} Checking if ${BLU}Homebrew${END} is installed..."
echo ""
if [[ "$(command -v brew)" == "" ]]; then
retries=0
max_retries=5
while [ "$retries" -lt "$max_retries" ]; do
reply "- ${BLU}Homebew${END} is ${YLW}not installed${END}."
qstn="$(ask "Would you like to install it now?")"
read -q "$qstn" answer
echo ""
case "$answer" in
"y" | "Y" | "yes" | "Yes")
reply "- Okay! Installing Homebrew."
/usr/bin/ruby -e \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo ""
reply "Turning analytics off..."
echo ""
brew analytics off
break
;;
"n" | "N" | "no" | "No")
reply "- Okay! Not installing ${BLU}Homebrew${END}."
echo ""
break
;;
*)
invalid_answer
if [ "$retries" -ge "$max_retries" ]; then
reply "${X} Too many invalid answers."
break
fi
;;
esac
done
else
reply "- Homebrew is installed!"
echo ""
brew analytics off
fi
echo ""
}
function check_settings() {
echo "${S} Checking for settings directory... (there should only be one!!)"
echo ""
if [[ -d "${SETTINGS}" ]]; then
cd "$SETTINGS" || echo " - Something went ${RED}wrong :(${END}"
reply "- ${GRN}Found it!${END}"
echo ""
reply "- Checking for settings scripts..."
echo ""
local sources=(./*)
retries=0
max_retries=5
while [ "$retries" -lt "$max_retries" ]; do
qstn="$(ask "Would you like to set your global settings?")"
read "$qstn" answer
echo ""
case "$answer" in
"y" | "Y" | "yes" | "Yes")
reply "- Okay! Doing that now."
echo ""
source_files
break
;;
"n" | "N" | "no" | "no")
reply "- Okay! Not setting anything right now."
echo ""
break
;;
*)
invalid_answer
if [ "$retries" -ge "$max_retries" ]; then
reply "${X} Too many invalid answers."
break
fi
;;
esac
done
fi
echo ""
}
function check_install_dir() {
echo "${S} Checking for an install directory... (there should only be one!)"
echo ""
if [[ -d "${INSTALL}" ]]; then
cd "$INSTALL" || echo " - Something went ${RED}wrong :(${END}"
reply "- ${GRN}Found it!${END}"
echo ""
reply "- Checking for install scripts..."
echo ""
local sources=(./*)
if [ ${#sources[@]} -eq 0 ]; then
reply "${YLW}Didn't find any :(${END}"
echo ""
else
reply "${GRN}Found some.${END}"
echo ""
printf " - %s\n" "${sources[@]}" | sed 's/\.\/install-//g'
echo ""
retries=0
max_retries=5
while [ "$retries" -lt "$max_retries" ]; do
qstn="$(ask "Would you like to install these programs")"
read "$qstn" answer
echo ""
case "$answer" in
"y" | "Y" | "yes" | "Yes")
reply "- Okay! Installing."
echo ""
source_files
echo ""
break
;;
"n" | "N" | "no" | "No")
reply "- Okay. Not installing."
echo ""
break
;;
*)
invalid_answer
if [ "$retries" -ge "$max_retries" ]; then
reply "${X} Too many invalid answers."
break
fi
;;
esac
done
fi
else
reply "${X} Didn't find one."
echo ""
fi
echo ""
}
function setup() {
get_os
if [[ "$OS" == "mac" ]]; then
check_brew
check_settings
fi
check_install_dir
}
setup
echo "${S} ${GRN}Done ${BLU}:)${END}"