-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
446 lines (404 loc) · 14 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#!/usr/bin/env zsh
# shellcheck shell=bash
################################################################################
# bootstrap
#
# This script is intended to set up a new Mac computer with my homefiles and
# other preferences.
################################################################################
# Thank you, thoughtbot!
bootstrap_echo() {
local fmt="$1"
shift
# shellcheck disable=SC2059
printf "\\n[INFO] $fmt\\n" "$@"
}
bootstrap_error() {
local fmt="$1"
shift
# shellcheck disable=SC2059
printf "\\n[ERROR] $fmt\\n" "$@"
exit 1
}
bootstrap_done() {
bootstrap_echo "Step $1 \\e[0;32m[✔]\\e[0m"
}
################################################################################
# VARIABLE DECLARATIONS
################################################################################
step='1'
DEFAULT_TIME_ZONE="Europe/Paris"
ACTUAL_COMPUTER_NAME="$(scutil --get ComputerName)"
HOMEBREW_PREFIX="/usr/local"
GATEKEEPER_DISABLE="Yes"
MACOS_DEFAULT_URL="https://raw.githubusercontent.com/deild/mac-bootstrap/main/macos-defaults"
DEFAULT_PASSPHRASE=""
QUIET=false
while getopts ":q" opts; do
case "${opts}" in
q)
QUIET=true
;;
*)
bootstrap_error "unknown option -${OPTARG}"
;;
esac
done
################################################################################
# Make sure we're on a Mac before continuing
################################################################################
if [ "$(uname)" != "Darwin" ]; then
bootstrap_error "Oops, it looks like you're using a non-Darwin system. This script
only supports macOS. Exiting..."
fi
################################################################################
# Welcome and setup
################################################################################
printf '\n'
printf '************************************************************************\n'
printf '******* ******\n'
printf '******* Welcome to Mac Bootstrap! ******\n'
printf '******* ******\n'
printf '************************************************************************\n'
printf '\n'
# Authenticate
if ! sudo -nv &> /dev/null; then
printf 'Before we get started, we need to have sudo access\n'
printf 'Enter your password (for sudo access):\n'
sudo /usr/bin/true
# Keep-alive: update existing `sudo` time stamp until bootstrap has finished
while true; do
sudo -n /usr/bin/true
sleep 60
kill -0 "$$" || exit
done 2> /dev/null &
fi
set -e
if ! $QUIET; then
printf "Let's get some infos about your setup.\\n"
fi
if ! $QUIET; then
printf "\\nEnter your desired time zone.
To view available options run 'sudo systemsetup -listtimezones' in other terminal
Leave blank for default: %s)\\n>_ " "$DEFAULT_TIME_ZONE"
read -r TIME_ZONE
fi
export TIME_ZONE=${TIME_ZONE:-$DEFAULT_TIME_ZONE}
if ! $QUIET; then
printf '\nEnter your desired computer name for your Mac. (Leave blank for default: %s)\n>_ ' "$ACTUAL_COMPUTER_NAME"
read -r COMPUTER_NAME
fi
export COMPUTER_NAME="${COMPUTER_NAME:-$ACTUAL_COMPUTER_NAME}"
if ! $QUIET; then
printf '\nEnter url for masOS defaults file. (Leave blank for default: %s)\n>_ ' "$MACOS_DEFAULT_URL"
read -r MACOS_URL
fi
export MACOS_URL="${MACOS_URL:-$MACOS_DEFAULT_URL}"
if ! $QUIET; then
printf 'Do you want disable Gatekeeper? (Y/n) \n>_ '
read -r REPLY
if [[ $REPLY =~ ^[Nn]$ ]]; then
GATEKEEPER_DISABLE="No"
fi
fi
if ! $QUIET; then
printf '\nEnter a passphrase for generete ssh key. (Leave blank for default: %s)\n>_ ' "$DEFAULT_PASSPHRASE"
read -r PASSPHRASE
fi
export PASSPHRASE="${PASSPHRASE:-$DEFAULT_PASSPHRASE}"
printf "\\nLooks good. Here's what we've got so far.\\n"
bootstrap_echo "Time zone: [%s]" "$TIME_ZONE"
bootstrap_echo "Computer name: [%s]" "$COMPUTER_NAME"
bootstrap_echo "Disable Gatekeeper: [%s]" "$GATEKEEPER_DISABLE"
bootstrap_echo "macos defaults file: [%s]" "$MACOS_URL"
bootstrap_echo "Passphrase [%s]" "$PASSPHRASE"
printf '\n'
if ! $QUIET; then
printf 'Continue? (y/N) \n>_ '
read -r REPLY
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
bootstrap_echo "Exit on demand"
exit 0
fi
fi
set -e
################################################################################
# Set the timezone; see `sudo systemsetup -listtimezones` for other values
################################################################################
bootstrap_echo "Step $step: Set the timezone to $TIME_ZONE"
sudo systemsetup -settimezone "$TIME_ZONE" > /dev/null
bootstrap_done "$((step++))"
################################################################################
# Set computer name (as done via System Preferences → Sharing)
################################################################################
bootstrap_echo "Step $step: Set computer name to $COMPUTER_NAME"
if [ "$COMPUTER_NAME" != "$ACTUAL_COMPUTER_NAME" ]; then
sudo scutil --set ComputerName "$COMPUTER_NAME"
sudo scutil --set HostName "$COMPUTER_NAME"
sudo scutil --set LocalHostName "$COMPUTER_NAME"
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$COMPUTER_NAME"
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
fi
bootstrap_done "$((step++))"
################################################################################
# Install Apple's Command Line Tools
################################################################################
bootstrap_echo "Step $step: Ensuring Apple's command line tools are installed"
# Checks if path to command line tools exist
# Credit: https://apple.stackexchange.com/questions/219507/best-way-to-check-in-bash-if-command-line-tools-are-installed
if command -v xcode-select >&- && xpath=$(xcode-select --print-path) \
&& test -d "${xpath}" && test -x "${xpath}"; then
bootstrap_echo "Apple's command line tools are already installed."
else
bootstrap_echo "Installing Apple's command line tools"
xcode-select --install
while ! command -v xcode-select >&-; do
sleep 60
done
fi
bootstrap_done "$((step++))"
################################################################################
# Gatekeeper
################################################################################
bootstrap_echo "Step $step: Disable or enable Gatekeeper control"
if [[ $GATEKEEPER_DISABLE =~ Yes ]]; then
sudo spctl --master-disable
else
sudo spctl --master-enable
fi
bootstrap_done "$((step++))"
################################################################################
# Homebrew
################################################################################
bootstrap_echo "Step $step: Ensuring Homebrew is installed and updated"
if [ -d "$HOMEBREW_PREFIX" ]; then
if ! [ -r "$HOMEBREW_PREFIX" ]; then
sudo chown -vR "$(whoami):admin" $HOMEBREW_PREFIX
fi
else
sudo mkdir "$HOMEBREW_PREFIX"
sudo chflags norestricted "$HOMEBREW_PREFIX"
sudo chown -vR "$(whoami):admin" "$HOMEBREW_PREFIX"
fi
if ! command -v brew > /dev/null; then
bootstrap_echo "Installing Homebrew"
zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
export PATH="/usr/local/bin:$PATH"
fi
brew update
bootstrap_done "$((step++))"
################################################################################
bootstrap_echo "Step $step: Disable Homebrew analytics"
if [ "$(brew analytics)" != "Analytics are disabled." ]; then
brew analytics off
fi
bootstrap_done "$((step++))"
###############################################################################
# Download Rustup and install Rust
if ! command -v rustup; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
cargo install -q -- cargo-outdated
cargo install -q -- cargo-release
###############################################################################
# Homebrew formula
###############################################################################
bootstrap_echo "Step $step: Install or upgrade formula dependencies"
brew tap "homebrew/bundle"
brew bundle --file=- << EOF
tap "homebrew/core"
tap "jez/formulae"
brew "asciidoctor"
brew "freetype"
brew "gettext"
brew "libffi"
brew "pcre"
brew "readline"
brew "sqlite"
brew "xz"
#brew "python@3.9"
#brew "ansible"
brew "autoconf"
brew "automake"
brew "bat"
brew "boost"
#brew "circleci"
brew "curl"
brew "exiftool"
brew "gmp"
brew "libunistring"
brew "lame"
brew "xvid"
brew "ffmpeg"
brew "findutils"
brew "mpfr"
brew "gawk"
brew "gd"
brew "git"
brew "git-filter-repo"
brew "git-lfs"
brew "glib-networking"
brew "gnu-sed"
brew "go"
brew "pkg-config"
brew "gts"
brew "libtool"
brew "graphviz"
brew "gtk-doc"
brew "hledger"
brew "htop"
brew "hugo"
brew "libgit2"
brew "libmypaint"
brew "libressl"
brew "node"
brew "nvm"
brew "openfortivpn"
brew "openssh"
brew "p7zip"
brew "pandoc"
brew "py2cairo"
brew "pygobject3"
brew "ruby-build"
brew "rbenv"
brew "rsync"
brew "ruby"
brew "shellcheck"
brew "shfmt"
brew "shunit2"
brew "telnet"
brew "texinfo"
brew "tmux"
brew "tree"
brew "vifm"
brew "vim"
brew "youtube-dl"
brew "jez/formulae/pandoc-sidenote"
EOF
bootstrap_done "$((step++))"
###############################################################################
# Homebrew cask
###############################################################################
bootstrap_echo "Step $step: Install or upgrade cask"
brew bundle --file=- << EOF
tap "homebrew/cask-fonts"
tap "homebrew/cask"
tap "homebrew/cask-versions"
cask "alacritty"
cask "osxfuse"
cask "1password"
cask "alt-tab"
cask "appcleaner"
cask "basictex"
cask "brave-browser"
cask "calibre"
#cask "countdown"
#cask "epoch-flip-clock"
cask "font-sauce-code-pro-nerd-font"
cask "fork"
#cask "grid-clock"
cask "imageoptim"
cask "kitty"
cask "onyx"
cask "remember-the-milk"
cask "slack"
cask "teamviewer"
cask "the-unarchiver"
cask "tor-browser"
cask "vagrant"
cask "veracrypt"
#cask "virtualbox"
cask "visual-studio-code"
cask "vlc"
#cask "xquartz"
cask "zoom"
brew "encfs"
brew "ntfs-3g"
EOF
brew cleanup -s --prune 1
if ! command -v virtualbox; then
if ! brew cask install virtualbox; then
printf 'Continue? (y/N) \n>_ '
read -r REPLY
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
bootstrap_echo "Exit on demand"
exit 0
fi
fi
fi
bootstrap_done "$((step++))"
################################################################################
# zsh plugin
################################################################################
bootstrap_echo "Step $step: Install or upgrade zsh plugin"
if ! [ -f ~/.config/powerlevel10k/powerlevel10k.zsh-theme ]; then
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.config/powerlevel10k
echo 'source ~/.config/powerlevel10k/powerlevel10k.zsh-theme' ~/.zshrc >> !
fi
brew bundle --file=- << EOF
brew "zsh-autosuggestions"
brew "zsh-syntax-highlighting"
EOF
bootstrap_done "$((step++))"
################################################################################
# Install dotfiles
################################################################################
bootstrap_echo "Step $step: Install or upgrade and then reload dotfiles"
if [ ! -d "$HOME/.cfg/" ]; then
curl -fsSOk https://bitbucket.org/!api/2.0/snippets/deild/Gr7nX9/c752be0b868270dbda0959e845eabfa59995c5ce/files/home-cfg.sh | bash
else
git --git-dir="$HOME/.cfg/" --work-tree="$HOME" checkout
fi
bootstrap_done "$((step++))"
################################################################################
# Ruby
################################################################################
bootstrap_echo "Step $step: Check which Ruby and Gem installs we are using at this point"
bootstrap_echo 'Ruby: [%s]\n' "$(command -v ruby);$(ruby -v)"
bootstrap_echo 'Gem: [%s]\n' "$(command -v gem);$(gem -v)"
gem update --system --quiet
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))
bootstrap_done "$((step++))"
###############################################################################
bootstrap_echo "Step $step: Generate ed25519 and RSA key"
if ! $QUIET; then
[ ! -f ~/.ssh/id_ed25519 ] && ssh-keygen -t ed25519 -a 100 -q -N "$PASSPHRASE"
[ ! -f ~/.ssh/id_rsa ] && ssh-keygen -t rsa -b 4096 -o -a 100 -q -N "$PASSPHRASE"
else
[ ! -f ~/.ssh/id_ed25519 ] && ssh-keygen -t ed25519 -a 100 -q -N "$PASSPHRASE" -f ~/.ssh/id_ed25519
[ ! -f ~/.ssh/id_rsa ] && ssh-keygen -t rsa -b 4096 -o -a 100 -q -N "$PASSPHRASE" -f ~/.ssh/id_rsa
fi
bootstrap_done "$((step++))"
###############################################################################
bootstrap_echo "Step $step: Prefer tools installed by Homebrew according to the PATH environment variable"
UB_POS=$(echo "$PATH" | awk '{print index($1, "/usr/bin")}')
ULB_POS=$(echo "$PATH" | awk '{print index($1, "/usr/local/bin")}')
if [ ! "$ULB_POS" -eq "0" ] && [ ! "$ULB_POS" -gt "$UB_POS" ]; then
PATH="/usr/local/bin:${PATH//:\/usr\/local\/bin:/:}"
export PATH
fi
bootstrap_done "$((step++))"
################################################################################
# Set macOS preferences
################################################################################
bootstrap_echo "Step $step: Set macOS preferences"
if [[ $MACOS_URL =~ ^http ]]; then
bootstrap_echo "Load from url $MACOS_DEFAULT_URL"
curl -fsSL "$MACOS_URL" | zsh
else
bootstrap_echo "Load from local file $MACOS_URL"
[ -f "$MACOS_URL" ] && zsh "$MACOS_URL"
fi
bootstrap_done "$((step++))"
################################################################################
# End
################################################################################
printf '\n'
printf '************************************************************************\n'
printf '**** ******\n'
printf '**** Mac Bootstrap complete! Please restart your computer. ******\n'
printf '**** ******\n'
printf '************************************************************************\n'
printf '\n'
# vim:syntax=sh:filetype=sh