-
Notifications
You must be signed in to change notification settings - Fork 134
/
mac-install-all.sh
executable file
·4328 lines (3600 loc) · 156 KB
/
mac-install-all.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
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
#!/usr/local/bin/bash
# mac-install-all.sh in https://github.com/wilsonmar/DevSecOps
# This downloads and installs all the utilities related to use of Git,
# customized based on specification in file secrets.sh within the same repo.
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/wilsonmar/DevSecOps/???/master/macos-install-all.sh)"
# See https://github.com/wilsonmar/git-utilities/blob/master/README.md
# Based on https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
# and https://git-scm.com/docs/git-config
# and https://medium.com/my-name-is-midori/how-to-prepare-your-fresh-mac-for-software-development-b841c05db18
# https://www.bonusbits.com/wiki/Reference:Mac_OS_DevOps_Workstation_Setup_Check_List
# TOC: Functions (GPG_MAP_MAIL2KEY, Python, Python3, Java, Node, Go, Docker) >
# Starting: Secrets > XCode > XCode/Ruby > bash.profile > Brew > gitconfig > gitignore > Git web browsers > p4merge > linters > Git clients > git users > git tig > BFG > gitattributes > Text Editors > git [core] > git coloring > rerere > prompts > bash command completion > git command completion > Git alias keys > Git repos > git flow > git hooks > Large File Storage > gcviewer, jmeter, jprofiler > code review > git signing > Cloud CLI/SDK > Selenium > SSH KeyGen > SSH Config > Paste SSH Keys in GitHub > GitHub Hub > dump contents > disk space > show log
# set -o nounset -o pipefail -o errexit # "strict mode"
# set -u # -uninitialised variable exits script.
# set -e # -exit the script if any statement returns a non-true return value.
# set -a # Mark variables which are modified or created for export. Each variable or function that is created or modified is given the export attribute and marked for export to the environment of subsequent commands.
# set -v # -verbose Prints shell input lines as they are read.
#bar=${MY_RUNTYPE:-none} # :- sets undefine value. See http://redsymbol.net/articles/unofficial-bash-strict-mode/
IFS=$'\n\t' # Internal Field Separator for word splitting is line or tab, not spaces.
#trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
trap cleanup EXIT
trap sig_cleanup INT QUIT TERM
function fancy_echo() {
local fmt="$1"; shift
printf "\\n>>> $fmt\\n" "$@"
}
# From https://gist.github.com/somebox/6b00f47451956c1af6b4
function echo_ok { echo -e '\033[1;32m'"$1"'\033[0m'; }
function echo_warn { echo -e '\033[1;33m'"$1"'\033[0m'; }
function echo_error { echo -e '\033[1;31mERROR: '"$1"'\033[0m'; }
######### Starting time stamp, OS versions, command attributes:
# For Git on Windows, see http://www.rolandfg.net/2014/05/04/intellij-idea-and-git-on-windows/
TIME_START="$(date -u +%s)"
FREE_DISKBLOCKS_START="$(df | sed -n -e '2{p;q}' | cut -d' ' -f 6)"
# ISO-8601 plus RANDOM=$((1 + RANDOM % 1000)) # 3 digit random number.
LOG_PREFIX=$(date +%Y-%m-%dT%H:%M:%S%z)-$((1 + RANDOM % 1000))
LOGFILE="$0.$LOG_PREFIX.log"
if [ ! -z $1 ]; then # not empty
echo "$0 $1 starting with logging to file:" >$LOGFILE # new file
else
echo "$0 starting with logging to file:" >$LOGFILE # new file
fi
echo "$LOGFILE ..." >>$LOGFILE
fancy_echo "sw_vers ::" >>$LOGFILE
echo -e "$(sw_vers)" >>$LOGFILE
fancy_echo "uname -a ::" >>$LOGFILE
echo -e "$(uname -a)" >>$LOGFILE
######### Bash utility functions:
function cleanup() {
err=$?
echo "At cleanup() LOGFILE=$LOGFILE"
open -a "TextEdit" $LOGFILE
trap '' EXIT INT TERM
exit $err
}
cleanup2() {
err=$?
echo "At cleanup() LOGFILE=$LOGFILE"
# pico $LOGFILE
trap '' EXIT INT TERM
exit $err
}
sig_cleanup() {
trap '' EXIT # some shells will call EXIT after the INT handler
false # sets $?
cleanup
}
# TODO: Accept custom secrets.sh file name/location.
# Read first parameter from command line supplied at runtime to invoke:
MY_RUNTYPE="$1"
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then # variable made lower case.
echo "MY_RUNTYPE=\"$MY_RUNTYPE\" means all packages here will be upgraded ..." >>$LOGFILE
fi
# TODO: Add tryout for all.
######### MacOS maxfiles config:
FILE="/Library/LaunchDaemons/limit.maxfiles.plist"
if [ ! -f "$FILE" ]; then # NOT found, so add it
fancy_echo "Copying configs/ to $FILE ..."
sudo cp configs/limit.maxfiles.plist $FILE
#see http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/
sudo chmod 644 $FILE
fi
FILE="/Library/LaunchDaemons/limit.maxproc.plist"
if [ ! -f "$FILE" ]; then # NOT found, so add it
fancy_echo "Copying configs/ to $FILE ..."
sudo cp configs/limit.maxproc.plist $FILE
sudo chmod 644 $FILE
# https://apple.stackexchange.com/questions/168495/why-wont-kern-maxfiles-setting-in-etc-sysctl-conf-stick
fi
if grep -q "ulimit -n " "/etc/profile" ; then
fancy_echo "ulimit -n already in /etc/profile" >>$LOGFILE
else
fancy_echo "Concatenating ulimit 2048 to /etc/profile ..."
echo 'ulimit -n 2048' | sudo tee -a /etc/profile
fancy_echo "Now please reboot so the settings take. Exiting ..."
exit
#see http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/
fi
# Based on https://docs.microsoft.com/en-us/dotnet/core/macos-prerequisites?tabs=netcore2x
fancy_echo "launchctl limit ::" >>$LOGFILE
launchctl limit >>$LOGFILE
OPEN_FILES=$(ulimit -n) # 256 default
fancy_echo "ulimit -a = $OPEN_FILES" >>$LOGFILE
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/sysctl.3.html
/usr/sbin/sysctl -a | grep files >>$LOGFILE
#kern.maxfiles: 49152
#kern.maxfilesperproc: 24576
#kern.num_files: 4692s
FILE="/etc/sysctl.conf"
if [ ! -f "$FILE" ]; then # NOT found, so add it
fancy_echo "Copying kern to $FILE ..."
echo "kern.maxfiles=49152" | sudo tee -a $FILE
echo "kern.maxfilesperproc=24576" | sudo tee -a $FILE
fi
######### MacOS hidden files configuration:
fancy_echo "Configure OSX Finder to show hidden files too:" >>$LOGFILE
defaults write com.apple.finder AppleShowAllFiles YES
# NOTE: Additional config dotfiles for Mac?
# NOTE: See osx-init.sh in https://github.com/wilsonmar/DevSecOps/osx-init
# installs other programs on Macs for developers.
# Ensure Apple's command line tools (such as cc) are installed by node:
if ! command -v cc >/dev/null; then
fancy_echo "Installing Apple's xcode command line tools (this takes a while) ..."
xcode-select --install
# Xcode installs its git to /usr/bin/git; recent versions of OS X (Yosemite and later) ship with stubs in /usr/bin, which take precedence over this git.
fi
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/pkgutil.1.html
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version
# Tools_Executables | grep version
# version: 9.2.0.0.1.1510905681
# TODO: https://gist.github.com/tylergets/90f7e61314821864951e58d57dfc9acd
######### bash.profile configuration:
BASHFILE=$HOME/.bash_profile # on Macs
# if ~/.bash_profile has not been defined, create it:
if [ ! -f "$BASHFILE" ]; then # NOT found:
fancy_echo "Creating blank \"${BASHFILE}\" ..." >>$LOGFILE
touch "$BASHFILE"
echo "PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" >>"$BASHFILE"
# El Capitan no longer allows modifications to /usr/bin, and /usr/local/bin is preferred over /usr/bin, by default.
else
LINES=$(wc -l < "${BASHFILE}")
fancy_echo "\"${BASHFILE}\" already created with $LINES lines." >>$LOGFILE
fancy_echo "Backing up file $BASHFILE to $BASHFILE-$LOG_PREFIX.bak ..." >>$LOGFILE
cp "$BASHFILE" "$BASHFILE-$LOG_PREFIX.bak"
fi
######### bash completion:
echo -e "$(bash --version | grep 'bash')" >>$LOGFILE
# BREW_VERSION="$(brew --version)"
# TODO: Completion of bash commands on MacOS:
# See https://kubernetes.io/docs/tasks/tools/install-kubectl/#on-macos-using-bash
# Also see https://github.com/barryclark/bashstrap
# TODO: Extract 4 from $BASH_VERSION
# GNU bash, version 4.4.19(1)-release (x86_64-apple-darwin17.3.0)
## or, if running Bash 4.1+
#brew install bash-completion@2
## If running Bash 3.2 included with macOS
#brew install bash-completion
# brew info atom >>$LOGFILE
# brew list atom >>$LOGFILE
###### bash.profile locale settings missing in OS X Lion+:
# See https://stackoverflow.com/questions/7165108/in-os-x-lion-lang-is-not-set-to-utf-8-how-to-fix-it
# https://unix.stackexchange.com/questions/87745/what-does-lc-all-c-do
# LC_ALL forces applications to use the default language for output, and forces sorting to be bytewise.
if grep -q "LC_ALL" "$BASHFILE" ; then
fancy_echo "LC_ALL Locale setting already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding LC_ALL Locale in $BASHFILE..." >>$LOGFILE
echo "# Added by $0 ::" >>"$BASHFILE"
echo "export LC_ALL=en_US.utf-8" >>"$BASHFILE"
#export LANG="en_US.UTF-8"
#export LC_CTYPE="en_US.UTF-8"
# Run .bash_profile to have changes take, run $FILEPATH:
source "$BASHFILE"
fi
#locale
# LANG="en_US.UTF-8"
# LC_COLLATE="en_US.UTF-8"
# LC_CTYPE="en_US.utf-8"
# LC_MESSAGES="en_US.UTF-8"
# LC_MONETARY="en_US.UTF-8"
# LC_NUMERIC="en_US.UTF-8"
# LC_TIME="en_US.UTF-8"
# LC_ALL=
if grep -q "export ARCHFLAGS=" "$BASHFILE" ; then
fancy_echo "ARCHFLAGS setting already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding ARCHFLAGS in $BASHFILE..." >>$LOGFILE
echo "export ARCHFLAGS=\"-arch x86_64\"" >>"$BASHFILE"
source "$BASHFILE"
fi
###### Install homebrew using whatever Ruby is installed:
# Ruby comes with MacOS:
fancy_echo "Using whatever Ruby version comes with MacOS:" >>$LOGFILE
echo -e "$(ruby -v)" >>$LOGFILE
# ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]
# Set the permissions that Brew expects
# sudo chflags norestricted /usr/local && sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
if ! command -v brew >/dev/null; then
fancy_echo "Installing homebrew using Ruby..." >>$LOGFILE
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap caskroom/cask
else
# Upgrade if run-time attribute contains "upgrade":
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Brew upgrading ..." >>$LOGFILE
brew --version
brew upgrade
fi
fi
#brew --version
echo -e "\n$(brew --version)" >>$LOGFILE
# Homebrew 1.5.12
# Homebrew/homebrew-core (git revision 9a81e; last commit 2018-03-22)
#brew tap caskroom/cask
# Casks are GUI program installers defined in https://github.com/caskroom/homebrew-cask/tree/master/Casks
# brew cask installs GUI apps (see https://caskroom.github.io/)
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
brew analytics off # see https://github.com/Homebrew/brew/blob/master/docs/Analytics.md
######### Mac tools:
if [[ "$MAC_TOOLS" == *"iterm"* ]]; then
# https://www.iterm2.com/documentation.html
if [ ! -d "/Applications/iTerm.app" ]; then
fancy_echo "Installing MAC_TOOLS iterm2 iTerm.app ..."
brew cask install iterm2
brew info iterm2 >>$LOGFILE
brew list iterm2 >>$LOGFILE
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Upgrading MAC_TOOLS iterm2 ..."
#iterm2 version # before upgrade
brew cask upgrade iterm2
fi
fi
echo -e "$(iterm2 no version)" >>$LOGFILE
if grep -q "alias iterm=" "$BASHFILE" ; then
fancy_echo "PATH to iTerm.app already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding PATH to iTterm.app in $BASHFILE..." >>$LOGFILE
echo "alias iterm2='open -a \"/Applications/iTerm.app\"'" >>"$BASHFILE"
fi
if grep -q "export CLICOLOR=" "$BASHFILE" ; then
fancy_echo "export CLICOLOR=1 already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding export CLICOLOR= to $BASHFILE..." >>$LOGFILE
echo "alias export CLICOLOR=1" >>"$BASHFILE"
fi
if [[ $TRYOUT == *"iterm"* ]] || [[ $TRYOUT == *"all"* ]]; then
fancy_echo "Starting iTerm ..." >>$LOGFILE
open -a "/Applications/iTerm.app"
fi
# http://sourabhbajaj.com/mac-setup/iTerm/README.html
# TODO: https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/schemes
fi
if [[ "$MAC_TOOLS" == *"mas"* ]]; then
# To manage apps purchased & installed using App Store on MacOS:
if ! command -v mas >/dev/null; then # /usr/local/bin/mas
fancy_echo "Installing MAC_TOOLS mas ..."
brew install mas
brew info mas >>$LOGFILE
brew list mas >>$LOGFILE
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Upgrading MAC_TOOLS mas ..."
mas version # before upgrade
brew upgrade mas
fi
fi
echo -e "$(mas version)" >>$LOGFILE # mas 1.4.1
fi
if [[ "$MAC_TOOLS" == *"ansible"* ]]; then
# To install programs. See http://wilsonmar.github.io/ansible/
if ! command -v ansible >/dev/null; then # /usr/local/bin/ansible
fancy_echo "Installing MAC_TOOLS ansible ..."
brew install ansible
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Upgrading MAC_TOOLS ansible ..."
ansible --version # before upgrade
brew upgrade ansible
fi
fi
echo -e "$(ansible -v)" >>$LOGFILE # ansible 2.5.0
fi
if [[ "$MAC_TOOLS" == *"1Password"* ]]; then
# See https://1password.com/ to store secrets on laptops securely.
if [ ! -d "/Applications/1Password 6.app" ]; then
#if ! command -v 1Password >/dev/null; then # /usr/local/bin/1Password
fancy_echo "Installing MAC_TOOLS 1Password - password needed ..."
brew cask install --appdir="/Applications" 1Password
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
# 1Password -v
fancy_echo "Upgrading MAC_TOOLS 1Password ..."
brew cask upgrade 1Password
fi
fi
#echo -e "$(1Password -v)" >>$LOGFILE # 1Password v6.0.0-beta.7
fi
if [[ "$MAC_TOOLS" == *"PowerShell"* ]]; then
# https://docs.microsoft.com/en-us/powershell/scripting/powershell-scripting?view=powershell-6
if [ ! -d "/Applications/PowerShell.app" ]; then
#if ! command -v PowerShell >/dev/null; then # /usr/local/bin/PowerShell
fancy_echo "Installing MAC_TOOLS PowerShell - password needed ..."
brew cask install --appdir="/Applications" PowerShell
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
# PowerShell -v
fancy_echo "Upgrading MAC_TOOLS PowerShell ..."
brew cask upgrade PowerShell
fi
if grep -q "alias PowerShell=" "$BASHFILE" ; then
fancy_echo "PATH to PowerShell.app already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding PATH to PowerShell.app in $BASHFILE..."
echo "alias PowerShell='open -a \"/Applications/PowerShell.app\"'" >>"$BASHFILE"
fi
fi
#echo -e "$(PowerShell -v)" >>$LOGFILE # powershell v6.0.0-beta.7
fi
if [[ "$MAC_TOOLS" == *"alfred"* ]]; then
# https://www.alfredapp.com/ multi-function utility
if [ ! -d "/Applications/Alfred 3.app" ]; then
fancy_echo "Installing MAC_TOOLS alfred ..."
brew cask install --appdir="/Applications" alfred
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Upgrading MAC_TOOLS alfred ..."
# alfred -v
brew cask upgrade alfred
fi
fi
#echo -e "$(alfred -v)" >>$LOGFILE # alfred v6.0.0-beta.7
if grep -q "alias alfred=" "$BASHFILE" ; then
fancy_echo "PATH to alfred 3.app already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding alias alfred to alfred 3.app in $BASHFILE..."
echo "alias alfred='open -a \"/Applications/alfred 3.app\"'" >>"$BASHFILE"
fi
if [[ $TRYOUT == *"alfred"* ]] || [[ $TRYOUT == *"all"* ]]; then
fancy_echo "Starting alfred ..." >>$LOGFILE
open -a "/Applications/alfred 3.app"
fi
# Buy the $19 https://www.alfredapp.com/powerpack/
fi
if [[ "$MAC_TOOLS" == *"others"* ]]; then
echo "Installing MAC_TOOLS=others ...";
# brew cask install --appdir="/Applications" monolingual # remove unneeded osx lang files https://ingmarstein.github.io/Monolingual/
# brew cask install --appdir="/Applications" vmware-fusion # run Windows
# brew install google-drive
# brew install dropbox
# brew install box
# brew install amazon
# brew cask install --appdir="/Applications" charles # proxy
# brew cask install --appdir="/Applications" xtrafinder
# brew cask install --appdir="/Applications" sizeup # $12.99 resize windows http://www.irradiatedsoftware.com/sizeup/
# brew cask install --appdir="/Applications" bartender # manage icons at top launch bar
# brew cask install --appdir="/Applications" duet
# brew cask install --appdir="/Applications" logitech-harmony # multi-controller of TVs etc
# brew cask install --appdir="/Applications" cheatsheet # hold ⌘ gives you all the shortcuts you can use with the active app.
# brew cask install --appdir="/Applications" steam
# brew cask install --appdir="/Applications" fritzing
# brew cask install --appdir="/Applications" nosleep
# brew cask install --appdir="/Applications" balsamiq-mockups # for designing website forms
# brew cask install --appdir="/Applications" smartsynchronize
# brew cask install --appdir="/Applications" toggldesktop
# brew cask install --appdir="/Applications" xmind
# brew cask install --appdir="/Applications" webstorm
# brew install jsdoc3
# brew cask install --appdir="/Applications" appcleaner
# brew cask install --appdir="/Applications" qlcolorcode
# brew cask install --appdir="/Applications" qlstephen
# brew cask install --appdir="/Applications" qlmarkdown
# brew cask install --appdir="/Applications" quicklook-json
# brew cask install --appdir="/Applications" quicklook-csv
# brew cask install --appdir="/Applications" betterzipql
# brew cask install --appdir="/Applications" asepsis
# brew cask install --appdir="/Applications" cheatsheet
# http://almworks.com/jiraclient/download.html
fi
######### Install git client to download the rest:
if ! command -v git >/dev/null; then
fancy_echo "Installing git using Homebrew ..."
brew install git
brew info git >>$LOGFILE
brew list git >>$LOGFILE
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Git upgrading ..." >>$LOGFILE
git --version
# To avoid response "Error: git not installed" to brew upgrade git
brew uninstall git
# QUESTION: This removes .gitconfig file?
brew install git
fi
fi
echo -e "\n$(git --version)" >>$LOGFILE
# git version 2.14.3 (Apple Git-98)
######### TODO: Download/clone GITHUB_REPO_URL repo:
######### Read and use secrets.sh file:
# If the file still contains defaults, it should not be used:
SECRETSFILE="secrets.sh"
if [ ! -f "$SECRETSFILE" ]; then # NOT found:
fancy_echo "$SECRETSFILE not found. Aborting run ..."
exit
fi
if grep -q "wilsonmar@gmail.com" "$SECRETSFILE" ; then # not customized:
fancy_echo "Please edit file $SECRETSFILE with your own credentials. Aborting this run..."
exit # so script ends now
else
fancy_echo "Reading from $SECRETSFILE ..."
#chmod +x $SECRETSFILE
source "$SECRETSFILE"
echo -e "\n git ls-files -v|grep '^h' ::" >>$LOGFILE
git update-index --skip-worktree $SECRETSFILE
echo "$(git ls-files -v|grep '^S')" >>$LOGFILE
echo -e "\n $SECRETSFILE ::" >>$LOGFILE
echo "GIT_NAME=$GIT_NAME">>$LOGFILE
echo "GIT_ID=$GIT_ID" >>$LOGFILE
echo "GIT_EMAIL=$GIT_EMAIL" >>$LOGFILE
echo "GIT_USERNAME=$GIT_USERNAME" >>$LOGFILE
echo "GITS_PATH=$GITS_PATH" >>$LOGFILE
echo "GITHUB_ACCOUNT=$GITHUB_ACCOUNT" >>$LOGFILE
echo "GITHUB_REPO=$GITHUB_REPO" >>$LOGFILE
# DO NOT echo $GITHUB_PASSWORD. Do not cat $SECRETFILE because it contains secrets.
echo "GIT_CLIENT=$GIT_CLIENT" >>$LOGFILE
echo "GIT_EDITOR=$GIT_EDITOR" >>$LOGFILE
echo "GIT_BROWSER=$GIT_BROWSER" >>$LOGFILE
echo "GIT_TOOLS=$GIT_TOOLS" >>$LOGFILE
echo "GIT_LANG=$GUI_LANG" >>$LOGFILE
echo "JAVA_TOOLS=$JAVA_TOOLS" >>$LOGFILE
echo "PYTHON_TOOLS=$PYTHON_TOOLS" >>$LOGFILE
echo "NODE_TOOLS=$NODE_TOOLS" >>$LOGFILE
echo "DATA_TOOLS=$DATA_TOOLS" >>$LOGFILE
echo "TEST_TOOLS=$TEST_TOOLS" >>$LOGFILE
echo "CLOUD=$CLOUD" >>$LOGFILE
# AWS_ACCESS_KEY_ID=""
# AWS_SECRET_ACCESS_KEY=""
# AWS_REGION="us-west-1"
# SAUCE_USERNAME=""
# SAUCE_ACCESS_KEY=""
echo "MON_TOOLS=$MON_TOOLS" >>$LOGFILE
echo "VIZ_TOOLS=$VIZ_TOOLS" >>$LOGFILE
echo "COLAB_TOOLS=$COLAB_TOOLS" >>$LOGFILE
# TODO: Artifactory, Jira,
echo "MEDIA_TOOLS=$MEDIA_TOOLS" >>$LOGFILE
echo "LOCALHOSTS=$LOCALHOSTS" >>$LOGFILE
echo "NGINX_PORT=$NGINX_PORT" >>$LOGFILE # from default 8080
echo "TOMCAT_PORT=$TOMCAT_PORT" >>$LOGFILE # from default 8080
echo "JENKINS_PORT=$JENKINS_PORT" >>$LOGFILE # from default 8080
echo "GRAFANA_PORT=$GRAFANA_PORT" >>$LOGFILE # from default 8080
echo "MINIKUBE_PORT=$MINKUBE_PORT" >>$LOGFILE # from default 8080
echo "TRYOUT=$TRYOUT" >>$LOGFILE
fi
######### ~/.gitconfig initial settings:
GITCONFIG=$HOME/.gitconfig # file
if [ ! -f "$GITCONFIG" ]; then
fancy_echo "$GITCONFIG! file not found."
else
fancy_echo "Backing up $GITCONFIG-$LOG_PREFIX.bak ..." >>$LOGFILE
cp "$GITCONFIG" "$GITCONFIG-$LOG_PREFIX.bak"
fi
######### Git functions:
# Based on https://gist.github.com/dciccale/5560837
# Usage: GIT_BRANCH=$(parse_git_branch)$(parse_git_hash) && echo ${GIT_BRANCH}
# Check if branch has something pending:
function git_parse_dirty() {
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*"
}
# Get the current git branch (using git_parse_dirty):
function git_parse_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(git_parse_dirty)/"
}
# Get last commit hash prepended with @ (i.e. @8a323d0):
function git_parse_hash() {
git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/@\1/"
}
######### Language function definitions:
# Add function to read in string and email, and return a KEY found for that email.
# GPG_MAP_MAIL2KEY associates the key and email in an array
function GPG_MAP_MAIL2KEY(){
KEY_ARRAY=($(echo "$str" | awk -F'sec rsa2048/|2018* [SC]' '{print $2}' | awk '{print $1}'))
# Remove trailing blank: KEY="$(echo -e "${str}" | sed -e 's/[[:space:]]*$//')"
MAIL_ARRAY=($(echo "$str" | awk -F'<|>' '{print $2}'))
#Test if the array count of the emails and the keys are the same to avoid conflicts
if [ ${#KEY_ARRAY[@]} == ${#MAIL_ARRAY[@]} ]; then
declare -A KEY_MAIL_ARRAY=()
for i in "${!KEY_ARRAY[@]}"
do
KEY_MAIL_ARRAY[${MAIL_ARRAY[$i]}]=${KEY_ARRAY[$i]}
done
#Return key matching email passed into function
echo "${KEY_MAIL_ARRAY[$1]}"
else
#exit from script if array count of emails and keys are not the same
exit 1 && fancy_echo "Email count and Key count do not match"
fi
}
function VIRTUALBOX_INSTALL(){
if [ ! -d "/Applications/VirtualBox.app" ]; then
#if ! command -v virtualbox >/dev/null; then # /usr/local/bin/virtualbox
fancy_echo "Installing virtualbox ..."
brew cask install --appdir="/Applications" virtualbox
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "virtualbox upgrading ..."
# virtualbox --version
brew cask upgrade virtualbox
else
fancy_echo "virtualbox already installed." >>$LOGFILE
fi
fi
#echo -e "\n$(virtualbox --version)" >>$LOGFILE
if [ ! -d "/Applications/Vagrant Manager.app" ]; then
fancy_echo "Installing vagrant-manager ..."
brew cask install --appdir="/Applications" vagrant-manager
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "vagrant-manager upgrading ..."
brew cask upgrade vagrant-manager
else
fancy_echo "vagrant-manager already installed." >>$LOGFILE
fi
fi
}
function PYTHON_INSTALL(){
# Python2 is a pre-requisite for git-cola & GCP installed below.
# Python3 is a pre-requisite for aws.
# Because there are two active versions of Pythong (2.7.4 and 3.6 now)...
# See https://docs.brew.sh/Homebrew-and-Python
# See https://docs.python-guide.org/en/latest/starting/install3/osx/
if ! command -v python >/dev/null; then
# No upgrade option.
fancy_echo "Installing Python, a pre-requisite for git-cola & GCP ..."
brew install python
brew info python >>$LOGFILE
brew list python >>$LOGFILE
# Not brew install pyenv # Python environment manager.
#brew linkapps python
# pip comes with brew install Python 2 >=2.7.9 or Python 3 >=3.4
pip --version
else
fancy_echo -e "\n$(python --version) already installed:" >>$LOGFILE
fi
command -v python
ls -al "$(command -v python)" # /usr/local/bin/python
echo -e "\n$(python --version)" >>$LOGFILE
# Python 2.7.14
echo -e "\n$(pip --version)" >>$LOGFILE
# pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)
# Define command python as going to version 2.7:
if grep -q "alias python=" "$BASHFILE" ; then
fancy_echo "Python 2.7 alias already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding Python 2.7 alias in $BASHFILE ..."
echo "export alias python=/usr/local/bin/python2.7" >>"$BASHFILE"
fi
# To prevent the older MacOS default python being seen first in PATH ...
if grep -q "/usr/local/opt/python/libexec/bin" "$BASHFILE" ; then
fancy_echo "Python PATH already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding Python PATH in $BASHFILE..."
echo "export PATH=\"/usr/local/opt/python/libexec/bin:$PATH\"" >>"$BASHFILE"
fi
# Run .bash_profile to have changes take, run $FILEPATH:
source "$BASHFILE"
#echo "$PATH"
# TODO: Python add-ons
#brew install freetype # http://www.freetype.org to render fonts
#brew install openexr
#brew install freeimage
#brew install gmp
#fancy_echo "Installing other popular Python helper modules ..."
#pip install jupyter
#pip install numpy
#pip install scipy
#pip install matplotlib
#pip install ipython[all]
# There is also a Enthought Python Distribution -- www.enthought.com
}
function PYTHON3_INSTALL(){
fancy_echo "Installing Python3 is a pre-requisite for AWS-CLI"
# Because there are two active versions of Python (2.7.4 and 3.6 now)...
# See https://docs.brew.sh/Homebrew-and-Python
# See https://docs.python-guide.org/en/latest/starting/install3/osx/
if ! command -v python3 >/dev/null; then
# No upgrade option.
fancy_echo "Installing Python3, a pre-requisite for awscli and azure ..."
brew install python3
brew info python3 >>$LOGFILE
brew list python3 >>$LOGFILE
#
# To use anaconda, add the /usr/local/anaconda3/bin directory to your PATH environment
# variable, eg (for bash shell):
# export PATH=/usr/local/anaconda3/bin:"$PATH"
#brew doctor fails run here due to /usr/local/anaconda3/bin/curl-config, etc.
#Cask anaconda installs files under "/usr/local". The presence of such
#files can cause warnings when running "brew doctor", which is considered
#to be a bug in Homebrew-Cask.
fi
command -v python3 >>$LOGFILE
ls -al "$(command -v python3)" # /usr/local/bin/python
echo -e "\n$(python3 --version)" >>$LOGFILE
# Python 3.6.4
echo -e "\n$(pip3 --version)" >>$LOGFILE
# pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)
# NOTE: To make "python" command reach Python3 instead of 2.7, per docs.python-guide.org/en/latest/starting/install3/osx/
# Put in PATH Python 3.6 bits at /usr/local/bin/ before Python 2.7 bits at /usr/bin/
if ! python3 -c "import pytz">/dev/null 2>&1 ; then
fancy_echo "Installing utility import pytz ..."
python3 -m pip install pytz # in /usr/local/lib/python3.6/site-packages
fi
if [[ "$PYTHON_TOOLS" == *"anaconda"* ]]; then
if [ ! -d "/Applications/Google Chrome.app" ]; then
# if ! command -v anaconda >/dev/null; then # /usr/bin/anacondadriver
fancy_echo "Installing PYTHON_TOOLS=\"anaconda\" for libraries ..."
brew cask install --appdir="/Applications" anaconda
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "PYTHON_TOOLS=\"anaconda upgrading ..."
anaconda --version # anaconda 5.1.0
brew cask upgrade anaconda
fi
fi
#fancy_echo "Opening PYTHON_TOOLS=\" ..."
#anaconda
echo -e "\n anaconda" >>$LOGFILE
echo -e "$(anaconda --version)" >>$LOGFILE
echo -e "$(conda list)" >>$LOGFILE
if grep -q "/usr/local/anaconda3/bin" "$BASHFILE" ; then
fancy_echo "anaconda3 PATH already in $BASHFILE"
else
fancy_echo "Adding anaconda3 PATH in $BASHFILE..."
echo "export PATH=\"/usr/local/anaconda3/bin:$PATH\"" >>"$BASHFILE"
fi
# QUESTION: What is the MacOS equivalent to pipe every .py file to anaconda's python:
# assoc .py=Python.File
# ftype Python.File=C:\path\to\Anaconda\python.exe "%1" %*
fi
}
function GROOVY_INSTALL(){
# See http://groovy-lang.org/install.html
if ! command -v groovy >/dev/null; then # /usr/local/bin/groovy
fancy_echo "Installing groovy ..."
brew install groovy
brew info groovy >>$LOGFILE
brew list groovy >>$LOGFILE
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "groovy upgrading ..."
groovy --version # upgrading from.
brew upgrade groovy
fi
fi
groovy --version # Groovy Version: 2.4.14 JVM: 1.8.0_162 Vendor: Oracle Corporation OS: Mac OS X
if grep -q "export GROOVY_HOME=" "$BASHFILE" ; then
fancy_echo "export GROOVY_HOME already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding export GROOVY_HOME in $BASHFILE..."
echo "export GROOVY_HOME=/usr/local/opt/groovy/libexec" >>"$BASHFILE"
source "$BASHFILE"
fi
if [[ $TRYOUT == *"groovy"* ]] || [[ $TRYOUT == *"all"* ]]; then
fancy_echo "TRYOUT = groovy = run a Groovy script :"
groovy tests/groovy_smoketest
fi
# https://stackoverflow.com/questions/41110256/how-do-i-tell-intellij-about-groovy-installed-with-brew-on-osx
}
function JAVA_INSTALL(){
# See https://wilsonmar.github.io/java-on-apple-mac-osx/
# and http://sourabhbajaj.com/mac-setup/Java/
if ! command -v java >/dev/null; then
# /usr/bin/java
fancy_echo "Installing Java, a pre-requisite for Selenium, JMeter, etc. ..."
# Don't rely on Oracle to install Java properly on your Mac.
brew tap caskroom/versions
brew cask install --appdir="/Applications" java8
# CAUTION: A specific version of JVM needs to be specified because code that use it need to be upgraded.
fi
TEMP=$(java -version | grep "java version") # | cut -d'=' -f 2 ) # | awk -F= '{ print $2 }'
JAVA_VERSION=${TEMP#*=};
echo "JAVA_VERSION=$JAVA_VERSION"
export JAVA_VERSION=$(java -version)
echo -e "\n$(java -version)" >>$LOGFILE
# java version "1.8.0_144"
# Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
# Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
echo -e "$($JAVA_HOME)" >>$LOGFILE
# /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home is a directory
# https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
if [ ! -z ${JAVA_HOME+x} ]; then # variable has NOT been defined already.
echo "$JAVA_HOME=$JAVA_HOME"
else
echo "JAVA_HOME being set ..." # per http://sourabhbajaj.com/mac-setup/Java/
echo "export JAVA_HOME=$(/usr/libexec/java_home -v $JAVA_VERSION)" >>$BASHFILE
#echo "export JAVA_HOME=$(/usr/libexec/java_home -v 9)" >>$BASHFILE
fi
# /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
# echo "export IDEA_JDK=$(/usr/libexec/java_home -v $JAVA_VERSION)" >>$BASHFILE
# echo "export RUBYMINE_JDK=$(/usr/libexec/java_home -v $JAVA_VERSION)" >>$BASHFILE
source $BASHFILE
# TODO: https://github.com/alexkaratarakis/gitattributes/blob/master/Java.gitattributes
}
function SCALA_INSTALL(){
# See http://scala-lang.org/install.html and http://sourabhbajaj.com/mac-setup/Scala/README.html
# There's also brew scala@2.10 scala@2.11
if ! command -v scala >/dev/null; then # /usr/local/bin/scala
fancy_echo "Installing scala ..."
brew install scala # --with-docs
brew info scala >>$LOGFILE
brew list scala >>$LOGFILE
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "scala upgrading ..."
scala -version # upgrading from.
brew upgrade scala
fi
fi
fancy_echo -e "scala : $(scala -version)" >>$LOGFILE
# 2.12.5
if grep -q "export scala_HOME=" "$BASHFILE" ; then
fancy_echo "export scala_HOME already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding export scala_HOME in $BASHFILE..."
echo "export scala_HOME=/usr/local/opt/scala/libexec" >>"$BASHFILE"
source "$BASHFILE"
fi
# echo '-J-XX:+CMSClassUnloadingEnabled' >> /usr/local/etc/sbtopts
# echo '-J-Xmx2G' >> /usr/local/etc/sbtopts
# within Eclipse > Help → Install New Software..., add the Add... button in the dialog.
# To use with IntelliJ, set the Scala home to: /usr/local/opt/scala/idea
if ! command -v sbt >/dev/null; then # /usr/local/bin/sbt
fancy_echo "Installing sbt ..."
brew install sbt # --with-docs
brew info sbt >>$LOGFILE
brew list sbt >>$LOGFILE
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "sbt upgrading ..."
# sbt -version # upgrading from. Too verbose
brew upgrade sbt
fi
fi
#echo -e "sbt : $(sbt -version)" >>$LOGFILE
# Getting org.scala-sbt sbt 1.1.4 (this may take some time)...
if [[ $TRYOUT == *"scala"* ]] || [[ $TRYOUT == *"all"* ]]; then
fancy_echo "TRYOUT = run program HelloWorld.scala :"
scala tests/HelloWorld.scala
fi
# https://stackoverflow.com/questions/41110256/how-do-i-tell-intellij-about-scala-installed-with-brew-on-osx
}
function NODE_INSTALL(){
fancy_echo "In function NODE_INSTALL ..."
# See https://wilsonmar.github.io/node-starter/
# http://treehouse.github.io/installation-guides/mac/node-mac.html
# We begin with NVM to install Node versions: https://www.airpair.com/javascript/node-js-tutorial
# in order to have several diffent versions of node installed simultaneously.
# See https://github.com/creationix/nvm
if [ ! -d "$HOME/.nvm" ]; then
fancy_echo "Making $HOME/.nvm folder ..."
mkdir $HOME/.nvm
fi
if grep -q "export NVM_DIR=" "$BASHFILE" ; then
fancy_echo "export NVM_DIR= already in $BASHFILE"
else
fancy_echo "Adding export NVM_DIR= in $BASHFILE..."
echo "export NVM_DIR=\"$HOME/.nvm\"" >>$BASHFILE
source $BASHFILE
fi
if ! command -v nvm >/dev/null; then # /usr/local/bin/node
fancy_echo "Installing nvm (to manage node versions)"
brew install nvm # curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
brew info nvm >>$LOGFILE
brew list nvm >>$LOGFILE
# 0.33.8
# TODO: How to tell if nvm.sh has run?
fancy_echo "Running /usr/local/opt/nvm/nvm.sh ..."
source "/usr/local/opt/nvm/nvm.sh" # nothing returned.
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "nvm upgrading ..."
brew upgrade nvm
fi
fi
nvm --version #0.33.8
if ! command -v node >/dev/null; then # /usr/local/bin/node
fancy_echo "Installing node using nvm"
nvm install node # use nvm to install the latest version of node.
# v9.10.1...
nvm install --lts # lastest Long Term Support version # v8.11.1...
# nvm install 8.9.4 # install a specific version
else
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "node upgrading ..."
# nvm i nvm # instead of brew upgrade node
fi
fi
node --version
# $NVM_HOME
# $NODE_ENV
}
function GO_INSTALL(){
if ! command -v go >/dev/null; then # /usr/local/bin/go
fancy_echo "Installing go ..."
brew install go
brew info go >>$LOGFILE
brew list go >>$LOGFILE
else
# specific to each MacOS version
if [[ "${MY_RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "go upgrading ..."
go version # upgrading from.
brew upgrade go
fi
fi
go version # go version go1.10.1 darwin/amd64
if grep -q "export GOPATH=" "$BASHFILE" ; then
fancy_echo "GOPATH already in $BASHFILE"
else
fancy_echo "Adding GOPATH in $BASHFILE..."
echo "export GOPATH=$HOME/golang" >>"$BASHFILE"
fi
# export GOROOT=$HOME/go
# export PATH=$PATH:$GOROOT/bin
}
######### Git clients:
fancy_echo "GIT_CLIENT=$GIT_CLIENT in secrets.sh ..."
echo "The last one installed is set as the Git client."