-
Notifications
You must be signed in to change notification settings - Fork 69
/
mac-setup.command
executable file
·4567 lines (4030 loc) · 173 KB
/
mac-setup.command
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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# Quick Start
case "${SHELL}" in
(*zsh) ;;
(*) chsh -s "$(which zsh)"; exit 1 ;;
esac
# Initialize New Terminal
if test -z "${1}"; then
osascript - "${0}" << EOF > /dev/null 2>&1
on run { _this }
tell app "Terminal" to do script "source " & quoted form of _this & " 0"
end run
EOF
fi
# Define Function =ask=
ask () {
osascript - "${1}" "${2}" "${3}" << EOF 2> /dev/null
on run { _title, _action, _default }
tell app "System Events" to return text returned of (display dialog _title with title _title buttons { "Cancel", _action } default answer _default)
end run
EOF
}
# Define Function =ask2=
ask2 () {
osascript - "$1" "$2" "$3" "$4" "$5" "$6" << EOF 2> /dev/null
on run { _text, _title, _cancel, _action, _default, _hidden }
tell app "Terminal" to return text returned of (display dialog _text with title _title buttons { _cancel, _action } cancel button _cancel default button _action default answer _default hidden answer _hidden)
end run
EOF
}
# Define Function =p=
p () {
printf "\n\033[1m\033[34m%s\033[0m\n\n" "${1}"
}
# Define Function =run=
run () {
osascript - "${1}" "${2}" "${3}" << EOF 2> /dev/null
on run { _title, _cancel, _action }
tell app "Terminal" to return button returned of (display dialog _title with title _title buttons { _cancel, _action } cancel button 1 default button 2 giving up after 5)
end run
EOF
}
# Define Function =init=
init () {
init_sudo
init_cache
init_no_sleep
init_hostname
init_perms
init_maskeep
init_updates
config_new_account
config_rm_sudoers
}
if test "${1}" = 0; then
printf "\n$(which init)\n"
fi
# Define Function =init_paths=
init_paths () {
test -x "/usr/libexec/path_helper" && \
eval $(/usr/libexec/path_helper -s)
}
# Eliminate Prompts for Password
init_sudo () {
printf "%s\n" "%wheel ALL=(ALL) NOPASSWD: ALL" | \
sudo tee "/etc/sudoers.d/wheel" > /dev/null && \
sudo dscl /Local/Default append /Groups/wheel GroupMembership "$(whoami)"
}
# Select Installation Cache Location
init_cache () {
grep -q "CACHES" "/etc/zshenv" 2> /dev/null || \
a=$(osascript << EOF 2> /dev/null
on run
return text 1 through -2 of POSIX path of (choose folder with prompt "Select Installation Cache Location")
end run
EOF
) && \
test -d "${a}" || \
a="${HOME}/Library/Caches/"
grep -q "CACHES" "/etc/zshenv" 2> /dev/null || \
printf "%s\n" \
"export CACHES=\"${a}\"" \
"export HOMEBREW_CACHE=\"${a}/brew\"" \
"export BREWFILE=\"${a}/brew/Brewfile\"" | \
sudo tee -a "/etc/zshenv" > /dev/null
. "/etc/zshenv"
if test -d "${CACHES}/upd"; then
sudo chown -R "$(whoami)" "/Library/Updates"
rsync -a --delay-updates \
"${CACHES}/upd/" "/Library/Updates/"
fi
}
# Set Defaults for Sleep
init_no_sleep () {
sudo pmset -a sleep 0
sudo pmset -a disksleep 0
}
# Set Hostname from DNS
init_hostname () {
a=$(ask2 "Set Computer Name and Hostname" "Set Hostname" "Cancel" "Set Hostname" $(ruby -e "print '$(hostname -s)'.capitalize") "false")
if test -n $a; then
sudo scutil --set ComputerName $(ruby -e "print '$a'.capitalize")
sudo scutil --set HostName $(ruby -e "print '$a'.downcase")
fi
}
# Set Permissions on Install Destinations
_dest='/usr/local/bin
/Library/Desktop Pictures
/Library/ColorPickers
/Library/Fonts
/Library/Input Methods
/Library/PreferencePanes
/Library/QuickLook
/Library/Screen Savers
/Library/User Pictures'
init_perms () {
printf "%s\n" "${_dest}" | \
while IFS="$(printf '\t')" read d; do
test -d "${d}" || sudo mkdir -p "${d}"
sudo chgrp -R admin "${d}"
sudo chmod -R g+w "${d}"
done
}
# Install Developer Tools
init_devtools () {
p="${HOMEBREW_CACHE}/Cask/Command Line Tools (macOS High Sierra version 10.13).pkg"
i="com.apple.pkg.CLTools_SDK_macOS1013"
if test -f "${p}"; then
if ! pkgutil --pkg-info "${i}" > /dev/null 2>&1; then
sudo installer -pkg "${p}" -target /
fi
else
xcode-select --install
fi
}
# Install Xcode
init_xcode () {
if test -f ${HOMEBREW_CACHE}/Cask/xcode*.xip; then
p "Installing Xcode"
dest="${HOMEBREW_CACHE}/Cask/xcode"
if ! test -d "$dest"; then
pkgutil --expand ${HOMEBREW_CACHE}/Cask/xcode*.xip "$dest"
curl --location --silent \
"https://gist.githubusercontent.com/pudquick/ff412bcb29c9c1fa4b8d/raw/24b25538ea8df8d0634a2a6189aa581ccc6a5b4b/parse_pbzx2.py" | \
python - "${dest}/Content"
find "${dest}" -empty -name "*.xz" -type f -print0 | \
xargs -0 -l 1 rm
find "${dest}" -name "*.xz" -print0 | \
xargs -0 -L 1 gunzip
cat ${dest}/Content.part* > \
${dest}/Content.cpio
fi
cd /Applications && \
sudo cpio -dimu --file=${dest}/Content.cpio
for pkg in /Applications/Xcode*.app/Contents/Resources/Packages/*.pkg; do
sudo installer -pkg "$pkg" -target /
done
x="$(find '/Applications' -maxdepth 1 -regex '.*/Xcode[^ ]*.app' -print -quit)"
if test -n "${x}"; then
sudo xcode-select -s "${x}"
sudo xcodebuild -license accept
fi
fi
}
# Install macOS Updates
init_updates () {
sudo softwareupdate --install --all
}
# Save Mac App Store Packages
# #+begin_example sh
# sudo lsof -c softwareupdated -F -r 2 | sed '/^n\//!d;/com.apple.SoftwareUpdate/!d;s/^n//'
# sudo lsof -c storedownloadd -F -r 2 | sed '/^n\//!d;/com.apple.appstore/!d;s/^n//'
# #+end_example
_maskeep_launchd='add :KeepAlive bool false
add :Label string com.github.ptb.maskeep
add :ProcessType string Background
add :Program string /usr/local/bin/maskeep
add :RunAtLoad bool true
add :StandardErrorPath string /dev/stderr
add :StandardOutPath string /dev/stdout
add :UserName string root
add :WatchPaths array
add :WatchPaths:0 string $(sudo find '"'"'/private/var/folders'"'"' -name '"'"'com.apple.SoftwareUpdate'"'"' -type d -user _softwareupdate -print -quit 2> /dev/null)
add :WatchPaths:1 string $(sudo -u \\#501 -- sh -c '"'"'getconf DARWIN_USER_CACHE_DIR'"'"' 2> /dev/null)com.apple.appstore
add :WatchPaths:2 string $(sudo -u \\#502 -- sh -c '"'"'getconf DARWIN_USER_CACHE_DIR'"'"' 2> /dev/null)com.apple.appstore
add :WatchPaths:3 string $(sudo -u \\#503 -- sh -c '"'"'getconf DARWIN_USER_CACHE_DIR'"'"' 2> /dev/null)com.apple.appstore
add :WatchPaths:4 string /Library/Updates'
init_maskeep () {
sudo softwareupdate --reset-ignored > /dev/null
cat << EOF > "/usr/local/bin/maskeep"
#!/bin/sh
asdir="/Library/Caches/storedownloadd"
as1="\$(sudo -u \\#501 -- sh -c 'getconf DARWIN_USER_CACHE_DIR' 2> /dev/null)com.apple.appstore"
as2="\$(sudo -u \\#502 -- sh -c 'getconf DARWIN_USER_CACHE_DIR' 2> /dev/null)com.apple.appstore"
as3="\$(sudo -u \\#503 -- sh -c 'getconf DARWIN_USER_CACHE_DIR' 2> /dev/null)com.apple.appstore"
upd="/Library/Updates"
sudir="/Library/Caches/softwareupdated"
su="\$(sudo find '/private/var/folders' -name 'com.apple.SoftwareUpdate' -type d -user _softwareupdate 2> /dev/null)"
for i in 1 2 3 4 5; do
mkdir -m a=rwxt -p "\$asdir"
for as in "\$as1" "\$as2" "\$as3" "\$upd"; do
test -d "\$as" && \
find "\${as}" -type d -print | \\
while read a; do
b="\${asdir}/\$(basename \$a)"
mkdir -p "\${b}"
find "\${a}" -type f -print | \\
while read c; do
d="\$(basename \$c)"
test -e "\${b}/\${d}" || \\
ln "\${c}" "\${b}/\${d}" && \\
chmod 666 "\${b}/\${d}"
done
done
done
mkdir -m a=rwxt -p "\${sudir}"
find "\${su}" -name "*.tmp" -type f -print | \\
while read a; do
d="\$(basename \$a)"
test -e "\${sudir}/\${d}.xar" ||
ln "\${a}" "\${sudir}/\${d}.xar" && \\
chmod 666 "\${sudir}/\${d}.xar"
done
sleep 1
done
exit 0
EOF
chmod a+x "/usr/local/bin/maskeep"
rehash
config_launchd "/Library/LaunchDaemons/com.github.ptb.maskeep.plist" "$_maskeep_launchd" "sudo" ""
}
# Define Function =install=
install () {
install_macos_sw
install_node_sw
install_perl_sw
install_python_sw
install_ruby_sw
which config
}
# Install macOS Software with =brew=
install_macos_sw () {
p "Installing macOS Software"
install_paths
install_brew
install_brewfile_taps
install_brewfile_brew_pkgs
install_brewfile_cask_args
install_brewfile_cask_pkgs
install_brewfile_mas_apps
x=$(find '/Applications' -maxdepth 1 -regex '.*/Xcode[^ ]*.app' -print -quit)
if test -n "$x"; then
sudo xcode-select -s "$x"
sudo xcodebuild -license accept
fi
brew bundle --file="${BREWFILE}"
x=$(find '/Applications' -maxdepth 1 -regex '.*/Xcode[^ ]*.app' -print -quit)
if test -n "$x"; then
sudo xcode-select -s "$x"
sudo xcodebuild -license accept
fi
install_links
sudo xattr -rd "com.apple.quarantine" "/Applications" > /dev/null 2>&1
sudo chmod -R go=u-w "/Applications" > /dev/null 2>&1
}
# Add =/usr/local/bin/sbin= to Default Path
install_paths () {
if ! grep -Fq "/usr/local/sbin" /etc/paths; then
sudo sed -i "" -e "/\/usr\/sbin/{x;s/$/\/usr\/local\/sbin/;G;}" /etc/paths
fi
}
# Install Homebrew Package Manager
install_brew () {
if ! which brew > /dev/null; then
ruby -e \
"$(curl -Ls 'https://github.com/Homebrew/install/raw/master/install')" \
< /dev/null > /dev/null 2>&1
fi
printf "" > "${BREWFILE}"
brew analytics off
brew update
brew doctor
brew tap "homebrew/bundle"
}
# Add Homebrew Taps to Brewfile
_taps='caskroom/cask
caskroom/fonts
caskroom/versions
homebrew/bundle
homebrew/command-not-found
homebrew/nginx
homebrew/php
homebrew/services
ptb/custom
railwaycat/emacsmacport'
install_brewfile_taps () {
printf "%s\n" "${_taps}" | \
while IFS="$(printf '\t')" read tap; do
printf 'tap "%s"\n' "${tap}" >> "${BREWFILE}"
done
printf "\n" >> "${BREWFILE}"
}
# Add Homebrew Packages to Brewfile
_pkgs='aspell
bash
certbot
chromedriver
coreutils
dash
duti
e2fsprogs
fasd
fdupes
gawk
getmail
git
git-flow
git-lfs
gnu-sed
gnupg
gpac
httpie
hub
ievms
imagemagick
mas
mercurial
mp4v2
mtr
nmap
node
nodenv
openssl
p7zip
perl-build
pinentry-mac
plenv
pyenv
rbenv
rsync
selenium-server-standalone
shellcheck
sleepwatcher
sqlite
stow
syncthing
syncthing-inotify
tag
terminal-notifier
the_silver_searcher
trash
unrar
vcsh
vim
yarn
youtube-dl
zsh
zsh-syntax-highlighting
zsh-history-substring-search
homebrew/php/php71
ptb/custom/dovecot
ptb/custom/ffmpeg
sdl2
zimg
x265
webp
wavpack
libvorbis
libvidstab
two-lame
theora
tesseract
speex
libssh
libsoxr
snappy
schroedinger
rubberband
rtmpdump
opus
openh264
opencore-amr
libmodplug
libgsm
game-music-emu
fontconfig
fdk-aac
libcaca
libbs2b
libbluray
libass
chromaprint
ptb/custom/nginx-full'
install_brewfile_brew_pkgs () {
printf "%s\n" "${_pkgs}" | \
while IFS="$(printf '\t')" read pkg; do
# printf 'brew "%s", args: [ "force-bottle" ]\n' "${pkg}" >> "${BREWFILE}"
printf 'brew "%s"\n' "${pkg}" >> "${BREWFILE}"
done
printf "\n" >> "${BREWFILE}"
}
# Add Caskroom Options to Brewfile
_args='colorpickerdir /Library/ColorPickers
fontdir /Library/Fonts
input_methoddir /Library/Input Methods
prefpanedir /Library/PreferencePanes
qlplugindir /Library/QuickLook
screen_saverdir /Library/Screen Savers'
install_brewfile_cask_args () {
printf 'cask_args \' >> "${BREWFILE}"
printf "%s\n" "${_args}" | \
while IFS="$(printf '\t')" read arg dir; do
printf '\n %s: "%s",' "${arg}" "${dir}" >> "${BREWFILE}"
done
sed -i "" -e '$ s/,/\
/' "${BREWFILE}"
}
# Add Homebrew Casks to Brewfile
_casks='java
xquartz
adium
alfred
arduino
atom
bbedit
betterzip
bitbar
caffeine
carbon-copy-cloner
charles
dash
dropbox
exifrenamer
find-empty-folders
firefox
github-desktop
gitup
google-chrome
hammerspoon
handbrake
hermes
imageoptim
inkscape
integrity
istat-menus
iterm2
jubler
little-snitch
machg
menubar-countdown
meteorologist
moom
mp4tools
musicbrainz-picard
namechanger
nvalt
nzbget
nzbvortex
openemu
opera
pacifist
platypus
plex-media-server
qlstephen
quitter
radarr
rescuetime
resilio-sync
scrivener
sizeup
sketch
sketchup
skitch
skype
slack
sonarr
sonarr-menu
sourcetree
steermouse
subler
sublime-text
the-unarchiver
time-sink
torbrowser
tower
unrarx
vimr
vlc
vmware-fusion
wireshark
xld
caskroom/fonts/font-inconsolata-lgc
caskroom/versions/transmit4
ptb/custom/adobe-creative-cloud-2014
ptb/custom/blankscreen
ptb/custom/composer
ptb/custom/enhanced-dictation
ptb/custom/ipmenulet
ptb/custom/pcalc-3
ptb/custom/sketchup-pro
ptb/custom/text-to-speech-alex
ptb/custom/text-to-speech-allison
ptb/custom/text-to-speech-samantha
ptb/custom/text-to-speech-tom
railwaycat/emacsmacport/emacs-mac-spacemacs-icon'
install_brewfile_cask_pkgs () {
printf "%s\n" "${_casks}" | \
while IFS="$(printf '\t')" read cask; do
printf 'cask "%s"\n' "${cask}" >> "${BREWFILE}"
done
printf "\n" >> "${BREWFILE}"
}
# Add App Store Packages to Brewfile
_mas='1Password 443987910
Affinity Photo 824183456
Coffitivity 659901392
Duplicate Photos Fixer Pro 963642514
Growl 467939042
HardwareGrowler 475260933
I Love Stars 402642760
Icon Slate 439697913
Justnotes 511230166
Keynote 409183694
Metanota Pro 515250764
Numbers 409203825
Pages 409201541
WiFi Explorer 494803304
Xcode 497799835'
install_brewfile_mas_apps () {
open "/Applications/App Store.app"
run "Sign in to the App Store with your Apple ID" "Cancel" "OK"
MASDIR="$(getconf DARWIN_USER_CACHE_DIR)com.apple.appstore"
sudo chown -R "$(whoami)" "${MASDIR}"
rsync -a --delay-updates \
"${CACHES}/mas/" "${MASDIR}/"
printf "%s\n" "${_mas}" | \
while IFS="$(printf '\t')" read app id; do
printf 'mas "%s", id: %s\n' "${app}" "${id}" >> "${BREWFILE}"
done
}
# Link System Utilities to Applications
_links='/System/Library/CoreServices/Applications
/Applications/Xcode.app/Contents/Applications
/Applications/Xcode.app/Contents/Developer/Applications
/Applications/Xcode-beta.app/Contents/Applications
/Applications/Xcode-beta.app/Contents/Developer/Applications'
install_links () {
printf "%s\n" "${_links}" | \
while IFS="$(printf '\t')" read link; do
find "${link}" -maxdepth 1 -name "*.app" -type d -print0 2> /dev/null | \
xargs -0 -I {} -L 1 ln -s "{}" "/Applications" 2> /dev/null
done
}
# Install Node.js with =nodenv=
_npm='eslint
eslint-config-cleanjs
eslint-plugin-better
eslint-plugin-fp
eslint-plugin-import
eslint-plugin-json
eslint-plugin-promise
eslint-plugin-standard
gatsby
json
sort-json'
install_node_sw () {
if which nodenv > /dev/null; then
NODENV_ROOT="/usr/local/node" && export NODENV_ROOT
sudo mkdir -p "$NODENV_ROOT"
sudo chown -R "$(whoami):admin" "$NODENV_ROOT"
p "Installing Node.js with nodenv"
git clone https://github.com/nodenv/node-build-update-defs.git \
"$(nodenv root)"/plugins/node-build-update-defs
nodenv update-version-defs > /dev/null
nodenv install --skip-existing 8.7.0
nodenv global 8.7.0
grep -q "${NODENV_ROOT}" "/etc/paths" || \
sudo sed -i "" -e "1i\\
${NODENV_ROOT}/shims
" "/etc/paths"
init_paths
rehash
fi
T=$(printf '\t')
printf "%s\n" "$_npm" | \
while IFS="$T" read pkg; do
npm install --global "$pkg"
done
rehash
}
# Install Perl 5 with =plenv=
install_perl_sw () {
if which plenv > /dev/null; then
PLENV_ROOT="/usr/local/perl" && export PLENV_ROOT
sudo mkdir -p "$PLENV_ROOT"
sudo chown -R "$(whoami):admin" "$PLENV_ROOT"
p "Installing Perl 5 with plenv"
plenv install 5.26.0 > /dev/null 2>&1
plenv global 5.26.0
grep -q "${PLENV_ROOT}" "/etc/paths" || \
sudo sed -i "" -e "1i\\
${PLENV_ROOT}/shims
" "/etc/paths"
init_paths
rehash
fi
}
# Install Python with =pyenv=
install_python_sw () {
if which pyenv > /dev/null; then
CFLAGS="-I$(brew --prefix openssl)/include" && export CFLAGS
LDFLAGS="-L$(brew --prefix openssl)/lib" && export LDFLAGS
PYENV_ROOT="/usr/local/python" && export PYENV_ROOT
sudo mkdir -p "$PYENV_ROOT"
sudo chown -R "$(whoami):admin" "$PYENV_ROOT"
p "Installing Python 2 with pyenv"
pyenv install --skip-existing 2.7.13
p "Installing Python 3 with pyenv"
pyenv install --skip-existing 3.6.2
pyenv global 2.7.13
grep -q "${PYENV_ROOT}" "/etc/paths" || \
sudo sed -i "" -e "1i\\
${PYENV_ROOT}/shims
" "/etc/paths"
init_paths
rehash
pip install --upgrade "pip" "setuptools"
# Reference: https://github.com/mdhiggins/sickbeard_mp4_automator
pip install --upgrade "babelfish" "guessit<2" "qtfaststart" "requests" "stevedore==1.19.1" "subliminal<2"
pip install --upgrade "requests-cache" "requests[security]"
# Reference: https://github.com/pixelb/crudini
pip install --upgrade "crudini"
fi
}
# Install Ruby with =rbenv=
install_ruby_sw () {
if which rbenv > /dev/null; then
RBENV_ROOT="/usr/local/ruby" && export RBENV_ROOT
sudo mkdir -p "$RBENV_ROOT"
sudo chown -R "$(whoami):admin" "$RBENV_ROOT"
p "Installing Ruby with rbenv"
rbenv install --skip-existing 2.4.2
rbenv global 2.4.2
grep -q "${RBENV_ROOT}" "/etc/paths" || \
sudo sed -i "" -e "1i\\
${RBENV_ROOT}/shims
" "/etc/paths"
init_paths
rehash
printf "%s\n" \
"gem: --no-document" | \
tee "${HOME}/.gemrc" > /dev/null
gem update --system > /dev/null
trash "$(which rdoc)"
trash "$(which ri)"
gem update
gem install bundler
fi
}
# Define Function =config=
config () {
config_admin_req
config_bbedit
config_certbot
config_desktop
config_dovecot
config_emacs
config_environment
config_ipmenulet
config_istatmenus
config_nginx
config_openssl
config_sysprefs
config_zsh
config_guest
which custom
}
# Define Function =config_defaults=
config_defaults () {
printf "%s\n" "${1}" | \
while IFS="$(printf '\t')" read domain key type value host; do
${2} defaults ${host} write ${domain} "${key}" ${type} "${value}"
done
}
# Define Function =config_plist=
T="$(printf '\t')"
config_plist () {
printf "%s\n" "$1" | \
while IFS="$T" read command entry type value; do
case "$value" in
(\$*)
$4 /usr/libexec/PlistBuddy "$2" \
-c "$command '${3}${entry}' $type '$(eval echo \"$value\")'" 2> /dev/null ;;
(*)
$4 /usr/libexec/PlistBuddy "$2" \
-c "$command '${3}${entry}' $type '$value'" 2> /dev/null ;;
esac
done
}
# Define Function =config_launchd=
config_launchd () {
test -d "$(dirname $1)" || \
$3 mkdir -p "$(dirname $1)"
test -f "$1" && \
$3 launchctl unload "$1" && \
$3 rm -f "$1"
config_plist "$2" "$1" "$4" "$3" && \
$3 plutil -convert xml1 "$1" && \
$3 launchctl load "$1"
}
# Mark Applications Requiring Administrator Account
_admin_req='Carbon Copy Cloner.app
Charles.app
Composer.app
Dropbox.app
iStat Menus.app
Moom.app
VMware Fusion.app
Wireshark.app'
config_admin_req () {
printf "%s\n" "${_admin_req}" | \
while IFS="$(printf '\t')" read app; do
sudo tag -a "Red, admin" "/Applications/${app}"
done
}
# Configure BBEdit
config_bbedit () {
if test -d "/Applications/BBEdit.app"; then
test -f "/usr/local/bin/bbdiff" || \
ln /Applications/BBEdit.app/Contents/Helpers/bbdiff /usr/local/bin/bbdiff && \
ln /Applications/BBEdit.app/Contents/Helpers/bbedit_tool /usr/local/bin/bbedit && \
ln /Applications/BBEdit.app/Contents/Helpers/bbfind /usr/local/bin/bbfind && \
ln /Applications/BBEdit.app/Contents/Helpers/bbresults /usr/local/bin/bbresults
fi
}
# Configure Let’s Encrypt
config_certbot () {
test -d "/etc/letsencrypt" || \
sudo mkdir -p /etc/letsencrypt
sudo tee "/etc/letsencrypt/cli.ini" << EOF > /dev/null
agree-tos = True
authenticator = standalone
eff-email = True
manual-public-ip-logging-ok = True
nginx-ctl = $(which nginx)
nginx-server-root = /usr/local/etc/nginx
preferred-challenges = tls-sni-01
keep-until-expiring = True
rsa-key-size = 4096
text = True
EOF
if ! test -e "/etc/letsencrypt/.git"; then
a=$(ask "Existing Let’s Encrypt Git Repository Path or URL?" "Clone Repository" "")
test -n "$a" && \
case "$a" in
(/*)
sudo tee "/etc/letsencrypt/.git" << EOF > /dev/null ;;
gitdir: $a
EOF
(*)
sudo git -C "/etc/letsencrypt" remote add origin "$a"
sudo git -C "/etc/letsencrypt" fetch origin master ;;
esac
sudo git -C "/etc/letsencrypt" reset --hard
sudo git checkout -f -b master HEAD
fi
sudo launchctl unload /Library/LaunchDaemons/org.nginx.nginx.plist 2> /dev/null
sudo certbot renew
while true; do
test -n "$1" && server_name="$1" || \
server_name="$(ask 'New SSL Server: Server Name?' 'Create Server' 'example.com')"
test -n "$server_name" || break
test -n "$2" && proxy_address="$2" || \
proxy_address="$(ask "Proxy Address for $server_name?" 'Set Address' 'http://127.0.0.1:80')"
sudo certbot certonly --domain $server_name
key1="$(openssl x509 -pubkey < /etc/letsencrypt/live/$server_name/fullchain.pem | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64)"
key2="$(curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem | openssl x509 -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64)"
key3="$(curl -s https://letsencrypt.org/certs/isrgrootx1.pem | openssl x509 -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64)"
pkp="$(printf "add_header Public-Key-Pins 'pin-sha256=\"%s\"; pin-sha256=\"%s\"; pin-sha256=\"%s\"; max-age=2592000;';\n" $key1 $key2 $key3)"
cat << EOF > "/usr/local/etc/nginx/servers/$server_name.conf"
server {
server_name $server_name;
location / {
proxy_pass $proxy_address;
}
ssl_certificate /etc/letsencrypt/live/$server_name/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$server_name/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/$server_name/chain.pem;
$pkp
add_header Content-Security-Policy "upgrade-insecure-requests;";
add_header Referrer-Policy "strict-origin";
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" always;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
add_header X-Robots-Tag none;
add_header X-XSS-Protection "1; mode=block";
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_stapling on;
ssl_stapling_verify on;
# https://securityheaders.io/?q=https%3A%2F%2F$server_name&hide=on&followRedirects=on
# https://www.ssllabs.com/ssltest/analyze.html?d=$server_name&hideResults=on&latest
}
EOF
unset argv
done
sudo launchctl load /Library/LaunchDaemons/org.nginx.nginx.plist
}
# Configure Default Apps
config_default_apps () {
true
}
# Configure Desktop Picture
config_desktop () {
sudo rm -f "/Library/Caches/com.apple.desktop.admin.png"
base64 -D << EOF > "/Library/Desktop Pictures/Solid Colors/Solid Black.png"
iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAQAAAADrRVxmAAAAGElEQVR4AWOgMxgFo2AUjIJRMApGwSgAAAiAAAH3bJXBAAAAAElFTkSuQmCC
EOF
}
# Configure Dovecot
config_dovecot () {
if which /usr/local/sbin/dovecot > /dev/null; then
if ! run "Configure Dovecot Email Server?" "Configure Server" "Cancel"; then
sudo tee "/usr/local/etc/dovecot/dovecot.conf" << EOF > /dev/null
auth_mechanisms = cram-md5
default_internal_user = _dovecot
default_login_user = _dovenull
log_path = /dev/stderr
mail_location = maildir:~/.mail:INBOX=~/.mail/Inbox:LAYOUT=fs
mail_plugins = zlib
maildir_copy_with_hardlinks = no
namespace {
inbox = yes
mailbox Drafts {
auto = subscribe
special_use = \Drafts
}
mailbox Junk {
auto = subscribe
special_use = \Junk