-
Notifications
You must be signed in to change notification settings - Fork 4
/
bootstrap.sh
executable file
·308 lines (242 loc) · 9.17 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
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
#!/usr/bin/env bash
#/ Usage: bootstrap.sh [OPTIONS]
#/ Setup macOS development box.
#/
#/ -d, --debug run in debug mode
#/ -h, --help show help
# With liberal pilfering from https://github.com/MikeMcQuaid/strap
function show_usage {
grep '^#/' "$0" | cut -c4- 1>&2
exit 1
}
while true; do
case "$1" in
-d | --debug) DEBUG="1"; shift ;;
-h | --help) show_usage; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ -n "$DEBUG" ]; then
set -x
fi
#
# Logging
#
RESET='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
abort() { echo -e "${RED}==❗️ $*${RESET}" >&2; exit 1; }
step() { echo -e "\n${GREEN}==🚀 $*${RESET}"; }
log() { echo -e "$*"; }
warn() { echo -e "${YELLOW}==⚠️ $*${RESET}"; }
ok() { echo -e "${GREEN}==✅${RESET}"; }
[ "$USER" = "root" ] && abort "Run bootstrap as yourself, not root."
groups | grep $Q admin || abort "Add $USER to the admin group."
DOTFILES_FULL_PATH="$(cd "$(dirname "$0")" && pwd)"
HOSTNAME=$(hostname -f)
step "Ensure Homebrew is installed"
if [[ ! -x /opt/homebrew/bin/brew ]]; then
log "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
ok
step "Configure enough git to get started"
if ! git config user.name >/dev/null; then
git config --global user.name "Ray Grasso"
fi
if ! git config user.email >/dev/null; then
git config --global user.email "ray.grasso@gmail.com"
fi
if ! git config github.user >/dev/null; then
git config --global github.user grassdog
fi
# No git 2.x warning message when pushing
if ! git config push.default >/dev/null; then
git config --global push.default simple
fi
ok
step "Ensure common directories and file exist"
mkdir -p ~/dev
mkdir -p ~/.config
mkdir -p ~/.ssh
[ ! -r ~/dev/scripts ] && [ -d $HOME/Library/CloudStorage/Dropbox/Code/ ] && ln -s $HOME/Library/CloudStorage/Dropbox/Code/scripts ~/dev
touch ~/.z
ok
step "Ensuring dotfiles repo is downloaded and up to date"
if [ ! -d $HOME/.dotfiles ]; then
git clone https://github.com/grassdog/dotfiles.git $HOME/.dotfiles
else
cd $HOME/.dotfiles && git pull origin main --autostash
fi
ok
function link_files {
local SOURCE_DIR=$1
local TARGET_DIR=${2:-$HOME}
log "Linking files in $SOURCE_DIR"
for f in $(find $SOURCE_DIR -maxdepth 1 -mindepth 1 \( ! -name .DS_Store ! -name README.md ! -name _dontlink ! -name .config ! -name bootstrap.sh \)); do
log "Linking $f to $TARGET_DIR"
ln -sf "$f" "$TARGET_DIR"
done
}
step "Link dotfiles"
[ -d $DOTFILES_FULL_PATH/files ] && link_files $DOTFILES_FULL_PATH/files
[ -d $DOTFILES_FULL_PATH/hosts/$HOSTNAME ] && link_files $DOTFILES_FULL_PATH/hosts/$HOSTNAME
ok
step "Link dotfiles in Dropbox"
[ -d $HOME/Library/CloudStorage/Dropbox/Backups/hosts/$HOSTNAME ] && link_files $HOME/Library/CloudStorage/Dropbox/Backups/hosts/$HOSTNAME
ok
step "Link .config files"
link_files $DOTFILES_FULL_PATH/files/.config $HOME/.config
ok
if [ -r ~/.Brewfile ]; then
step "Install linked Brewfiles"
brew bundle -v --no-upgrade --file=~/.Brewfile
ok
fi
step "Install apps from the App Store"
mas install 1365531024 # 1Blocker - Ad Blocker
mas install 1569813296 # 1Password for Safari
mas install 1091189122 # Bear
mas install 1451400394 # bookmarker for pinboard
mas install 1465439395 # Dark Noise
mas install 1055511498 # Day one
mas install 288545208 # Instapaper
# mas install 2145332318 # Ivory for Mastodon
mas install 1622835804 # Kagi Search for Safari
mas install 1614730313 # MusicBox: Save Music for Later
mas install 1289197285 # MindNode 6
mas install 1006739057 # NepTunes
mas install 1505432629 # NotePlan
mas install 1596506190 # Play: Save Videos Watch Later
mas install 1376402589 # StopTheMadness
# mas install 2112214276 # Supercopy for Safari (1.0)
mas install 1475387142 # Tailscale
mas install 904280696 # Things
mas install 1225570693 # Uylsses
mas install 1621370168 # WorldWideWeb – Desktop
ok
if [ -r $DOTFILES_FULL_PATH/hosts/$HOSTNAME/bootstrap.sh ]; then
step "Run host specific bootstrap script"
"$DOTFILES_FULL_PATH/hosts/$HOSTNAME/bootstrap.sh"
ok
fi
step "Set shell to zsh"
[[ $(echo $SHELL) != $(which zsh) ]] && sudo dscl . -create /Users/${whoami} UserShell $(which zsh)
ok
step "Install vim config"
mkdir -p ~/.cache/vim/tmp/undo
mkdir -p ~/.cache/vim/tmp/backups
ln -sf $DOTFILES_FULL_PATH/files/.vim $HOME
ln -sf $DOTFILES_FULL_PATH/files/.vim/vimrc $HOME/.vimrc
mkdir -p $HOME/.vim/autoload
[ ! -f $HOME/.vim/autoload/plug.vim ] && curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
ok
step "Install neovim config"
~/.config/nvim/setup.sh
ok
# Have to copy this as a symlink doesn't seem to work
step "Copy Karabiner config"
mkdir -p ~/.config/karabiner
[ ! -f $HOME/.config/karabiner/karabiner.json ] && [ -d $HOME/Library/CloudStorage/Dropbox/Backups/ ] && cp "$HOME/Library/CloudStorage/Dropbox/Backups/karabiner/karabiner.json" "$HOME/.config/karabiner"
ok
step "Install tmux config"
mkdir -p ~/.tmux/plugins
[ ! -d $HOME/.tmux/plugins/tpm ] && git clone https://github.com/tmux-plugins/tpm $HOME/.tmux/plugins/tpm
ok
step "Install asdf plugins"
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf plugin add elixir https://github.com/asdf-vm/asdf-elixir.git
asdf plugin update --all
ok
step "Install default asdf versions"
while read plugin; do
asdf install $plugin
done < ~/.tool-versions
ok
step "Install service menu items"
mkdir -p ~/Library/Services
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in $(find $DOTFILES_FULL_PATH/services -maxdepth 1 -mindepth 1 ! -name .DS_Store); do
log "Copying $f to ~/Library/Services"
cp -R "$f" ~/Library/Services
done
IFS=$SAVEIFS
ok
step "Install fonts"
mkdir -p ~/Library/Fonts
[ -d $HOME/Library/CloudStorage/Dropbox/Backups/ ] && find ~/Library/CloudStorage/Dropbox/Backups/Fonts/ToInstall -name '*.ttf' -o -name '*.otf' -exec cp {} ~/Library/Fonts \;
chmod -x ~/Library/Fonts/*.ttf
chmod -x ~/Library/Fonts/*.otf
ok
step "Install spelling files"
[ -d $HOME/Library/CloudStorage/Dropbox/Backups/ ] && ln -sf $HOME/Dropbox/Backups/Spell/aspell.en.pws "$HOME/.aspell.en.pws"
[ -d $HOME/Library/CloudStorage/Dropbox/Backups/ ] && ln -sf $HOME/Dropbox/Backups/Spell/aspell.en.prepl "$HOME/.aspell.en.prepl"
ok
step "Write macOS defaults"
# Autohide the dock
defaults write com.apple.dock autohide -bool true
# Full keyboard access to controls
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# expanded save panel
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
# expanded print panel
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
# no launch warnings
defaults write com.apple.LaunchServices LSQuarantine -bool false
# no press and hold
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# no auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# copy from Quicklook windows
defaults write com.apple.finder QLEnableTextSelection -bool true
# full path in window titles
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# debug menu in safari enabled
defaults write com.apple.Safari IncludeDebugMenu -bool true
# increase window resize speed
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
# save screenshots in PNG format
defaults write com.apple.screencapture type -string png
# avoid creating DS_Store files on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
# disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# disable the warning before emptying the Trash
defaults write com.apple.finder WarnOnEmptyTrash -bool false
# empty Trash securely
defaults write com.apple.finder EmptyTrashSecurely -bool true
# make Dock icons of hidden applications translucent
defaults write com.apple.dock showhidden -bool true
# add a context menu item for showing the Web Inspector in web views
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
# dock icon size is 38 pixels
defaults write com.apple.dock tilesize -int 38
# menu bar clock
defaults write com.apple.menuextra.clock DateFormat -string "d MMM h:mm a"
# time machine off
defaults write com.apple.TimeMachine AutoBackup -bool false
# disable smart quotes
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# disable smart dashes
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# finder show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# finder show status bar
defaults write com.apple.finder ShowStatusBar -bool true
# finder show path bar
defaults write com.apple.finder ShowPathbar -bool true
# use column view in all Finder windows by default
defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
# no feedback sound when changing volume.defaults
defaults write NSGlobalDomain com.apple.sound.beep.feedback -bool false
ok
step "Check FileVault is enabled"
if fdesetup status | grep $Q "FileVault is Off"; then
warn "Please run 'sudo fdesetup enable -user \"$USER\"' to enable full-disk encryption."
else
ok
fi