-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·396 lines (316 loc) · 11.2 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
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
#!/usr/bin/env bash
main() {
# Ask for sudo password upfront
sudo -v
remap_caps_lock_to_escape
install_homebrew
install_from_brewfile
make_fish_default_shell
set_macos_defaults
update_hosts_file
setup_dnscrypt_proxy
configure_dock
install_rustup
install_dotfiles
setup_neovim
}
function remap_caps_lock_to_escape() {
# /Library/LaunchAgents/com.user.remap_keys.plist
sudo cp remap_keys.sh /usr/local/bin
sudo chmod 0755 /usr/local/bin/remap_keys.sh
sudo chown root:wheel /usr/local/bin/remap_keys.sh
cp com.user.remap_keys.plist $HOME/Library/LaunchAgents/
success "CapsLock remapped to Escape!"
}
function install_homebrew() {
if hash brew 2>/dev/null; then
info "Homebrew already installed"
else
url=https://raw.githubusercontent.com/Homebrew/install/master/install
if /usr/bin/ruby -e "$(curl -fsSL ${url})"; then
success "Homebrew installed!"
else
error "Homebrew installation failed!"
exit 1
fi
fi
}
function install_from_brewfile() {
# brew services is automatically installed when run.
brew services > /dev/null 2>&1
success "Brew services installed!"
# Install packages specified in Brewfile
brew bundle
success "Brewfile packages installed!"
}
function make_fish_default_shell() {
fish_shell="/usr/local/bin/fish"
config="/etc/shells"
user=$USER
current_shell=$(finger $user | grep 'Shell: *' | cut -f3 -d ":" | xargs)
if [ ! $(grep $fish_shell $config) ]; then
echo "$fish_shell" | sudo tee -a $config
fi
if [ "$current_shell" != "$fish_shell" ]; then
sudo chsh -s `which fish` $user
success "Default shell changed to fish!"
fi
symlink_dotfile "fish_aliases"
symlink_dotfile "fish_variables"
symlink_dotfile "config.fish" "$HOME/.config/fish/config.fish"
# Do not install OMF yet
# omf_directory=~/.local/share/omf
# if [ ! -d "$omf_directory" ]; then
# curl -l https://get.oh-my.fish > install-omf
# fish install --path=$omf_directory --config=~/.config/omf
# rm install-omf
# fi
}
function set_macos_defaults() {
set_global_defaults
set_software_update_defaults
set_menubar_defaults
set_finder_defaults
set_safari_defaults
enable_firewall
success "MacOS defaults set!"
}
function set_global_defaults() {
# Close any open System Preferences panes, to prevent them from overriding
# settings we
osascript -e 'tell application "System Preferences" to quit'
# Show the ~/Library folder.
chflags nohidden ~/Library
# Disable Guest user
sudo defaults write /Library/Preferences/com.apple.loginwindow GuestEnabled -bool FALSE
# Use a dark menu bar / dock
defaults write -g AppleInterfaceStyle Dark
# Disable system sounds
# defaults write -g com.apple.sound.uiaudio.enabled -bool false
defaults write com.apple.systemsound "com.apple.sound.uiaudio.enabled" -int 1
# Don't show Siri in the menu bar
defaults write com.apple.Siri StatusMenuVisible -bool false
# Disable auto-correct
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
defaults write -g WebAutomaticSpellingCorrectionEnabled -bool false
# Disable Dashboard
defaults write com.apple.dashboard mcx-disabled -bool true
# Require password immediately after sleep or screen saver begins"
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
# Disable crash reporter
sudo defaults write com.apple.CrashReporter DialogType none
launchctl unload -w /System/Library/LaunchAgents/com.apple.ReportCrash.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist
sudo launchctl unload -w com.apple.ReportPanic
}
function set_software_update_defaults() {
# Enable the automatic update check
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Download newly available updates in background
defaults write com.apple.SoftwareUpdate AutomaticDownload -int 1
# Install System data files & security updates
defaults write com.apple.SoftwareUpdate CriticalUpdateInstall -int 1
}
function set_menubar_defaults() {
defaults write com.apple.systemuiserver menuExtras -array \
"/System/Library/CoreServices/Menu Extras/Bluetooth.menu" \
"/System/Library/CoreServices/Menu Extras/Clock.menu" \
"/System/Library/CoreServices/Menu Extras/Displays.menu" \
"/System/Library/CoreServices/Menu Extras/Volume.menu"
# Restart SystemUIServer for changes to take effect
killall SystemUIServer
}
function enable_night_shift() {
CORE_BRIGHTNESS="/var/root/Library/Preferences/com.apple.CoreBrightness.plist"
ENABLE='{
CBBlueReductionStatus = {
AutoBlueReductionEnabled = 1;
BlueLightReductionDisableScheduleAlertCounter = 3;
BlueLightReductionSchedule = {
DayStartHour = 8;
DayStartMinute = 0;
NightStartHour = 22;
NightStartMinute = 0;
};
BlueReductionEnabled = 0;
BlueReductionMode = 1;
BlueReductionSunScheduleAllowed = 1;
Version = 1;
};
}'
defaults write $CORE_BRIGHTNESS "CBUser-0" "$ENABLE"
defaults write $CORE_BRIGHTNESS "CBUser-$(dscl . -read $HOME GeneratedUID | sed 's/GeneratedUID: //')" "$ENABLE"
}
function set_finder_defaults() {
# Avoid creating .DS_Store files on network or USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Show all files (including dotfiles)
defaults write com.apple.finder AppleShowAllFiles -bool true
# Open new window to User Home
defaults write com.apple.finder NewWindowTarget -string PfHm
# Keep folders on top when sorting by name (restart Finder):
defaults write com.apple.Finder _FXSortFoldersFirst -bool true
# Restart Finder to make changes effective now
killall -9 Finder
}
function set_safari_defaults() {
info "Make sure the terminal has 'Full Disk Access' enabled, otherwise Safari
settings won't work"
info "Press ENTER to confirm."
read
# Safari opens with all windows from last session
defaults write -app Safari AlwaysRestoreSessionAtLaunch -bool true
# Enable "Do Not Track"
defaults write -app Safari SendDoNotTrackHTTPHeader -bool true
# Show full URLs
defaults write -app Safari ShowFullURLInSmartSearchField -bool true
# New tabs instead of new windows
defaults write -app Safari TargetedClicksCreateTabs -bool true
# Enable the Develop menu and the Web Inspector in Safari
defaults write -app Safari IncludeDevelopMenu -bool true
defaults write -app Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
# Disable AutoFill
defaults write -app Safari AutoFillPasswords -bool false
# Restart Safari to make changes effective now
# osascript -e 'tell application "Safari" to quit'
}
function update_hosts_file() {
# Update hosts file to block known malware, adware etc.
curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts | sudo tee /etc/hosts
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
success "Hosts file updated with "
}
function setup_dnscrypt_proxy() {
# dnscrypt-proxy runs on 53 by defaults, so it needs to be run under root
sudo brew services restart dnscrypt-proxy
sudo networksetup -setdnsservers "Wi-Fi" 127.0.0.1
success "Dnscrypt-proxy configured & running!"
}
function enable_firewall() {
local fw="sudo /usr/libexec/ApplicationFirewall/socketfilterfw"
# Enable the firewall
$fw --setglobalstate on
# Enable logging on the firewall
$fw --setloggingmode on
# Enable stealth mode
# (computer does not respond to PING or TCP connections on closed ports)
$fw --setstealthmode on
# # Prevent built-in software as well as code-signed, downloaded software from
# being whitelisted automatically
$fw --setallowsigned off
$fw --setallowsignedapp off
# Restart the firewall (this should remain last)
sudo pkill -HUP socketfilterfw
}
function configure_dock() {
if ! hash dockutil 2>/dev/null; then
error "Dockutil is not installed, but should have been already present!"
exit 1
fi
dockutil --no-restart --remove all
dockutil --no-restart --add "/Applications/System Preferences.app"
dockutil --no-restart --add "/Applications/Safari.app"
dockutil --no-restart --add "/Applications/Notes.app"
dockutil --no-restart --add "/Applications/Alacritty.app"
# Don't show recent applications in Dock
defaults write com.apple.dock show-recents -bool false
# Set the icon size of Dock items to 36 pixels
defaults write com.apple.dock tilesize -int 36
# Don't show Dashboard as a Space
defaults write com.apple.dock dashboard-in-overlay -bool true
# Don't automatically rearrange Spaces based on most recent use:
defaults write com.apple.dock mru-spaces -bool false
# Auto-hide dock
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock autohide-delay -float 0
# Restart Dock to make changes effective now
killall -9 Dock
}
function install_rustup() {
rustup_directory=~/.rustup
if [ -d "$rustup_directory" ]; then
info "rustup already installed"
return
fi
if ! hash rustup-init 2>/dev/null; then
error "rustup-init command not present!"
exit 1
fi
info "Running the rustup installer"
# Run the rustup installer
rustup-init
# Add cargo's bin to $PATH using fish's universal variable
fish -c 'set -U fish_user_paths $HOME/.cargo/bin $fish_user_paths'
# Install Rust Language Server
rustup component add rls rust-analysis rust-src
success "Rustup installed!"
}
function install_dotfiles {
symlink_dotfile tmux.conf
symlink_dotfile gitconfig
symlink_dotfile init.vim $HOME/.config/nvim/init.vim
symlink_dotfile alacritty.yml $HOME/.config/alacritty/alacritty.yml
}
function setup_neovim {
autoload_file=$HOME/.local/share/nvim/site/autoload/plug.vim
if [ ! -f $autoload_file ]; then
# Install vim-plug for neovim
curl -fLo $autoload_file --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
success "vim-plug for neovim installed"
nvim --headless +PlugInstall +qa
success "Neovim plugins installed"
else
info "vim-plug for neovim is already installed"
fi
}
function symlink_dotfile {
local fname="$1"
local destination="$2"
local dotfiles_dir=$(pwd)/dotfiles
local default_destination=$HOME/.$fname
local source=$dotfiles_dir/$fname
if [ -z "$destination" ]; then
ln -fs $source $default_destination
else
mkdir -p $(dirname $destination)
ln -fs $source $destination
fi
}
function colored_echo() {
local exp="$1";
local color="$2";
local arrow="$3";
if ! [[ $color =~ '^[0-9]$' ]] ; then
case $(echo $color | tr '[:upper:]' '[:lower:]') in
black) color=0 ;;
red) color=1 ;;
green) color=2 ;;
yellow) color=3 ;;
blue) color=4 ;;
magenta) color=5 ;;
cyan) color=6 ;;
white|*) color=7 ;; # white or invalid color
esac
fi
tput bold;
tput setaf "$color";
echo "$arrow $exp";
tput sgr0;
}
function info() {
colored_echo "$1" blue "========>"
}
function substep() {
colored_echo "$1" magenta "===="
}
function success() {
colored_echo "$1" green "========>"
}
function error() {
colored_echo "$1" red "========>"
}
main "$@"