-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
1307 lines (1167 loc) · 37.4 KB
/
setup.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
######################################
# Kzenlab Builder
# Copyright (C) 2024 Indra Wahjoedi<[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
######################################
# DESC: Define Common Vars
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
FORCE_COLOR=0
NO_COLOR=1
OSVERSION=$(uname)
## LOCAL ENV
_qemu_home=default
_vbox_home=default
_vbox_vm_home=default
_vbox_disk_home=default
_iso_home=default
_vm_name=default
_vm_domain=default
_vm_hostname=default
_hyper_type=default
_vm_disk_size=default
_disk_efi=default
_disk_swap=default
_disk_root=default
_dvd1=default
_dvd2=default
_dvd3=default
_dvd4=default
_dvd5=default
_dvd6=default
_dvd7=default
_dvd8=default
_dvd9=default
_dvd10=default
_dvd11=default
_dvd12=default
_dvd13=default
_dvd14=default
_dvd15=default
_dvd16=default
_dvd17=default
_dvd18=default
_dvd19=default
_dvd20=default
_dvd21=default
## Local VARS
_device=default
_loops=default
_verbose=""
##### Functions #####
# DESC: Define Script Debugging
# Enable xtrace if the DEBUG environment variable is set
if [[ ${DEBUG-} =~ ^1|yes|true$ ]]; then
set -o xtrace # Trace the execution of the script (debug)
_verbose=--verbose
fi
# Only enable these shell behaviours if we're not being sourced
# Approach via: https://stackoverflow.com/a/28776166/8787985
if ! (return 0 2> /dev/null); then
# A better class of script...
set -o errexit # Exit on most errors (see the manual)
set -o nounset # Disallow expansion of unset variables
set -o pipefail # Use last non-zero exit code in a pipeline
fi
# Enable errtrace or the error trap handler will not work as expected
set -o errtrace # Ensure the error trap handler is inherited
# DESC: Import external .env file to script
# ARGS: None
# OUTS: None
# RETS: None
function import_env() {
_iso_home=$(grep -F -- "ISO_HOME" .env | cut -d'=' -f2)
_dvd1=$(grep -F -- "DVD_01" .env | cut -d'=' -f2)
_dvd2=$(grep -F -- "DVD_02" .env | cut -d'=' -f2)
_dvd3=$(grep -F -- "DVD_03" .env | cut -d'=' -f2)
_dvd4=$(grep -F -- "DVD_04" .env | cut -d'=' -f2)
_dvd5=$(grep -F -- "DVD_05" .env | cut -d'=' -f2)
_dvd6=$(grep -F -- "DVD_06" .env | cut -d'=' -f2)
_dvd7=$(grep -F -- "DVD_07" .env | cut -d'=' -f2)
_dvd8=$(grep -F -- "DVD_08" .env | cut -d'=' -f2)
_dvd9=$(grep -F -- "DVD_09" .env | cut -d'=' -f2)
_dvd10=$(grep -F -- "DVD_10" .env | cut -d'=' -f2)
_dvd11=$(grep -F -- "DVD_11" .env | cut -d'=' -f2)
_dvd12=$(grep -F -- "DVD_12" .env | cut -d'=' -f2)
_dvd13=$(grep -F -- "DVD_13" .env | cut -d'=' -f2)
_dvd14=$(grep -F -- "DVD_14" .env | cut -d'=' -f2)
_dvd15=$(grep -F -- "DVD_15" .env | cut -d'=' -f2)
_dvd16=$(grep -F -- "DVD_16" .env | cut -d'=' -f2)
_dvd17=$(grep -F -- "DVD_17" .env | cut -d'=' -f2)
_dvd18=$(grep -F -- "DVD_18" .env | cut -d'=' -f2)
_dvd19=$(grep -F -- "DVD_19" .env | cut -d'=' -f2)
_dvd20=$(grep -F -- "DVD_20" .env | cut -d'=' -f2)
_dvd21=$(grep -F -- "DVD_21" .env | cut -d'=' -f2)
_qemu_home=$(grep -F -- "QEMU_HOME" .env | cut -d'=' -f2)
_vbox_home=$(grep -F -- "VBOX_HOME" .env | cut -d'=' -f2)
_vbox_vm_home=$(grep -F -- "VBOX_VM_HOME" .env | cut -d'=' -f2)
_vbox_disk_home=$(grep -F -- "VBOX_DISK_HOME" .env | cut -d'=' -f2)
_vm_hyper_type=$(grep -F -- "VM_HYPER_TYPE" .env | cut -d'=' -f2)
_vm_name=$(grep -F -- "VM_NAME" .env | cut -d'=' -f2)
_vm_hostname=$(grep -F -- "VM_HOSTNAME" .env | cut -d'=' -f2)
_vm_domain=$(grep -F -- "VM_DOMAIN" .env | cut -d'=' -f2)
_vm_disk_size=$(grep -F -- "VM_DISK_SIZE" .env | cut -d'=' -f2)
_disk_root=$(grep -F -- "DISK_ROOT" .env | cut -d'=' -f2)
_disk_swap=$(grep -F -- "DISK_SWAP" .env | cut -d'=' -f2)
_disk_efi=$(grep -F -- "DISK_EFI" .env | cut -d'=' -f2)
}
# DESC: Setup CMAKE
# ARGS: None
# OUTS: None
# RETS: None
function setup_cmake(){
if ! [[ -d build/log ]]; then
mkdir -p build/log
fi
cmake -S . -B build \
-DISO_HOME=$_iso_home \
-DVBOX_HOME=$_vbox_home \
-DVBOX_DISK_HOME=$_vbox_disk_home \
-DVBOX_VM_HOME=$_vbox_vm_home \
-DVM_HYPER_TYPE=$_vm_hyper_type \
-DVM_DISK_SIZE=$_vm_disk_size \
-DVM_NAME=$_vm_name \
-DVM_HOSTNAME=$_vm_hostname \
-DVM_DOMAIN=$_vm_domain \
-DDISK_EFI=$_disk_efi \
-DDISK_SWAP=$_disk_swap \
-DDISK_ROOT=$_disk_root
cmake --build build --target check_tools
cmake --build build --target print_vm_env
cmake --build build --target write_vm_env
}
# DESC: Clean CMAKE
# ARGS: None
# OUTS: None
# RETS: None
function clean_cmake(){
unmount_linux && \
unloop && \
sudo rm -rf build/*
#cmake --build build --target clean_cmake
}
# DESC: Build empty virtual disk
# ARGS: None
# OUTS: None
# RETS: None
function build_raw_disk(){
cmake --build build --target create_raw_disk $_verbose && \
cmake --build build --target mounting_raw_disk $_verbose
}
function download_debian9(){
cmake --build build --target download_debian9
}
function download_debian12(){
cmake --build build --target download_debian12
}
function unpack_debian9(){
cmake --build build --target unpack_debian9
}
function unpack_debian12(){
cmake --build build --target unpack_debian12 $_verbose
}
function unloop(){
echo "UNLOOP()"
# Unloop RAWDISK
_devloop=$(losetup -a | grep $_vm_name | cut -d' ' -f1 | grep -oE '/dev/loop[0-9]+' )
echo $_devloop
if [[ -n "$_devloop" ]]; then
losetup -d $_devloop
if [ $? -ne 0 ]; then
echo "Error unloop..."
else
echo $_devloop" unloopped"
fi
else
echo "Loop device already unloopped"
fi
}
function start_qemu_uefi(){
_dvdxfce=debian-live-12.8.0-amd64-xfce.iso
#-drive file=$_iso_home/$_dvdxfce,media=cdrom \
_file=$_vm_name
_file+='.raw'
#echo $_file
qemu-system-x86_64 \
-m 2048M \
-drive file=build/$_file,format=raw,if=virtio \
-enable-kvm \
-bios /usr/share/OVMF/OVMF_CODE.fd \
-boot c
#-boot menu=on
}
function create_vmdk(){
_devloop=$(losetup -a | grep $_vm_name | cut -d' ' -f1 | grep -oE '/dev/loop[0-9]+')
echo $_devloop
#vboxmanage closemedium disk build/$_vm_name'.vmdk'
rm -rf build/$_vm_name'.vmdk'
vboxmanage createmedium disk \
--filename build/$_vm_name'.vmdk' \
--format=VMDK \
--variant RawDisk \
--property RawDrive=$_devloop
}
function create_usb_vmdk(){
_device=$1
echo $_device
rm -rf build/usb.vmdk
vboxmanage createmedium disk \
--filename build/usb.vmdk \
--format=VMDK \
--variant RawDisk \
--property RawDrive=$_device
}
function create_usb_vboxvm(){
# System
_vm_name="USB-OS"
vboxmanage createvm --basefolder=$_vbox_vm_home --name $_vm_name --register
vboxmanage modifyvm $_vm_name --description "Klaudizen Lab"
vboxmanage modifyvm $_vm_name --memory=2048 --vram=128 --acpi=on --ioapic=on --cpus=2 --pae=on --long-mode=on
vboxmanage modifyvm $_vm_name --hwvirtex=on --paravirt-provider=kvm --nested-paging=on --nested-hw-virt=on
vboxmanage modifyvm $_vm_name --chipset=piix3
#vboxmanage modifyvm $_vm_name --boot1=disk
vboxmanage modifyvm $_vm_name --graphicscontroller vmsvga
vboxmanage modifyvm $_vm_name --tpm-type 2.0
vboxmanage modifyvm $_vm_name --firmware efi64
VBoxManage modifynvram $_vm_name inituefivarstore
vboxmanage modifynvram $_vm_name enrollmssignatures
vboxmanage modifynvram $_vm_name enrollorclpk
# Other
vboxmanage modifyvm $_vm_name --mouse=ps2 --keyboard=ps2
vboxmanage modifyvm $_vm_name --uart1 0x3f8 4 --uart-type1=16550A --uart-mode1 server /tmp/vbox
# Network
vboxmanage modifyvm $_vm_name --nic1=nat --nic-type1=Am79C973 --cable-connected1=on
vboxmanage modifyvm $_vm_name --nat-pf1 "SSH,tcp,,2200,,22"
vboxmanage modifyvm $_vm_name --nat-pf1 "VNC,tcp,,15900,,5900"
# Storage
vboxmanage storagectl $_vm_name --name "SATA01" --add sata --controller IntelAHCI
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 0 --device 0 --type hdd --medium build/usb.vmdk
}
function create_vboxvm(){
# System
vboxmanage createvm --basefolder=$_vbox_vm_home --name $_vm_name --register
vboxmanage modifyvm $_vm_name --description "Klaudizen Lab"
vboxmanage modifyvm $_vm_name --memory=2048 --vram=128 --acpi=on --ioapic=on --cpus=2 --pae=on --long-mode=on
vboxmanage modifyvm $_vm_name --hwvirtex=on --paravirt-provider=kvm --nested-paging=on --nested-hw-virt=on
vboxmanage modifyvm $_vm_name --chipset=piix3
#vboxmanage modifyvm $_vm_name --boot1=disk
vboxmanage modifyvm $_vm_name --graphicscontroller vmsvga
vboxmanage modifyvm $_vm_name --tpm-type 2.0
vboxmanage modifyvm $_vm_name --firmware efi64
VBoxManage modifynvram $_vm_name inituefivarstore
vboxmanage modifynvram $_vm_name enrollmssignatures
vboxmanage modifynvram $_vm_name enrollorclpk
# Other
vboxmanage modifyvm $_vm_name --mouse=ps2 --keyboard=ps2
vboxmanage modifyvm $_vm_name --uart1 0x3f8 4 --uart-type1=16550A --uart-mode1 server /tmp/vbox
# Network
vboxmanage modifyvm $_vm_name --nic1=nat --nic-type1=Am79C973 --cable-connected1=on
vboxmanage modifyvm $_vm_name --nat-pf1 "SSH,tcp,,2200,,22"
vboxmanage modifyvm $_vm_name --nat-pf1 "VNC,tcp,,15900,,5900"
# Storage
vboxmanage storagectl $_vm_name --name "SATA01" --add sata --controller IntelAHCI
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 0 --device 0 --type hdd --medium build/$_vm_name'.vmdk'
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 1 --device 0 --type dvddrive --medium $_iso_home/$_dvd1
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 2 --device 0 --type dvddrive --medium $_iso_home/$_dvd2
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 3 --device 0 --type dvddrive --medium $_iso_home/$_dvd3
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 4 --device 0 --type dvddrive --medium $_iso_home/$_dvd4
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 5 --device 0 --type dvddrive --medium $_iso_home/$_dvd5
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 6 --device 0 --type dvddrive --medium $_iso_home/$_dvd6
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 7 --device 0 --type dvddrive --medium $_iso_home/$_dvd7
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 8 --device 0 --type dvddrive --medium $_iso_home/$_dvd8
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 9 --device 0 --type dvddrive --medium $_iso_home/$_dvd9
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 10 --device 0 --type dvddrive --medium $_iso_home/$_dvd10
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 11 --device 0 --type dvddrive --medium $_iso_home/$_dvd11
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 12 --device 0 --type dvddrive --medium $_iso_home/$_dvd12
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 13 --device 0 --type dvddrive --medium $_iso_home/$_dvd13
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 14 --device 0 --type dvddrive --medium $_iso_home/$_dvd14
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 15 --device 0 --type dvddrive --medium $_iso_home/$_dvd15
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 16 --device 0 --type dvddrive --medium $_iso_home/$_dvd16
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 17 --device 0 --type dvddrive --medium $_iso_home/$_dvd17
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 18 --device 0 --type dvddrive --medium $_iso_home/$_dvd18
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 19 --device 0 --type dvddrive --medium $_iso_home/$_dvd19
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 20 --device 0 --type dvddrive --medium $_iso_home/$_dvd20
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 21 --device 0 --type dvddrive --medium $_iso_home/$_dvd21
# Must detach dvd1 otherwise boot will go to DVD1
vbox_dettach_dvd1
#vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 1 --device 0 --type dvddrive --medium none
#vboxmanage showvminfo $VM_NAME
#vboxmanage startvm $VM_NAME -type headless
#vboxmanage startvm $VM_NAME -type gui
#vboxmanage controlvm $VM_NAME reset
#vboxmanage controlvm $VM_NAME poweroff
}
function vbox_attach_dvd1(){
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 1 --device 0 --type dvddrive --medium $_iso_home/$_dvd1
}
function vbox_dettach_dvd1(){
# while VM off
echo "WARN! VM should be non-active state"
vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 1 --device 0 --type dvddrive --medium emptydrive
#vboxmanage storageattach $_vm_name --storagectl "SATA01" --port 1 --device 0 --type dvddrive --medium none
}
function remove_vboxvm(){
vboxmanage unregistervm $_vm_name --delete
}
function remove_usb_vboxvm(){
_vm_name="USB-OS"
vboxmanage unregistervm $_vm_name --delete
}
function unmount_linux(){
## /dev
if mount | grep -q "on /media/$USER/root/dev "; then
mount | grep ${USER}'/root/dev' | cut -d' ' -f3 | sort -r | xargs -I {} sudo umount {}
echo "/root/dev unmounted"
fi
if ! mount | grep -q "on /media/$USER/root/dev "; then
rm -rf build/log/linux-dev
fi
## /sys
if mount | grep -q "on /media/$USER/root/sys "; then
mount | grep ${USER}'/root/sys/' | cut -d' ' -f3 | xargs -I {} sudo umount {}
fi
if mount | grep -q "on /media/$USER/root/sys "; then
sudo umount /media/$USER/root/sys
echo "/root/sys unmounted"
fi
if ! mount | grep -q "on /media/$USER/root/sys "; then
rm -rf build/log/linux-sys
fi
## /proc
if mount | grep -q "on /media/$USER/root/proc "; then
mount | grep ${USER}'/root/proc' | cut -d' ' -f3 | sort -r | xargs -I {} sudo umount {}
echo "/root/proc unmounted"
fi
if mount | grep -q "on /media/$USER/root/proc "; then
sudo umount /media/$USER/root/proc
echo "/root/proc unmounted2"
fi
if ! mount | grep -q "on /media/$USER/root/proc "; then
rm -rf build/log/linux-proc
fi
# Run
if mount | grep -q "on /media/$USER/root/run "; then
mount | grep ${USER}'/root/run/user/1000' | cut -d' ' -f3 | sort -r | xargs -I {} sudo umount {}
fi
if mount | grep -q "on /media/$USER/root/run "; then
mount | grep ${USER}'/root/run' | cut -d' ' -f3 | sort -r | xargs -I {} sudo umount {}
echo "/root/run unmounted"
fi
if ! mount | grep -q "on /media/$USER/root/run "; then
rm -rf build/log/linux-run
fi
_loops_p1=$(losetup -a | grep $_vm_name | cut -d' ' -f1 | grep -oE '/dev/loop[0-9]+')
_loops_p3=$(losetup -a | grep $_vm_name | cut -d' ' -f1 | grep -oE '/dev/loop[0-9]+')
_loops_p1+="p1"
_loops_p3+="p3"
# EFI
if mount | grep -q "on /media/$USER/root/boot/efi "; then
sudo umount /media/$USER/root/boot/efi
#echo $_loops_p1" unmounted"
fi
if mount | grep -q "on /media/$USER/EFI "; then
udisksctl unmount -b $_loops_p1
echo $_loops_p1" unmounted"
fi
if ! mount | grep -q "on /media/$USER/EFI "; then
rm -rf build/log/efi
fi
# ROOT
if mount | grep -q "on /media/$USER/root "; then
udisksctl unmount -b $_loops_p3
echo $_loops_p3" unmounted"
fi
if ! mount | grep -q "on /media/$USER/root "; then
rm -rf build/log/root
fi
}
function remounting(){
echo "WARN: Remouting at base-os stage"
if [ -f build/log/loops ] ; then
rm build/log/loops
fi
if [ -f build/log/loops ] ; then
rm build/log/root
fi
if [ -f build/log/loops ] ; then
rm build/log/efi
fi
if [ -f build/log/linux-dev ] ; then
rm build/log/linux-dev
fi
if [ -f build/log/linux-proc ] ; then
rm build/log/linux-proc
fi
if [ -f build/log/linux-sys ] ; then
rm build/log/linux-sys
fi
if [ -f build/log/linux-pts ] ; then
rm build/log/linux-pts
fi
if [ -f build/log/linux-pts ] ; then
rm build/log/linux-run
fi
if ! mount | grep -q "on /media/$USER/root " ; then
cmake --build build --target make_loops_mounted $_verbose && \
cmake --build build --target mounting_linux $_verbose
fi
}
function set_repo_active(){
sudo cp -f base-os/debian.list /media/$USER/root/etc/apt/sources.list.d/
}
function set_repo_deactive(){
sudo rm -rf /media/$USER/root/etc/apt/sources.list.d/debian.list
}
function mount_dvd(){
mount_dvd1 && \
mount_dvd2 && \
mount_dvd3 && \
mount_dvd4 && \
mount_dvd5 && \
mount_dvd6 && \
mount_dvd7 && \
mount_dvd8 && \
mount_dvd9 && \
mount_dvd10 && \
mount_dvd11 && \
mount_dvd12 && \
mount_dvd13 && \
mount_dvd14 && \
mount_dvd15 && \
mount_dvd16 && \
mount_dvd17 && \
mount_dvd18 && \
mount_dvd19 && \
mount_dvd20 && \
mount_dvd21 && \
sudo cp -f base-os/DVD.list /media/$USER/root/etc/apt/sources.list.d/
}
function unmount_dvd(){
unmount_dvd1 && \
unmount_dvd2 && \
unmount_dvd3 && \
unmount_dvd4 && \
unmount_dvd5 && \
unmount_dvd6 && \
unmount_dvd7 && \
unmount_dvd8 && \
unmount_dvd9 && \
unmount_dvd10 && \
unmount_dvd11 && \
unmount_dvd12 && \
unmount_dvd13 && \
unmount_dvd14 && \
unmount_dvd15 && \
unmount_dvd16 && \
unmount_dvd17 && \
unmount_dvd18 && \
unmount_dvd19 && \
unmount_dvd20 && \
unmount_dvd21 && \
sudo rm -rf /media/$USER/root/etc/apt/sources.list.d/DVD.list
}
function mount_dvd1(){
if ! mount | grep -q "DVD1" ; then
sudo mkdir -p /mnt/DVD1 && sudo mkdir -p /media/$USER/root/mnt/DVD1
sudo mount -t iso9660 -o loop $_iso_home/$_dvd1 /mnt/DVD1 && \
sudo mount --bind /mnt/DVD1 /media/$USER/root/mnt/DVD1
fi
}
function mount_dvd2(){
if ! mount | grep -q "DVD2" ; then
sudo mkdir -p /mnt/DVD2 && sudo mkdir -p /media/$USER/root/mnt/DVD2
sudo mount -t iso9660 -o loop $_iso_home/$_dvd2 /mnt/DVD2 && \
sudo mount --bind /mnt/DVD2 /media/$USER/root/mnt/DVD2
fi
}
function mount_dvd3(){
if ! mount | grep -q "DVD3" ; then
sudo mkdir -p /mnt/DVD3 && sudo mkdir -p /media/$USER/root/mnt/DVD3
sudo mount -t iso9660 -o loop $_iso_home/$_dvd3 /mnt/DVD3 && \
sudo mount --bind /mnt/DVD3 /media/$USER/root/mnt/DVD3
fi
}
function mount_dvd4(){
if ! mount | grep -q "DVD4" ; then
sudo mkdir -p /mnt/DVD4 && sudo mkdir -p /media/$USER/root/mnt/DVD4
sudo mount -t iso9660 -o loop $_iso_home/$_dvd4 /mnt/DVD4 && \
sudo mount --bind /mnt/DVD4 /media/$USER/root/mnt/DVD4
fi
}
function mount_dvd5(){
if ! mount | grep -q "DVD5" ; then
sudo mkdir -p /mnt/DVD5 && sudo mkdir -p /media/$USER/root/mnt/DVD5
sudo mount -t iso9660 -o loop $_iso_home/$_dvd5 /mnt/DVD5 && \
sudo mount --bind /mnt/DVD5 /media/$USER/root/mnt/DVD5
fi
}
function mount_dvd6(){
if ! mount | grep -q "DVD6" ; then
sudo mkdir -p /mnt/DVD6 && sudo mkdir -p /media/$USER/root/mnt/DVD6
sudo mount -t iso9660 -o loop $_iso_home/$_dvd6 /mnt/DVD6 && \
sudo mount --bind /mnt/DVD6 /media/$USER/root/mnt/DVD6
fi
}
function mount_dvd7(){
if ! mount | grep -q "DVD7" ; then
sudo mkdir -p /mnt/DVD7 && sudo mkdir -p /media/$USER/root/mnt/DVD7
sudo mount -t iso9660 -o loop $_iso_home/$_dvd7 /mnt/DVD7 && \
sudo mount --bind /mnt/DVD7 /media/$USER/root/mnt/DVD7
fi
}
function mount_dvd8(){
if ! mount | grep -q "DVD8" ; then
sudo mkdir -p /mnt/DVD8 && sudo mkdir -p /media/$USER/root/mnt/DVD8
sudo mount -t iso9660 -o loop $_iso_home/$_dvd8 /mnt/DVD8 && \
sudo mount --bind /mnt/DVD8 /media/$USER/root/mnt/DVD8
fi
}
function mount_dvd9(){
if ! mount | grep -q "DVD9" ; then
sudo mkdir -p /mnt/DVD9 && sudo mkdir -p /media/$USER/root/mnt/DVD9
sudo mount -t iso9660 -o loop $_iso_home/$_dvd9 /mnt/DVD9 && \
sudo mount --bind /mnt/DVD9 /media/$USER/root/mnt/DVD9
fi
}
function mount_dvd10(){
if ! mount | grep -q "DVD10" ; then
sudo mkdir -p /mnt/DVD10 && sudo mkdir -p /media/$USER/root/mnt/DVD10
sudo mount -t iso9660 -o loop $_iso_home/$_dvd10 /mnt/DVD10 && \
sudo mount --bind /mnt/DVD10 /media/$USER/root/mnt/DVD10
fi
}
function mount_dvd11(){
if ! mount | grep -q "DVD11" ; then
sudo mkdir -p /mnt/DVD11 && sudo mkdir -p /media/$USER/root/mnt/DVD11
sudo mount -t iso9660 -o loop $_iso_home/$_dvd11 /mnt/DVD11 && \
sudo mount --bind /mnt/DVD11 /media/$USER/root/mnt/DVD11
fi
}
function mount_dvd12(){
if ! mount | grep -q "DVD12" ; then
sudo mkdir -p /mnt/DVD12 && sudo mkdir -p /media/$USER/root/mnt/DVD12
sudo mount -t iso9660 -o loop $_iso_home/$_dvd12 /mnt/DVD12 && \
sudo mount --bind /mnt/DVD12 /media/$USER/root/mnt/DVD12
fi
}
function mount_dvd13(){
if ! mount | grep -q "DVD13" ; then
sudo mkdir -p /mnt/DVD13 && sudo mkdir -p /media/$USER/root/mnt/DVD13
sudo mount -t iso9660 -o loop $_iso_home/$_dvd13 /mnt/DVD13 && \
sudo mount --bind /mnt/DVD13 /media/$USER/root/mnt/DVD13
fi
}
function mount_dvd14(){
if ! mount | grep -q "DVD14" ; then
sudo mkdir -p /mnt/DVD14 && sudo mkdir -p /media/$USER/root/mnt/DVD14
sudo mount -t iso9660 -o loop $_iso_home/$_dvd14 /mnt/DVD14 && \
sudo mount --bind /mnt/DVD14 /media/$USER/root/mnt/DVD14
fi
}
function mount_dvd15(){
if ! mount | grep -q "DVD15" ; then
sudo mkdir -p /mnt/DVD15 && sudo mkdir -p /media/$USER/root/mnt/DVD15
sudo mount -t iso9660 -o loop $_iso_home/$_dvd15 /mnt/DVD15 && \
sudo mount --bind /mnt/DVD15 /media/$USER/root/mnt/DVD15
fi
}
function mount_dvd16(){
if ! mount | grep -q "DVD16" ; then
sudo mkdir -p /mnt/DVD16 && sudo mkdir -p /media/$USER/root/mnt/DVD16
sudo mount -t iso9660 -o loop $_iso_home/$_dvd16 /mnt/DVD16 && \
sudo mount --bind /mnt/DVD16 /media/$USER/root/mnt/DVD16
fi
}
function mount_dvd17(){
if ! mount | grep -q "DVD17" ; then
sudo mkdir -p /mnt/DVD17 && sudo mkdir -p /media/$USER/root/mnt/DVD17
sudo mount -t iso9660 -o loop $_iso_home/$_dvd17 /mnt/DVD17 && \
sudo mount --bind /mnt/DVD17 /media/$USER/root/mnt/DVD17
fi
}
function mount_dvd18(){
if ! mount | grep -q "DVD18" ; then
sudo mkdir -p /mnt/DVD18 && sudo mkdir -p /media/$USER/root/mnt/DVD18
sudo mount -t iso9660 -o loop $_iso_home/$_dvd18 /mnt/DVD18 && \
sudo mount --bind /mnt/DVD18 /media/$USER/root/mnt/DVD18
fi
}
function mount_dvd19(){
if ! mount | grep -q "DVD19" ; then
sudo mkdir -p /mnt/DVD19 && sudo mkdir -p /media/$USER/root/mnt/DVD19
sudo mount -t iso9660 -o loop $_iso_home/$_dvd19 /mnt/DVD19 && \
sudo mount --bind /mnt/DVD19 /media/$USER/root/mnt/DVD19
fi
}
function mount_dvd20(){
if ! mount | grep -q "DVD20" ; then
sudo mkdir -p /mnt/DVD20 && sudo mkdir -p /media/$USER/root/mnt/DVD20
sudo mount -t iso9660 -o loop $_iso_home/$_dvd20 /mnt/DVD20 && \
sudo mount --bind /mnt/DVD20 /media/$USER/root/mnt/DVD20
fi
}
function mount_dvd21(){
if ! mount | grep -q "DVD21" ; then
sudo mkdir -p /mnt/DVD21 && sudo mkdir -p /media/$USER/root/mnt/DVD21
sudo mount -t iso9660 -o loop $_iso_home/$_dvd21 /mnt/DVD21 && \
sudo mount --bind /mnt/DVD21 /media/$USER/root/mnt/DVD21
fi
}
function unmount_dvd1(){
#sudo umount $_iso_home/$_dvd1
sudo umount /media/$USER/root/mnt/DVD1 && sudo umount /mnt/DVD1
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD1."
else
echo "Done unmounting DVD1."
fi
if [ -d "/mnt/DVD1" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD1
sudo rm -rf /mnt/DVD1
fi
}
function unmount_dvd2(){
sudo umount /media/$USER/root/mnt/DVD2 && sudo umount /mnt/DVD2
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD2."
else
echo "Done unmounting DVD2."
fi
if [ -d "/mnt/DVD2" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD2
sudo rm -rf /mnt/DVD2
fi
}
function unmount_dvd3(){
sudo umount /media/$USER/root/mnt/DVD3 && sudo umount /mnt/DVD3
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD3."
else
echo "Done unmounting DVD3."
fi
if [ -d "/mnt/DVD3" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD3
sudo rm -rf /mnt/DVD3
fi
}
function unmount_dvd4(){
sudo umount /media/$USER/root/mnt/DVD4 && sudo umount /mnt/DVD4
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD4."
else
echo "Done unmounting DVD4."
fi
if [ -d "/mnt/DVD4" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD4
sudo rm -rf /mnt/DVD4
fi
}
function unmount_dvd5(){
sudo umount /media/$USER/root/mnt/DVD5 && sudo umount /mnt/DVD5
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD5."
else
echo "Done unmounting DVD5."
fi
if [ -d "/mnt/DVD5" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD5
sudo rm -rf /mnt/DVD5
fi
}
function unmount_dvd6(){
sudo umount /media/$USER/root/mnt/DVD6 && sudo umount /mnt/DVD6
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD6."
else
echo "Done unmounting DVD6."
fi
if [ -d "/mnt/DVD6" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD6
sudo rm -rf /mnt/DVD6
fi
}
function unmount_dvd7(){
sudo umount /media/$USER/root/mnt/DVD7 && sudo umount /mnt/DVD7
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD7."
else
echo "Done unmounting DVD7."
fi
if [ -d "/mnt/DVD7" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD7
sudo rm -rf /mnt/DVD7
fi
}
function unmount_dvd8(){
sudo umount /media/$USER/root/mnt/DVD8 && sudo umount /mnt/DVD8
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD8."
else
echo "Done unmounting DVD8."
fi
if [ -d "/mnt/DVD8" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD8
sudo rm -rf /mnt/DVD8
fi
}
function unmount_dvd9(){
sudo umount /media/$USER/root/mnt/DVD9 && sudo umount /mnt/DVD9
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD9."
else
echo "Done unmounting DVD9."
fi
if [ -d "/mnt/DVD9" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD9
sudo rm -rf /mnt/DVD9
fi
}
function unmount_dvd10(){
sudo umount /media/$USER/root/mnt/DVD10 && sudo umount /mnt/DVD10
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD10."
else
echo "Done unmounting DVD10."
fi
if [ -d "/mnt/DVD10" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD10
sudo rm -rf /mnt/DVD10
fi
}
function unmount_dvd11(){
sudo umount /media/$USER/root/mnt/DVD11 && sudo umount /mnt/DVD11
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD11."
else
echo "Done unmounting DVD11."
fi
if [ -d "/mnt/DVD11" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD11
sudo rm -rf /mnt/DVD11
fi
}
function unmount_dvd12(){
sudo umount /media/$USER/root/mnt/DVD12 && sudo umount /mnt/DVD12
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD12."
else
echo "Done unmounting DVD12."
fi
if [ -d "/mnt/DVD12" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD12
sudo rm -rf /mnt/DVD12
fi
}
function unmount_dvd13(){
sudo umount /media/$USER/root/mnt/DVD13 && sudo umount /mnt/DVD13
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD13."
else
echo "Done unmounting DVD13."
fi
if [ -d "/mnt/DVD13" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD13
sudo rm -rf /mnt/DVD13
fi
}
function unmount_dvd14(){
sudo umount /media/$USER/root/mnt/DVD14 && sudo umount /mnt/DVD14
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD14."
else
echo "Done unmounting DVD14."
fi
if [ -d "/mnt/DVD14" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD14
sudo rm -rf /mnt/DVD14
fi
}
function unmount_dvd15(){
sudo umount /media/$USER/root/mnt/DVD15 && sudo umount /mnt/DVD15
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD15."
else
echo "Done unmounting DVD15."
fi
if [ -d "/mnt/DVD15" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD15
sudo rm -rf /mnt/DVD15
fi
}
function unmount_dvd16(){
sudo umount /media/$USER/root/mnt/DVD16 && sudo umount /mnt/DVD16
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD16."
else
echo "Done unmounting DVD16."
fi
if [ -d "/mnt/DVD16" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD16
sudo rm -rf /mnt/DVD16
fi
}
function unmount_dvd17(){
sudo umount /media/$USER/root/mnt/DVD17 && sudo umount /mnt/DVD17
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD17."
else
echo "Done unmounting DVD17."
fi
if [ -d "/mnt/DVD17" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD17
sudo rm -rf /mnt/DVD17
fi
}
function unmount_dvd18(){
sudo umount /media/$USER/root/mnt/DVD18 && sudo umount /mnt/DVD18
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD18."
else
echo "Done unmounting DVD18."
fi
if [ -d "/mnt/DVD18" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD18
sudo rm -rf /mnt/DVD18
fi
}
function unmount_dvd19(){
sudo umount /media/$USER/root/mnt/DVD19 && sudo umount /mnt/DVD19
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD19."
else
echo "Done unmounting DVD19."
fi
if [ -d "/mnt/DVD19" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD19
sudo rm -rf /mnt/DVD19
fi
}
function unmount_dvd20(){
sudo umount /media/$USER/root/mnt/DVD20 && sudo umount /mnt/DVD20
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD20."
else
echo "Done unmounting DVD20."
fi
if [ -d "/mnt/DVD20" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD20
sudo rm -rf /mnt/DVD20
fi
}
function unmount_dvd21(){
sudo umount /media/$USER/root/mnt/DVD21 && sudo umount /mnt/DVD21
if [[ $? -ne 0 ]]; then
echo "Error unmounting DVD21."
else
echo "Done unmounting DVD21."
fi
if [ -d "/mnt/DVD21" ]; then
sudo rm -rf /media/$USER/root/mnt/DVD21
sudo rm -rf /mnt/DVD21
fi
}
function set_base_os(){
unpack_debian12 && \
cmake --build build --target mounting_linux $_verbose && \
cmake --build build --target chroot_debian $_verbose
}
function set_kernel(){
if [ ! -d "/mnt/DVD1" ]; then
echo "Mount DVD1 before installing some packages."
else
cmake --build build --target set_kernel $_verbose
fi
}