-
Notifications
You must be signed in to change notification settings - Fork 105
/
setup.sh
executable file
·549 lines (410 loc) · 18.4 KB
/
setup.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
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
#!/bin/sh
# _ _ _ _
# ___ _____ __ (_)_ __ ___| |_ __ _| | |
# / _ \/ __\ \/ / | | '_ \/ __| __/ _` | | |
#| (_) \__ \> < | | | | \__ \ || (_| | | |
# \___/|___/_/\_\ |_|_| |_|___/\__\__,_|_|_|
echo "I ❤️ 🍎"
echo "Mac OS Install Setup Script"
echo "By Nina Zakharenko"
echo "Follow me on twitter! https://twitter.com/nnja"
# Some configs reused from:
# https://github.com/ruyadorno/installme-osx/
# https://gist.github.com/millermedeiros/6615994
# https://gist.github.com/brandonb927/3195465/
# Colorize
# Set the colours you can use
black=$(tput setaf 0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
# Resets the style
reset=`tput sgr0`
# Color-echo. Improved. [Thanks @joaocunha]
# arg $1 = message
# arg $2 = Color
cecho() {
echo "${2}${1}${reset}"
return
}
echo ""
cecho "###############################################" $red
cecho "# DO NOT RUN THIS SCRIPT BLINDLY #" $red
cecho "# YOU'LL PROBABLY REGRET IT... #" $red
cecho "# #" $red
cecho "# READ IT THOROUGHLY #" $red
cecho "# AND EDIT TO SUIT YOUR NEEDS #" $red
cecho "###############################################" $red
echo ""
# Set continue to false by default.
CONTINUE=false
echo ""
cecho "Have you read through the script you're about to run and " $red
cecho "understood that it will make changes to your computer? (y/n)" $red
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
CONTINUE=true
fi
if ! $CONTINUE; then
# Check if we're continuing and output a message if not
cecho "Please go read the script, it only takes a few minutes" $red
exit
fi
# Here we go.. ask for the administrator password upfront and run a
# keep-alive to update existing `sudo` time stamp until script has finished
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
##############################
# Prerequisite: Install Brew #
##############################
echo "Installing brew..."
if test ! $(which brew)
then
## Don't prompt for confirmation when installing homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null
fi
# Latest brew, install brew cask
brew upgrade
brew update
brew tap caskroom/cask
#############################################
### Generate ssh keys & add to ssh-agent
### See: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
#############################################
echo "Generating ssh keys, adding to ssh-agent..."
read -p 'Input email for ssh key: ' useremail
echo "Use default ssh file location, enter a passphrase: "
ssh-keygen -t rsa -b 4096 -C "$useremail" # will prompt for password
eval "$(ssh-agent -s)"
# Now that sshconfig is synced add key to ssh-agent and
# store passphrase in keychain
ssh-add -K ~/.ssh/id_rsa
# If you're using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.
if [ -e ~/.ssh/config ]
then
echo "ssh config already exists. Skipping adding osx specific settings... "
else
echo "Writing osx specific settings to ssh config... "
cat <<EOT >> ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
EOT
fi
#############################################
### Add ssh-key to GitHub via api
#############################################
echo "Adding ssh-key to GitHub (via api)..."
echo "Important! For this step, use a github personal token with the admin:public_key permission."
echo "If you don't have one, create it here: https://github.com/settings/tokens/new"
retries=3
SSH_KEY=`cat ~/.ssh/id_rsa.pub`
for ((i=0; i<retries; i++)); do
read -p 'GitHub username: ' ghusername
read -p 'Machine name: ' ghtitle
read -sp 'GitHub personal token: ' ghtoken
gh_status_code=$(curl -o /dev/null -s -w "%{http_code}\n" -u "$ghusername:$ghtoken" -d '{"title":"'$ghtitle'","key":"'"$SSH_KEY"'"}' 'https://api.github.com/user/keys')
if (( $gh_status_code -eq == 201))
then
echo "GitHub ssh key added successfully!"
break
else
echo "Something went wrong. Enter your credentials and try again..."
echo -n "Status code returned: "
echo $gh_status_code
fi
done
[[ $retries -eq i ]] && echo "Adding ssh-key to GitHub failed! Try again later."
##############################
# Install via Brew #
##############################
echo "Starting brew app install..."
### Window Management
# Todo: Try Divvy and spectacles in the future
brew cask install sizeup # window manager
# Start SizeUp at login
defaults write com.irradiatedsoftware.SizeUp StartAtLogin -bool true
# Don’t show the preferences window on next start
defaults write com.irradiatedsoftware.SizeUp ShowPrefsOnNextStart -bool false
### Developer Tools
brew cask install iterm2
brew cask install dash
brew install ispell
### Development
brew cask install docker
brew install postgresql
brew install redis
### Command line tools - install new ones, update others to latest version
brew install git # upgrade to latest
brew install git-lfs # track large files in git https://github.com/git-lfs/git-lfs
brew install wget
brew install zsh # zshell
brew install tmux
brew install tree
brew link curl --force
brew install grep --with-default-names
brew install trash # move to osx trash instead of rm
brew install less
### Python
brew install python
brew install pyenv
### Microcontrollers & Electronics
brew install avrdude
brew cask install arduino
# Manually install teensyduino from:
# https://www.pjrc.com/teensy/td_download.html
### Dev Editors
brew cask install visual-studio-code
brew cask install pycharm
### spacemacs github.com/syl20bnr/spacemacs
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
brew tap d12frosted/emacs-plus
brew install emacs-plus --HEAD --with-natural-title-bars
brew linkapps emacs-plus
### Writing
brew cask install evernote
brew cask install macdown
brew cask install notion
### Conferences, Blogging, Screencasts
brew cask install deckset
brew cask install ImageOptim # for optimizing images
brew cask install screenflow
### Productivity
brew cask install wavebox
brew cask install google-chrome
brew cask install alfred
brew cask install dropbox
brew cask install timing # time and project tracker
brew cask install keycastr # show key presses on screen (for gifs & screencasts)
brew cask install betterzip
brew cask install caffeine # keep computer from sleeping
brew cask install skitch # app to annotate screenshots
brew cask install muzzle
brew cask install flux
### Keyboard & Mouse
brew cask install karabiner-elements # remap keys, emacs shortcuts
brew cask install scroll-reverser # allow natural scroll for trackpad, not for mouse
### Quicklook plugins https://github.com/sindresorhus/quick-look-plugins
brew cask install qlcolorcode # syntax highlighting in preview
brew cask install qlstephen # preview plaintext files without extension
brew cask install qlmarkdown # preview markdown files
brew cask install quicklook-json # preview json files
brew cask install epubquicklook # preview epubs, make nice icons
brew cask install quicklook-csv # preview csvs
### Chat / Video Conference
brew cask install slack
brew cask install microsoft-teams
brew cask install zoomus
brew cask install signal
### Music and Video
brew cask install marshallofsound-google-play-music-player
brew cask install vlc
### Run Brew Cleanup
brew cleanup
#############################################
### Fonts
#############################################
echo "Installing fonts..."
brew tap caskroom/fonts
### programming fonts
brew cask install font-fira-mono-for-powerline
brew cask install font-fira-code
### SourceCodePro + Powerline + Awesome Regular (for powerlevel 9k terminal icons)
cd ~/Library/Fonts && { curl -O 'https://github.com/Falkor/dotfiles/blob/master/fonts/SourceCodePro+Powerline+Awesome+Regular.ttf?raw=true' ; cd -; }
#############################################
### Installs from Mac App Store
#############################################
echo "Installing apps from the App Store..."
### find app ids with: mas search "app name"
brew install mas
### Mas login is currently broken on mojave. See:
### Login manually for now.
cecho "Need to log in to App Store manually to install apps with mas...." $red
echo "Opening App Store. Please login."
open "/Applications/App Store.app"
echo "Is app store login complete.(y/n)? "
read response
if [ "$response" != "${response#[Yy]}" ]
then
mas install 907364780 # Tomato One - Pomodoro timer
mas install 485812721 # Tweetdeck
mas install 668208984 # GIPHY Capture. The GIF Maker (For recording my screen as gif)
mas install 1351639930 # Gifski, convert videos to gifs
mas install 414030210 # Limechat, IRC app.
else
cecho "App Store login not complete. Skipping installing App Store Apps" $red
fi
#############################################
### Install few global python packages
#############################################
echo "Installing global Python packages..."
pip3 install --upgrade pip
pip3 install --user pylint
pip3 install --user flake8
#############################################
### Set OSX Preferences - Borrowed from https://github.com/mathiasbynens/dotfiles/blob/master/.macos
#############################################
# 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'
##################
### Finder, Dock, & Menu Items
##################
# Finder: allow quitting via ⌘ + Q; doing so will also hide desktop icons
defaults write com.apple.finder QuitMenuItem -bool true
# Keep folders on top when sorting by name
defaults write com.apple.finder _FXSortFoldersFirst -bool true
# Expand save panel by default
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true
# Save to disk (not to iCloud) by default
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
# Finder: show all filename extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Remove the auto-hiding Dock delay
defaults write com.apple.dock autohide-delay -float 0
# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true
# Only Show Open Applications In The Dock
defaults write com.apple.dock static-only -bool true
# Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
# Automatically quit printer app once the print jobs complete
defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
# Disable the “Are you sure you want to open this application?” dialog
defaults write com.apple.LaunchServices LSQuarantine -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
# 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 -string "Nlsv"
# Minimize windows into their application’s icon
defaults write com.apple.dock minimize-to-application -bool true
# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true
# Don’t show recent applications in Dock
# defaults write com.apple.dock show-recents -bool false
# Menu bar: hide the Time Machine, User icons, but show the volume Icon.
for domain in ~/Library/Preferences/ByHost/com.apple.systemuiserver.*; do
defaults write "${domain}" dontAutoLoad -array \
"/System/Library/CoreServices/Menu Extras/TimeMachine.menu" \
"/System/Library/CoreServices/Menu Extras/User.menu"
done
defaults write com.apple.systemuiserver menuExtras -array \
"/System/Library/CoreServices/Menu Extras/Volume.menu" \
"/System/Library/CoreServices/Menu Extras/Bluetooth.menu" \
"/System/Library/CoreServices/Menu Extras/AirPort.menu" \
"/System/Library/CoreServices/Menu Extras/Battery.menu" \
"/System/Library/CoreServices/Menu Extras/Clock.menu"
##################
### Text Editing / Keyboards
##################
# Disable smart quotes and smart dashes
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# Use function F1, F, etc keys as standard function keys
defaults write NSGlobalDomain com.apple.keyboard.fnState -bool true
###############################################################################
# Screenshots / Screen #
###############################################################################
# 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
# Save screenshots to the desktop
defaults write com.apple.screencapture location -string "$HOME/Desktop"
# Save screenshots in PNG format (other options: BMP, GIF, JPG, PDF, TIFF)
defaults write com.apple.screencapture type -string "png"
# Disable shadow in screenshots
defaults write com.apple.screencapture disable-shadow -bool true
###############################################################################
# Address Book, Dashboard, iCal, TextEdit, and Disk Utility #
###############################################################################
# Use plain text mode for new TextEdit documents
defaults write com.apple.TextEdit RichText -int 0
###############################################################################
# Spotlight #
###############################################################################
# Hide Spotlight tray-icon (and subsequent helper)
#sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search
# 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"
# Load new settings before rebuilding the index
killall mds
###############################################################################
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
###############################################################################
# Disable “natural” (Lion-style) scrolling
# Uncomment if you don't use scroll reverser
# defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
# Stop iTunes from responding to the keyboard media keys
#launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/null
# Trackpad: enable tap to click for this user and for the login screen
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
# Disable force click and haptic feedback
defaults write ~/Library/Preferences/com.apple.AppleMultitouchTrackpad.plist ForceSuppressed -bool true
# Mouse settings
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse.plist MouseOneFingerDoubleTapGesture -int 0
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse.plist MouseTwoFingerDoubleTapGesture -int 3
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse.plist MouseTwoFingerHorizSwipeGesture -int 2
defaults write ~/Library/Preferences/.GlobalPreferences.plist com.apple.mouse.scaling -float 3
defaults write ~/Library/Preferences/.GlobalPreferences.plist com.apple.swipescrolldirection -boolean NO
###############################################################################
# Mac App Store #
###############################################################################
# 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
###############################################################################
# Photos #
###############################################################################
# Prevent Photos from opening automatically when devices are plugged in
defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool true
###############################################################################
# Google Chrome #
###############################################################################
# Disable the all too sensitive backswipe on trackpads
defaults write com.google.Chrome AppleEnableSwipeNavigateWithScrolls -bool false
#############################################
### Install dotfiles repo, run link script
#############################################
# TODO:
# clean up my personal repo to make it public
# dotfiles for vs code, emacs, gitconfig, oh my zsh, etc.
# git clone [email protected]:nnja/dotfiles.git
# cd dotfiles
# fetch submodules for oh-my-zsh
# git submodule init && git submodule update && git submodule status
# make symbolic links and change shell to zshell
# ./makesymlinks.sh
# upgrade_oh_my_zsh
echo ""
cecho "Done!" $cyan
echo ""
echo ""
cecho "################################################################################" $white
echo ""
echo ""
cecho "Note that some of these changes require a logout/restart to take effect." $red
echo ""
echo ""
echo -n "Check for and install available OSX updates, install, and automatically restart? (y/n)? "
read response
if [ "$response" != "${response#[Yy]}" ] ;then
softwareupdate -i -a --restart
fi