-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·917 lines (883 loc) · 35.5 KB
/
Copy pathcli.sh
File metadata and controls
executable file
·917 lines (883 loc) · 35.5 KB
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
#!/usr/bin/env bash
########################################################################################################################
# SERENDITREE COMMANDLINE INTERFACE
########################################################################################################################
# shellcheck disable=SC2154
_ST_HELP_DETAIL="'sc <command> --help' for details about a certain command!"
_ST_HELP="Please type 'sc <help>' for a list of commands or $_ST_HELP_DETAIL"
#
# ARG_POSITIONAL_SINGLE([command],[Command to execute. Please type sc <help> for a list of commands!],[])
# ARG_OPTIONAL_BOOLEAN([all],[a],[All...])
# ARG_OPTIONAL_BOOLEAN([compose],[c],[Run or build for podman compose.])
# ARG_OPTIONAL_BOOLEAN([delete],[],[Deletion flag.])
# ARG_OPTIONAL_BOOLEAN([dryrun],[D],[Activates dryrun mode.])
# ARG_OPTIONAL_BOOLEAN([expose],[E],[Exposes database ports on local pods.])
# ARG_OPTIONAL_BOOLEAN([help],[h],[Command help. Please type sc <help> for a list of commands!])
# ARG_OPTIONAL_BOOLEAN([init],[],[Initialization flag.])
# ARG_OPTIONAL_BOOLEAN([insert],[],[Inserts a new plot.])
# ARG_OPTIONAL_BOOLEAN([integration],[],[Run for integration testing.])
# ARG_OPTIONAL_BOOLEAN([kubernetes],[k],[Use vanilla kubernetes.])
# ARG_OPTIONAL_BOOLEAN([local],[l],[Target local cluster.])
# ARG_OPTIONAL_BOOLEAN([notify],[n],[Enable desktop notifications.])
# ARG_OPTIONAL_BOOLEAN([open],[],[Open plots.])
# ARG_OPTIONAL_BOOLEAN([openshift],[o],[Use openshift.])
# ARG_OPTIONAL_BOOLEAN([prod],[P],[Sets the target stage to prod. (default is dev)])
# ARG_OPTIONAL_BOOLEAN([reset],[],[Reset flag.])
# ARG_OPTIONAL_BOOLEAN([setup],[],[Setup flag.])
# ARG_OPTIONAL_BOOLEAN([test],[T],[Sets the target stage to test. (default is dev)])
# ARG_OPTIONAL_BOOLEAN([upgrade],[],[Upgrade flag.])
# ARG_OPTIONAL_BOOLEAN([wait],[w],[Wait for completion.])
# ARG_OPTIONAL_INCREMENTAL([verbose],[v],[Verbose flag.])
# ARG_OPTIONAL_INCREMENTAL([yes],[y],[Assumes yes on prompts.])
# ARG_OPTIONAL_BOOLEAN([xissuer],[x],[Set cert-issuer to prod when stage is not prod and vice versa.])
# ARG_OPTIONAL_SINGLE([scale],[s],[Machine auto-scaling.])
# ARG_OPTIONAL_SINGLE([resume],[],[Resume plots from the given plot.])
# ARG_LEFTOVERS([Other arguments passed to command.])
# ARG_DEFAULTS_POS([])
# ARG_RESTRICT_VALUES([no-any-options])
# ARG_POSITIONAL_DOUBLEDASH([])
# ARGBASH_SET_INDENT([ ])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.11.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.dev for more info
die()
{
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
evaluate_strictness()
{
! [[ "$2" =~ ^--?[a-zA-Z] ]] || die "ERROR: Unknown option: $2"
}
begins_with_short_option()
{
local first_option all_short_options='acDEhklnoPTwvyxs'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
_arg_command=
_arg_leftovers=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_all="off"
_arg_compose="off"
_arg_delete="off"
_arg_dryrun="off"
_arg_expose="off"
_arg_help="off"
_arg_init="off"
_arg_insert="off"
_arg_integration="off"
_arg_kubernetes="off"
_arg_local="off"
_arg_notify="off"
_arg_open="off"
_arg_openshift="off"
_arg_prod="off"
_arg_reset="off"
_arg_setup="off"
_arg_test="off"
_arg_upgrade="off"
_arg_wait="off"
_arg_verbose=0
_arg_yes=0
_arg_xissuer="off"
_arg_scale=
_arg_resume=
print_help()
{
printf 'Usage: %s [-a|--all] [-c|--compose] [--delete] [-D|--dryrun] [-E|--expose] [-h|--help] [--init] [--insert] [--integration] [-k|--kubernetes] [-l|--local] [-n|--notify] [--open] [-o|--openshift] [-P|--prod] [--reset] [--setup] [-T|--test] [--upgrade] [-w|--wait] [-v|--verbose] [-y|--yes] [-x|--xissuer] [-s|--scale <arg>] [--resume <arg>] [--] <command> ... \n' " sc" && echo
printf '\t%-20s%s\n' "<command>:" "Command to execute. Please type sc <help> for a list of commands!"
printf '\t%-20s%s\n' "... :" "Other arguments passed to command."
printf '\t%-20s%s\n' "-a, --all:" "All..."
printf '\t%-20s%s\n' "-c, --compose:" "Run or build for podman compose."
printf '\t%-20s%s\n' "--delete:" "Deletion flag."
printf '\t%-20s%s\n' "-D, --dryrun:" "Activates dryrun mode."
printf '\t%-20s%s\n' "-E, --expose:" "Exposes database ports on local pods."
printf '\t%-20s%s\n' "-h, --help:" "Command help. Please type sc <help> for a list of commands!"
printf '\t%-20s%s\n' "--init:" "Initialization flag."
printf '\t%-20s%s\n' "--insert:" "Inserts a new plot."
printf '\t%-20s%s\n' "--integration:" "Run for integration testing."
printf '\t%-20s%s\n' "-k, --kubernetes:" "Use vanilla kubernetes."
printf '\t%-20s%s\n' "-l, --local:" "Target local cluster."
printf '\t%-20s%s\n' "-n, --notify:" "Enable desktop notifications."
printf '\t%-20s%s\n' "--open:" "Open plots."
printf '\t%-20s%s\n' "-o, --openshift:" "Use openshift."
printf '\t%-20s%s\n' "-P, --prod:" "Sets the target stage to prod. (default is dev)"
printf '\t%-20s%s\n' "--reset:" "Reset flag."
printf '\t%-20s%s\n' "--setup:" "Setup flag."
printf '\t%-20s%s\n' "-T, --test:" "Sets the target stage to test. (default is dev)"
printf '\t%-20s%s\n' "--upgrade:" "Upgrade flag."
printf '\t%-20s%s\n' "-w, --wait:" "Wait for completion."
printf '\t%-20s%s\n' "-v, --verbose:" "Verbose flag."
printf '\t%-20s%s\n' "-y, --yes:" "Assumes yes on prompts."
printf '\t%-20s%s\n' "-x, --xissuer:" "Set cert-issuer to prod when stage is not prod and vice versa."
printf '\t%-20s%s\n' "-s, --scale:" "Machine auto-scaling. (no default)"
printf '\t%-20s%s\n' "--resume:" "Resume plots from the given plot. (no default)"
}
parse_commandline()
{
_positionals_count=0
local _key
while test $# -gt 0
do
_key="$1"
if test "$_key" = '--'
then
shift
test $# -gt 0 || break
_positionals+=("$@")
_positionals_count=$((_positionals_count + $#))
shift $(($# - 1))
_last_positional="$1"
break
fi
case "$_key" in
-a|--no-all|--all)
_arg_all="on"
test "${1:0:5}" = "--no-" && _arg_all="off"
;;
-a*)
_arg_all="on"
_next="${_key##-a}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-a" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-c|--no-compose|--compose)
_arg_compose="on"
test "${1:0:5}" = "--no-" && _arg_compose="off"
;;
-c*)
_arg_compose="on"
_next="${_key##-c}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-c" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
--no-delete|--delete)
_arg_delete="on"
test "${1:0:5}" = "--no-" && _arg_delete="off"
;;
-D|--no-dryrun|--dryrun)
_arg_dryrun="on"
test "${1:0:5}" = "--no-" && _arg_dryrun="off"
;;
-D*)
_arg_dryrun="on"
_next="${_key##-D}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-D" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-E|--no-expose|--expose)
_arg_expose="on"
test "${1:0:5}" = "--no-" && _arg_expose="off"
;;
-E*)
_arg_expose="on"
_next="${_key##-E}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-E" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-h|--no-help|--help)
_arg_help="on"
test "${1:0:5}" = "--no-" && _arg_help="off"
;;
-h*)
_arg_help="on"
_next="${_key##-h}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-h" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
--no-init|--init)
_arg_init="on"
test "${1:0:5}" = "--no-" && _arg_init="off"
;;
--no-insert|--insert)
_arg_insert="on"
test "${1:0:5}" = "--no-" && _arg_insert="off"
;;
--no-integration|--integration)
_arg_integration="on"
test "${1:0:5}" = "--no-" && _arg_integration="off"
;;
-k|--no-kubernetes|--kubernetes)
_arg_kubernetes="on"
test "${1:0:5}" = "--no-" && _arg_kubernetes="off"
;;
-k*)
_arg_kubernetes="on"
_next="${_key##-k}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-k" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-l|--no-local|--local)
_arg_local="on"
test "${1:0:5}" = "--no-" && _arg_local="off"
;;
-l*)
_arg_local="on"
_next="${_key##-l}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-l" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-n|--no-notify|--notify)
_arg_notify="on"
test "${1:0:5}" = "--no-" && _arg_notify="off"
;;
-n*)
_arg_notify="on"
_next="${_key##-n}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-n" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
--no-open|--open)
_arg_open="on"
test "${1:0:5}" = "--no-" && _arg_open="off"
;;
-o|--no-openshift|--openshift)
_arg_openshift="on"
test "${1:0:5}" = "--no-" && _arg_openshift="off"
;;
-o*)
_arg_openshift="on"
_next="${_key##-o}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-o" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-P|--no-prod|--prod)
_arg_prod="on"
test "${1:0:5}" = "--no-" && _arg_prod="off"
;;
-P*)
_arg_prod="on"
_next="${_key##-P}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-P" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
--no-reset|--reset)
_arg_reset="on"
test "${1:0:5}" = "--no-" && _arg_reset="off"
;;
--no-setup|--setup)
_arg_setup="on"
test "${1:0:5}" = "--no-" && _arg_setup="off"
;;
-T|--no-test|--test)
_arg_test="on"
test "${1:0:5}" = "--no-" && _arg_test="off"
;;
-T*)
_arg_test="on"
_next="${_key##-T}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-T" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
--no-upgrade|--upgrade)
_arg_upgrade="on"
test "${1:0:5}" = "--no-" && _arg_upgrade="off"
;;
-w|--no-wait|--wait)
_arg_wait="on"
test "${1:0:5}" = "--no-" && _arg_wait="off"
;;
-w*)
_arg_wait="on"
_next="${_key##-w}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-w" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-v|--verbose)
_arg_verbose=$((_arg_verbose + 1))
;;
-v*)
_arg_verbose=$((_arg_verbose + 1))
_next="${_key##-v}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-v" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-y|--yes)
_arg_yes=$((_arg_yes + 1))
;;
-y*)
_arg_yes=$((_arg_yes + 1))
_next="${_key##-y}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-y" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-x|--no-xissuer|--xissuer)
_arg_xissuer="on"
test "${1:0:5}" = "--no-" && _arg_xissuer="off"
;;
-x*)
_arg_xissuer="on"
_next="${_key##-x}"
if test -n "$_next" -a "$_next" != "$_key"
then
{ begins_with_short_option "$_next" && shift && set -- "-x" "-${_next}" "$@"; } || die "The short option '$_key' can't be decomposed to ${_key:0:2} and -${_key:2}, because ${_key:0:2} doesn't accept value and '-${_key:2:1}' doesn't correspond to a short option."
fi
;;
-s|--scale)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_scale="$2"
shift
evaluate_strictness "$_key" "$_arg_scale"
;;
--scale=*)
_arg_scale="${_key##--scale=}"
evaluate_strictness "$_key" "$_arg_scale"
;;
-s*)
_arg_scale="${_key##-s}"
evaluate_strictness "$_key" "$_arg_scale"
;;
--resume)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_resume="$2"
shift
evaluate_strictness "$_key" "$_arg_resume"
;;
--resume=*)
_arg_resume="${_key##--resume=}"
evaluate_strictness "$_key" "$_arg_resume"
;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
_positionals_count=$((_positionals_count + 1))
;;
esac
shift
done
}
handle_passed_args_count()
{
local _required_args_string="'command'"
test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes die "ERROR: Not enough positional arguments - we require at least 1 (namely: $_required_args_string).
Please type 'sc <help>' for a list of commands or 'sc <command> --help' for details about a certain command!" 1
}
assign_positional_args()
{
local _positional_name _shift_for=$1
_positional_names="_arg_command "
_our_args=$((${#_positionals[@]} - 1))
for ((ii = 0; ii < _our_args; ii++))
do
_positional_names="$_positional_names _arg_leftovers[$((ii + 0))]"
done
shift "$_shift_for"
for _positional_name in ${_positional_names}
do
test $# -gt 0 || break
eval "$_positional_name=\${1}" || die "Error during argument parsing, possibly an Argbash bug." 1
evaluate_strictness "$_positional_name" "${1##_arg}"
shift
done
}
parse_commandline "$@"
handle_passed_args_count
assign_positional_args 1 "${_positionals[@]}"
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
#
pushd "$(dirname "$(realpath $0)")" &>/dev/null || exit 1
########################################################################################################################
# ARGUMENTS
########################################################################################################################
export _ARG_COMMAND=$_arg_command
export _ARG_SUB_COMMAND=${_arg_leftovers[0]}
# shellcheck disable=SC2206
export _ARG_LEFTOVERS=(${_arg_leftovers[*]})
export _ARG_PROD=${_arg_prod/off/}
export _ARG_TEST=${_arg_test/off/}
export _ARG_ALL=${_arg_all/off/}
export _ARG_DRYRUN=${_arg_dryrun/off/}
export _ARG_VERBOSE=${_arg_verbose/0/}
export _ARG_YES=${_arg_yes/0/}
export _ARG_NOTIFY=${_arg_notify/off/}
export _ARG_COMPOSE=${_arg_compose/off/}
export _ARG_KUBERNETES=${_arg_kubernetes/off/}
export _ARG_LOCAL=${_arg_local/off/}
export _ARG_OPENSHIFT=${_arg_openshift/off/}
export _ARG_DELETE=${_arg_delete/off/}
export _ARG_INIT=${_arg_init/off/}
export _ARG_RESET=${_arg_reset/off/}
export _ARG_RESUME=$_arg_resume
export _ARG_SCALE=$_arg_scale
export _ARG_SETUP=${_arg_setup/off/}
export _ARG_UPGRADE=${_arg_upgrade/off/}
export _ARG_EXPOSE=${_arg_expose/off/}
export _ARG_INSERT=${_arg_insert/off/}
export _ARG_OPEN=${_arg_open/off/}
_ARG_WAIT=${_arg_wait/off/}
_ARG_WAIT=${_ARG_WAIT/on/true}
export _ARG_WAIT
export _ARG_XISSUER=${_arg_xissuer//off/}
export _ARG_INTEGRATION=${_arg_integration/off/}
export _ARG_HELP=${_arg_help/off/}
########################################################################################################################
# IMPORT
########################################################################################################################
source ./src/env.sh
source ./src/cluster.sh
source ./src/compose.sh
source ./src/container.sh
source ./src/context.sh
source ./src/git.sh
source ./src/helm.sh
source ./src/login.sh
source ./src/plots.sh
source ./src/pods.sh
source ./src/status.sh
source ./src/update.sh
source ./src/utils.sh
source ./src/terra.sh
source ./src/test.sh
########################################################################################################################
# HELP
########################################################################################################################
function sc_help() {
sc_heading 2 "Serenditree CLI"
print_help
local _options
printf '\n\t%s\n' "${_BOLD}Local commands:${_NORMAL}"
_options='[--expose] [--wait] [--compose] [--integration]'
printf '\t%-20s%s\n' "up [svc]:" "Starts a local development stack or a single container. $_options"
_options='[--compose] [--integration]'
printf '\t%-20s%s\n\n' "down [svc]:" "Stops local stack or single containers. $_options"
printf '\t%-20s%s\n' "build [svc]:" "Builds all or individual images."
printf '\t%-20s%s\n' "backup:" "Backup local databases."
printf '\t%-20s%s\n' "charts:" "Prints charts information."
printf '\t%-20s%s\n' "completion:" "Adds bash-completion script to /etc/bash_completion.d/. [--all]"
printf '\t%-20s%s\n' "compose [--] <cmd>:" "Run podman compose commands."
printf '\t%-20s%s\n' "config:" "Prints cli and java config."
printf '\t%-20s%s\n' "context [id]:" "Switch or display contexts."
printf '\t%-20s%s\n' "database <db>:" "Open local database console. {user|seed}"
printf '\t%-20s%s\n' "deploy [svc]:" "Deploys all or individual services to the local stack."
printf '\t%-20s%s\n' "env:" "Prints global environment variables based on context."
printf '\t%-20s%s\n' "expose:" "Port-forward operation-services. [--reset|--delete]"
printf '\t%-20s%s\n' "git [--] <cmd>:" "Execute arbitrary git commands."
printf '\t%-20s%s\n' "helm <cmd> [chart]:" "Push commons, update dependencies or render charts."
printf '\t%-20s%s\n' "health:" "Runs health-checks on services. [--wait|--verbose]"
printf '\t%-20s%s\n' "loc:" "Prints lines of code."
printf '\t%-20s%s\n' "login <reg>:" "Login to configured registries."
printf '\t%-20s%s\n' "logs|log [svc]:" "Prints logs of all or individual services on the local pod."
printf '\t%-20s%s\n' "plots:" "Prints or inserts/deletes plots. [--open] [--insert|--delete]"
printf '\t%-20s%s\n' "proxy:" "Proxy kubernetes services."
printf '\t%-20s%s\n' "ps:" "Lists locally running serenditree containers."
printf '\t%-20s%s\n' "push [svc]:" "Push all or individual images."
printf '\t%-20s%s\n' "registry:" "Inspect images in remote registries. [--verbose]"
printf '\t%-20s%s\n' "release:" "Updates the parent git repository and pushes new commits."
printf '\t%-20s%s\n' "reset:" "Removes all local images created by this cli."
printf '\t%-20s%s\n' "restore:" "Restores local databases from remote data."
printf '\t%-20s%s\n' "rotate:" "Rotates JWK material locally."
printf '\t%-20s%s\n' "status:" "Prints status information and checks prerequisites."
printf '\t%-20s%s\n' "terra <cmd>:" "Run infra commands with all variables set."
printf '\t%-20s%s\n' "test:" "Prepares and runs tests. [--delete][--verbose]"
printf '\t%-20s%s\n' "update [comp]:" "Update components."
printf '\n\t%s\n' "${_BOLD}Cluster commands:${_NORMAL}"
printf '\t%-20s%s\n' "up:" "Cluster start/setup. [--init] [--setup] [--wait] [--dashboard]"
printf '\t%-20s%s\n\n' "down:" "Cluster stop/deletion. [--reset|--delete] [--yes]"
printf '\t%-20s%s\n' "backup:" "Setup backup cronjobs or run backups from cronjobs. [--setup]"
printf '\t%-20s%s\n' "certificate:" "Prints certificate information."
printf '\t%-20s%s\n' "clean:" "Deletes dispensable resources."
printf '\t%-20s%s\n' "dashboard:" "Launches the clusters dashboard."
printf '\t%-20s%s\n' "database <db>:" "Open database console. {user|seed}"
printf '\t%-20s%s\n' "deploy:" "Deploys new images."
printf '\t%-20s%s\n' "expose:" "Port-forward operation-services. [--reset|--delete]"
printf '\t%-20s%s\n' "keys:" "List all keys in the cluster's vault."
printf '\t%-20s%s\n' "login:" "Login to OpenShift and its internal registry."
printf '\t%-20s%s\n' "logs <svc>:" "Prints logs of the given pod(s)."
printf '\t%-20s%s\n' "proxy:" "Proxy kubernetes services."
printf '\t%-20s%s\n' "registry [img]:" "Inspects the OpenShift image registry."
printf '\t%-20s%s\n' "resources [csv]:" "Prints resource allocations. Optionally in CSV."
printf '\t%-20s%s\n' "restore:" "Restore databases."
printf '\t%-20s%s\n' "scale [type]:" "Adds an instance type to the karpenter nodepool."
printf '\t%-20s%s\n' "status:" "Prints cluster status information."
printf '\t%-20s%s\n' "tekton [svc]:" "Triggers tekton runs for all or individual services."
printf '\t%-20s%s\n' "test:" "Run tests using k6-operator. [--delete]"
printf '\t%-20s%s\n' "unseal:" "Unseal the cluster's vault"
echo -e "\nPlease type $_ST_HELP_DETAIL"
}
########################################################################################################################
# MAIN
########################################################################################################################
case ${_ARG_COMMAND} in
########################################################################################################################
# LOCAL
########################################################################################################################
up)
[[ "$_ARG_COMMAND" == "uc" ]] && export _ARG_COMPOSE=on
if [[ -n "$_ARG_INTEGRATION" ]]; then
sc_pod_integration_up ${_ARG_LEFTOVERS[*]}
elif [[ -n "$_ARG_COMPOSE" ]]; then
time sc_compose_up ${_ARG_LEFTOVERS[*]}
else
time sc_pod_up ${_ARG_LEFTOVERS[*]}
fi
;;
down)
if [[ -n "$_ARG_INTEGRATION" ]]; then
sc_pod_integration_down ${_ARG_LEFTOVERS[*]}
elif [[ -n "$_ARG_COMPOSE" ]]; then
time sc_compose_down ${_ARG_LEFTOVERS[*]}
else
time sc_pod_down ${_ARG_LEFTOVERS[*]}
fi
;;
build)
time sc_build ${_ARG_LEFTOVERS[*]}
;;
backup)
sc_pod_data_backup
;;
charts)
sc_helm charts
;;
completion)
sc_completion
;;
compose)
sc_compose ${_ARG_LEFTOVERS[*]}
;;
context)
sc_context ${_ARG_LEFTOVERS[*]}
;;
config)
sc_status_config
;;
database)
sc_login_db local ${_ARG_SUB_COMMAND}
;;
deploy)
time sc_pod_deploy ${_ARG_LEFTOVERS[*]}
;;
env)
sc_status_env
;;
expose)
if [[ -n "$_ARG_RESET" ]]; then
_ARG_DELETE=on sc_cluster_expose "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
unset _ARG_DELETE
fi
sc_cluster_expose "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
;;
git)
if [[ "${_ARG_SUB_COMMAND}" == "backup" ]]; then
sc_git push local --all
else
sc_git ${_ARG_LEFTOVERS[*]}
fi
;;
helm)
sc_helm ${_ARG_SUB_COMMAND}
;;
health)
if [[ -n "$_ARG_WAIT" ]]; then
_ST_START="$(date +%s)"
export _ST_START
watch -tn1 sc_pod_health
else
sc_pod_health
fi
;;
loc)
tokei -e .idea,.iml,.git,e2e,node_modules,target,lucene,javadoc,docs,dist -s files $_ST_HOME |
sed -e '/-/d' -e 's/^ //' -e 's/=/-/g'
;;
login)
if [[ -n "$_ARG_HELP" ]]; then
sc_heading 2 "sc login <reg>"
echo "Login to configured registries: redhat, quay, openshift, openshift/local"
else
sc_login "${_ARG_SUB_COMMAND}"
fi
;;
logs | log)
sc_pod_logs ${_ARG_LEFTOVERS[*]} || echo "Did you mean 'sc cluster logs'?"
;;
plots)
if [[ -n "$_ARG_HELP" ]]; then
sc_heading 2 "sc plots [ordinal [name path]]"
echo "Prints or inserts/deletes plots. [--all] [--open] [--insert|--delete]"
echo "Path needs to be absolute."
elif [[ -n "$_ARG_INSERT" ]]; then
sc_plots_insert "${_ARG_SUB_COMMAND}" "1" | sort -nk3
sc_plots_template ${_ARG_LEFTOVERS[*]}
elif [[ -n "$_ARG_DELETE" ]]; then
sc_plots_insert "${_ARG_SUB_COMMAND}" "-1" | sort -nk3
else
sc_plots_inspect "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
fi
;;
proxy)
sc_cluster_proxy
;;
ps)
sc_pod_list silent
;;
push)
time sc_push_plots "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
;;
registry)
if [[ -n "$_ARG_HELP" ]]; then
sc_heading 2 "sc registry {info|scan|age} [comp]"
echo "Retrieves information from the registry."
else
export _ARG_LEFTOVERS=(${_ARG_LEFTOVERS[*]:1})
case ${_ARG_SUB_COMMAND} in
info)
time sc_registry_inspect "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
;;
scan)
time sc_registry_scan "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
;;
age)
time sc_registry_age
;;
esac
fi
;;
release)
sc_git_release
;;
reset)
sc_pod_down
podman image ls --format '{{.Repository}}:{{.Tag}}' | grep "localhost/serenditree" | xargs podman rmi
;;
restore)
sc_pod_data_restore
;;
rotate)
sc_rotate_keys
;;
secrets)
sc_terra_vault
;;
status)
sc_status
;;
terra)
sc_terra_run ${_ARG_LEFTOVERS[*]}
;;
test)
sc_test ${_ARG_LEFTOVERS[*]}
;;
update)
if [[ -n "$_ARG_HELP" ]]; then
sc_heading 2 "sc update <comp> [--yes] [--yes]"
echo "Update components. Without specification, all components are updated or checked for latest versions."
printf '\n\t%-20s%s\n' "helm" "Update chart versions."
printf '\n\t%-20s%s\n' "kustomize" "Update additional kustomize deployments."
printf '\n\t%-20s%s' "{image*}" "Update base images or check for upgrades."
printf '\n\t%-20s%s' "{kubernetes | k}" "Update Kubernetes."
printf '\n\t%-20s%s\n' "{maven | mvn | java}" "Update maven dependencies."
printf '\n\t%-20s%s' "tile*" "Update Tileserver."
printf '\n\t%-20s%s\n' "yarn" "Update node modules."
else
case ${_ARG_SUB_COMMAND} in
helm)
sc_update_helm
;;
kustomize)
sc_update_kustomize
;;
img | image*)
sc_update_image "$(sc_args_to_pattern "${_ARG_LEFTOVERS[*]:1}")"
;;
kubernetes)
sc_update_kubernetes
;;
maven | mvn | java)
sc_update_maven
;;
tile*)
sc_update_tileserver
;;
yarn)
sc_update_yarn
;;
"")
sc_heading 1 helm
sc_update_helm
sc_heading 1 kustomize
sc_update_kustomize
sc_heading 1 images
sc_update_image
sc_heading 1 kubernetes
sc_update_kubernetes
sc_heading 1 maven
sc_update_maven
sc_heading 1 tileserver
sc_update_tileserver
sc_heading 1 yarn
sc_update_yarn
;;
*)
echo "Unknown component '${_ARG_SUB_COMMAND}'. Enter sc update --help for available components!"
;;
esac
fi
;;
[1-4])
sc_context $_ARG_COMMAND
;;
########################################################################################################################
# CLUSTER
########################################################################################################################
cluster)
if [[ -z "${_ST_CONTEXT}" ]]; then
tput cuu1
sc_heading 2 "Aborting..." >&2
exit 1
fi
export _ST_CONTEXT_CLUSTER=on
# shift leftovers array
# shellcheck disable=SC2206
export _ARG_LEFTOVERS=(${_ARG_LEFTOVERS[*]:1})
case ${_ARG_SUB_COMMAND} in
up)
if [[ -n "$_ARG_HELP" ]]; then
_help_message="sc cluster up"
_help_message+="[--init|--setup|--upgrade]"
sc_heading 2 "$_help_message"
echo "Start or install the cluster of the current context."
printf '\n\t%-20s%s\n' "--init" "Initialize OpenTofu and create assets for openshift-install."
printf '\n\t%-20s%s\n' "--setup" "Setup the cluster of the current context."
printf '\n\t%-20s%s\n' "--upgrade" "Upgrade the cluster of the current context."
else
if [[ -n "${_ARG_SETUP}${_ARG_INIT}" ]]; then
time sc_terra_up
else
time sc_cluster_up
fi
fi
;;
down)
if [[ -n "$_ARG_HELP" ]]; then
_help_message="sc cluster down"
_help_message+="[--reset|--delete]"
sc_heading 2 "$_help_message"
echo "Stop, delete or reset the cluster of the current context. "
printf '\t%-20s%s\n' "--reset" "Reset the cluster of the current context."
printf '\t%-20s%s\n' "--delete" "Delete the cluster of the current context."
else
if [[ -n "$_ARG_DELETE" ]]; then
sc_prompt "Delete cluster?" && time sc_terra_down
else
sc_prompt "Stop worker nodes?" && time sc_cluster_down
fi
fi
;;
clean)
time sc_cluster_clean
;;
database)
sc_login_db cluster ${_ARG_LEFTOVERS[*]}
;;
deploy)
sc_cluster_deploy "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
;;
expose)
if [[ -n "$_ARG_RESET" ]]; then
_ARG_DELETE=on sc_cluster_expose "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
unset _ARG_DELETE
fi
sc_cluster_expose "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})"
;;
key*)
sc_cluster_keys
;;
login)
if [[ -n "$_ST_CONTEXT_OPENSHIFT" ]]; then
sc_login openshift
else
sc_login openshift/local
fi
;;
logs | log)
sc_cluster_logs ${_ARG_LEFTOVERS[*]}
;;
proxy)
sc_cluster_proxy
;;
registry)
time sc_cluster_registry ${_ARG_LEFTOVERS[*]}
;;
resources)
time sc_cluster_resources ${_ARG_LEFTOVERS[*]}
;;
restore)
time sc_cluster_restore
;;
scale)
time sc_cluster_scale ${_ARG_LEFTOVERS[*]}
;;
status)
sc_status_cluster
;;
backup)
time sc_cluster_backup
;;
certificate)
time sc_cluster_certificate
;;
tekton)
time sc_plots_do "$(sc_args_to_pattern ${_ARG_LEFTOVERS[*]})" tekton
;;
test)
sc_test_run_cluster
;;
unseal)
sc_cluster_unseal
;;
*)
sc_heading 2 "Unknown cluster command: ${_ARG_SUB_COMMAND}"
print_help
;;
esac
;;
help)
sc_help
;;
*)
if [[ -z "$_ST_ARGBASH" ]]; then
sc_heading 2 "Unknown command: ${_ARG_COMMAND}"
print_help
fi
;;
esac
#
# ] <-- needed because of Argbash