forked from joshukraine/mac-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·306 lines (211 loc) · 9.78 KB
/
bootstrap
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
#!/usr/bin/env bash
################################################################################
# bootstrap
#
# This script is intended to set up a new Mac computer with my dotfiles and
# other development preferences.
################################################################################
# Thank you, thoughtbot!
bootstrap_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\\n[BOOTSTRAP] $fmt\\n" "$@"
}
################################################################################
# VARIABLE DECLARATIONS
################################################################################
osname=$(uname)
export COMMANDLINE_TOOLS="/Library/Developer/CommandLineTools"
export OLD_DOTFILES_BAK="${HOME}/old_dotfiles_bak"
export DICTIONARY_DIR="${HOME}/Library/Spelling"
export DOTFILES_REPO_URL="https://github.com/joshukraine/dotfiles.git"
export DOTFILES_DIR="${HOME}/dotfiles"
export BOOTSTRAP_REPO_URL="https://github.com/paveq/mac-bootstrap.git"
export BOOTSTRAP_DIR="${HOME}/mac-bootstrap"
PS3="> "
comp=$(scutil --get ComputerName)
host=$(scutil --get LocalHostName)
if [ -z "$comp" ] || [ -z "$host" ]; then
DEFAULT_COMPUTER_NAME="My Mac Computer"
DEFAULT_HOST_NAME="my-mac-computer"
else
DEFAULT_COMPUTER_NAME="$comp"
DEFAULT_HOST_NAME="$host"
fi
DEFAULT_BOOTSTRAP_VERSION="master"
DEFAULT_DOTFILES_BRANCH="master"
################################################################################
# Make sure we're on a Mac before continuing
################################################################################
if [ "$osname" == "Linux" ]; then
bootstrap_echo "Oops, looks like you're on a Linux machine. Please have a look at
my Linux Bootstrap script: https://github.com/joshukraine/linux-bootstrap"
exit 1
elif [ "$osname" != "Darwin" ]; then
bootstrap_echo "Oops, it looks like you're using a non-UNIX system. This script
only supports Mac. Exiting..."
exit 1
fi
################################################################################
# Check for presence of command line tools if macOS
################################################################################
if [ ! -d "$COMMANDLINE_TOOLS" ]; then
bootstrap_echo "Apple's command line developer tools must be installed before
running this script. To install them, just run 'xcode-select --install' from
the terminal and then follow the prompts. Once the command line tools have been
installed, you can try running this script again."
exit 1
fi
################################################################################
# Authenticate
################################################################################
sudo -v
# Keep-alive: update existing `sudo` time stamp until bootstrap has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
set -e
################################################################################
# Welcome and setup
################################################################################
echo
echo "*************************************************************************"
echo "******* *******"
echo "******* Welcome to Mac Bootstrap! *******"
echo "******* *******"
echo "******* *******"
echo "*************************************************************************"
echo
printf "Before we get started, let's get some info about your setup.\\n"
printf "\\nBootstrap script will be cloned from:
==> %s.\\n" "$BOOTSTRAP_REPO_URL"
printf "Which version should we use? (Leave blank for default: %s)\\n" "$DEFAULT_BOOTSTRAP_VERSION"
read -r -p "> " BOOTSTRAP_VERSION
if [ -n "$BOOTSTRAP_VERSION" ]; then
export BOOTSTRAP_VERSION
else
export BOOTSTRAP_VERSION="$DEFAULT_BOOTSTRAP_VERSION"
fi
printf "\\nDotfiles will be cloned from:
==> %s.\\n" "$DOTFILES_REPO_URL"
printf "Which branch should we use? (Leave blank for default: %s)\\n" "$DEFAULT_DOTFILES_BRANCH"
read -r -p "> " DOTFILES_BRANCH
if [ -n "$DOTFILES_BRANCH" ]; then
export DOTFILES_BRANCH
else
export DOTFILES_BRANCH="$DEFAULT_DOTFILES_BRANCH"
fi
printf "\\nEnter a name for your Mac. (Leave blank for default: %s)\\n" "$DEFAULT_COMPUTER_NAME"
read -r -p "> " COMPUTER_NAME
export COMPUTER_NAME=${COMPUTER_NAME:-$DEFAULT_COMPUTER_NAME}
printf "\\nEnter a host name for your Mac. (Leave blank for default: %s)\\n" "$DEFAULT_HOST_NAME"
read -r -p "> " HOST_NAME
export HOST_NAME=${HOST_NAME:-$DEFAULT_HOST_NAME}
printf "\\nEnter your name (eg. Firstname Lastname)"
read -r -p "> " FULL_NAME
printf "\\nEnter your company email (eg. [email protected])"
read -r -p "> " EMAIL
printf "\\nLooks good. Here's what we've got so far.\\n"
printf "Bootstrap version: ==> [%s]\\n" "$BOOTSTRAP_VERSION"
printf "Dotfiles branch: ==> [%s]\\n" "$DOTFILES_BRANCH"
printf "Computer name: ==> [%s]\\n" "$COMPUTER_NAME"
printf "Host name: ==> [%s]\\n" "$HOST_NAME"
printf "Name: ==> [%s]\\n" "$FULL_NAME"
printf "Email ==> [%s]\\n" "$EMAIL"
echo
read -p "Continue? (y/n) " -n 1 -r
echo
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
echo "Exiting..."
exit 1
fi
################################################################################
# Clone mac-bootstrap repo
################################################################################
bootstrap_echo "Cloning mac-bootstrap repo..."
if [ -d "$BOOTSTRAP_DIR" ]; then
rm -rf "$BOOTSTRAP_DIR"
fi
git clone "$BOOTSTRAP_REPO_URL" -b "$BOOTSTRAP_VERSION" "$BOOTSTRAP_DIR"
# Filevault
sudo cp "$BOOTSTRAP_DIR"/lib/FileVaultMaster.keychain-db /Library/Keychains/FileVaultMaster.keychain
sudo chown root:wheel /Library/Keychains/FileVaultMaster.keychain
sudo chmod 644 /Library/Keychains/FileVaultMaster.keychain
if fdesetup status | grep Off >/dev/null; then
sudo fdesetup enable -keychain -norecoverykey -user $(whoami)
fi
################################################################################
# 1. Provision with my adaptation of Laptop (install/laptop)
################################################################################
bootstrap_echo "Step 1: Installing Laptop script..."
sh "${BOOTSTRAP_DIR}/install/laptop" 2>&1 | tee ~/laptop.log
bootstrap_echo "Done!"
################################################################################
# 2. Install Oh My Zsh
################################################################################
bootstrap_echo "Step 2: Installing Oh My Zsh..."
if [ -d "${HOME}/.oh-my-zsh" ]; then
rm -rf "${HOME}/.oh-my-zsh"
fi
git clone https://github.com/robbyrussell/oh-my-zsh.git "${HOME}/.oh-my-zsh"
if [ -d /usr/local/share/zsh ]; then
bootstrap_echo "Setting permissions for /usr/local/share/zsh..."
sudo chmod -R 755 /usr/local/share/zsh
fi
if [ -d /usr/local/share/zsh/site-functions ]; then
bootstrap_echo "Setting permissions for /usr/local/share/zsh/site-functions..."
sudo chmod -R 755 /usr/local/share/zsh/site-functions
fi
bootstrap_echo "Done!"
################################################################################
# 3. Set macOS preferences
################################################################################
bootstrap_echo "Step 3: Setting macOS preferences..."
# shellcheck source=/dev/null
source "${BOOTSTRAP_DIR}/install/macos-defaults"
bootstrap_echo "Done!"
################################################################################
# 4. Install ~/bin utilities
################################################################################
bootstrap_echo "Step 4: Installing ~/bin utilities..."
cp -R "$BOOTSTRAP_DIR"/bin/* "${HOME}/bin/"
bootstrap_echo "Done!"
################################################################################
# 5. Set up Tmuxinator (https://github.com/tmuxinator/tmuxinator)
################################################################################
bootstrap_echo "Step 5: Setting up Tmuxinator..."
if [ ! -d "${HOME}/.tmuxinator/" ]; then
mkdir "${HOME}/.tmuxinator"
fi
if [ "$DEFAULT_SHELL" == "zsh" ]; then
bootstrap_echo "Installing zsh completions..."
wget https://raw.githubusercontent.com/tmuxinator/tmuxinator/master/completion/tmuxinator.zsh -O /usr/local/share/zsh/site-functions/_tmuxinator
fi
cp "${BOOTSTRAP_DIR}/lib/default.yml" "${HOME}/.tmuxinator/"
bootstrap_echo "Done!"
################################################################################
# 6. Setup dotfiles (http://jsua.co/dotfiles)
################################################################################
# bootstrap_echo "Step 7: Installing dotfiles..."
# if [[ -d $DOTFILES_DIR ]]; then
# bootstrap_echo "Backing up old dotfiles to ${HOME}/old_dotfiles_bak..."
# rm -rf "$OLD_DOTFILES_BAK"
# cp -R "$DOTFILES_DIR" "$OLD_DOTFILES_BAK"
# rm -rf "$DOTFILES_DIR"
# fi
# bootstrap_echo "Cloning dotfiles repo to ${DOTFILES_DIR} ..."
# git clone "$DOTFILES_REPO_URL" -b "$DOTFILES_BRANCH" "$DOTFILES_DIR"
# # shellcheck source=/dev/null
# source "${DOTFILES_DIR}/install.sh"
bootstrap_echo "Done!"
git config --global user.name "${FULL_NAME}"
git config --global user.email "${EMAIL}"
rm -rf "$BOOTSTRAP_DIR"
echo
echo "**********************************************************************"
echo "**********************************************************************"
echo "**** ****"
echo "**** Mac Bootstrap script complete! Please restart your computer. ****"
echo "**** ****"
echo "**** ****"
echo "**********************************************************************"
echo "**********************************************************************"
echo