-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.sh
executable file
·278 lines (232 loc) · 9.57 KB
/
bootstrap.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
#!/bin/bash
# Colors
GREEN='\e[1;32m'
RED='\e[1;31m'
BLUE='\e[1;34m'
PURPLE='\e[1;35m'
YELLOW='\e[1;33m'
CYAN='\e[1;36m'
GRAY='\e[1;37m'
DARK_GRAY='\e[1;30m'
WHITE='\e[1;37m'
COLOR_OFF='\e[0m'
VERBOSE=0
ANSIBLE_VERSION="2.4.0.0"
ORIGINAL_PWD=$PWD
OPTS="vhi:r:c:"
function output_running {
printf "${PURPLE}--> ${COLOR_OFF}$1\n" 1>&2
}
function output_success {
printf "${GREEN}++ OK: ${COLOR_OFF}$1\n" 1>&2
}
function output_skip {
printf "${GREEN}-- SKIPPED: ${COLOR_OFF}$1\n" 1>&2
}
function output_header {
printf "\n${WHITE}[[ ${COLOR_OFF}$1${WHITE} ]]${COLOR_OFF}\n\n" 1>&2
}
function output_debug {
if [ "$VERBOSE" = 1 ] ; then
printf "${DARK_GRAY}| DEBUG: ${COLOR_OFF}$1\n" 1>&2
fi
}
function output_warning {
printf "${YELLOW}! WARNING: ${COLOR_OFF}$1\n" 1>&2
}
function error {
printf "\n${RED}!! ERROR: ${COLOR_OFF}$1\n\nExiting.\n" 1>&2
exit 1
}
function banner {
printf "${GREEN} ____ _____ _ _ _ ${COLOR_OFF}\n"
printf "${GREEN} / __ \ / ____| | | | | | | ${COLOR_OFF}\n"
printf "${GREEN} _ __ ___ __ _ ___| | | | (___ | |__ ___ ___ | |_ ___| |_ _ __ __ _ _ __ ${COLOR_OFF}\n"
printf "${GREEN}| \'_ \` _ \ / _\` |/ __| | | |\___ \ | '_ \ / _ \ / _ \| __/ __| __| '__/ _\` | \'_ \ ${COLOR_OFF}\n"
printf "${GREEN}| | | | | | (_| | (__| |__| |____) | | |_) | (_) | (_) | |_\__ \ |_| | | (_| | |_) |${COLOR_OFF}\n"
printf "${GREEN}|_| |_| |_|\__,_|\___|\____/|_____/ |_.__/ \___/ \___/ \__|___/\__|_| \__,_| .__/ ${COLOR_OFF}\n"
printf "${GREEN} | | ${COLOR_OFF}\n"
printf "${GREEN} https://feffi.org/macos-bootstrap |_| ${COLOR_OFF}\n\n"
printf "${DARK_GRAY}Thanks: ${COLOR_OFF}\n"
printf "${BLUE}http://superlumic.com https://github.com/boxcutter/osx ${COLOR_OFF}\n"
printf "${BLUE}https://github.com/jeremyltn http://patorjk.com/software/taag ${COLOR_OFF}\n"
printf "${BLUE}https://gist.github.com/pkuczynski/8665367 https://github.com/geerlingguy ${COLOR_OFF}\n\n"
}
# Check whether a command exists - returns 0 if it does, 1 if it does not
function exists {
output_debug "Checking if the '$1' command is present."
if command -v $1 >/dev/null 2>&1
then
output_debug "Command '$1' is present."
return 0
else
output_debug "Command '$1' is not present."
return 1
fi
}
function fail_on_error {
if ! $1
then error "Command '$1' returned a non zero exit code."
fi
}
function warn_on_error {
if ! $1
then output_warning "Command '$1' returned a non zero exit code."
fi
}
usage()
{
cat << EOF
usage: $0 options
OPTIONS:
-h Show this message.
-v Enable verbose output.
EOF
}
###################################################################################
# Install: Installing Command Line Tools #
# #
# credits: https://github.com/boxcutter/osx/blob/master/script/xcode-cli-tools.sh #
###################################################################################
function install_clt {
output_header "Installing Command Line Tools"
if [[ -f "/Library/Developer/CommandLineTools/usr/bin/clang" ]]; then
output_skip "Command Line Tools already installed."
return 0
fi
# Get and install Xcode CLI tools
OSX_VERS=$(sw_vers -productVersion | awk -F "." '{print $2}')
output_running "Detected macOS $(sw_vers -productVersion)"
# on 10.9+, we can leverage SUS to get the latest CLI tools
if [ "$OSX_VERS" -ge 9 ]; then
# create the placeholder file that's checked by CLI updates' .dist code
# in Apple's SUS catalog
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# find the CLI Tools update
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
output_running "Installing '$PROD'"
# install it
softwareupdate -i "$PROD" --verbose
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
# on 10.7/10.8, we instead download from public download URLs, which can be found in
# the dvtdownloadableindex:
# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex
else
[ "$OSX_VERS" -eq 7 ] && DMGURL=http://devimages.apple.com.edgekey.net/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg
[ "$OSX_VERS" -eq 7 ] && ALLOW_UNTRUSTED=-allowUntrusted
[ "$OSX_VERS" -eq 8 ] && DMGURL=http://devimages.apple.com.edgekey.net/downloads/xcode/command_line_tools_for_osx_mountain_lion_april_2014.dmg
TOOLS=clitools.dmg
output_running "Downloading '$DMGURL'"
curl "$DMGURL" -o "$TOOLS"
output_running "Installing '$TOOLS'"
TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX`
hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT"
installer $ALLOW_UNTRUSTED -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target /
hdiutil detach "$TMPMOUNT"
rm -rf "$TMPMOUNT"
rm "$TOOLS"
fi
if [[ ! -f "/Library/Developer/CommandLineTools/usr/bin/clang" ]]; then
error "Command Line Tools installation failed. Exiting."
else
output_success "Command Line Tools successfully installed."
fi
}
###################################################################################
# Install: pip (via easy_install) #
###################################################################################
function install_pip {
output_header "Installing pip"
if ! exists pip; then
fail_on_error "sudo easy_install --quiet pip"
if ! exists pip; then
error "Error installing pip."
else
output_success "pip successfully installed."
fi
else
output_skip "pip already installed."
fi
}
###################################################################################
# Install: ansible (via pip) #
###################################################################################
function install_ansible {
output_header "Installing Ansible"
if ! exists ansible; then
fail_on_error "sudo pip install -I ansible==$ANSIBLE_VERSION"
if ! exists ansible; then
error "Error installing Ansible."
else
output_success "Ansible successfully installed."
fi
else
output_skip "Ansible already installed."
fi
}
###################################################################################
# Show banner #
###################################################################################
banner
###################################################################################
# Check cli options (not yet implemented) #
###################################################################################
while getopts "$OPTS" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
v)
VERBOSE=1
;;
?)
usage
exit
;;
esac
done
shell="$1"
if [ -z "$shell" ]; then
shell="$(basename "$SHELL")"
fi
if [ "$VERBOSE" = 1 ] ; then
output_debug "Detected verbose (-v) flag."
fi
###################################################################################
# Check privilege escalation #
###################################################################################
#output_debug "Checking if we need to ask for a sudo password"
#sudo -v
#output_debug "Keep-alive: update existing sudo time stamp until we are finished"
#while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
###################################################################################
# Install neccessary toolchain #
###################################################################################
install_clt
install_pip
install_ansible
###################################################################################
# Bootstrap #
###################################################################################
#sudo -k
output_header "Bootstrapping via ansible"
output_running "Installing requirements..."
$(which ansible-galaxy) install -r requirements.yml -p roles
#$(which ansible-galaxy) install -r requirements.yml -p roles --ignore-errors
output_running "Bootstrapping..."
output_running "Using config from: '$1'"
$(which ansible-playbook) -i "inventory" bootstrap.yml -K --connection=local --extra-vars cli_path=$1
###################################################################################
# Kill all affected applications #
###################################################################################
output_header "Kill all affected applications..."
for app in "Activity Monitor" "Address Book" "Calendar" "Contacts" "cfprefsd" \
"Dock" "Finder" "Mail" "Messages" "Safari" "SizeUp" "SystemUIServer" \
"Transmission" "Twitter" "iCal"; do
output_running "$app"
killall "${app}" > /dev/null 2>&1
done
###################################################################################
output_success "Done. Note that some of these changes require a logout/restart to take effect."