This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup_prerequisites_kvm.sh
executable file
·891 lines (807 loc) · 26 KB
/
setup_prerequisites_kvm.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
#!/bin/bash
#
# Copyright (c) 2020-2022 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
EXIT_CODE_SUCCESS=0
EXIT_CODE_ERROR=2
EXIT_CODE_CANCEL=4
print_info () {
echo "$1" | sed 's/^/ /'
}
# 0 - ok
# 1 - not ok
check_total_memory () {
echo
echo -n "Checking for total memory..............................."
mem=$(free -g | awk '/^Mem:/{print $2}');
if [ "$mem" -lt "$required_memory" ]; then
echo "Fail"
print_info "Total memory is $mem GB. Required $required_memory GB."
return $EXIT_CODE_ERROR
fi
echo "Done"
print_info "Total memory is $mem GB. Required $required_memory GB."
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
check_free_memory () {
echo
echo -n "Checking for available memory..........................."
free=$(free -g | awk '/^Mem:/{print $7}');
#check_status ("Error - Something went wrong")
if [ "$free" -lt "$required_free_memory" ]; then
echo "Fail"
print_info "Free memory is $free GB. Required $required_free_memory GB"
return $EXIT_CODE_ERROR
fi
echo "Done"
print_info "Free memory is $free GB. Required $required_free_memory GB"
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
check_free_diskspace () {
echo
echo -n "Checking for free disk space............................"
free=$(df -k --output=avail "$PWD" | tail -n1)
if [ "$free" -lt "$required_free_disk" ]; then
echo "Fail"
local freeg=$(df -BG --output=avail "$PWD" | tail -n1 | sed -e 's/^[[:space:]]*//')
local reqg=$(($required_free_disk / 1048576))"G"
print_info "Free disk space is $freeg. Required $reqg."
return $EXIT_CODE_ERROR
fi
echo "Done"
local freeg=$(df -BG --output=avail "$PWD" | tail -n1 | sed -e 's/^[[:space:]]*//')
local reqg=$(($required_free_disk / 1048576))"G"
print_info "Free disk space is $freeg. Required $reqg."
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
check_os () {
echo
echo -n "Checking for OS version................................."
data=`lsb_release -r`
readarray -d : -t strarr <<< "$data"
data=${strarr[1]}
data=`echo $data | sed 's/ *$//g'`
if [ "$data" != "$required_os" ]; then
echo "Fail"
print_info "Current OS is Ubuntu $data. Required Ubuntu $required_os."
return $EXIT_CODE_ERROR
fi
echo "Done"
print_info "Current OS is Ubuntu $data. Required Ubuntu $required_os."
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
check_kvm_support () {
echo
echo -n "Checking for KVM support................................"
if [ $(dpkg-query -W -f='${Status}' cpu-checker 2>/dev/null | grep -c "ok installed") -eq 0 ];
then
apt-get update >> $log_file 2>&1
if [ "$?" != 0 ]; then
echo "Fail";
print_info "Error while installing packages to perform system checks."
return $EXIT_CODE_ERROR;
fi
apt-get install -y cpu-checker >> $log_file 2>&1
if [ "$?" != 0 ]; then
echo "Fail";
print_info "Error while installing packages to perform system checks."
return $EXIT_CODE_ERROR;
fi
fi
local ret=`kvm-ok`
if [[ "$ret" != *"/dev/kvm exists"* ]]; then
echo "Fail"
print_info "Virtualization support for KVM is not enabled\nin BIOS or your CPU does not support KVM acceleration."
return $EXIT_CODE_ERROR
fi
echo "Done"
print_info "Virtualization support enabled."
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
check_tpm_support () {
echo
echo -n "Checking for TPM support................................"
local ret=`dmesg |grep -i TPM`
if [[ "$ret" == *"ima: No TPM chip found"* ]]; then
tpm_support_response=""
echo "Fail"
print_info "TPM support not available."
return $EXIT_CODE_ERROR
fi
echo "Done"
print_info "TPM support available."
return $EXIT_CODE_SUCCESS
}
install_build_tools () {
#Build tools
echo -n "Installing Build tools...."
apt install -y build-essential automake libtool libssl-dev python3 python3-pip net-tools >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing build tools packages."
return $EXIT_CODE_ERROR
fi
echo "Done"
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
install_qemu () {
#Install the QEMU related packages for Ubuntu 20.04
echo
echo -n "Installing Qemu packages...."
apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing Qemu packages."
return $EXIT_CODE_ERROR
else
echo "Done"
fi
#Check QEMU Version and install from sources if needed.
ret=`qemu-system-x86_64 --version`
print_info "QEMU version installed is $ret"
ret=`echo $ret|awk 'NR==1{print $4}'`
readarray -d . -t strarr <<< "$ret"
maj_ver=${strarr[0]}
min_ver=${strarr[1]}
new_qemu_needed=0
if [ $maj_ver -lt 2 ]; then
new_qemu_needed=1
fi
if [ $maj_ver -eq 2 ]; then
if [ $min_ver -lt 12 ]; then
new_qemu_needed=1
fi
fi
if [ $new_qemu_needed -eq 1 ]; then
print_info "Qemu is not at required version..."
echo
echo -n "Downloading, compiling and installing Qemu 5.1.0 from www.qemu.org...."
apt-get install -y libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev libnfs-dev libiscsi-dev >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing Qemu build tools packages."
return $EXIT_CODE_ERROR
fi
wget https://download.qemu.org/qemu-5.1.0.tar.xz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while downloading the Qemu source."
return $EXIT_CODE_ERROR
fi
tar -xJf qemu-5.1.0.tar.xz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while unpacking the Qemu source."
return $EXIT_CODE_ERROR
fi
pushd qemu-5.1.0>> $log_file 2>&1
./configure --target-list=x86_64-softmmu >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for Qemu build."
return $EXIT_CODE_ERROR
fi
make -j8 >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error while building Qemu."
return $EXIT_CODE_ERROR
fi
make install >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error installing Qemu."
return $EXIT_CODE_ERROR
fi
echo "Done"
print_info "New version of QEMU is installed under /usr/local/bin...."
print_info "Adjust the path for new QEMU in your scripts...."
popd >> $log_file 2>&1
fi
}
# 0 - ok
# 1 - not ok
install_swtpm () {
#Install SWTPM for vTPM
echo
echo -n "Installing Software TPM for vTPM......"
wget https://github.com/stefanberger/libtpms/archive/v0.7.7.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while downloading the Libtpms source."
return $EXIT_CODE_ERROR
fi
tar -xzf v0.7.7.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while unpacking the Libtpms source."
return $EXIT_CODE_ERROR
fi
pushd libtpms-0.7.7/ >> $log_file 2>&1
./autogen.sh --with-tpm2 --with-openssl >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for Libtpms build."
print_info "Please refer https://github.com/stefanberger/libtpms/blob/master/INSTALL"
return $EXIT_CODE_ERROR
fi
make >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error while building Libtpms."
return $EXIT_CODE_ERROR
fi
make install >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error installing Libtpms."
return $EXIT_CODE_ERROR
fi
popd >> $log_file 2>&1
echo "Done"
#Install known dependencies for swtpm
echo
echo -n "Installing Software TPM Emulator......"
apt-get install -y pkg-config libtasn1-6-dev gnutls-bin libgnutls28-dev expect socat libseccomp-dev selinux-policy-dev python3-setuptools >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing SWTPM build tools packages."
return $EXIT_CODE_ERROR
fi
wget https://github.com/stefanberger/swtpm/archive/v0.5.2.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while downloading the SWTPM source."
return $EXIT_CODE_ERROR
fi
tar -xzf v0.5.2.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while unpacking the SWTPM source."
return $EXIT_CODE_ERROR
fi
pushd swtpm-0.5.2/ >> $log_file 2>&1
./autogen.sh >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for SWTPM build."
print_info "Please refer https://github.com/stefanberger/swtpm/blob/master/INSTALL"
return $EXIT_CODE_ERROR
fi
./configure --prefix=/usr --with-gnutls >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for SWTPM build."
print_info "Please refer https://github.com/stefanberger/swtpm/blob/master/INSTALL"
return $EXIT_CODE_ERROR
fi
make >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error while building SWTPM."
return $EXIT_CODE_ERROR
fi
make install >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error installing SWTPM."
return $EXIT_CODE_ERROR
fi
ldconfig
if [ $? != 0 ];then
echo "Failed updating the ldconfig for SWTPM."
return $EXIT_CODE_ERROR
fi
popd >> $log_file 2>&1
echo "Done"
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
install_tss () {
#TSS
echo
echo -n "Installing TPM2 Software Stack...."
apt-get install -y libjson-c-dev libcurl4-openssl-dev doxygen >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing TPM2-TSS build tools packages."
return $EXIT_CODE_ERROR
fi
wget https://github.com/tpm2-software/tpm2-tss/releases/download/3.0.3/tpm2-tss-3.0.3.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while downloading the TPM2-TSS source."
return $EXIT_CODE_ERROR
fi
tar -xvzf tpm2-tss-3.0.3.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while unpacking the TPM2-TSS source."
return $EXIT_CODE_ERROR
fi
pushd tpm2-tss-3.0.3 >> $log_file 2>&1
./configure --with-udevrulesdir=/etc/udev/rules.d/ --prefix=/usr >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for TPM2-TSS build."
print_info "Please refer https://github.com/tpm2-software/tpm2-tss/blob/master/INSTALL.md"
return $EXIT_CODE_ERROR
fi
make -j8 >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error while building TPM2-TSS."
return $EXIT_CODE_ERROR
fi
make install >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error installing TPM2-TSS."
return $EXIT_CODE_ERROR
fi
ldconfig >> $log_file 2>&1
if [ $? != 0 ];then
echo "Failed updating the ldconfig for TPM2-TSS."
return $EXIT_CODE_ERROR
fi
udevadm control --reload-rules && sudo udevadm trigger >> $log_file 2>&1
if [ $? != 0 ];then
echo "Failed configuring TPM2-TSS."
return $EXIT_CODE_ERROR
fi
mkdir -p /var/lib/tpm >> $log_file 2>&1
groupadd -f tss >> $log_file 2>&1
useradd -M -d /var/lib/tpm -s /bin/false -g tss tss >> $log_file 2>&1
pkill -HUP dbus-daemon >> $log_file 2>&1
popd >> $log_file 2>&1
echo "Done"
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
install_abrmd () {
#ABRMD
echo
echo -n "Installing TPM2 ABRMD...."
apt-get install -y libglib2.0-dev >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing TPM2 ABRMD build tools packages."
return $EXIT_CODE_ERROR
fi
wget https://github.com/tpm2-software/tpm2-abrmd/releases/download/2.4.0/tpm2-abrmd-2.4.0.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while downloading the TPM2 ABRMD source."
return $EXIT_CODE_ERROR
fi
tar -xvzf tpm2-abrmd-2.4.0.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while unpacking the TPM2 ABRMD source."
return $EXIT_CODE_ERROR
fi
pushd tpm2-abrmd-2.4.0 >> $log_file 2>&1
./configure --with-dbuspolicydir=/etc/dbus-1/system.d --prefix=/usr >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for TPM2 ABRMD build."
print_info "Please refer https://github.com/tpm2-software/tpm2-abrmd/blob/master/INSTALL.md"
return $EXIT_CODE_ERROR
fi
make -j8 >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error while building TPM2 ABRMD."
return $EXIT_CODE_ERROR
fi
make install >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error installing TPM2 ABRMD."
return $EXIT_CODE_ERROR
fi
ldconfig >> $log_file 2>&1
if [ $? != 0 ];then
echo "Failed updating the ldconfig for SWTPM."
return $EXIT_CODE_ERROR
fi
popd >> $log_file 2>&1
echo "Done"
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
install_tpmtools () {
#TOOLS
echo
echo -n "Installing TPM2 Tools..."
apt-get install -y pandoc uuid-dev >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing TPM2 Tools build tools packages."
return $EXIT_CODE_ERROR
fi
wget https://github.com/tpm2-software/tpm2-tools/releases/download/5.0/tpm2-tools-5.0.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while downloading the TPM2 Tools source."
return $EXIT_CODE_ERROR
fi
tar -xvzf tpm2-tools-5.0.tar.gz >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while unpacking the TPM2 Tools source."
return $EXIT_CODE_ERROR
fi
pushd tpm2-tools-5.0 >> $log_file 2>&1
./configure --prefix=/usr >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Missing package dependencies for TPM2 Tools build."
print_info "Please refer https://github.com/tpm2-software/tpm2-tools/blob/master/INSTALL.md"
return $EXIT_CODE_ERROR
fi
make -j8 >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error while building TPM2 Tools."
return $EXIT_CODE_ERROR
fi
make install >> $log_file 2>&1
if [ $? != 0 ];then
echo "Fail"
print_info "Error installing TPM2 Tools."
return $EXIT_CODE_ERROR
fi
sed -i '2 i /usr/lib/' /etc/ld.so.conf.d/x86_64-linux-gnu.conf >> $log_file 2>&1
ldconfig >> $log_file 2>&1
if [ $? != 0 ];then
echo "Failed updating the ldconfig for TPM2 Tools."
return $EXIT_CODE_ERROR
fi
popd >> $log_file 2>&1
echo "Done"
return $EXIT_CODE_SUCCESS
}
# 0 - ok
# 1 - not ok
install_docker () {
echo
echo -n "Installing Docker Packages...."
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing dependent packages for Docker installation."
return $EXIT_CODE_ERROR
fi
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while adding Docker's official GPG key."
return $EXIT_CODE_ERROR
fi
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable" >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while adding Docker repository."
return $EXIT_CODE_ERROR
fi
apt-get update >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing Docker packages."
return $EXIT_CODE_ERROR
fi
apt-get remove docker docker-engine docker.io containerd runc >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while removing existing docker packages."
return $EXIT_CODE_ERROR
fi
apt-get install -y docker-ce docker-ce-cli containerd.io >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error while installing Docker packages."
return $EXIT_CODE_ERROR
fi
echo "Done"
return $EXIT_CODE_SUCCESS
}
install_host_packages () {
#Build and install the required packages
rm -rf dep_packages
mkdir -p dep_packages
pushd dep_packages > /dev/null
local result=0
clear
echo -ne \
"Install host dependency packages
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
install_build_tools
result=$(($result + $?))
install_qemu
result=$(($result + $?))
install_swtpm
result=$(($result + $?))
install_tss
result=$(($result + $?))
install_abrmd
result=$(($result + $?))
install_tpmtools
result=$(($result + $?))
install_docker
result=$(($result + $?))
echo
echo -n "Removing all the downloaded sources..."
popd >> $log_file 2>&1
rm -rf dep_packages >> $log_file 2>&1
echo "Done"
if [ $result -eq 0 ]; then
echo -ne \
"Installed all the host dependency packages successfully.
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
return $EXIT_CODE_SUCCESS
else
echo
echo -ne \
"Packages installation failed.
Check the installation log $log_file for more details.
You can resolve the issues, and then run the installation again.
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
read -n 1 -s -r -p "Press any key to continue to quit: "
echo ""
exit $EXIT_CODE_CANCEL
fi
}
check_system_prerequisites ()
{
required_memory=7
required_free_memory=5
required_free_disk=41943040 #40GBs
required_os="20.04"
local result=0
clear
echo -ne \
"System Prerequisite Check
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
check_total_memory
result=$(($result + $?))
check_free_memory
result=$(($result + $?))
check_free_diskspace
result=$(($result + $?))
check_os
result=$(($result + $?))
check_kvm_support
result=$(($result + $?))
check_tpm_support
result=$(($result + $?))
if [ $result -eq 0 ]; then
echo
echo -ne \
"Prerequisites check completed.
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
return $EXIT_CODE_SUCCESS
else
echo
echo -ne \
"There are one or more unresolved issues based on your system configuration.
You can resolve the issues, and then run the installation again.
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
read -n 1 -s -r -p "Press any key to continue to quit: "
echo ""
exit $EXIT_CODE_CANCEL
fi
}
read_ek_cert_from_tpm () {
# READ EK Cert
# Location 1 - TPM2 NV Index 0x1c00002 is the TCG specified location for RSA-EK-certificate.
RSA_EK_CERT_NV_INDEX=0x01C00002
echo -n "Reading EK Certificate size from TPM2...."
tpm2_nvreadpublic $RSA_EK_CERT_NV_INDEX >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "Error running the TPM2 commands."
return $EXIT_CODE_ERROR
fi
NV_SIZE=`tpm2_nvreadpublic $RSA_EK_CERT_NV_INDEX | grep size | awk '{print $2}'` >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "EK Certificate not provisioned."
return $EXIT_CODE_ERROR
fi
echo "Done"
if [ $NV_SIZE -eq 0 ]
then
echo
echo -n "Reading EK Certificate from TPM2 - ECC EK Certificate...."
tpm2_getekcertificate -u tpm_ek.pub -x -X -o tpm_hw_ek_cert.bin >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "EK Certificate not provisioned."
return $EXIT_CODE_ERROR
fi
echo "Done"
else
echo
echo -n "Read EK Certificate from TPM2...."
tpm2_nvread \
--hierarchy owner \
--size $NV_SIZE \
--output tpm_ek_cert.bin \
$RSA_EK_CERT_NV_INDEX >> $log_file 2>&1
if [ "$?" != 0 ]
then
echo "Fail"
print_info "EK Certificate not provisioned."
return $EXIT_CODE_ERROR
fi
echo "Done"
fi
return $EXIT_CODE_SUCCESS
}
check_tpm_provisioned () {
local result=0
clear
echo -ne \
"System Prerequisite Check
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
read_ek_cert_from_tpm
if [ $? -eq 0 ]; then
echo
echo -ne \
"TPM module has been provisioned
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
return $EXIT_CODE_SUCCESS
else
echo
echo -ne \
"TPM module not provisioned and cannot be used.
--------------------------------------------------------------------------------
" | sed -e 's/^[[:space:]]*//'
read -n 1 -s -r -p "Press any key to continue to quit: "
echo ""
exit $EXIT_CODE_CANCEL
fi
}
# script start
log_file=$PWD/log.txt
rm -f $log_file
clear
echo -ne \
"--------------------------------------------------------------------------------
Welcome to Intel® OpenVINO™ Security Add-on setup prerequisite wizard.
The setup prerequisite wizard will check the system requirements required to
install and run the OpenVINO™ Security Add-on tools and runtime components.
Please note that after the prerequisite setup is complete, additional
steps are still required to install the OpenVINO™ Security Add-on components.
For the complete documentation on the OpenVINO™ Security Add-on,
refer to the Installation guide:
https://docs.openvino.ai/latest/ovsa_get_started.html
The setup wizard will complete the following steps:
1. System Prerequisite check
2. Install host dependency packages
3. Verify TPM provision status
Note : Installation logs will be available in $log_file
--------------------------------------------------------------------------------"
echo
# check for sudo or root access
if [ $(id -u) -ne 0 ] ; then
echo "Root or sudo permissions are required to run this script"
echo "To continue, please run this script under root account or with sudo."
echo
read -s -p "Press ENTER key to exit."
echo
exit $EXIT_CODE_CANCEL
fi;
# check for internet
echo -n "Please wait... Checking internet connectivity..."
wget -T 3 -q --spider http://google.com
if [ $? -eq 0 ]; then
echo "OK"
else
echo "No Internet. "
echo "Some packages need to be downloaded from the internet."
echo "To continue, ensure you are able to connect to the internet."
echo
read -s -p "Press ENTER key to exit."
echo
exit $EXIT_CODE_CANCEL
fi
#echo "Press any key to continue or \"q\" to quit: "
#read -r ans
read -rsp $'Press any key to continue or \"q\" to quit: ' -n1 ans
case $ans in
q)
exit $EXIT_CODE_CANCEL
;;
*)
#echo "Checking for system prerequisites. This may take a while..."
check_system_prerequisites
echo "Next: Install host dependency packages"
read -n 1 -s -r -p "Press any key to continue: "
install_host_packages
echo "Next: Verify TPM provision status"
read -n 1 -s -r -p "Press any key to continue: "
check_tpm_provisioned
echo
echo -ne \
"Prerequisite checks completed and all the required packages have been installed.
Next: Proceed with the following:
1. Download and build OpenVINO™ Model Server
2. Create VMs
3. Build OpenVINO™ Security Add-on
4. Install the OpenVINO™ Security Add-on Tools & Runtime to the VMs
Refer the docs/ovsa_get_started_kvm.md for details on installation
" | sed -e 's/^[[:space:]]*//'
echo ""
echo ""
read -n 1 -s -r -p "Press any key to exit: "
echo
;;
esac