-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmacOS_bootstraper.sh
More file actions
313 lines (236 loc) · 10.4 KB
/
macOS_bootstraper.sh
File metadata and controls
313 lines (236 loc) · 10.4 KB
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
#!/bin/sh
macOS_bootstrap="$(pwd -P)"
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
# export RBENV_ROOT=/usr/local/var/rbenv
# export NVM_DIR=/usr/local/var/nvm
red=$(tput setaf 1)
green=$(tput setaf 2)
color_reset=$(tput sgr0)
error_echo() {
printf "\n${red}%s.${color_reset}\n" "$1"
}
info_echo() {
printf "\n${green}%s ...${color_reset}\n" "$1"
}
version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
}
catch_exit() {
ret=$?
test $ret -ne 0 && error_echo "Installation fails" >&2
exit $ret
}
# ====================
# Check macOS version
# ====================
required_osx_version="10.15.0"
osx_version=$(/usr/bin/sw_vers -productVersion)
info_echo "Checking OS X version"
if [ "$(version "$osx_version")" -lt "$(version "$required_osx_version")" ]; then
error_echo "Your OS X $osx_version version is older then required $required_osx_version version. Exiting"
exit
fi
# ====================
# update macOS version
# ====================
info_echo "Running OS X Software updates"
sudo softwareupdate -i -a
# ====================
# setting up ssh
# ====================
# info_echo "Checking for SSH key, generating one if it doesn't exist"
# [[ -f ~/.ssh/id_rsa.pub ]] || ssh-keygen -t rsa
# info_echo "Copying public key to clipboard. Paste it into your Github account"
# [[ -f ~/.ssh/id_rsa.pub ]] && pbcopy < ~/.ssh/id_rsa.pub
# open https://github.com/account/ssh
# ====================
# install brew and apps
# ====================
if test ! "$(which brew)"; then
info_echo "Install Homebrew, a good OS X package manager"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
info_echo "Update Homebrew"
brew update
fi
info_echo "Install Brew formalue"
brew tap "Homebrew/bundle" 2> /dev/null
brew bundle --file="./Brewfile"
# https://github.com/eventmachine/eventmachine/issues/602#issuecomment-152184551
info_echo "Link keg-only openssl to /usr/local to let software outside of Homebrew to find it"
brew unlink openssl && brew link openssl --force
info_echo "Link Curl with openssl"
brew link --force curl
info_echo "Remove outdated versions from the cellar"
brew cleanup
# ====================
# setting up zsh with oh-my-zsh
# ====================
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
sudo chsh -s $(which zsh) $(whoami)
# ====================
# setting up ruby env
# ====================
info_echo "Enable rbenv alias"
eval "$(rbenv init -)"
info_echo "Set default gems list"
echo "bundler" >> "$(brew --prefix rbenv)/default-gems"
echo "tmuxinator" >> "$(brew --prefix rbenv)/default-gems"
echo "rails" >> "$(brew --prefix rbenv)/default-gems"
echo "powder" >> "$(brew --prefix rbenv)/default-gems"
ruby_version="2.5.1"
if test -z "$(rbenv versions --bare|grep $ruby_version)"; then
info_echo "Install Ruby $ruby_version"
rbenv install $ruby_version
fi
info_echo "Set Ruby $ruby_version as global default Ruby"
rbenv global $ruby_version
info_echo "Update to latest Rubygems version"
gem update --system --no-document
# ====================
# setting up node env
# ====================
info_echo "Enable NVM alias"
# we need disable -e during sourcing nvm.sh b/c of
# https://github.com/creationix/nvm/issues/721
# https://github.com/travis-ci/travis-ci/issues/3854#issuecomment-99492695
set +e
source "$(brew --prefix nvm)/nvm.sh"
set -e
if test -z "$(nvm ls|grep "node")"; then
info_echo "Install Node.js LTS version"
nvm install --lts
fi
info_echo "Set latest Node.js version as global default Node"
nvm use --lts
# nvm alias default --lts
export npm_config_global=true
export npm_config_loglevel=silent
# ====================
# restore from mackup
# ====================
# TODO
# ====================
# config macOS defaults
# ====================
info_echo "Set OS X defaults"
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Enable full keyboard access for all controls
# (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Disable Press and hold function
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false
# shorter initial key repeat waiting time
defaults write NSGlobalDomain InitialKeyRepeat -int 12
# Faster key repeat speed
defaults write NSGlobalDomain KeyRepeat -int 1
###############################################################################
# Finder #
###############################################################################
# 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
# Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# When performing a search, search the current folder by default
defaults write com.apple.finder FXDefaultSearchScope -string "SCcf"
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Avoid creating .DS_Store files on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
# Use list view in all Finder windows by default
# Four-letter codes for the other view modes: `icnv`, `clmv`, `Flwv`
defaults write com.apple.Finder FXPreferredViewStyle Nlsv
# Enable AirDrop over Ethernet and on unsupported Macs running Lion
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
# Set $HOME as the default location for new Finder windows
# For other paths, use `PfLo` and `file:///full/path/here/`
defaults write com.apple.finder NewWindowTarget -string "PfLo"
defaults write com.apple.finder NewWindowTargetPath -string "file://${HOME}"
###############################################################################
# Dock, Dashboard, and hot corners #
###############################################################################
# Wipe all (default) app icons from the Dock
# This is only really useful when setting up a new Mac, or if you don’t use
# the Dock to launch apps.
#
# defaults write com.apple.dock persistent-apps -array
# Add applications to Dock
#
# for app in \
# System\ Preferences \
# Safari \
# HipChat \
# iTerm \
# Sublime\ Text
# do
# defaults write com.apple.dock "persistent-apps" -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/$app.app/</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
# done
# Disable Dashboard
defaults write com.apple.dashboard mcx-disabled -bool true
# Don’t automatically rearrange Spaces based on most recent use
defaults write com.apple.dock mru-spaces -bool false
# Make Dock icons of hidden applications translucent
defaults write com.apple.dock showhidden -bool true
###############################################################################
# Safari & WebKit #
###############################################################################
# Prevent Safari from opening ‘safe’ files automatically after downloading
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false
# Show status bar
defaults write com.apple.Safari ShowStatusBar -bool true
# Enable the Develop menu and the Web Inspector in Safari
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
###############################################################################
# Spotlight #
###############################################################################
# Disable Spotlight indexing for any volume that gets mounted and has not yet
# been indexed before.
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
# sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"
# Change indexing order and disable some file types
defaults write com.apple.spotlight orderedItems -array \
'{"enabled" = 1;"name" = "APPLICATIONS";}' \
'{"enabled" = 1;"name" = "SYSTEM_PREFS";}' \
'{"enabled" = 1;"name" = "DIRECTORIES";}' \
'{"enabled" = 1;"name" = "PDF";}' \
'{"enabled" = 1;"name" = "FONTS";}' \
'{"enabled" = 0;"name" = "DOCUMENTS";}' \
'{"enabled" = 0;"name" = "MESSAGES";}' \
'{"enabled" = 0;"name" = "CONTACT";}' \
'{"enabled" = 0;"name" = "EVENT_TODO";}' \
'{"enabled" = 0;"name" = "IMAGES";}' \
'{"enabled" = 0;"name" = "BOOKMARKS";}' \
'{"enabled" = 0;"name" = "MUSIC";}' \
'{"enabled" = 0;"name" = "MOVIES";}' \
'{"enabled" = 0;"name" = "PRESENTATIONS";}' \
'{"enabled" = 0;"name" = "SPREADSHEETS";}' \
'{"enabled" = 0;"name" = "SOURCE";}'
# Make sure indexing is enabled for the main volume
sudo mdutil -i on / > /dev/null
# Rebuild the index from scratch
sudo mdutil -E / > /dev/null
###############################################################################
# Terminal & iTerm 2 #
###############################################################################
# Only use UTF-8 in Terminal.app
defaults write com.apple.terminal StringEncodings -array 4
# Don’t display the annoying prompt when quitting iTerm
defaults write com.googlecode.iterm2 PromptOnQuit -bool false
###############################################################################
# Kill affected applications #
###############################################################################
for app in "cfprefsd" "Dock" "Finder" "Safari" "SystemUIServer" "iTerm"; do
killall "${app}" > /dev/null 2>&1 || true
done