-
Notifications
You must be signed in to change notification settings - Fork 60
/
mac-setup-all.sh
executable file
·5883 lines (4879 loc) · 222 KB
/
mac-setup-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
#!/bin/bash
#for bash v4
# mac-setup-all.sh in https://github.com/wilsonmar/mac-setup
# 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/mac-setup/master/mac-setup-all.sh)"
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# 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.
IFS=$'\n\t' # Internal Field Separator for word splitting is line or tab, not spaces.
# shellcheck disable=SC2059
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
# shellcheck disable=SC2059
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'; }
command_exists() {
command -v "$@" > /dev/null 2>&1
}
######### 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)"
THISPGM="mac-setup-all.sh"
# ISO-8601 plus RANDOM=$((1 + RANDOM % 1000)) # 3 digit random number.
LOG_DATETIME=$(date +%Y-%m-%dT%H:%M:%S%z)-$((1 + RANDOM % 1000))
LOGFILE="$HOME/$THISPGM.$LOG_DATETIME.log"
echo "$THISPGM starting with logging to file:" >$LOGFILE # new file
echo $LOGFILE >>$LOGFILE
clear # screen
echo $LOGFILE # to screen
RUNTYPE="" # value to be replaced with definition in secrets.sh.
#bar=${RUNTYPE:-none} # :- sets undefine value. See http://redsymbol.net/articles/unofficial-bash-strict-mode/
function pause(){
read -p "Press any key to continue..."
}
function cleanup() {
err=$?
fancy_echo "At cleanup() LOGFILE=$LOGFILE"
#open -a "Atom" $LOGFILE
open -e $LOGFILE # open for edit using TextEdit
#rm $LOGFILE
FREE_DISKBLOCKS_END=$(df | sed -n -e '2{p;q}' | cut -d' ' -f 6)
DIFF=$(((FREE_DISKBLOCKS_START-FREE_DISKBLOCKS_END)/2048))
fancy_echo "$DIFF MB of disk space consumed during this script run." >>$LOGFILE
# 380691344 / 182G = 2091710.681318681318681 blocks per GB
# 182*1024=186368 MB
# 380691344 / 186368 G = 2042 blocks per MB
TIME_END=$(date -u +%s);
DIFF=$((TIME_END-TIME_START))
MSG="End of script $THISPGM after $((DIFF/60))m $((DIFF%60))s seconds elapsed."
fancy_echo "$MSG"
echo -e "\n$MSG" >>$LOGFILE
#say "script ended." # through speaker on Mac.
trap '' EXIT INT TERM
exit $err
}
cleanup2() {
err=$?
echo "At cleanup2() LOGFILE=$LOGFILE"
# pico $LOGFILE
trap '' EXIT INT TERM
exit $err
}
sig_cleanup() {
echo "Run interrupted."
trap '' EXIT # some shells will call EXIT after the INT handler
false # sets $?
cleanup
}
# On macOS only:
macos_ver=$(sw_vers -productVersion | cut -d. -f2)
case "$macos_ver" in # See https://wilsonmar.github.io/apple-mac-osx-versions
14) macos_ver_name="Mojave" ;;
13) macos_ver_name="High Sierra" ;;
12) macos_ver_name="Sierra" ;;
11) macos_ver_name="El Capitan" ;;
10) macos_ver_name="Yosemite" ;;
esac
fancy_echo "sw_vers :: $macos_ver = $macos_ver_name" >>$LOGFILE
echo "$(sw_vers)" >>$LOGFILE
echo "uname -a : $(uname -a)" >>$LOGFILE
if echo "$MAC_TOOLS" | grep -iq "ntpdate"; then
# Using Bash compare (( in arithmetic context )):
# See https://apple.stackexchange.com/questions/117864/how-can-i-tell-if-my-mac-is-keeping-the-clock-updated-properly
if (( "$macos_ver" >= "13" )); then
if [[ $string = *"My long"* ]]; then
fancy_echo "MAC_TOOLS ntpdate to check clock offset on High Sierra or later ..."
ntpdate -d pool.ntp.org | grep "step time server"
# host found : clocka.ntpjs.org
# 29 Jun 04:47:46 ntpdate[77897]: step time server 74.117.214.3 offset -15.533466 sec
fi
else
fancy_echo "MAC_TOOLS ntpdate to check clock offset on Sierra or older ..."
ntpq -p
# remote refid st t when poll reach delay offset jitter
#*uslax1-ntp-001. .GPSs. 1 u 54 128 17 26.492 18.039 7.154
echo "(delay/offset/jitter less than 100 are acceptable)"
fi
else
fancy_echo "MAC_TOOLS ntpdate not specified." >>$LOGFILE
fi
exit
# Disable inputting password:
MAC_USERID=$(id -un 2>/dev/null || true) # example: wilsonmar
fancy_echo "MAC_USERID=$MAC_USERID ..." >>$LOGFILE
if [[ "${MAC_TOOLS,,}" = *"nopassword"* ]]; then
fancy_echo "MAC_TOOLS nopassword sudo visudo using MAC_USERID=$MAC_USERID ..."
sudo visudo
# TODO: $USERNAME ALL=(root) NOPASSWD: /usr/sbin/installer
else
fancy_echo "MAC_TOOLS nopassword not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" = *"xcode"* ]]; then
fancy_echo "MAC_TOOLS xcode is a pre-requisite for many ..."
# Ensure Apple's command line tools (such as cc) are installed by node:
# from open "https://developer.apple.com/downloads/index.action"
# Based on http://www.mokacoding.com/blog/how-to-install-xcode-cli-tools-without-gui/
# and https://github.com/why-jay/osx-init/blob/master/install.sh
XCODE="$(xcode-select -p)" # =/Library/Developer/CommandLineTools
if [ $? -ne 0 ]; then
echo "Xcode $XCODE not found. Installing them ..."
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress;
PROD=$(softwareupdate -l |
grep "\*.*Command Line" |
head -n 1 | awk -F"*" '{print $2}' |
sed -e 's/^ *//' |
tr -d '\n') # PROD=Command Line Tools (macOS High Sierra version 10.13) for Xcode-9.4
softwareupdate -i "$PROD" -v;
fi
if ! command_exists cc ; then
fancy_echo "cc not found. Accept Apple's license ..."
xcodebuild -license
fancy_echo "Installing Apple's command line tools (this takes a while) ..."
# using /System/Library/CoreServices/Install Command Line Developer Tools.app
xcode-select --install # /Library/Developer/CommandLineTools
# 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
if [[ $XCODE =~ ^([yY][eE][sS]|[yY])$ ]]; then
fancy_echo "XCode is installed."
xcode-select --version >>$LOGFILE # xcode-select version 2349.
else
fancy_echo "XCode is not installed. Exiting ..."
exit
fi
else
fancy_echo "MAC_TOOLS xcode not specified." >>$LOGFILE
fi
######### 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
echo "Backing up file $BASHFILE to $BASHFILE-$LOG_DATETIME.bak ..." >>$LOGFILE
cp "$BASHFILE" "$BASHFILE-$LOG_DATETIME.bak"
fi
function BASHFILE_EXPORT() {
# example: BASHFILE_EXPORT "gitup" "open -a /Applications/GitUp.app"
name=$1
value=$2
if grep -q "export $name=" "$BASHFILE" ; then
fancy_echo "$name alias already in $BASHFILE" >>$LOGFILE
else
fancy_echo "Adding $name in $BASHFILE..."
# Do it now:
export "$name=$value"
# For after a Terminal is started:
echo "export $name='$value'" >>"$BASHFILE"
fi
}
######### bash completion:
# Because of the shebang, bash v4 is expected.
fancy_echo "$(bash --version | grep 'bash')" >>$LOGFILE
# 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)
###### Install homebrew using whatever Ruby is installed:
# Ruby comes with MacOS:
fancy_echo "About Ruby ..." >>$LOGFILE
ruby -v >>$LOGFILE # ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin16]
if [[ "${RUNTYPE,,}" == *"upgrade"* ]]; then
sudo gem update --system
# https://asciidoctor.org/docs/install-asciidoctor-macos/
fi
# Set the permissions that Brew expects
# sudo chflags norestricted /usr/local && sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
#Mandatory:
if ! command_exists brew ; 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 [[ "${RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "Brew upgrading ..." >>$LOGFILE
brew --version
# brew upgrade # upgrades all modules.
fi
fi
fancy_echo "$(brew --version)" >>$LOGFILE
# Homebrew 1.5.12
# Homebrew/homebrew-core (git revision 9a81e; last commit 2018-03-22)
brew analytics off # see https://github.com/Homebrew/brew/blob/master/docs/Analytics.md
function BREW_INSTALL() {
# Example call: BREW_INSTALL "GIT_CLIENTS" "git --something" "--version"
local category="$1" # sample: "DATA_TOOLS"
local package_in="$2" # sample: "moreutils --without-parallel"
local versions="$3" # sample: "brew"
prefix="$category BREW_INSTALL"
package="$(echo $package_in | head -n1 | awk '{print $1;}')"
RESPONSE=$(brew info $package)
package_info="$(brew cask info $package | grep "$package:")"
if [[ "${RUNTYPE,,}" == *"remove"* ]]; then
if [[ "$RESPONSE" == *"No available formula"* ]] || [[ $RESPONSE == *"Not installed"* ]]; then
fancy_echo "$category $package_info already removed ..."
else
fancy_echo "$category $package_info removing ..."
brew uninstall --force $package
rm -rf "/Applications/$appname.app" #needed with uninstall
fi
else # other RUNTYPEs:
fancy_echo "$prefix brew info $RESPONSE"
if [[ $RESPONSE == *"No available formula"* ]] || [[ $RESPONSE == *"Not installed"* ]]; then
fancy_echo "$category $package_info installing ..."
brew install "$package_in"
else
if [[ "${RUNTYPE,,}" == *"upgrade"* ]]; then
fancy_echo "$category $package_info upgrading ..."
brew upgrade $package
fi
fi
if [[ -z "${versions// }" ]]; then #it's blank
echo "$prefix (no version)"
else
if [[ "$versions" == "brew" ]]; then
VER="$(brew info $package | grep "$package:")"
echo "$prefix $VER"
elif command_exists $package ; then
#echo "$category $package command available now."
if [[ "$versions" == "version" ]]; then
VER="$($package version | head -n 1)"
echo "$prefix $VER"
elif [[ "$versions" == "--version" ]]; then
VER="$($package --version | head -n 1)"
echo "$prefix $VER"
elif [[ "$versions" == "-v" ]]; then
VER="$($package -v | head -n 1)"
echo "$prefix $VER"
else
VER="$($versions)"
echo "$prefix $VER"
# find / -name $package 2>/dev/null
fi
fi
if [[ "$category" == "LOCALHOSTS" ]] || [[ "$category" == "CLOUD_TOOLS" ]]; then
echo "$prefix $package_info ..."
elif [[ "${TRYOUT,,}" == *"$package"* ]] || [[ "${TRYOUT,,}" == *"all"* ]]; then
echo "$prefix $package opening ..."
"$package" &
fi
fi
fi
}
## or, if running Bash 4.1+
#BREW_INSTALL bash-completion@2
## If running Bash 3.2 included with macOS
#BREW_INSTALL bash-completion
function BREW_CASK_INSTALL() {
# Example: BREW_CASK_INSTALL "EDITORS" "webstorm" "Webstorm" "brew"
local category="$1"
local package_in="$2"
local appname="$3"
local versions="$4" # sample: "brew"
prefix="$category BREW_INSTALL $RUNTYPE"
package=$(echo "$package_in" | head -n1 | awk '{print $1;}')
RESPONSE=$(brew cask info $package)
package_info="$(brew cask info $package | grep "$package:")"
if [[ "${RUNTYPE,,}" == *"remove"* ]]; then
# TODO: Confirm response_file contents if removed:
if [[ "$RESPONSE" == *"Not installed"* ]] || [[ "$RESPONSE" == *"No available formula"* ]]; then
fancy_echo "$prefix $package_info already removed ..."
else
fancy_echo "$category $package_info being removed ..."
brew remove "$package"
# Error: No such keg
fi
if [ -d "/usr/local/Caskroom/$appname" ]; then # found:
rm -rf "/usr/local/Caskroom/$appname"
fi
if [ -d "/Applications/$appname.app" ]; then # found:
rm -rf "/Applications/$appname.app"
fi
else # other RUNTYPEs:
if [[ "$RESPONSE" == *"No available formula"* ]] || [[ "$RESPONSE" == *"Not installed"* ]]; then
#if grep -q "Not installed" "response_file" ; then # for update too:
fancy_echo "$category $package_info installing ..."
brew cask install --appdir="/Applications" "$package_in"
else # installed already:
if [[ "${RUNTYPE,,}" == *"upgrade"* ]]; then
# $package -v >>$LOGFILE
fancy_echo "$category $package_info upgrading ..."
brew cask upgrade $package
fi
fi
if command_exists $package ; then
echo "$category $package command available, so alias not needed."
else
echo "$prefix $(brew cask info $package)"
if grep -q "alias $package=" "$BASHFILE" ; then
echo "$category $package alias to $appname.app already in $BASHFILE"
else
echo "$category $package alias to $appname.app adding in $BASHFILE ..."
alias "$package='open -a \"/Applications/$appname.app\"'"
echo "alias $package='open -a \"/Applications/$appname.app\"'" >>"$BASHFILE"
source $BASHFILE # Activate
fi
fi
if [[ "${TRYOUT,,}" == *"$package"* ]] || [[ "${TRYOUT,,}" == *"all"* ]]; then
if command -v $prefix >/dev/null 2>/dev/null; then
echo "$prefix $package opening ..."
open -a "/Applications/$appname.app" &
else
echo "$prefix $package not available!"
fi
fi
fi
}
######### Install git client to download the rest:
# TODO: Check for git command caz this is Mandatory:
if [[ "${GIT_CLIENTS,,}" == *"git"* ]]; then
BREW_INSTALL "GIT_TOOLS" "git" "--version"
# git version 2.14.3 (Apple Git-98)
else
fancy_echo "GIT_TOOLS git not specified." >>$LOGFILE
fi
function GITHUB_UPDATE() {
UPSTREAM="${1:-'@{u}'}"
LOCAL="$(git rev-parse @)"
REMOTE="$(git rev-parse "$UPSTREAM")"
BASE="$(git merge-base @ "$UPSTREAM")"
if [ $LOCAL == $REMOTE ]; then
echo "Up-to-date"
elif [ $LOCAL = $BASE ]; then
git fetch # instead of git pull
git log ..@{u} --oneline
#git reset --hard HEAD@{1} to go back and discard result of git pull if you don't like it.
git merge # Response: Already up to date.
elif [ $REMOTE == $BASE ]; then
git add . -A
git commit -m"GITHUB_UPDATE in $THISPGM"
git push
else
echo "Plese resolve diverged repo."
gitk master..upstream/master
#p4merge
fi
}
######### Download/clone GITHUB_REPO_URL repo:
# In order to keep secrets.sh out of the repo where it can be sent up to public GitHub:
SECRETSFILE="$HOME/secrets.sh"
GITHUB_PATH="https://github.com/wilsonmar/mac-setup.git"
REPO_PATH="$HOME/mac-setup"
if [ ! -f "$SECRETSFILE" ]; then # NOT found:
fancy_echo "$SECRETSFILE not found." >>$LOGFILE
if [ ! -d "$REPO_PATH" ]; then # NOT found:
fancy_echo "Cloning from $GITHUB_PATH ..." >>$LOGFILE
echo "to $REPO_PATH ..." >>$LOGFILE
git clone $GITHUB_PATH "$REPO_PATH"
cd $REPO_PATH
cp secrets.sh "$SECRETSFILE" # once only on init.
rm secrets.sh # so it's not edited by mistaks
else
cd $REPO_PATH
GITHUB_UPDATE
fi
else
fancy_echo "$SECRETSFILE in $REPO_PATH not updated." >>$LOGFILE
fi
fancy_echo "At $(pwd)" >>$LOGFILE
######### Read and use secrets.sh file:
# If the file still contains defaults, it should not be used:
if grep -q "[email protected]" "$SECRETSFILE" ; then # file contents 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 ..." >>$LOGFILE
# To preven fatal: '/Users/wilsonmar/secrets.sh' is outside repository
#pushd $HOME # not needed since SECRETSFILE var contains full path
# secrets.unlock.sh # prompt for password so can be read
chmod +x $SECRETSFILE
source "$SECRETSFILE" # to load contents into memory.
# TODO: run secrets.unlock.sh to lock it again
#popd
#git update-index --skip-worktree $SECRETSFILE
#fancy_echo "git ls-files -v|grep '^h' ::" >>$LOGFILE
#echo "$(git ls-files -v|grep '^S')" >>$LOGFILE
echo "SECRETSFILE=$SECRETSFILE ::" >>$LOGFILE
echo "RUNTYPE=$RUNTYPE ::" >>$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_CLIENTS=$GIT_CLIENTS" >>$LOGFILE
echo "GIT_TOOLS=$GIT_TOOLS" >>$LOGFILE
echo "EDITORS=$EDITORS" >>$LOGFILE
echo "BROWSERS=$BROWSERS" >>$LOGFILE
echo "LANG_TOOLS=$GUI_LANG" >>$LOGFILE
echo "JAVA_TOOLS=$JAVA_TOOLS" >>$LOGFILE
echo "PYTHON_TOOLS=$PYTHON_TOOLS" >>$LOGFILE
echo "NODE_TOOLS=$NODE_TOOLS" >>$LOGFILE
echo "RUBY_TOOLS=$RUBY_TOOLS" >>$LOGFILE
echo "DATA_TOOLS=$DATA_TOOLS" >>$LOGFILE
echo "MARIADB_PASSWORD=$MARIADB_PASSWORD" >>$LOGFILE
echo "MONGODB_DATA_PATH=$MONGODB_DATA_PATH" >>$LOGFILE
echo "TEST_TOOLS=$TEST_TOOLS" >>$LOGFILE
echo "CLOUD_TOOLS=$CLOUD_TOOLS" >>$LOGFILE
# echo "IRON_TOKEN=$IRON_TOKEN" >>$LOGFILE # secret
# echo "IRON_PROJECT_ID=$IRON_PROJECT_ID" >>$LOGFILE # secret
# 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 "DOCKERHOSTS=$DOCKERHOSTS" >>$LOGFILE
echo "VIZ_TOOLS=$VIZ_TOOLS" >>$LOGFILE
echo "LOCALHOSTS=$LOCALHOSTS" >>$LOGFILE
echo "CUCUMBER_PORT=$CUCUMBER_PORT" >>$LOGFILE
echo "ELASTIC_PORT=$ELASTIC_PORT" >>$LOGFILE
echo "GRAFANA_PORT=$GRAFANA_PORT" >>$LOGFILE
echo "HYGIEIA_PORT=$HYGIEIA_PORT" >>$LOGFILE
echo "JEKYLL_PORT=$JEKYLL_PORT" >>$LOGFILE
echo "JENKINS_PORT=$JENKINS_PORT" >>$LOGFILE
echo "JPETSTORE_PORT=$JPETSTORE_PORT" >>$LOGFILE
echo "KIBANA_PORT=$KIBANA_PORT" >>$LOGFILE
echo "MYSQL_PORT=$MYSQL_PORT" >>$LOGFILE
echo "MEANJS_PORT=$MEANJS_PORT" >>$LOGFILE
echo "MINIKUBE_PORT=$MINKUBE_PORT" >>$LOGFILE
echo "MONGODB_PORT=$MONGODB_PORT" >>$LOGFILE
echo "NEO4J_PORT=$NEO4J_PORT" >>$LOGFILE
echo "NEXUS_PORT=$NEXUS_PORT" >>$LOGFILE
echo "NGINX_PORT=$NGINX_PORT" >>$LOGFILE
echo "PACT_PORT=$PACT_PORT" >>$LOGFILE
echo "POSTGRESQL_PORT=$POSTGRESQL_PORT" >>$LOGFILE
echo "PROMETHEUS_PORT=$PROMETHEUS_PORT" >>$LOGFILE
echo "REDIS_PORT=$REDIS_PORT" >>$LOGFILE
echo "SONAR_PORT=$SONAR_PORT" >>$LOGFILE
echo "TOMCAT_PORT=$TOMCAT_PORT" >>$LOGFILE
echo "TRYOUT=$TRYOUT" >>$LOGFILE
echo "TRYOUT_KEEP=$TRYOUT_KEEP" >>$LOGFILE
echo "COLAB_TOOLS=$COLAB_TOOLS" >>$LOGFILE
# TODO: Artifactory, Jira,
echo "MEDIA_TOOLS=$MEDIA_TOOLS" >>$LOGFILE
fi
GITS_PATH_INIT() {
newdir=$1
if [ ! -z "$GITS_PATH" ]; then # fall-back if not set in secrets.sh:
GITS_PATH="$HOME/gits" # the default
fi
if [ ! -d "$GITS_PATH" ]; then # no path, so create:
fancy_echo "GITS_PATH_INIT creating $GITS_PATH ..."
mkdir "$GITS_PATH"
fi
if [[ ! -z "${newdir// }" ]]; then #it's not blank
fancy_echo "GITS_PATH_INIT creating newdir=$newdir ..."
mkdir "$GITS_PATH/$newdir"
fi
}
######### MacOS hidden files configuration:
if [[ "${MAC_TOOLS,,}" == *"unhide"* ]]; then
fancy_echo "MAC_TOOLS: unhide hidden files in OSX Finder." >>$LOGFILE
defaults write com.apple.finder AppleShowAllFiles YES
# also see dotfiles.
defaults write NSGlobalDomain AppleShowAllExtensions -bool true; # show all file extensions
else
fancy_echo "MAC_TOOLS unhide not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"autohide"* ]]; then
fancy_echo "MAC_TOOLS: Auto-hide Dock items." >>$LOGFILE
defaults write com.apple.dock autohide -bool true; # turn Dock auto-hidng on
defaults write com.apple.dock autohide-delay -float 0; # remove Dock show delay
defaults write com.apple.dock autohide-time-modifier -float 0; # remove Dock show delay
else
fancy_echo "MAC_TOOLS autohide not specified." >>$LOGFILE
fi
######### MacOS maxlimits config:
echo "MAC_TOOLS=$MAC_TOOLS" >>$LOGFILE
if [[ "${MAC_TOOLS,,}" == *"maxlimits"* ]]; then
# CAUTION: This is not working yet.
# if version = Sierra or High Sierra:
FILE="/Library/LaunchDaemons/limit.maxfiles.plist"
if [ ! -f "$FILE" ]; then # NOT found, so add it
fancy_echo "Copying from configs/ to $FILE ..."
# https://github.com/wilsonmar/mac-setup/blob/master/configs/limit.maxfiles.plist at 524288
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
# Both plist files must be owned by root:wheel
# See https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x
sudo chown root:wheel $FILE
echo ">>> $(ls -al $FILE)" # Should be -rw-r--r--@ 1 root wheel 536 Jun 21 10:33 /Library/LaunchDaemons/limit.maxfiles.plist
fi
FILE="/Library/LaunchDaemons/limit.maxproc.plist"
if [ ! -f "$FILE" ]; then # NOT found, so add it
# https://github.com/wilsonmar/mac-setup/blob/master/configs/limit.maxproc.plist at 2048
fancy_echo "Copying from configs/ to $FILE ..."
sudo cp configs/limit.maxproc.plist $FILE
sudo chmod 644 $FILE
# Both plist files must be owned by root:wheel
# See https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x
sudo chown root:wheel $FILE
echo ">>> $(ls -al $FILE)" # Should be -rw-r--r--
# See 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
# see http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/
fi
# Apply limits manually:
# Based on https://docs.microsoft.com/en-us/dotnet/core/macos-prerequisites?tabs=netcore2x
fancy_echo "$(launchctl limit | grep max) ::" >>$LOGFILE # no sudo needed
# maxproc 1418 2128
# maxfiles 65536 200000
OPEN_FILES=$(ulimit -n) # 256 default
fancy_echo "ulimit -n = $OPEN_FILES" >>$LOGFILE
# 10032
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/sysctl.3.html
fancy_echo "$(/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 kernal settings to $FILE ..."
echo "kern.maxfiles=49152" | sudo tee -a $FILE
echo "kern.maxfilesperproc=24576" | sudo tee -a $FILE
fi
# Based on https://blog.dekstroza.io/ulimit-shenanigans-on-osx-el-capitan/
echo ">>> First, do a full backup so you can fall-back to prior system settings."
echo ">>> Manually click the Apple icon to Shut Down."
echo ">>> Reboot in Recovery Mode by holding command + R "
echo ">>> While in Recovery mode, open Utility > Terminal and run: csrutil disable Sys Integrity Protection"
echo ">>> Rerun this, the get into Recovery mode mode > Terminal and run: csrutil enable"
else
fancy_echo "MAC_TOOLS maxlimits not specified." >>$LOGFILE
fi
###### bash.profile locale settings missing in OS X Lion+:
if [[ "${MAC_TOOLS,,}" == *"locale"* ]]; then
# 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=
BASHFILE_EXPORT "ARCHFLAGS" "-arch x86_64"
else
fancy_echo "MAC_TOOLS locale not specified." >>$LOGFILE
fi
######### Mac tools:
# Replaced OS X commands with the GNU version:
if [[ "${MAC_TOOLS,,}" == *"coreutils"* ]]; then
# See https://wilsonmar.github.io/mac-utilities
MANPATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnuman"
echo "export MANPATH=\"$HOMEBREW_PREFIX/opt/coreutils/libexec/gnuman\"" >>$BASHFILE
export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"
echo "export PATH=\"$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH\"" >>$BASHFILE
# add `$(brew --prefix coreutils)/libexec/gnubin` to `$PATH` of /usr/local/opt/coreutils/libexec/gnubin
# BTW: brew --prefix coreutils yields /usr/local/bin/coreutils
BREW_INSTALL "MAC_TOOLS" "coreutils" "brew"
# Warning: coreutils 8.29 is already installed and up-to-date
# Install GNU `find`, `locate`, `updatedb`, and `xargs`, `g`-prefixed.
# more From https://gist.github.com/xuhdev/8b1b16fb802f6870729038ce3789568f
# https://github.com/mathiasbynens/dotfiles/blob/master/brew.sh
BREW_INSTALL "coreutils" "less" "--version"
### Utilities for Mac only
BREW_INSTALL "coreutils" "htop" "--version" # like GNU top
BREW_INSTALL "coreutils" "nmap" "--version"
BREW_INSTALL "coreutils" "tmux" "--version"
### GNU utilities for Mac:
BREW_INSTALL "coreutils" "watch" "--version" # /usr/local/Cellar/watch/3.3.14: 9 files, 80KB
BREW_INSTALL "coreutils" "tree" "--version"
# BREW_INSTALL findutils
# BREW_INSTALL screen # for Terminal multiplexer with VT100/ANSI terminal emulation
BREW_INSTALL "coreutils" "moreutils" "--version"
else
fancy_echo "MAC_TOOLS coreutils not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"iterm2"* ]]; then
# https://www.iterm2.com/documentation.html
BREW_CASK_INSTALL "MAC_TOOLS" "iterm2" "iTerm" ""
# BASHFILE_EXPORT "CLICOLOR" "1"
# http://sourabhbajaj.com/mac-setup/iTerm/README.html
# TODO: https://github.com/mbadolato/iTerm2-Color-Schemes/tree/master/schemes
else
fancy_echo "MAC_TOOLS iterm2 not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"mas"* ]]; then
# To manage apps purchased & installed using App Store on MacOS:
BREW_INSTALL "MAC_TOOLS" "mas" "mas version"
if [[ "${RUNTYPE,,}" != *"remove"* ]]; then
if [[ "${TRYOUT,,}" == *"mas"* ]] || [[ "${TRYOUT,,}" == *"all"* ]]; then
fancy_echo "TRYOUT: mas listing apps added via App Store ..." >>$LOGFILE
mas list >>$LOGFILE
fi
fi
else
fancy_echo "MAC_TOOLS mas not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"paragon-ntfs"* ]]; then
# https://www.paragon-software.com/home/ntfs-mac/#
# See http://wilsonmar.github.io/mac-diskspace/
BREW_CASK_INSTALL "MAC_TOOLS" "paragon-ntfs" "Paragon" "-v"
# Restart is necessary.
else
fancy_echo "MAC_TOOLS paragon-ntfs not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"ansible"* ]]; then
# To install programs. See http://wilsonmar.github.io/ansible/
BREW_INSTALL "MAC_TOOLS" "ansible" "ansible -v"
else
fancy_echo "MAC_TOOLS ansible not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"1Password"* ]]; then
# See https://1password.com/ to store secrets on laptops securely.
BREW_CASK_INSTALL "MAC_TOOLS" "1password" "1Password 6" "brew"
#echo -e "$(1Password -v)" >>$LOGFILE # 1Password v6.0.0-beta.7
else
fancy_echo "MAC_TOOLS 1password not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"powershell"* ]]; then
# See https://wilsonmar.github.io/powershell-on-mac/
# https://docs.microsoft.com/en-us/powershell/scripting/powershell-scripting?view=powershell-6
# https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-macos-and-linux?view=powershell-6#macos-1012
BREW_CASK_INSTALL "MAC_TOOLS" "powershell" "PowerShell" "-v"
# PowerShell v6.0.2
# From https://github.com/PowerShell/PowerShell
if [[ "${TRYOUT,,}" == *"powershell"* ]] || [[ "${TRYOUT,,}" == *"all"* ]]; then
fancy_echo "MAC_TOOLS powershell verify ..." >>$LOGFILE
{ echo '$psversiontable';
echo 'Get-ExecutionPolicy -List | Format-Table -AutoSize';
echo 'exit';
} | pwsh &
fi
else
fancy_echo "MAC_TOOLS powershell not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"alfred"* ]]; then
# https://www.alfredapp.com/ multi-function utility
# https://github.com/nikitavoloboev/my-mac-os for Alfred workflows
# TODO: Get version 3 $(ls -dt /Applications/Alfred*|head -1)
BREW_CASK_INSTALL "MAC_TOOLS" "alfred" "Alfred 3" "brew"
# Buy the $19 https://www.alfredapp.com/powerpack/
else
fancy_echo "MAC_TOOLS Alfred not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"vmware-fusion"* ]]; then
BREW_CASK_INSTALL "MAC_TOOLS" "vmware-fusion" "VMware Fusion" "brew"
else
fancy_echo "MAC_TOOLS vmware-fusion not specified." >>$LOGFILE
fi
if echo "$TRYOUT" | grep -iq "istats"; then
# command-line tool to display CPU temperature, fan speeds and battery info
# See http://chris911.github.io/iStats/
gem install iStats # uses whatever Ruby is installed.
#istats enable key # to run SMC (System Management Controller) sensors
# See https://support.apple.com/en-us/ht201295
if echo "$TRYOUT" | grep -iq "istats" || echo "$TRYOUT" | grep -iq "all"; then
istats
fi
else
fancy_echo "MAC_TOOLS istats not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"bartender"* ]]; then
# manage icons at top launch bar
BREW_CASK_INSTALL "MAC_TOOLS" "bartender" "Bartender" "brew"
else
fancy_echo "MAC_TOOLS bartender not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"charles"* ]]; then
# https://stackoverflow.com/questions/33322334/charles-proxy-response-unreadable
# https://www.bonusbits.com/wiki/HowTo:Setup_Charles_Proxy_on_Mac
BREW_CASK_INSTALL "MAC_TOOLS" "charles" "Charles" "brew"
else
fancy_echo "MAC_TOOLS charles not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"carthage"* ]]; then
# Package manager for Apple Mac Coacoa
BREW_INSTALL "MAC_TOOLS" "carthage" "brew"
else
fancy_echo "MAC_TOOLS carthage not specified." >>$LOGFILE
fi
if [[ "${MAC_TOOLS,,}" == *"others"* ]]; then
echo "Installing MAC_TOOLS=others ...";
# BREW_CASK_INSTALL monolingual # remove unneeded osx lang files https://ingmarstein.github.io/Monolingual/
# BREW_CASK_INSTALL vmware-fusion # run Windows
# BREW_CASK_INSTALL xtrafinder
# BREW_CASK_INSTALL sizeup # $12.99 resize windows http://www.irradiatedsoftware.com/sizeup/
# BREW_CASK_INSTALL duet
# BREW_CASK_INSTALL logitech-harmony # multi-controller of TVs etc
# BREW_CASK_INSTALL cheatsheet # hold ⌘ gives you all the shortcuts you can use with the active app.
# BREW_CASK_INSTALL steam
# BREW_CASK_INSTALL fritzing
# BREW_CASK_INSTALL nosleep
# BREW_CASK_INSTALL balsamiq-mockups # for designing website forms
# BREW_CASK_INSTALL smartsynchronize
# BREW_CASK_INSTALL toggldesktop
# BREW_CASK_INSTALL xmind
# BREW_INSTALL jsdoc3
# BREW_CASK_INSTALL appcleaner
# BREW_CASK_INSTALL qlcolorcode
# BREW_CASK_INSTALL qlstephen
# BREW_CASK_INSTALL qlmarkdown
# BREW_CASK_INSTALL quicklook-json
# BREW_CASK_INSTALL quicklook-csv
# BREW_CASK_INSTALL betterzipql
# BREW_CASK_INSTALL asepsis
# BREW_CASK_INSTALL cheatsheet
# http://almworks.com/jiraclient/download.html
# BREW_CASK_INSTALL bluestacks # to emulate Android phone
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_DATETIME.bak ..." >>$LOGFILE
cp "$GITCONFIG" "$GITCONFIG-$LOG_DATETIME.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/"
}
# Added 21 Jun 2018:
if [[ "${RUNTYPE,,}" != *"remove"* ]]; then
BASHFILE_EXPORT "PS1" "\n \w\[\033[33m\] \$(parse_git_branch)\[\033[00m\]\n$ "
# See http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
BASHFILE_EXPORT "CLICOLOR" "1"
BASHFILE_EXPORT "LSCOLORS" "GxFxCxDxBxegedabagaced" # for Dark Terminal themes
# BASHFILE_EXPORT "LSCOLORS" "eafxcxdxbxegedabagacad" # for White Terminal themes
# See it work with ls -GFh
BASHFILE_EXPORT "GREP_OPTIONS" "--color=auto" # Tell grep to highlight matches.
fi
######### 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() {
BREW_CASK_INSTALL "VIRTUALBOX_INSTALL" "virtualbox" "VirtualBox" "brew"
BREW_CASK_INSTALL "VIRTUALBOX_INSTALL" "vagrant-manager" "Vagrant Manager" "brew"
}