-
Notifications
You must be signed in to change notification settings - Fork 60
/
mac-setup.zsh
executable file
·6807 lines (5803 loc) · 264 KB
/
mac-setup.zsh
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/bin/env zsh
# This is mac-setup.zsh from template https://github.com/wilsonmar/mac-setup/blob/main/mac-setup.zsh
# Coding of this shell script is explained in https://wilsonmar.github.io/mac-setup
# Shell scripting techniques are explained in https://wilsonmar.github.io/shell-scripts
# Like https://medium.com/@maxy_ermayank/developer-environment-setup-script-5fcb7b854acc
# shellcheck does not work on zsh.
# After you obtain a Terminal (console) in your environment,
# cd to folder, copy this line (without the # comment character) and paste in the terminal so
# it installs utilities:
# zsh -c "$(curl -fsSL https://raw.githubusercontent.com/wilsonmar/mac-setup/main/mac-setup.zsh)" -v
# This downloads and installs all the utilities, then invokes programs to prove they work
# This was run on macOS Mojave and Ubuntu 16.04.
SCRIPT_VERSION="v1.208 brew analytics off :mac-setup.zsh"
# sudo password mac-setup.env init : mac-setup.zsh"
# Identify latest https://github.com/balena-io/etcher/releases/download/v1.18.11/balenaEtcher-1.18.11.dmg from https://etcher.balena.io/#download-etcher
# working github -aiac : mac-setup.zsh"
# Restruc github vars : mac-setup.zsh"
# TODO: Download $HOME folder data from local drive or internet
# TODO: Remove circleci from this script.
# TODO: Add test for duplicate run using flock https://www.baeldung.com/linux/bash-ensure-instance-running
# TODO: Add encryption of log output.
# TODO: https://github.com/hashicorp/docker-consul/ to create a prod image from Dockerfile (for security)
### 01. Capture time stamps to later calculate how long the script runs, no matter how it ends:
# See https://wilsonmar.github.io/mac-setup/#StartingTimes
LOG_DATETIME=$( date +%Y%m%dT%H%M%S%z)-$((1 + RANDOM % 1000)) # 2023-09-21T05:07:45-0600-264
# clear # screen (but not history)
EPOCH_START="$( date -u +%s )" # such as 1572634619
THIS_PROGRAM="${0##*/}" # excludes the ./ in "$0"
### 02. Display a menu if no parameter is specified in the command line
# See https://wilsonmar.github.io/mac-setup/#Args
# See https://wilsonmar.github.io/mac-setup/#EchoFunctions
args_prompt() {
echo "OPTIONS: $SCRIPT_VERSION"
echo " -cont continue (NOT stop) on error"
echo " -v run -verbose (list space use and images)"
echo " -vv run -very verbose diagnostics (brew upgrade, update, doctor)"
echo " -x set -x to trace command lines"
echo " -q quiet heading h2 for each step"
echo " -trace trace using OpenTelemtry (Jaeger)"
echo " "
echo " -zsh convert from bash to Zsh"
echo " "
echo " -init copy mac-setup.env,.zsh, .zshrc files from GitHub.com"
echo " -envf \"/alt-folder\" (alternate path to store/read env files)"
echo " "
echo " -I Install brew utilities, apps"
echo " -U Upgrade installed packages if already installed"
echo " -mount \"abc\" mount USB drive to backup/restore"
echo " -utils install utilities we all need and love"
echo " -ossec install OSSEC file integrity monitor"
echo " "
echo " -N \"Proj\" Alternative name of Projects folder"
echo " -url \"https://.../filename.gz\" = URL to download"
echo " -F \"abc\" Folder inside repo"
echo " -od \"directory\" = output directory"
echo " -of \"filename\" = output file"
echo " -DB Delete Before run"
echo " -f \"a9y.py\" file (program) to process"
echo " -P \"-v\" Parameters controlling program called"
echo " -sha generate SHA256 from -f (file)"
echo " -hash \"...\" hash to compare against the -sha downloaded"
echo " -unzip unzip (untar) .zip/.gz downloaded -f (file)"
echo " -vsc install VSCode extensions listed in -f (file)"
echo " "
echo " -fn \"John Doe\" user full name"
echo " -n \"weirdo\" github.com account name"
echo " -e \"[email protected]\" GitHub user -email"
echo " "
echo " -golang install Golang language"
echo " -ruby install Ruby and Refinery"
echo " -js install JavaScript (NodeJs) app (no MongoDB/PostgreSQL)"
echo " -java install Java and __"
echo " "
echo " -conda install Miniconda to run Python (instead of VirtualEnv)"
echo " -venv install Python to run in conda venv (pipenv is default)"
echo " -pyenv install Python to run with Pyenv"
echo " -python install Python interpreter stand-alone (no pyenv or conda)"
echo " -y install Python Flask"
echo " -A run with Python -Anaconda "
echo " -tsf tensorflow"
echo " "
echo " -a actually run server (not dry run)"
echo " -sd sd card initialize locally"
echo " "
echo " -aws AWS cloud"
echo " -eks eks (Elastic Kubernetes Service) in AWS cloud"
echo " -azure Azure cloud"
echo " -gcp Google cloud"
echo " -g \"...\" gcloud API credentials for calls"
echo " -p \"cp100\" project in gcloud"
echo " -quantum Quantum computing within each cloud"
echo " "
echo " -akeyless install/use Akeyless secret manager"
# echo " -Consul Install Hashicorp Consul in Docker"
# echo " -Doormat install/use Hashicorp's doormat-cli & hcloud"
# echo " -Envoy install/use Hashicorp's Envoy client"
echo " -HV install/use -Hashicorp Vault secret manager"
echo " -m Setup Vault SSH CA cert"
echo " -steampipe Steampipe.io database"
echo " "
echo " -d delete GitHub and pyenv from previous run"
echo " -c clone from GitHub"
echo " -gru \"acct/repo\" GITHUB_REPO_URL to download from GitHub"
echo " -d1 depth 1 during GitHub clone for main branch only"
echo " -ssh use SSH to construct GITHUB_REPO_URL to download"
echo " -pfn PROJECT_FOLDER_NAME folder to clone locally"
echo " -gfn GITHUB_FOLDER_NAME folder to clone locally"
echo " -ghb \"v0.5\" git checkout branch or tag"
echo " -u update GitHub (scan for secrets)"
echo " "
# echo " -chezmoi ???"
#echo " -circleci Use CircleCI SaaS"
echo " -docsify install docsify locally"
echo " -podman install and use Podman (instead of Docker)"
echo " -k install and use Docker"
echo " -b build Docker image"
echo " -dps \"dev1\" override default name of a docker process"
echo " -dc use docker-compose.yml file"
echo " -w write image to DockerHub"
echo " -k8s Kubernetes minikube & OpenShift CLI"
echo " -kraft \"\" kraftkit metro"
echo " -r restart (Docker) before run"
echo " "
echo " -aiac \"ec2\" AI to create Terraform Infra as Code"
echo " -pike determine min permissions on tf/IaC"
echo " -hp run HashiCorp Packer"
echo " -tf run terraform"
echo " -ts setup -testserver to run tests"
echo " -o open/view app or web page in default browser"
echo " "
echo " -K Keep OS processes running at end of run (instead of killing them)"
echo " -C remove -Cloned files after run (to save disk space)"
echo " -DA Delete After run containers and other files (to save disk space)"
echo " -M remove Docker iMages pulled from DockerHub (to save disk space)"
echo " -usage usage commands"
echo "# USAGE EXAMPLES:"
echo "chmod +x mac-setup.zsh # change permissions"
echo "./mac-setup.zsh # display this menu"
echo "./mac-setup.zsh -usage # display usage examples"
} # args_prompt()
### 03. Usage Examples
usage_examples() {
echo "./mac-setup.zsh -usage # USAGE EXAMPLES:"
echo "./mac-setup.zsh -init -v # to download .env & aliases into \$HOME folder ${HOME}"
echo "./mac-setup.zsh -init -gfb \"~/github-wilsonmar\" -ssh -v # create GITHUB_FOLDER_BASE"
echo "./mac-setup.zsh -mount \"V-64G-4\" -UM -v # mount USB drive and backup to it"
echo " "
echo "./mac-setup.zsh -I -U -utils -v # install or update utilities spec'd in .env file"
echo "# Using default configuration settings downloaed to \$HOME/mac-setup.env "
echo " "
echo "./mac-setup.zsh -python -I -U -file \"~/github-wilsonmar\" -v "
echo "./mac-setup.zsh -golang -I -U -v "
echo "./mac-setup.zsh -v -Consul -k -a -K # Use HashicorpVault in Docker for localhost Kept alive"
echo "./mac-setup.zsh -v -Consul -podman -a -K # Use HashicorpVault in Podman for localhost Kept alive"
echo "./mac-setup.zsh -v -k -HV -a -K # Use HashicorpVault in Docker for localhost Kept alive"
echo "./mac-setup.zsh -v -HV -m -ts # Use HashicorpVault -testserver"
echo "./mac-setup.zsh -v -HV -s -ts # Initiate Vault testserver"
echo " "
echo "./mac-setup.zsh -v -aws # for Terraform"
echo "./mac-setup.zsh -v -eks -DA "
echo "./mac-setup.zsh -v -g \"abcdef...89\" -p \"cp100-1094\" # Google API call"
echo " "
echo "./mac-setup.zsh -v -I -U -c -HV -G -N \"python-samples\" -f \"a9y-sample.py\" -P \"-v\" -t -AWS -C # Python sample app using Vault"
echo "./mac-setup.zsh -v -venv -c -T -F \"section_2\" -f \"2-1.ipynb\" -K # Jupyter Conda Tensorflow in Venv"
echo "./mac-setup.zsh -v -DA -M -C"
echo "./mac-setup.zsh -G -v -f \"challenge.py\" -P \"-v\" # to run a program in my python-samples repo"
echo "./mac-setup.zsh -v -I -U -c -s -y -r -a -aws # Python Flask web app in Docker"
echo " "
echo "./mac-setup.zsh -v -n -a # NodeJs app with MongoDB"
echo "./mac-setup.zsh -v -ruby -o # Ruby app"
echo "./mac-setup.zsh -v -venv -c -circleci -s # Use CircLeci based on secrets"
echo "./mac-setup.zsh -v -s -eggplant -k -a -console -dc -K -DA # eggplant use docker-compose of selenium-hub images"
echo "./mac-setup.zsh -docsify -d -c -v "
echo "./mac-setup.zsh -pike -c -gru \"alfonsof/terraform-azure-examples\" -d1 -gfn \"alonzo\" -F \"code/01-hello-world\" -o -v "
echo "./mac-setup.zsh -tf -F \"tf-module1\" -d1 -c -v -I -U"
echo "./mac-setup.zsh -steampipe -v -I -aws -c -d1 -gfn \"steampipe\" -of "
echo "./mac-setup.zsh -vsc -v -a -U"
echo "./mac-setup.zsh -akeyless -v -a -U"
echo "./mac-setup.zsh -gatewayd \"filename.gz\"-pfn \"work\" -DB -v"
echo "./mac-setup.zsh -down -url \"https://.../.../filename.gz\" -v"
echo "./mac-setup.zsh -sha -pfn \"work\" -f \"filename.gz\" -unzip -hash \"...\" -of \"gatewayd\" -v"
echo "./mac-setup.zsh -kraft \"fra0\" -v"
} # usage_examples()
### 04. Set display and exit
if [ $# -eq 0 ]; then # display if no parameters are provided:
args_prompt
exit 1
fi
exit_abnormal() { # Function: Exit with error.
echo "exiting abnormally"
#args_prompt
exit 1
}
### 05. Set custom functions to echo text to screen (with defaults)
# See https://wilsonmar.github.io/mac-setup/#TextColors
# \e ANSI color variables are defined in https://wilsonmar.github.io/bash-scripts#TextColors
h2() { if [ "${RUN_QUIET}" = false ]; then # heading
printf "\n\e[1m\e[33m\u2665 %s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
fi
}
info() { # output on every run
printf "\e[2m\n➜ %s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
}
note() { if [ "${SHOW_VERBOSE}" = true ]; then
printf "\n\e[1m\e[36m \e[0m \e[36m%s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
fi
}
secret_note() { if [ "${SHOW_VERBOSE}" = true ]; then
printf "\n\e[1m\e[36m \e[0m \e[36m%s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
fi
}
echo_debug() { if [ "${SHOW_DEBUG}" = true ]; then
printf "\n\e[1m\e[36m \e[0m \e[36m%s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
fi
}
success() {
printf "\n\e[32m\e[1m✔ %s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
}
error() { # ☓
printf "\n\e[31m\e[1m✖ %s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
}
warning() { # ☞ or ☛
printf "\n\e[5m\e[36m\e[1m☞ %s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
}
fatal() { # Skull: ☠ # Star: ★ ★ U+02606 # Toxic: ☢
printf "\n\e[31m\e[1m☢ %s\e[0m\n" "$(echo "$@" | sed '/./,$!d')"
}
blank_line(){
printf "\n"
}
RUN_QUIET=false
SHOW_VERBOSE=true
info "======= ${SCRIPT_VERSION} ${LOG_DATETIME}"
# note "Explained at https://wilsonmar.github.io/mac-setup"
### 06. Define hard-coded variable values that can be overridden as "feature flags"
# See https://wilsonmar.github.io/mac-setup/#FeatureFlags
# Normal:
CONTINUE_ON_ERR=false # -cont
RUN_ACTUAL=false # -a (dry run is default)
RUN_PARMS="" # -P
SHOW_VERBOSE=false # -v
SHOW_DEBUG=false # -vv
VERIFY_ENV=false # -V
RUN_QUIET=false # -q
USE_MOUNT_DRIVE=false # -mount
USE_MOUNT_NAME="" # in env file
INIT_ENV_FILES=false # -init # to use default ENV_FOLDERPATH_BASE:
ENV_FOLDERPATH="" # -envf "$HOME" or alt-folder (away from GitHub)
RUN_VSCODE=false # -VSC
# ///="vscode-ext.txt" # "file" override in .env to Install/Upgrade VSCode extensions from/to file"
CONVERT_TO_ZSH=false # -zsh
URL_TO_DOWNLOAD="" # -url "https://.../.../filename.gz"
GEN_SHA=false # -sha Generate SHA256 from file path specified"
RUN_UNZIP=false # -unzip
HASH_STING="" # -hash string to compare against gen from download"
SET_TRACE=false # -x
RUN_TRACE=false # -trace
OPEN_CONSOLE=false # -console
USE_TEST_SERVER=false # -ts
USE_PROD_ENV=false # -prod
# From secrets file mac-setup.env
SECRETS_FILE=".secrets.env.sample"
# AWS_ACCESS_KEY_ID=""
# AWS_SECRET_ACCESS_KEY=""
# AWS_USER_ARN=""
# AWS_MFA_ARN=""
AWS_DEFAULT_REGION="us-east-2"
EKS_CLUSTER_NAME="sample-k8s"
EKS_KEY_FILE_PREFIX="eksctl-1"
EKS_NODES="2"
EKS_NODE_TYPE="m5.large"
RUN_QUANTUM=false # -quantum
# To be overridden by values defined within mac-setup.env:
PROJECT_FOLDER_BASE="$HOME/Projects" # -P default
PROJECT_FOLDER_NAME="" # -pfn
PROJECT_NAME="" # -p
GITHUB_REPO_NAME="" # -grn
# GITHUB_REPO_PATH="$HOME/github-wilsonmar"
# GITHUB_REPO="wilsonmar.github.io"f
# GITHUB_USER_ACCOUNT="weirdo" # -gan
# GITHUB_USER_NAME="Wilson Mar" # -n
# GITHUB_USER_EMAIL="[email protected]" # -e
#GITHUB_USER_EMAIL="[email protected]"
USE_GITHUB_SSH=false # -ssh
GITHUB_REPO_URL="" # -gru "https://github.com/wilsonmar/xxx.git"
CLONE_GITHUB=false # -c
DELETE_BEFORE=false # -d
GITHUB_DEPTH_1=false # -d1
GITHUB_FOLDER_BASE="$HOME/github-wilsonmar" # -gfb
GITHUB_FOLDER_NAME="mac-setup" # -gfn
GITHUB_BRANCH="" # -ghb
# Different for each app:
MY_FOLDER="" # -F folder
MY_FILE="" # -f file
#MY_FILE="2-3.ipynb"
OUTPUT_DIRECTORY="" # -od
OUTPUT_FILENAME="" # -of
APP1_HOST="127.0.0.1" # default
APP1_PORT="8200" # default
APP1_FOLDER="" # custom specified
OPEN_APP=false # -o
USE_STEAMPIPE=false # -steampipe
USE_AKEYLESS=false # -akeyless
USE_ENVOY=false # -Envoy
USE_DOORMAT=false # -Doormat
RUN_CONSUL=false # -Consul
RUN_NOMAD=false # -Nomad
USE_VAULT=false # -HV
VAULT_HOST="localhost" # default value
#VAULT_ADDR="https://${VAULT_HOST}:8200" # assembled in code below.
VAULT_USER_TOKEN=""
VAULT_USERNAME=""
VAULT_RSA_FILENAME=""
VAULT_CA_KEY_FULLPATH="$HOME/.ssh/ca_key"
VAULT_PUT=false # -hvput # by app program
VAULT_VERSION="" # captured later by vault --version
# Cloud:
RUN_VIRTUALENV=false # -venv
RUN_CONDA=false # -conda
RUN_PYTHON=false # -python
RUN_GOLANG=false # -golang
RUN_JAVA=false # -java
RUN_EGGPLANT=false # -eggplant
RUN_TENSORFLOW=false # -tsf
USE_AIAC=false # -aiac prompt
AIAC_PROMPT=""
RUN_TERRAFORM=false # -tf
RUN_PACKER=false # -hp
RUN_WEBGOAT=false # -W
SET_MACOS_SYSPREFS=false # -macos
UPDATE_GITHUB=false # -u
UPDATE_PKGS=false # -U
USE_DOCKER=false # -k
USE_PODMAN=false # -podman
USE_CIRCLECI=false # -circleci
USE_AWS_CLOUD=false # -aws
# From AWS Management Console https://console.aws.amazon.com/iam/
# AWS_OUTPUT_FORMAT="json" # asked by aws configure CLI.
# EKS_CLUSTER_FILE="" # cluster.yaml instead
USE_YUBIKEY=false # -Y
USE_PIKE=false # -pike
USE_DOCSIFY=false # -docsify
USE_CHEZMOI=false # -chezmoi
USE_K8S=false # -k8s
USE_KRAFTKIT=false # -kraft
KRAFTKIT_METRO="" # -kraft "fra0"
RUN_EKS=false # -eks
EKS_CRED_IS_LOCAL=true
USE_AZURE_CLOUD=false # -azure
USE_GOOGLE_CLOUD=false # -g
GOOGLE_API_KEY="" # manually copied from APIs & services > Credentials
MOVE_SECURELY=false # -m
LOCAL_SSH_KEYFILE=""
GITHUB_ORG=""
RUBY_INSTALL=false # -ruby
NODE_INSTALL=false # -js
MONGO_DB_NAME=""
GATEWAYD_FILE="" # -gatewayd "file.gz"
# Install?
DOWNLOAD_INSTALL=false # -I
RUN_UTILS=false # -utils
RUN_OSSEC=false # -ossec
IMAGE_SD_CARD=false # -sd
# Pre-processing:
DELETE_BEFORE=false # -DB
USE_QEMU=false # -qemu
RESTART_DOCKER=false # -r
DOCKER_IMAGE_FILE="" # custom specified
DOCKER_PS_NAME="dev1" # -dps
BUILD_DOCKER_IMAGE=false # -b
WRITE_TO_DOCKERHUB=false # -w
USE_DOCKER_COMPOSE=false # -dc
USE_PYENV=false # -pyenv
# Post-processing:
DELETE_CONTAINER_AFTER=false # -DA
REMOVE_DOCKER_IMAGES=false # -M
UNMOUNT_AFTER=false # -UM
REMOVE_GITHUB_AFTER=false # -R
KEEP_PROCESSES=false # -K
### 07. Set traps to display information if script is interrupted.
# See https://wilsonmar.github.io/mac-setup/#SetTraps
# See https://github.com/MikeMcQuaid/strap/blob/master/bin/strap.zsh
trap this_ending EXIT
trap this_ending INT QUIT TERM
this_ending() {
EPOCH_END=$(date -u +%s);
EPOCH_DIFF=$((EPOCH_END-EPOCH_START))
sudo --reset-timestamp # prompt for password for sudo session
# Using BASH_VERSION identified above:
if [ "${BASH_VERSION}" -lt "4" ]; then
FREE_DISKBLOCKS_END="0"
else
FREE_DISKBLOCKS_END=$(read -d '' -ra df_arr < <(LC_ALL=C df -P /); echo "${df_arr[10]}" )
fi
FREE_DIFF=$(((FREE_DISKBLOCKS_END-FREE_DISKBLOCKS_START)))
MSG="Ending ${SCRIPT_VERSION} after $((EPOCH_DIFF/360)) seconds and $((FREE_DIFF*512)) bytes on disk"
# echo 'Elapsed HH:MM:SS: ' $( awk -v t=$beg-seconds 'BEGIN{t=int(t*1000); printf "%d:%02d:%02d\n", t/3600000, t/60000%60, t/1000%60}' )
# TODO: Delete stuff?
success "$MSG"
# note "Disk $FREE_DISKBLOCKS_START to $FREE_DISKBLOCKS_END"
}
sig_cleanup() {
trap '' EXIT # some shells call EXIT after the INT handler.
false # sets $?
this_ending
}
### 08. Read parameters as command arguments:
# See https://wilsonmar.github.io/mac-setup/#VariablesSet
while test $# -gt 0; do
case "$1" in
-a)
export RUN_ACTUAL=true
shift
;;
-akeyless)
export USE_AKEYLESS=true
shift
;;
-aiac)
export USE_AIAC=true
shift
AIAC_PROMPT=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export AIAC_PROMPT
shift
;;
-aws)
export USE_AWS_CLOUD=true
shift
;;
-azure)
export USE_AZURE_CLOUD=true
shift
;;
-b)
export BUILD_DOCKER_IMAGE=true
shift
;;
-circleci)
export USE_CIRCLECI=true
export PROJECT_FOLDER_NAME="circleci_demo"
export GITHUB_REPO_URL="https://github.com/fedekau/terraform-with-circleci-example"
#GITHUB_REPO_URL="https://github.com/wilsonmar/circleci_demo.git"
shift
;;
-conda)
export RUN_CONDA=true
shift
;;
-console)
export OPEN_CONSOLE=true
shift
;;
-Consul)
RUN_CONSUL=true
DOCKER_IMAGE_FILE="consul"
# https://hub.docker.com/_/consul
# https://github.com/hashicorp/docker-consul
# When -tf set:
GITHUB_REPO_URL="[email protected]:hashicorp/learn-consul-terraform.git"
MY_FOLDER="datacenter-deploy-ecs-hcp"
GITHUB_BRANCH="v0.5" # -ghb
shift
;;
-cont)
export CONTINUE_ON_ERR=true
shift
;;
-c)
export CLONE_GITHUB=true
shift
;;
-C)
export REMOVE_GITHUB_AFTER=true
shift
;;
-d1)
export GITHUB_DEPTH_1=true
shift
;;
-dc)
export USE_DOCKER_COMPOSE=true
shift
;;
-docsify)
export USE_DOCSIFY=true
PROJECT_FOLDER_NAME="docsify"
GITHUB_REPO_URL="https://github.com/liatrio/devops-bootcamp.git"
shift
;;
-Doormat)
export USE_DOORMAT=true
shift
;;
-dps*)
shift
DOCKER_PS_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export DOCKER_PS_NAME
shift
;;
-d)
export DELETE_BEFORE=true
shift
;;
-DA)
export DELETE_CONTAINER_AFTER=true
shift
;;
-DB)
export DELETE_BEFORE=true
shift
;;
-eks)
export USE_AWS_CLOUD=true
export RUN_EKS=true
shift
;;
-envoy)
export USE_ENVOY=true
shift
;;
-eggplant)
RUN_EGGPLANT=true
PROJECT_FOLDER_NAME="eggplant-demo"
GITHUB_REPO_URL="https://github.com/wilsonmar/Eggplant.git"
MY_FOLDER="docker-test.suite/Scripts"
MY_FILE="openurl.script"
EGGPLANT_HOST="10.190.70.30"
APP1_PORT="80"
shift
;;
-envf*)
shift
ENV_FOLDERPATH=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-e*)
shift
GITHUB_USER_EMAIL=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-E)
export CONTINUE_ON_ERR=true
shift
;;
-f*)
shift
MY_FILE=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-F*)
shift
MY_FOLDER=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-golang)
export RUN_GOLANG=true
shift
;;
-gan*)
shift
GITHUB_USER_ACCOUNT=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export GITHUB_USER_ACCOUNT
shift
;;
-gatewayd*)
shift
export GATEWAYD_FILE=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-gfb*)
shift
GITHUB_FOLDER_BASE=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export GITHUB_FOLDER_BASE
shift
;;
-gfn*)
shift
GITHUB_FOLDER_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export GITHUB_FOLDER_NAME
shift
;;
-ghb*)
shift
export GITHUB_BRANCH=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-grn*)
shift
export GITHUB_REPO_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-gru*)
shift
export GITHUB_REPO_URL=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-g*)
shift
export USE_GOOGLE_CLOUD=true
GOOGLE_API_KEY=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export GOOGLE_API_KEY
shift
;;
-hash*)
shift
export HASH_STRING=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-hp)
export RUN_PACKER=true
shift
;;
-HV)
export USE_VAULT=true
DOCKER_IMAGE_FILE="vault"
# https://hub.docker.com/_/vault
shift
;;
-hvput)
export VAULT_PUT=true
shift
;;
-init)
export INIT_ENV_FILES=true
shift
;;
-I)
export DOWNLOAD_INSTALL=true
shift
;;
-java)
export RUN_JAVA=true
shift
;;
-js)
export NODE_INSTALL=true
export GITHUB_REPO_URL="https://github.com/wesbos/Learn-Node.git"
PROJECT_FOLDER_NAME="delicious"
APPNAME="delicious"
MONGO_DB_NAME="delicious"
shift
;;
-k)
export USE_DOCKER=true
shift
;;
-k8s)
export USE_K8S=true
shift
;;
-kraft*)
shift
export KRAFTKIT_METRO=$( echo "$1" | sed -e 's/^[^=]*=//g' )
# See Available metros at https://docs.kraft.cloud/metros/
export USE_KRAFTKIT=true
shift
;;
-K)
export KEEP_PROCESSES=true
shift
;;
-macos)
export SET_MACOS_SYSPREFS=true
shift
;;
-mount*)
shift
export USE_MOUNT_DRIVE=true
export USE_MOUNT_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-m)
export MOVE_SECURELY=true
export LOCAL_SSH_KEYFILE="id_rsa"
export GITHUB_ORG="organizations/Mck-Internal-Test"
shift
;;
-M)
export REMOVE_DOCKER_IMAGES=true
shift
;;
-n*)
shift
# shellcheck disable=SC2034 # ... appears unused. Verify use (or export if used externally).
GITHUB_USER_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export GITHUB_USER_NAME
shift
;;
-N*)
shift
PROJECT_FOLDER_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export PROJECT_FOLDER_NAME
shift
;;
-od*)
shift
export OUTPUT_DIRECTORY=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-of*)
shift
export OUTPUT_FILENAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-o)
export OPEN_APP=true
shift
;;
-ossec)
export RUN_OSSEC=true
shift
;;
-pfn*)
shift
export PROJECT_FOLDER_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
shift
;;
-pike)
export USE_PIKE=true
shift
;;
-podman)
export USE_PODMAN=true
shift
;;
-prod)
export USE_PROD_ENV=true
shift
;;
-pyenv)
export USE_PYENV=true
shift
;;
-python)
export RUN_PYTHON=true
GITHUB_REPO_URL="https://github.com/wilsonmar/python-samples.git"
PROJECT_FOLDER_NAME="python-samples"
shift
;;
-p*)
shift
PROJECT_NAME=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export PROJECT_NAME
shift
;;
-P*)
shift
RUN_PARMS=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export RUN_PARMS
shift
;;
-qemu)
export USE_QEMU=true
# https://medium.com/@AbhijeetKasurde/running-podman-machine-on-macos-1f3fb0dbf73d
# https://wiki.qemu.org/Hosts/Mac
shift
;;
-quantum)
export RUN_QUANTUM=true
shift
;;
-q)
export RUN_QUIET=true
shift
;;
-ruby)
export RUBY_INSTALL=true
export GITHUB_REPO_URL="https://github.com/nickjj/build-a-saas-app-with-flask.git"
export PROJECT_FOLDER_NAME="bsawf"
#DOCKER_DB_NANE="snakeeyes-postgres"
#DOCKER_WEB_SVC_NAME="snakeeyes_worker_1" # from docker-compose ps
APPNAME="snakeeyes"
shift
;;
-r)
export RESTART_DOCKER=true
shift
;;
-scikit)
export RUN_VIRTUALENV=true
GITHUB_REPO_URL="https://github.com/PacktPublishing/Hands-On-Machine-Learning-with-Scikit-Learn-and-TensorFlow-2.0.git"
export PROJECT_FOLDER_NAME="scikit"
export APPNAME="scikit"
#MY_FOLDER="section_2" # or ="section_3"
shift
;;
-sd)
export IMAGE_SD_CARD=true
shift
;;
-sha)
export GEN_SHA=true
shift
;;
-ssh)
export USE_GITHUB_SSH=true
shift
;;
-steampipe)
export USE_STEAMPIPE=true
shift
;;
-tf)
export RUN_TERRAFORM=true
GITHUB_REPO_URL="https://github.com/wilsonmar/tf-module1"
# GITHUB_BRANCH="main"
# -gfn GITHUB_FOLDER_NAME "tf-module1"
# -pfn PROJECT_FOLDER_NAME "tf-module1"
shift
;;
-tsf)
export RUN_TENSORFLOW=true
export RUN_CONDA=true
shift
;;
-T)
export RUN_TENSORFLOW=true
export RUN_CONDA=true
shift
;;
-unzip)
export RUN_UNZIP=true
shift
;;
-UM)
export UNMOUNT_AFTER=true
shift
;;
-u)
export UPDATE_GITHUB=true
shift
;;
-usage)
usage_examples # local function
shift
;;
-utils)
export RUN_UTILS=true
shift
;;
-url*)
shift
URL_TO_DOWNLOAD=$( echo "$1" | sed -e 's/^[^=]*=//g' )
export URL_TO_DOWNLOAD
shift
;;
-U)
export UPDATE_PKGS=true
shift
;;
-V)
export VERIFY_ENV=true
shift
;;
-v)
export SHOW_VERBOSE=true
shift
;;
-vv)
export SHOW_DEBUG=true
shift
;;
-venv)
export RUN_VIRTUALENV=true
shift
;;
-vsc)
shift
export RUN_VSCODE=true
shift
;;
-v)
export SHOW_VERBOSE=true
shift
;;
-x)
export SET_TRACE=true
shift
;;
-w)
export WRITE_TO_DOCKERHUB=true
shift
;;
-W)
export RUN_WEBGOAT=true
export GITHUB_REPO_URL="https://github.com/wilsonmar/WebGoat.git"
export PROJECT_FOLDER_NAME="webgoat"
export APPNAME="webgoat"
export MY_FOLDER="Contrast" # "ShiftLeft"
export MY_FILE="docker-compose.yml"
export APP1_PORT="8080"
shift
;;
-y)
export GITHUB_REPO_URL="https://github.com/nickjj/build-a-saas-app-with-flask.git"
export PROJECT_FOLDER_NAME="rockstar"
export APPNAME="rockstar"
shift
;;
-Y)
export USE_YUBIKEY=true
shift
;;
-zsh)
export CONVERT_TO_ZSH=true
shift
;;
*)
error "Parameter \"$1\" not recognized. Aborting."
exit 0
break
;;
esac
done
### 08. Show Operating environment information
if [ "${SHOW_DEBUG}" = true ]; then # -vv
h2 "Header example -q to suppress."
info "info example"
note "note example, -v to show."
echo_debug "echo_debug example"
success "success example"
error "error example"
warning "warning (warnNotice) example"
fatal "fatal (warnError) example"
blank_line
fi
# TODO: print all command arguments submitted:
#while (( "$#" )); do
# echo $1
# shift
#done
### 09. Show Operating environment information
# See https://wilsonmar.github.io/mac-setup/#StrictMode
if [ "${CONTINUE_ON_ERR}" = true ]; then # -cont
warning "Set to continue despite error ..."
export CONTINUE_ON_ERR=true
else