forked from joshukraine/mac-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
249 lines (182 loc) · 8.66 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
#!/usr/bin/env bash
################################################################################
# bootstrap
#
# This script is intended to set up a new Mac computer with my dotfiles and
# other development preferences.
################################################################################
# TODO add checks for each step to skip them if the script is run again
# could set an environment variable for this, for each step
# then say "has this step run yet?"
# Thank you, thoughtbot!
bootstrap_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\\n[BOOTSTRAP] $fmt\\n" "$@"
}
################################################################################
# VARIABLE DECLARATIONS
################################################################################
osname=$(uname)
# TODO add repo branch selection back for testing
export COMMANDLINE_TOOLS="/Library/Developer/CommandLineTools"
export OLD_DOTFILES_BAK="${HOME}/old_dotfiles_bak"
export DOTFILES_REPO_URL="https://github.com/JSaterdalen/dotfiles.git"
export DOTFILES_DIR="${HOME}/dotfiles"
export BOOTSTRAP_REPO_URL="https://github.com/JSaterdalen/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_DOTFILES_BRANCH="main"
DEFAULT_TIME_ZONE="America/Chicago"
################################################################################
# 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 "******* https://github.com/JSaterdalen/mac-bootstrap *******"
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 "\\nDotfiles will be cloned from:
==> %s.\\n" "$DOTFILES_REPO_URL"
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 desired time zone.
To view available options run \`sudo systemsetup -listtimezones\`
(Leave blank for default: %s)\\n" "$DEFAULT_TIME_ZONE"
read -r -p "> " TIME_ZONE
export TIME_ZONE=${TIME_ZONE:-$DEFAULT_TIME_ZONE}
# printf "\\nWhich version of Node.js would you like to install?
# Available versions: https://semver.io/node/versions
# (Leave blank for default: %s)\\n" "$DEFAULT_NODEJS_VERSION"
# read -r -p "> " ASDF_NODEJS_VERSION
# export ASDF_NODEJS_VERSION=${ASDF_NODEJS_VERSION:-$DEFAULT_NODEJS_VERSION}
# printf "\\nWhich version of Ruby would you like to install?
# Available versions: https://raw.githubusercontent.com/postmodern/ruby-versions/master/ruby/versions.txt
# (Leave blank for default: %s)\\n" "$DEFAULT_RUBY_VERSION"
# read -r -p "> " ASDF_RUBY_VERSION
# export ASDF_RUBY_VERSION=${ASDF_RUBY_VERSION:-$DEFAULT_RUBY_VERSION}
printf "\\nLooks good. Here's what we've got so far.\\n"
printf "Computer name: ==> [%s]\\n" "$COMPUTER_NAME"
printf "Host name: ==> [%s]\\n" "$HOST_NAME"
printf "Time zone: ==> [%s]\\n" "$TIME_ZONE"
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" "$BOOTSTRAP_DIR"
################################################################################
# 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" # todo reenable
bootstrap_echo "Done!"
################################################################################
# 4. Setup dotfiles (https://github.com/JSaterdalen/dotfiles)
################################################################################
bootstrap_echo "Step 4: 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" "$DOTFILES_DIR"
# shellcheck source=/dev/null
source "${DOTFILES_DIR}/install.sh"
bootstrap_echo "Done!"
rm -rf "$BOOTSTRAP_DIR"
echo
echo "**********************************************************************"
echo "**********************************************************************"
echo "**** ****"
echo "**** Mac Bootstrap script complete! Please restart your computer. ****"
echo "**** ****"
echo "**** https://github.com/JSaterdalen/mac-bootstrap ****"
echo "**** ****"
echo "**********************************************************************"
echo "**********************************************************************"
echo