forked from mavam/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·363 lines (348 loc) · 15.1 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
#!/bin/sh
#
# This script prepares a productive environment for a user.
set -e
usage() {
printf "usage: %s [aspect...] \n" $(basename $0)
echo
echo "aspects"
echo
echo " system adjust system defaults for productivity"
echo " homebrew setup Homebrew and install bundled packages"
echo " dotfiles setup dotfiles and install plugins"
echo " postfix setup postfix as GMail relay"
echo " tmux install Tmux plugins"
echo " vim install Vim plugins"
echo " zsh setup Zsh as login shell"
echo " update update system"
echo
echo "without any arguments, all aspects will be setup (in the above order)"
echo
}
log() {
yellow="\e[0;33m"
magenta="\e[0;35m"
red="\e[0;31m"
reset="\e[0;0m"
printf "$magenta>$red>$yellow>$reset %s\n" "$*" 1>&2
}
# Keeps sudo priviledge alive throughout the execution of this script.
enter_sudo_mode() {
if ! sudo -n true 2> /dev/null; then
log "please enter your password to maintain a sudo session"
sudo -v
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
fi
}
# MacOS-specific system changes. Further inspiration:
# - https://github.com/holman/dotfiles/blob/master/macos/set-defaults.sh
# - https://github.com/mathiasbynens/dotfiles/blob/master/.macos
setup_macos() {
enter_sudo_mode
# -- Updates ----------------------------------------------------------------
# Enable Debug Menu in the Mac App Store
defaults write com.apple.appstore ShowDebugMenu -bool true
# Enable the automatic update check
defaults write com.apple.SoftwareUpdate AutomaticCheckEnabled -bool true
# Check for software updates daily, not just once per week.
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1
# 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
# Automatically download apps purchased on other Macs.
defaults write com.apple.SoftwareUpdate ConfigDataInstall -int 1
# Turn on app auto-update.
defaults write com.apple.commerce AutoUpdate -bool true
# Allow the App Store to reboot machine on macOS updates.
defaults write com.apple.commerce AutoUpdateRestartRequired -bool true
# -- System -----------------------------------------------------------------
# Disable the sound effects on boot.
sudo nvram SystemAudioVolume=" "
# Disable volume key feedback.
defaults write NSGlobalDomain com.apple.sound.beep.feedback -float 0
# Disable the over-the-top focus ring animation.
defaults write NSGlobalDomain NSUseAnimatedFocusRing -bool false
# Increase window resize speed for Cocoa applications.
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
# Expand save panel by default.
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Expand print panel by default.
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true
defaults write NSGlobalDomain PMPrintingExpandedStateForPrint2 -bool true
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Save to disk (not to iCloud) by default.
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Display ASCII control characters using caret notation in standard text
# views. Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`.
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true
# Reveal IP address, hostname, OS version, etc. when clicking the clock in
# the login window.
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
# Restart automatically if the computer freezes.
sudo systemsetup -setrestartfreeze on
# Accelerated playback when adjusting the window size (Cocoa applications).
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
# Show language menu in the top right corner of the boot screen.
sudo defaults write /Library/Preferences/com.apple.loginwindow showInputMenu -bool true
# Disable shadow in screenshots.
defaults write com.apple.screencapture disable-shadow -bool true
# Turn off Dashboard.
defaults write com.apple.dashboard mcx-disabled -boolean true
# Don't automatically rearrange Spaces based on most recent use.
defaults write com.apple.dock mru-spaces -bool false
# Automatically hide and show the Dock.
defaults write com.apple.dock autohide -bool true
# Remove the auto-hiding Dock delay
defaults write com.apple.dock autohide-delay -float 0
# Disable animations when you open an application from the Dock.
defaults write com.apple.dock launchanim -bool false
# Do not show recent applications in Dock.
defaults write com.apple.dock show-recents -bool false
# Disable animations when opening and closing windows.
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false
# -- Keyboard ---------------------------------------------------------------
# Set a really fast key repeat.
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 15
# Disable press-and-hold for keys in favor of key repeat.
defaults write -g ApplePressAndHoldEnabled -bool false
# Disable automatic capitalization.
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled -bool false
# Disable smart dashes.
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable automatic period.
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false
# Disable smart quotes.
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disable auto-correct.
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# -- Finder -----------------------------------------------------------------
# Show the ~/Library folder.
chflags nohidden ~/Library
# Show certain volumes on Desktop.
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true
defaults write com.apple.finder ShowMountedServersOnDesktop -bool true
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool true
# Always open in list view.
defaults write com.apple.Finder FXPreferredViewStyle Nlsv
# Always show the path bar.
defaults write com.apple.finder ShowPathbar -bool true
# Always show the status bar.
defaults write com.apple.finder ShowStatusBar -bool true
# Disable animations.
defaults write com.apple.finder DisableAllAnimations -bool true
# Show all file extensions.
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Keep folders on top when sorting by name.
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# When performing a search, search the current folder by default.
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Disable warning when changing a file extension.
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# 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
# Automatically open a new Finder window when a volume is mounted.
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true
# Expand the following File Info panes:
# "General", "Open with", and "Sharing & Permissions"
defaults write com.apple.finder FXInfoPanesExpanded -dict \
General -bool true \
OpenWith -bool true \
Privileges -bool true
# Allow text selection in Quick Look.
defaults write com.apple.finder QLEnableTextSelection -bool true
# Disable animations when opening a Quick Look window.
defaults write -g QLPanelAnimationDuration -float 0
# Do not warn before emptying the trash.
defaults write com.apple.finder WarnOnEmptyTrash -bool false
# Do not warn when moving files out of iCloud.
defaults write com.apple.finder FXEnableRemoveFromICloudDriveWarning -bool false
# Do not warn before emptying the trash.
defaults write com.apple.finder WarnOnEmptyTrash -bool false
# -- Safari -----------------------------------------------------------------
# Privacy: don’t send search queries to Apple.
defaults write com.apple.Safari UniversalSearchEnabled -bool false
defaults write com.apple.Safari SuppressSearchSuggestions -bool true
# Warn about fraudulent websites.
defaults write com.apple.Safari WarnAboutFraudulentWebsites -bool true
# Block pop-up windows.
defaults write com.apple.Safari WebKitJavaScriptCanOpenWindowsAutomatically -bool false
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaScriptCanOpenWindowsAutomatically -bool false
# Enable Do Not Track.
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true
# Update extensions automatically.
defaults write com.apple.Safari InstallExtensionUpdatesAutomatically -bool true
# Disable AutoFill.
defaults write com.apple.Safari AutoFillFromAddressBook -bool false
defaults write com.apple.Safari AutoFillPasswords -bool false
defaults write com.apple.Safari AutoFillCreditCardData -bool false
defaults write com.apple.Safari AutoFillMiscellaneousForms -bool false
# Show the full URL in the address bar (note: this still hides the scheme).
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true
# Prevent Safari from opening ‘safe’ files automatically after downloading.
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Hide bookmark bar.
defaults write com.apple.Safari ShowFavoritesBar -bool false
# Set up for development.
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true
defaults write com.apple.Safari IncludeDevelopMenu -bool true
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true
defaults write com.apple.Safari "com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled" -bool true
# Add a context menu item for showing the Web Inspector in web views.
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
# -- Tools ------------------------------------------------------------------
# Use plain text mode for new TextEdit documents.
defaults write com.apple.TextEdit RichText -int 0
# Open and save files as UTF-8 in TextEdit.
defaults write com.apple.TextEdit PlainTextEncoding -int 4
defaults write com.apple.TextEdit PlainTextEncodingForWrite -int 4
# Enable the debug menu in Disk Utility.
defaults write com.apple.DiskUtility DUDebugMenuEnabled -bool true
defaults write com.apple.DiskUtility advanced-image-options -bool true
# Load iTerm2 configuration from a predictable location.
defaults write com.googlecode.iterm2.plist PrefsCustomFolder -string "~/.iterm2"
defaults write com.googlecode.iterm2.plist LoadPrefsFromCustomFolder -bool true
}
setup_keyboard_layout() {
# enter_sudo_mode
log "Install keyboard layout"
#cp mavam.keylayout /Library/Keyboard\ Layouts/
}
setup_oh_my_zsh() {
log "install oh my zsh"
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
}
setup_pk10_config() {
log "Setup p10k"
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
p10k configure
}
setup_homebrew() {
if which brew > /dev/null 2>&1; then
log "upgrading existing Homebrew packages"
brew upgrade
elif which ruby > /dev/null 2>&1; then
log "installing Homebrew"
case "$(uname -s)" in
Darwin)
homebrew="Homebrew/install/master/install"
;;
Linux)
homebrew="Linuxbrew/install/master/install"
exit 1
;;
*)
log "$OS not yet supported"
exit 1
;;
esac
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
log "cannot install Homebrew (ruby not found)"
exit 1
fi
log "installing bundled Homebrew packages"
brew bundle "--file=$(dirname "$0")/Brewfile" || true
brew cleanup
}
# Configures the postfix MTA as a GMail relay.
#
# The function asks to a test message to make sure the setup works as expected.
# This can be also done manually:
#
# echo postfix test | mail -s test you@gmail.com
#
# Since macOS Sierra, there are no more logfiles and debugging requires
# invoking this command instead:
#
# sudo log stream --predicate '(process == "smtpd") || (process == "smtp")'
#
# If you have a message in the `mailq` that doesn't find its way out, try to
# force a flush via `sendmail -q` while watching the log stream output.
setup_tmux() {
if [ ! -d ~/.tmux/plugins/tpm ]; then
log "installing Tmux plugins"
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
~/.tmux/plugins/tpm/bin/install_plugins
else
log "updating Tmux plugins"
~/.tmux/plugins/tpm/bin/update_plugins all
fi
}
setup_vim() {
log "installing Vim plugins"
if [ ! -e "$HOME/.vim/autoload/plug.vim" ]; then
curl -fLo "$HOME/.vim/autoload/plug.vim" --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
else
vim -E -s +PlugUpgrade +qa
fi
vim +PlugUpdate +PlugCLean! +qa
log "installing vim-anywhere"
curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash
}
setup_zsh() {
log "setting Zsh as login shell"
zsh=$(which zsh)
if ! fgrep -q "$zsh" /etc/shells; then
log "adding $zsh to /etc/shells"
echo "$zsh" | sudo tee -a /etc/shells > /dev/null
fi
sudo chsh -s "$zsh" $USER
}
main() {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit 0
fi
command=$1
if [ "$command" = "system" ] || [ -z "$command" ]; then
case "$(uname -s)" in
Darwin)
# Close any open System Preferences panes, to prevent them from
# overriding settings we’re about to change.
osascript -e 'tell application "System Preferences" to quit'
log "adjusting macOS defaults"
setup_macos
log "installing XCode comand line developer tools"
xcode-select --install > /dev/null 2>&1 || true
;;
*)
log "$OS not yet supported"
exit 1
;;
esac
fi
if [ "$command" = "update" ] || [ -z "$command" ]; then
log "performing software update"
sudo softwareupdate -i -a > /dev/null 2>&1
fi
if [ "$command" = "homebrew" ] || [ -z "$command" ]; then
setup_homebrew
fi
if [ "$command" = "dotfiles" ] || [ -z "$command" ]; then
sh "$(dirname "$0")/dots" install -a
fi
# if [ "$command" = "tmux" ] || [ -z "$command" ]; then
# setup_tmux
# fi
if [ "$command" = "vim" ] || [ -z "$command" ]; then
setup_vim
fi
if [ "$command" = "zsh" ] || [ -z "$command" ]; then
setup_oh_my_zsh
setup_zsh
setup_pk10_config
fi
}
main "$@"