forked from zbychfish/gi-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·2055 lines (2004 loc) · 94.9 KB
/
init.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
#!/bin/bash
trap display_error EXIT
export MPID=$$
#author: zibi - [email protected]
#import global variables
. ./scripts/init.globals.sh
function display_error() {
msg "$1" 9
trap - EXIT
kill -s TERM $MPID
}
function msg() {
case "$2" in
"0")
printf "$1"
;;
"1")
printf "$1\n"
;;
"2")
printf "\e[1m>>> $1"
;;
"6")
printf "\e[32m\e[2mINFO:\e[22m $1\n\e[0m"
;;
"7")
printf "\e[34m\e[2mTASK:\e[22m $1\n\e[0m"
;;
"8")
printf "\e[2mINFO:\e[22m \e[97m$1\n\e[0m"
;;
"9")
printf "\e[31m----------------------------------------\n"
if [ "$1" ]
then
printf "Error: $1\n"
else
printf "Error in subfunction\n"
fi
printf -- "----------------------------------------\n"
printf "\e[0m"
;;
*)
display_error "msg with incorrect parameter - $2"
;;
esac
}
function save_variable() {
echo "export $1=$2" >> $file
}
function check_bastion_os() {
if [[ `hostnamectl|grep "Operating System"|awk -F ':' '{print $2}'|awk '{print $1}'` != 'Fedora' ]]
then
display_error "Your bastion machine is not Fedora OS - please use the supported Operating System"
else
msg "You use `hostnamectl|grep "Operating System"` - tested releases $fedora_supp_releases" 8
fi
}
function get_network_installation_type() {
while $(check_input "yn" ${use_air_gap})
do
get_input "yn" "Is your environment air-gapped? - " true
use_air_gap=${input_variable^^}
done
if [ $use_air_gap == 'Y' ]
then
switch_dnf_sync_off
save_variable GI_INTERNET_ACCESS "A"
else
while $(check_input "dp" ${use_proxy})
do
get_input "dp" "Has your environment direct access to the internet or use HTTP proxy? (\e[4mD\e[0m)irect/(P)roxy: " true
use_proxy=${input_variable^^}
done
save_variable GI_INTERNET_ACCESS $use_proxy
fi
}
function switch_dnf_sync_off() {
if [[ `grep "metadata_timer_sync=" /etc/dnf/dnf.conf|wc -l` -eq 0 ]]
then
echo "metadata_timer_sync=0" >> /etc/dnf/dnf.conf
else
sed -i 's/.*metadata_timer_sync=.*/metadata_timer_sync=0/' /etc/dnf/dnf.conf
fi
}
function get_software_selection() {
while $(check_input "yn" ${gi_install})
do
get_input "yn" "Would you like to install Guardium Insights? " false
gi_install=${input_variable^^}
done
save_variable GI_INSTALL_GI $gi_install
[ $gi_install == 'Y' ] && select_gi_version || select_ics_version
save_variable GI_ICS $ics_install
select_ocp_version
while $(check_input "yn" ${install_ldap})
do
get_input "yn" "Would you like to install OpenLDAP? " false
install_ldap=${input_variable^^}
done
save_variable GI_INSTALL_LDAP $install_ldap
}
function display_default_ics() {
local gi_version
local i=0
for gi_version in "${gi_versions[@]}"
do
msg "ICS - ${ics_versions[${bundled_in_gi_ics_versions[$i]}]} for GI $gi_version" 8
i=$((i+1))
done
}
function select_ics_version() {
ics_version_selected=""
while $(check_input "yn" ${ics_install})
do
get_input "yn" "Would you like to install Cloud Packs Foundational Services (IBM Common Services)? " false
ics_install=${input_variable^^}
done
if [[ $ics_install == 'Y' ]]
then
ics_version_selected=${ics_version_selected:-0}
while $(check_input "list" ${ics_version_selected} ${#ics_versions[@]})
do
get_input "list" "Select ICS version: " "${ics_versions[@]}"
ics_version_selected="$input_variable"
done
ics_version_selected=$(($ics_version_selected-1))
save_variable GI_ICS_VERSION $ics_version_selected
ics_install='Y'
else
ics_install='N'
fi
}
function select_gi_version() {
local nd_ics_install
while $(check_input "list" ${gi_version_selected} ${#gi_versions[@]})
do
get_input "list" "Select GI version: " "${gi_versions[@]}"
gi_version_selected="$input_variable"
done
msg "Guardium Insights installation choice assumes installation of bundled version of ICS" 8
gi_version_selected=$(($gi_version_selected-1))
save_variable GI_VERSION $gi_version_selected
ics_version_selected=${bundled_in_gi_ics_versions[$gi_version_selected]}
ics_install='Y'
if [[ $use_air_gap == 'N' ]]
then
msg "You can overwrite selection of default ICS ${ics_versions[$ics_version_selected]} version" 8
msg "In this case you must select supported ICS version by GI ${gi_versions[$gi_version_selected]}" 8
msg "Check documentation before to avoid GI installation problems" 8
while $(check_input "yn" ${nd_ics_install})
do
get_input "yn" "Would you like to install non-default Cloud Packs Foundational Services for GI? " true
nd_ics_install="${input_variable^^}"
done
[[ "$nd_ics_install" == 'Y' ]] && select_ics_version || save_variable GI_ICS_VERSION $ics_version_selected
else
display_default_ics
save_variable GI_ICS_VERSION $ics_version_selected
msg "In case of air-gapped installation you must install the bundled ICS version" 8
fi
}
function select_ocp_version() {
local i
if [[ $gi_install == 'Y' ]]
then
IFS=':' read -r -a ocp_versions <<< ${ocp_supported_by_gi[$gi_version_selected]}
elif [[ $ics_install == 'Y' ]]
then
IFS=':' read -r -a ocp_versions <<< ${ocp_supported_by_ics[$ics_version_selected]}
fi
local new_major_versions=()
local i=1
for ocp_version in "${ocp_versions[@]}"
do
new_major_versions+=("${ocp_major_versions[$ocp_version]}")
i=$((i+1))
done
ocp_major_version=${ocp_major_version:-0}
while $(check_input "list" ${ocp_major_version} ${#ocp_versions[@]})
do
get_input "list" "Select OCP major version: " "${new_major_versions[@]}"
ocp_major_version="$input_variable"
done
for i in "${!ocp_major_versions[@]}"; do
[[ "${ocp_major_versions[$i]}" == "${new_major_versions[$(($ocp_major_version-1))]}" ]] && break
done
ocp_major_version=$i
if [[ $use_air_gap == 'N' ]]
then
ocp_release_decision=${ocp_release_decision:-Z}
while $(check_input "es" ${ocp_release_decision})
do
get_input "es" "Would you provide exact version OC to install (E) or use the latest stable [S]? (E)xact/(\e[4mS\e[0m)table: " true
ocp_release_decision=${input_variable^^}
done
else
ocp_release_decision='E'
fi
if [[ $ocp_release_decision == 'E' ]]
then
msg "Insert minor version of OpenShift ${ocp_major_versions[${ocp_major_version}]}.x" 8
msg "It must be existing version - you can check list of available version using this URL: https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rhcos/${ocp_major_versions[${ocp_major_version}]}/latest/" 8
ocp_release_minor=${ocp_release_minor:-Z}
while $(check_input "int" ${ocp_release_minor} 0 1000)
do
get_input "txt" "Insert minor version of OCP ${ocp_major_versions[${ocp_major_version}]} to install (must be existing one): " false
ocp_release_minor=${input_variable}
done
ocp_release="${ocp_major_versions[${ocp_major_version}]}.${ocp_release_minor}"
else
ocp_release="${ocp_major_versions[${ocp_major_version}]}.latest"
fi
save_variable GI_OCP_RELEASE $ocp_release
}
function display_list () {
local list=("$@")
local i=1
for element in "${list[@]}"
do
if [[ $i -eq ${#list[@]} ]]
then
msg " \e[4m$i\e[24m - $element" 1
else
msg " $i - $element" 1
fi
i=$((i+1))
done
}
function check_input() {
case $1 in
"yn")
[[ $2 == 'N' || $2 == 'Y' ]] && echo false || echo true
;;
"dp")
[[ $2 == 'D' || $2 == 'P' ]] && echo false || echo true
;;
"es")
[[ $2 == 'E' || $2 == 'S' ]] && echo false || echo true
;;
"sto")
[[ $2 == 'O' || $2 == 'R' ]] && echo false || echo true
;;
"list")
if [[ $2 == +([[:digit:]]) ]]
then
[[ $2 -gt 0 && $2 -le $3 ]] && echo false || echo true
else
echo true
fi
;;
"int")
if [[ $2 == +([[:digit:]]) ]]
then
[[ $2 -ge $3 && $2 -le $4 ]] && echo false || echo true
else
echo true
fi
;;
"txt")
case $3 in
"1")
[[ $2 =~ ^[a-zA-Z][a-zA-Z0-9]{1,64}$ ]] && echo false || echo true
;;
"2")
[[ ! -z $2 ]] && echo false || echo true
;;
"3")
if [ -z "$2" ] || $(echo "$2" | egrep -q "[[:space:]]" && echo true || echo false)
then
echo true
else
[[ ${#2} -le $4 ]] && echo false || echo true
fi
;;
"*")
display_error "Error"
;;
esac
;;
"dir")
[ -d "$2" ] && echo false || echo true
;;
"domain")
[[ $2 =~ ^([a-zA-Z0-9](([a-zA-Z0-9-]){0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$ ]] && echo false || echo true
;;
"ip")
local ip
if [[ $2 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]
then
IFS='.' read -r -a ip <<< $2
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
[[ $? -eq 0 ]] && echo false || echo true
else
echo true
fi
;;
"ips")
local ip_value
IFS=',' read -r -a master_ip_arr <<< $2
if [[ ${#master_ip_arr[@]} -eq $3 && $(printf '%s\n' "${master_ip_arr[@]}"|sort|uniq -d|wc -l) -eq 0 ]]
then
local is_wrong=false
for ip_value in "${master_ip_arr[@]}"
do
$(check_input "ip" $ip_value) && is_wrong=true
done
echo $is_wrong
else
echo true
fi
;;
"mac")
[[ $2 =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]] && echo false || echo true
;;
"macs")
local mac_value
IFS=',' read -r -a master_mac_arr <<< $2
if [[ ${#master_mac_arr[@]} -eq $3 && $(printf '%s\n' "${master_mac_arr[@]}"|sort|uniq -d|wc -l) -eq 0 ]]
then
local is_wrong=false
for mac_value in "${master_mac_arr[@]}"
do
$(check_input "mac" $mac_value) && is_wrong=true
done
echo $is_wrong
else
echo true
fi
;;
"txt_list")
local txt_value
local txt_arr
IFS=',' read -r -a txt_arr <<< $2
if [[ ${#txt_arr[@]} -eq $3 ]]
then
local is_wrong=false
for txt_value in "${txt_arr[@]}"
do
[[ "$txt_value" =~ ^[a-zA-Z][a-zA-Z0-9_-]{0,}[a-zA-Z0-9]$ ]] || is_wrong=true
done
echo $is_wrong
else
echo true
fi
;;
"int")
if [[ $2 == +([[:digit:]]) ]]
then
[[ $2 -ge $3 && $2 -le $4 ]] && echo false || echo true
else
echo true
fi
;;
"tz")
if [[ "$2" =~ ^[a-zA-Z0-9_+-]{1,}/[a-zA-Z0-9_+-]{1,}$ ]]
then
timedatectl set-timezone "$2" 2>/dev/null
[[ $? -eq 0 ]] && echo false || echo true
else
echo true
fi
;;
"td")
timedatectl set-time "$2" 2>/dev/null
[[ $? -eq 0 ]] && echo false || echo true
;;
"nodes")
local element1
local element2
local i=0
local node_arr
local selected_arr
IFS=',' read -r -a selected_arr <<< "$2"
IFS=',' read -r -a node_arr <<< "$3"
if [[ $(printf '%s\n' "${selected_arr[@]}"|sort|uniq -d|wc -l) -eq 0 ]]
then
for element1 in ${selected_arr[@]}; do for element2 in ${node_arr[@]}; do [[ "$element1" == "$element2" ]] && i=$(($i+1));done; done
case $5 in
"max")
[ $i -ge $4 ] && echo false || echo true
;;
"def")
[ $4 -eq $i ] && echo false || echo true
;;
"*")
display_error "Incorrect nodes size specification"
;;
esac
else
echo true
fi
;;
"cidr")
if [[ "$2" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\/[0-9]{1,2}$ ]]
then
( ! $(check_input "ip" `echo "$2"|awk -F'/' '{print $1}'`) && ! $(check_input "int" `echo "$2"|awk -F'/' '{print $2}'` 8 22) ) && echo false || echo true
else
echo true
fi
;;
"cidr_list")
local cidr_arr
local cidr
if $3 && [ -z "$2" ]
then
echo false
else
if [ -z "$2" ] || $(echo "$2" | egrep -q "[[:space:]]" && echo true || echo false)
then
echo true
else
local result=false
IFS=',' read -r -a cidr_arr <<< "$2"
for cidr in "${cidr_arr[@]}"
do
check_input "cidr" "$cidr" && result=true
done
echo $result
fi
fi
;;
"jwt")
if [ "$2" ]
then
{ sed 's/\./\n/g' <<< $(cut -d. -f1,2 <<< "$2")|{ base64 --decode 2>/dev/null ;}|jq . ;} 1>/dev/null
[[ $? -eq 0 ]] && echo false || echo true
else
echo true
fi
;;
"cert")
if [ "$2" ]
then
case $3 in
"ca")
openssl x509 -in "$2" -text -noout &>/dev/null
[[ $? -eq 0 ]] && echo false || echo true
;;
"app")
openssl verify -CAfile "$4" "$2" &>/dev/null
[[ $? -eq 0 ]] && echo false || echo true
;;
"key")
openssl rsa -in "$2" -check &>/dev/null
if [[ $? -eq 0 ]]
then
[[ "$(openssl x509 -noout -modulus -in "$4" 2>/dev/null)" == "$(openssl rsa -noout -modulus -in "$2" 2>/dev/null)" ]] && echo false || echo true
else
echo true
fi
;;
"*")
display_error "Incorrect certificate type"
;;
esac
else
echo true
fi
;;
"cs")
[[ $2 == 'C' || $2 == 'S' ]] && echo false || echo true
;;
"ldap_domain")
if [ "$2" ]
then
[[ "$2" =~ ^([dD][cC]=[a-zA-Z-]{2,64},){1,}[dD][cC]=[a-zA-Z-]{2,64}$ ]] && echo false || echo true
else
echo true
fi
;;
"users_list")
local ulist
if [ -z "$2" ] || $(echo "$2" | egrep -q "[[:space:]]" && echo true || echo false)
then
echo true
else
local result=false
IFS=',' read -r -a ulist <<< "$2"
for user in ${ulist[@]}
do
[[ "$user" =~ ^[a-zA-Z][a-zA-Z0-9_-]{0,}[a-zA-Z0-9]$ ]] || result=true
done
echo $result
fi
;;
"ip_range")
local rlist
local ip_value
local is_wrong
if [ "$2" ]
then
if [[ "$2" =~ ^.*-.*$ ]]
then
is_wrong=false
IFS='-' read -r -a rlist <<< "$2"
for ip_value in ${rlist[@]}
do
$(check_input "ip" $ip_value) && is_wrong=true
done
echo $is_wrong
else
echo true
fi
else
echo true
fi
;;
*)
display_error "Error incorrect check_input type"
esac
}
function get_input() {
unset input_variable
msg "$2" 2
case $1 in
"yn")
$3 && msg "(\e[4mN\e[24m)o/(Y)es: " 0 || msg "(N)o/(\e[4mY\e[24m)es: " 0
read input_variable
printf "\e[0m"
$3 && input_variable=${input_variable:-N} || input_variable=${input_variable:-Y}
;;
"dp")
read input_variable
$3 && input_variable=${input_variable:-D} || input_variable=${input_variable:-P}
;;
"list")
msg "" 1
shift
shift
local list=("$@")
display_list $@
msg "Your choice: " 0
read input_variable
input_variable=${input_variable:-${#list[@]}}
;;
"es")
read input_variable
$3 && input_variable=${input_variable:-S} || input_variable=${input_variable:-E}
;;
"txt")
read input_variable
if $3
then
[ -z ${input_variable} ] && input_variable="$4"
fi
;;
"pwd")
local password=""
local password2=""
read -s -p "" password
echo
if [ "$password" == "" ] && $3
then
curr_password="$4";input_variable=false
else
if [ "$password" == "" ]
then
input_variable=true
else
read -s -p ">>> Insert password again: " password2
echo
if [ "$password" == "$password2" ]
then
curr_password=$password
input_variable=false
else
msg "Please try again" 7
input_variable=true
fi
fi
fi
;;
"sto")
read input_variable
$3 && input_variable=${input_variable:-R} || input_variable=${input_variable:-O}
;;
"int")
read input_variable
;;
"cs")
read input_variable
$3 && input_variable=${input_variable:-C} || input_variable=${input_variable:-S}
;;
*)
display_error "Error"
esac
}
function prepare_offline_bastion() {
local curr_password=""
msg "Bastion preparation to managed installation offline (air-gapped)" 7
msg "Offline installation requires setup the local image repository on bastion" 8
while $(check_input "txt" "${repo_admin}" 1)
do
if [[ ! -z "$GI_REPO_USER" ]]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$GI_REPO_USER] or insert local registry username: " true "$GI_REPO_USER"
else
get_input "txt" "Insert local registry username (default - repoadmin): " true "repoadmin"
fi
repo_admin="${input_variable}"
done
save_variable GI_REPO_USER $repo_admin
input_variable=true
while $input_variable
do
if [ ! -z "$GI_REPO_USER_PWD" ]
then
get_input "pwd" "Push <ENTER> to accept the previous choice [$GI_REPO_USER_PWD] or insert new password for $repo_admin user: " true "$GI_REPO_USER_PWD"
else
get_input "pwd" "Insert new password for $repo_admin user: " false
fi
done
save_variable GI_REPO_USER_PWD "'$curr_password'"
msg "Offline installation requires installation archives preparation using preinstall scripts" 8
msg "Archives must be copied to bastion before installation" 8
while $(check_input "dir" "${gi_archives}")
do
if [[ ! -z "$GI_ARCHIVES_DIR" ]]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$GI_ARCHIVES_DIR] or insert the full path to installation archives: " true "$GI_ARCHIVES_DIR"
else
get_input "txt" "Insert full path to installation archives (default location - $GI_HOME/download): " true "$GI_HOME/download"
fi
gi_archives="${input_variable}"
done
save_variable GI_ARCHIVES_DIR "'$gi_archives'"
process_offline_archives
software_installation_on_offline
}
function process_offline_archives() {
msg "Extracting archives - this process can take several minutes and even hours, be patient ..." 7
local archive
local archives=("os-Fedora_release_*" "coreos-registry-${ocp_release}.tar" "olm-registry-${major_ocp_release}*" "additions-registry-*")
local descs=('Fedora files' "CoreOS ${ocp_release} image" "OLM images for CoreOS ${major_ocp_release}" "Additional software images")
[ $storage_type == 'R' ] && { archives+=("rook-registry-${rook_version}.tar");descs+=("Rook-Ceph ${rook_version} images");}
[ $gi_install == 'Y' ] && { archives+=("gi_registry-${gi_versions[$gi_version_selected]}.tar");descs+=("Guardium Insights ${gi_versions[$gi_version_selected]}} images");}
[[ $ics_install == 'Y' && $gi_install == 'N' ]] && { archives+=("ics_registry-${ics_versions[$ics_version_selected]}}.tar");descs+=("Common Services ${ics_versions[$ics_version_selected]} images");}
local i=0
for archive in ${archives[@]}
do
if [ -e ${gi_archives}/${archive} ] && [ $(ls ${gi_archives}/${archive}|wc -l) -eq 1 ]
then
case $i in
0)
msg "Extracting Fedora software packages" 8
mkdir -p $GI_TEMP/os
tar -C $GI_TEMP/os -xf ${gi_archives}/$archive kernel.txt ansible/* galaxy/* os-packages/* os-updates/*
[ $? -ne 0 ] && display_error "Cannot extract content of operating system packages"
;;
1)
msg "Extracting CoreOS images, OCP container images and tools" 8
mkdir -p /opt/registry $GI_TEMP/coreos
tar -C $GI_TEMP/coreos -xf $gi_archives/$archive oc-registry.tar openshift-client-linux.tar.gz openshift-install-linux.tar.gz rhcos-live-initramfs.x86_64.img rhcos-live-kernel-x86_64 rhcos-live-rootfs.x86_64.img opm-linux.tar.gz matchbox-v0.9.0-linux-amd64.tar.gz
tar -C /opt/registry -xf $gi_archives/coreos-registry-${ocp_release}.tar data/*
[ $? -ne 0 ] && display_error "Cannot extract content of CoreOS archive"
;;
2)
msg "Extracting OLM container images" 8
mkdir -p $GI_TEMP/olm
tar -C $GI_TEMP/olm -xf $gi_archives/$archive manifests-*
tar -C /opt/registry -xf $gi_archives/$archive data/*
[ $? -ne 0 ] && display_error "Cannot extract content of OLM archive"
;;
3)
msg "Extracting additional container images, for instance openldap" 8
mkdir -p $GI_TEMP/adds
tar -C $GI_TEMP/adds -xf $gi_archives/$archive digests.txt
tar -C /opt/registry -xf $gi_archives/$archive data/*
[ $? -ne 0 ] && display_error "Cannot extract content of archive with additional images"
;;
4|5|6)
if [ "$archive" == rook-registry-${rook_version}.tar ]
then
msg "Extracting Rook-Ceph container images" 8
mkdir -p $GI_TEMP/rook
tar -C $GI_TEMP/rook -xf $gi_archives/$archive rook_images_sha
tar -C /opt/registry -xf $gi_archives/$archive data/*
[ $? -ne 0 ] && display_error "Cannot extract content of Rook-Ceph archive"
elif [ "$archive" == gi_registry-${gi_versions[$gi_version_selected]}.tar ]
then
msg "Extracting Guardium Insights container images" 8
mkdir -p $GI_TEMP/gi_arch
tar -C $GI_TEMP/gi_arch -xf $gi_archives/$archive cloudctl-linux-amd64.tar.gz gi_offline/*
tar -C /opt/registry -xf $gi_archives/$archive data/*
[ $? -ne 0 ] && display_error "Cannot extract content of Guardium Insights archive"
elif [ "$archive" == ics_registry-${ics_versions[$ics_version_selected]}}.tar ]
then
msg "Extracting Common Services container images" 8
mkdir -p $GI_TEMP/ics_arch
tar -C $GI_TEMP/ics_arch -xf $gi_archives/$archive cloudctl-linux-amd64.tar.gz ics_offline/*
tar -C /opt/registry -xf $gi_archives/$archive data/*
[ $? -ne 0 ] && display_error "Cannot extract content of Common Services archive"
else
display_error "Problem with extraction of archives, unknown archive type"
fi
;;
*)
display_error "Problem with extraction of archives, check their consitency"
;;
esac
else
display_error "Cannot find the ${descs[$i]} archive, please copy to archive to ${gi_archives} directory and restart init.sh"
fi
i=$(($i+1))
done
}
function get_software_architecture() {
msg "Some important architecture decisions and planned software deployment must be made now" 7
msg "OCP can be installed only on 3 nodes which create control and worker plane" 8
msg "This kind of architecture has some limitations:" 8
msg "- You cannot isolate storage on separate nodes" 8
msg "- You cannot isolate GI and CPFS" 8
while $(check_input "yn" ${is_master_only})
do
get_input "yn" "Is your installation the 3 nodes only? " true
is_master_only=${input_variable^^}
done
save_variable GI_MASTER_ONLY $is_master_only
if [[ $ocp_major_version -lt 2 ]]
then
msg "New Rook-Ceph releases do not support OCP 4.6 and 4.7" 8
msg "You must install OCS" 8
storage_type="O"
else
msg "Decide what kind of cluster storage option will be implemented:" 8
msg "- OpenShift Container Storage - commercial rook-ceph branch from RedHat" 8
msg "- Rook-Ceph - opensource cluster storage option" 8
while $(check_input "sto" ${storage_type})
do
get_input "sto" "Choice the cluster storage type? (O)CS/(\e[4mR\e[0m)ook: " true
storage_type=${input_variable^^}
done
fi
save_variable GI_STORAGE_TYPE $storage_type
if [[ $storage_type == "O" && $is_master_only == 'N' ]]
then
msg "OCS tainting will require minimum 3 additional workers in your cluster to manage cluster storage" 8
while $(check_input "yn" ${ocs_tainted})
do
get_input "yn" "Should be OCS tainted? " true
ocs_tainted=${input_variable^^}
done
save_variable GI_OCS_TAINTED $ocs_tainted
else
save_variable GI_OCS_TAINTED "N"
fi
if [[ $gi_install == "Y" ]]
then
while $(check_input "list" ${gi_size_selected} ${#gi_sizes[@]})
do
get_input "list" "Select Guardium Insights deployment template: " "${gi_sizes[@]}"
gi_size_selected=$input_variable
done
gi_size="${gi_sizes[$((${gi_size_selected} - 1))]}"
save_variable GI_SIZE_GI $gi_size
fi
if [[ $gi_install == "Y" && $is_master_only == 'N' ]]
then
msg "DB2 tainting will require additional workers in your cluster to manage Guardium Insights database backend" 8
while $(check_input "yn" ${db2_tainted})
do
get_input "yn" "Should be DB2 tainted? " true
db2_tainted=${input_variable^^}
done
save_variable GI_DB2_TAINTED $db2_tainted
fi
}
function software_installation_on_offline() {
local is_updated
msg "Update and installation of software packaged" 7
if [[ `uname -r` != `cat $GI_TEMP/os/kernel.txt` ]]
then
msg "Kernel of air-gap bastion differs from air-gap file generator!" 8
msg "In most cases the independent kernel update will lead to problems with system libraries" 8
while $(check_input "yn" ${is_updated})
do
get_input "yn" "Have you updated system before, would you like to continue? " true
is_updated=${input_variable^^}
done
if [ $is_updated != 'N' ]
then
display_error "Upload air-gap files corresponding to bastion kernel or generate files for bastion environment"
fi
fi
msg "Installing OS updates" 7
dnf -qy --disablerepo=* localinstall ${GI_TEMP}/os/os-updates/*rpm --allowerasing
msg "Installing OS packages" 7
dnf -qy --disablerepo=* localinstall ${GI_TEMP}/os/os-packages/*rpm --allowerasing
msg "Installing Ansible and python modules" 7
cd ${GI_TEMP}/os/ansible
pip3 install passlib-* --no-index --find-links '.' > /dev/null 2>&1
pip3 install dnspython-* --no-index --find-links '.' > /dev/null 2>&1
cd $GI_TEMP/os/galaxy
ansible-galaxy collection install community-general-3.3.2.tar.gz
cd $GI_HOME
mkdir -p /etc/ansible
echo -e "[bastion]\n127.0.0.1 ansible_connection=local" > /etc/ansible/hosts
msg "OS software update and installation successfully finished" 8
}
function software_installation_on_online() {
msg "Update and installation of software packaged" 7
msg "Installing OS updates" 7
dnf -qy update
msg "Installing OS packages" 8
local soft=("tar" "ansible" "haproxy" "openldap" "perl" "podman-docker" "ipxe-bootimgs" "chrony" "dnsmasq" "unzip" "wget" "httpd-tools" "policycoreutils-python-utils" "python3-ldap" "openldap-servers" "openldap-clients" "pip" "skopeo")
for package in "${soft[@]}"
do
msg "- installing $package ..." 8
dnf -qy install $package &>/dev/null
[[ $? -ne 0 ]] && display_error "Cannot install $package"
done
msg "Installing Python packages" 7
local python_soft=("passlib" "dnspython" "beautifulsoup4")
for package in "${python_soft[@]}"
do
msg "- installing $package ..." 8
[[ $use_proxy == 'D' ]] && pip3 install "$package" || pip3 install "$package" --proxy http://$proxy_ip:$proxy_port
[[ $? -ne 0 ]] && display_error "Cannot install python package $package"
done
msg "Configuring Ansible" 7
mkdir -p /etc/ansible
[[ $use_proxy == 'P' ]] && echo -e "[bastion]\n127.0.0.1 \"http_proxy=http://$proxy_ip:$proxy_port\" https_proxy=\"http://$proxy_ip:$proxy_port\" ansible_connection=local" > /etc/ansible/hosts || echo -e "[bastion]\n127.0.0.1 ansible_connection=local" > /etc/ansible/hosts
msg "Installing Ansible galaxy packages" 7
local ansible_galaxy=("community.general")
for package in "${ansible_galaxy[@]}"
do
msg "- installing $package ..." 8
ansible-galaxy collection install $package
[[ $? -ne 0 ]] && display_error "Cannot install Ansible Galaxy package $package"
done
mkdir -p ${GI_TEMP}/os
echo "pullSecret: '$rhn_secret'" > ${GI_TEMP}/os/pull_secret.tmp
}
function get_ocp_domain() {
msg "Set cluster domain name" 7
msg "Insert the OCP cluster domain name - it is local cluster, so it doesn't have to be registered as public one" 8
while $(check_input "domain" ${ocp_domain})
do
if [[ ! -z "$GI_DOMAIN" ]]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$GI_DOMAIN] or insert domain name: " true "$GI_DOMAIN"
else
get_input "txt" "Insert domain name: " false
fi
ocp_domain=${input_variable}
done
save_variable GI_DOMAIN $ocp_domain
}
function get_bastion_info() {
msg "Collecting data about bastion" 7
msg "Provide IP address of network interface on bastion which is connected to this same subnet,vlan where the OCP nodes are located" 8
while $(check_input "ip" ${bastion_ip})
do
if [[ ! -z "$GI_BASTION_IP" ]]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$GI_BASTION_IP] or insert bastion IP: " true "$GI_BASTION_IP"
else
get_input "txt" "Insert bastion IP: " false
fi
bastion_ip=${input_variable}
done
save_variable GI_BASTION_IP $bastion_ip
msg "Provide the hostname used to resolve bastion name by local DNS which will be set up" 8
while $(check_input "txt" ${bastion_name} 1)
do
if [[ ! -z "$GI_BASTION_NAME" ]]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$GI_BASTION_NAME] or insert bastion name: " true "$GI_BASTION_NAME"
else
get_input "txt" "Insert bastion name: " false
fi
bastion_name=${input_variable}
done
save_variable GI_BASTION_NAME $bastion_name
if [[ $one_subnet == 'Y' ]]
then
msg "Provide the IP gateway of subnet where cluster node are located" 8
while $(check_input "ip" ${subnet_gateway})
do
if [[ ! -z "$GI_GATEWAY" ]]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$GI_GATEWAY] or insert IP address of default gateway: " true "$GI_GATEWAY"
else
get_input "txt" "Insert IP address of default gateway: " false
fi
subnet_gateway=${input_variable}
done
save_variable GI_GATEWAY $subnet_gateway
fi
}
function get_nodes_info() {
local temp_ip
local temp_mac
local temp_name
case $2 in
"ocs")
local pl_names=("addresses" "names" "IP's" "hosts")
local node_type="OCS nodes"
local global_var_ip=$GI_OCS_IP
local global_var_mac=$GI_OCS_MAC_ADDRESS
local global_var_name=$GI_OCS_NAME
;;
"boot")
local pl_names=("address" "name" "IP" "host")
local node_type="bootstrap node"
local global_var_ip=$GI_BOOTSTRAP_IP
local global_var_mac=$GI_BOOTSTRAP_MAC_ADDRESS
local global_var_name=$GI_BOOTSTRAP_NAME
;;
"mst")
local pl_names=("addresses" "names" "IP's" "hosts")
local node_type="master nodes"
local global_var_ip=$GI_MASTER_IP
local global_var_mac=$GI_MASTER_MAC_ADDRESS
local global_var_name=$GI_MASTER_NAME
;;
"wrk")
local pl_names=("addresses" "names" "IP's" "hosts")
local node_type="worker nodes"
local global_var_ip=$GI_WORKER_IP
local global_var_mac=$GI_WORKER_MAC_ADDRESS
local global_var_name=$GI_WORKER_NAME
;;
"*")
exit 1
esac
msg "Insert $1 ${pl_names[2]} ${pl_names[0]} of $node_type, should be located in subnet with gateway - $subnet_gateway" 8
while $(check_input "ips" ${temp_ip} $1)
do
if [ ! -z "$global_var_ip" ]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$global_var_ip] or insert $node_type ${pl_names[2]}: " true "$global_var_ip"
else
get_input "txt" "Insert $node_type IP: " false
fi
temp_ip=${input_variable}
done
msg "Insert $1 MAC ${pl_names[0]} of $node_type" 8
while $(check_input "macs" ${temp_mac} $1)
do
if [ ! -z "$global_var_mac" ]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$global_var_mac] or insert $node_type MAC ${pl_names[0]}: " true "$global_var_mac"
else
get_input "txt" "Insert $node_type MAC ${pl_names[0]}: " false
fi
temp_mac=${input_variable}
done
msg "Insert $1 ${pl_names[3]} ${pl_names[1]} of $node_type" 8
while $(check_input "txt_list" ${temp_name} $1)
do
if [ ! -z "$global_var_name" ]
then
get_input "txt" "Push <ENTER> to accept the previous choice [$global_var_name] or insert $node_type ${pl_names[1]}: " true "$global_var_name"
else
get_input "txt" "Insert $node_type ${pl_names[1]}: " false
fi
temp_name=${input_variable}
done
case $2 in
"ocs")
ocs_ip=$temp_ip
save_variable GI_OCS_IP $temp_ip
save_variable GI_OCS_MAC_ADDRESS $temp_mac
save_variable GI_OCS_NAME $temp_name
;;
"boot")
boot_ip=$temp_ip
save_variable GI_BOOTSTRAP_IP $temp_ip
save_variable GI_BOOTSTRAP_MAC_ADDRESS $temp_mac
save_variable GI_BOOTSTRAP_NAME $temp_name
;;
"mst")