-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.sh
executable file
·1221 lines (1014 loc) · 44 KB
/
build.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
####
# simple wrapper to automate the steps from
# https://wiki.archlinux.org/index.php/ZFS#Installation
# and
# https://wiki.archlinux.org/index.php/Archiso#Installing_packages
#
# @author stev leibelt <[email protected]>
# @since 2016-05-09
####
# enable !! command completion
# ref: https://intoli.com/blog/exit-on-errors-in-bash-scripts/
set -o history -o histexpand
# copy all command output to a log file
exec &> >(tee "build.sh.log")
####
# @param <string: PATH_TO_THE_ARCHLIVE_ROOT>
####
function remove_files ()
{
_echo_if_be_verbose ":: Starting removing files"
#bo: variable
local PATH_TO_THE_ARCHLIVE_ROOT
PATH_TO_THE_ARCHLIVE_ROOT=${1:-""}
if [[ ! -d ${PATH_TO_THE_ARCHLIVE_ROOT} ]];
then
echo " Invalid path to the archlive provided >>${PATH_TO_THE_ARCHLIVE_ROOT}<< is not a directory."
exit 1
else
_echo_if_be_verbose " PATH_TO_THE_ARCHLIVE_ROOT >>${PATH_TO_THE_ARCHLIVE_ROOT}<<."
fi
#bo: variable
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT}/var/lib/pacman/local/*"
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT}/var/lib/pacman/sync/*"
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT}/var/log/*.log"
_echo_if_be_verbose ":: Finished removing files"
}
####
# @param <string: PATH_TO_THE_ARCHLIVE_ROOT_USER> - this is not >>/<< but >>/root<<
####
function add_files ()
{
_echo_if_be_verbose ":: Starting adding files"
#bo: variable
local PATH_TO_THE_ARCHLIVE_ROOT_USER
PATH_TO_THE_ARCHLIVE_ROOT_USER=${1:-""}
#eo: variable
#bo: argument validation
_exit_if_string_is_empty "PATH_TO_THE_ARCHLIVE_ROOT_USER" "${PATH_TO_THE_ARCHLIVE_ROOT_USER}"
#eo: argument validation
#bo: environment check
if [[ ! -d ${PATH_TO_THE_ARCHLIVE_ROOT_USER} ]];
then
echo " Invalid path to the archlive provided >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}<< is not a directory."
exit 1
else
_echo_if_be_verbose " PATH_TO_THE_ARCHLIVE_ROOT_USER >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}<<."
fi
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
if ! command -v git &> /dev/null;
then
_echo_if_be_verbose ":: No git found, installing it"
pacman -S --noconfirm git
fi
_echo_if_be_verbose " Creating directory >>document<<"
/usr/bin/mkdir "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/document"
exit_if_last_exit_code_is_not_zero ${?} "Creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/document<< failed."
_echo_if_be_verbose " Creating directory >>software<<"
/usr/bin/mkdir "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software"
exit_if_last_exit_code_is_not_zero ${?} "Creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software<< failed."
_echo_if_be_verbose " Adding repository >>arch-linux-configuration<< "
git clone https://github.com/stevleibelt/arch-linux-configuration "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/arch-linux-configuration/"
exit_if_last_exit_code_is_not_zero ${?} "Checkout and creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/arch-linux-configuration<< failed."
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/arch-linux-configuration/.git"
_echo_if_be_verbose " Adding repository >>arch-linux-live-cd-zfs-setup<< "
git clone https://github.com/stevleibelt/arch-linux-live-cd-zfs-setup "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/arch-linux-live-cd-zfs-setup/"
exit_if_last_exit_code_is_not_zero ${?} "Checkout and creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/arch-linux-live-cd-zfs-setup<< failed."
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/arch-linux-live-cd-zfs-setup/.git"
_echo_if_be_verbose " Adding repository >>downgrade<< "
git clone https://github.com/archlinux-downgrade/downgrade "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/downgrade/"
exit_if_last_exit_code_is_not_zero ${?} "Checkout and creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/downgrade<< failed."
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/downgrade/.git"
_echo_if_be_verbose " Adding directory >>zfsbootmenu<< with latest EFI file "
# ref: https://docs.zfsbootmenu.org/en/v2.2.x/guides/general/portable.html
curl --create-dirs --output "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/zfsbootmenu/vmlinuz.EFI" -LJO https://get.zfsbootmenu.org/efi
exit_if_last_exit_code_is_not_zero ${?} "Creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/zfsbootmenu<< or download of latest portable ZFSBootMenu failed."
cp "${PATH_TO_THIS_SCRIPT}/source/replace_zfsbootmenu.sh" "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/zfsbootmenu/"
exit_if_last_exit_code_is_not_zero ${?} "Copy of >>${PATH_TO_THIS_SCRIPT}/source/replace_zfsbootmenu.sh<< to >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/zfsbootmenu/<< failed."
_echo_if_be_verbose " Adding repository >>archinstall<< "
git clone https://github.com/archlinux/archinstall "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/archinstall/"
exit_if_last_exit_code_is_not_zero ${?} "Checkout and creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/archinstall<< failed."
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/archinstall/.git"
cp "${PATH_TO_THIS_SCRIPT}/source/start_archinstall.sh" "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/archinstall/"
exit_if_last_exit_code_is_not_zero ${?} "Copy of >>${PATH_TO_THIS_SCRIPT}/source/start_archinstall.sh<< to >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/archinstall/<< failed."
_echo_if_be_verbose " Adding repository >>bulk_hdd_testing<< "
git clone https://github.com/ezonakiusagi/bht "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/bulk_hdd_testing/"
exit_if_last_exit_code_is_not_zero ${?} "Checkout and creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/bulk_hdd_testing<< failed."
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/bulk_hdd_testing/.git"
_echo_if_be_verbose " Adding repository >>general_howtos<< "
git clone https://github.com/stevleibelt/general_howtos "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/document/general_howtos/"
exit_if_last_exit_code_is_not_zero ${?} "Checkout and creation of directory >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/document/general_howtos<< failed."
rm -fr "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/document/general_howtos/.git"
_echo_if_be_verbose " Adding script >>create_efibootmgr_entry.sh<< "
cp "${PATH_TO_THIS_SCRIPT}/source/create_efibootmgr_entry.sh" "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/"
exit_if_last_exit_code_is_not_zero ${?} "Copy of >>${PATH_TO_THIS_SCRIPT}/source/create_efibootmgr_entry.sh<< to >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/<< failed."
_echo_if_be_verbose " Adding script >>start_sshd.sh<< "
cp "${PATH_TO_THIS_SCRIPT}/source/start_sshd.sh" "${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/"
exit_if_last_exit_code_is_not_zero ${?} "Copy of >>${PATH_TO_THIS_SCRIPT}/source/start_sshd.sh<< to >>${PATH_TO_THE_ARCHLIVE_ROOT_USER}/software/<< failed."
fi
_echo_if_be_verbose ":: Finished adding files"
}
####
# @param <string: PATH_TO_THE_ARCHLIVE>
# [@param <string: REPO_INDEX_OR_EMPTY_STRING>]
####
function add_packages_and_repository ()
{
_echo_if_be_verbose ":: Starting adding packages and repository"
#bo: variable
local PATH_TO_THE_ARCHLIVE
local REPO_INDEX_OR_EMPTY_STRING
local PATH_TO_THE_PACKAGES_FILE
local PATH_TO_THE_PACMAN_CONF_FILE
local PATH_TO_THE_PACMAN_D_ARCHZFS_FILE
PATH_TO_THE_ARCHLIVE=${1:-""}
REPO_INDEX_OR_EMPTY_STRING=${2:-""}
PATH_TO_THE_PACKAGES_FILE="${PATH_TO_THE_ARCHLIVE}/packages.x86_64"
PATH_TO_THE_PACMAN_CONF_FILE="${PATH_TO_THE_ARCHLIVE}/pacman.conf"
PATH_TO_THE_PACMAN_D_DIRECTORY="${PATH_TO_THE_ARCHLIVE}/pacman.d"
PATH_TO_THE_PACMAN_D_ARCHZFS_FILE="${PATH_TO_THE_PACMAN_D_DIRECTORY}/archzfs"
#eo: variable
#bo: argument validation
_exit_if_string_is_empty "PATH_TO_THE_ARCHLIVE" "${PATH_TO_THE_ARCHLIVE}"
#eo: argument validation
#bo: environment check
if [[ ! -d ${PATH_TO_THE_ARCHLIVE} ]];
then
echo " Invalid path to the archlive provided >>${PATH_TO_THE_ARCHLIVE}<< is not a directory."
exit 1
else
_echo_if_be_verbose " PATH_TO_THE_ARCHLIVE >>${PATH_TO_THE_ARCHLIVE}<<."
fi
_echo_if_be_verbose ":: Adding repository and package >>archzfs-linux<<."
_echo_if_be_verbose " Using following path to the archlive >>${PATH_TO_THE_ARCHLIVE}<<."
if [[ ! -f "${PATH_TO_THE_PACKAGES_FILE}" ]];
then
echo " Required file >>${PATH_TO_THE_PACKAGES_FILE}<< was not found."
exit 5
else
_echo_if_be_verbose " PATH_TO_THE_PACKAGES_FILE >>${PATH_TO_THE_PACKAGES_FILE}<<."
fi
if [[ ! -f "${PATH_TO_THE_PACMAN_CONF_FILE}" ]];
then
echo " Required file >>${PATH_TO_THE_PACMAN_CONF_FILE}<< was not found."
exit 5
else
_echo_if_be_verbose " PATH_TO_THE_PACMAN_CONF_FILE >>${PATH_TO_THE_PACMAN_CONF_FILE}<<."
fi
if [[ ! -d "${PATH_TO_THE_PACMAN_D_DIRECTORY}" ]];
then
_echo_if_be_verbose " Creating >>${PATH_TO_THE_PACMAN_D_DIRECTORY}<<."
/usr/bin/mkdir "${PATH_TO_THE_PACMAN_D_DIRECTORY}"
fi
if [[ -f "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}" ]];
then
_echo_if_be_verbose " Truncating >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."
/usr/bin/truncate -s 0 "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
else
_echo_if_be_verbose " Creating >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."
/usr/bin/touch "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
fi
#eo: environment check
#bo: add archzfs key
if ! pacman-key --list-keys | grep -q "DDF7DB817396A49B2A2723F7403BD972F75D9D76";
then
_echo_if_be_verbose ":: Adding archzfs keys to keyring"
pacman-key --init
pacman-key --recv-keys DDF7DB817396A49B2A2723F7403BD972F75D9D76
pacman-key --lsign-key DDF7DB817396A49B2A2723F7403BD972F75D9D76
pacman -Sy
fi
#eo: add archzfs key
#bo: repo index
if [[ "${#REPO_INDEX_OR_EMPTY_STRING}" -gt 0 ]];
then
_echo_if_be_verbose " Adapted repo index to >>${REPO_INDEX_OR_EMPTY_STRING}<< in file >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."
#@see: https://github.com/stevleibelt/arch-linux-live-cd-iso-with-zfs/pull/6/files
# archzfs repo often lags behind core a week or so, causing zfs kmod/kernel version mismatch and build failure
# Adding in last week's core archive repo before the official repo as a workaround
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
_echo_if_be_verbose " Adding entry of >>Server = https://archive.archlinux.org/repos/${REPO_INDEX_OR_EMPTY_STRING}/\$repo/os/\$arch<< to:"
_echo_if_be_verbose " [core]"
sed -i -e 's|\[core\]|\[core\]\nServer = https://archive.archlinux.org/repos/'${REPO_INDEX_OR_EMPTY_STRING}'/\$repo/os/\$arch/|g' "${PATH_TO_THE_PACMAN_CONF_FILE}"
_echo_if_be_verbose " [extra]"
sed -i -e 's|\[extra\]|\[extra\]\nServer = https://archive.archlinux.org/repos/'${REPO_INDEX_OR_EMPTY_STRING}'/\$repo/os/\$arch/|g' "${PATH_TO_THE_PACMAN_CONF_FILE}"
_echo_if_be_verbose " [community]"
sed -i -e 's|\[community\]|\[community\]\nServer = https://archive.archlinux.org/repos/'${REPO_INDEX_OR_EMPTY_STRING}'/\$repo/os/\$arch/|g' "${PATH_TO_THE_PACMAN_CONF_FILE}"
fi
fi
#eo: repo index
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
local PACKAGE_NAME
local PACKAGE_TO_REMOVE_ARRAY
local PACKAGE_TO_ADD_ARRAY
_echo_if_be_verbose " Creating archzfs mirrorlist file >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."
#bo: adding repository
echo "Server = http://archzfs.com/\$repo/\$arch" >> "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
echo "Server = http://mirror.sum7.eu/archlinux/archzfs/\$repo/\$arch" >> "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
echo "Server = https://mirror.biocrafting.net/archlinux/archzfs/\$repo/\$arch" >> "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
_echo_if_be_verbose " Adding archzfs repositories to PATH_TO_THE_PACMAN_CONF_FILE >>${PATH_TO_THE_PACMAN_CONF_FILE}<<."
echo "" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
echo "[archzfs]" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
echo "Include = ${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
#eo: adding repository
#bo: removing package
IFS=',' read -r -a PACKAGE_TO_REMOVE_ARRAY <<< "${PACKAGES_TO_REMOVE}"
for PACKAGE_NAME in "${PACKAGE_TO_REMOVE_ARRAY[@]}";
do
_echo_if_be_verbose " Removing package >>${PACKAGE_NAME}<<."
sed -i "/${PACKAGE_NAME}/d" "${PATH_TO_THE_PACKAGES_FILE}"
done;
#eo: removing package
#bo: adding package
_echo_if_be_verbose " Adding packages."
IFS=',' read -r -a PACKAGE_TO_ADD_ARRAY <<< "${PACKAGES_TO_ADD}"
for PACKAGE_NAME in "${PACKAGE_TO_ADD_ARRAY[@]}";
do
_echo_if_be_verbose " Adding package >>${PACKAGE_NAME}<<."
echo "${PACKAGE_NAME}" >> "${PATH_TO_THE_PACKAGES_FILE}"
done
if [[ ${USE_DKMS} -eq 1 ]];
then
if [[ ${KERNEL} != 'linux' ]];
then
sed -i -e "s/^linux$/${KERNEL}/" "${PATH_TO_THE_PACKAGES_FILE}"
fi
_echo_if_be_verbose " Adding package >>${KERNEL}-headers<<."
echo "${KERNEL}-headers" >> "${PATH_TO_THE_PACKAGES_FILE}"
if [[ ${USE_GIT_PACKAGE} -eq 0 ]];
then
_echo_if_be_verbose " Adding package >>zfs-dkms<<."
echo "zfs-dkms" >> "${PATH_TO_THE_PACKAGES_FILE}"
else
_echo_if_be_verbose " Adding package >>zfs-dkms-git<<."
echo "zfs-dkms-git" >> "${PATH_TO_THE_PACKAGES_FILE}"
fi
else
if [[ ${USE_GIT_PACKAGE} -eq 0 ]];
then
_echo_if_be_verbose " Adding package >>zfs-${KERNEL}<<."
echo "zfs-${KERNEL}" >> "${PATH_TO_THE_PACKAGES_FILE}"
_echo_if_be_verbose " Adding package >>zfs-utils<<."
echo "zfs-utils" >> "${PATH_TO_THE_PACKAGES_FILE}"
else
_echo_if_be_verbose " Adding package >>zfs-${KERNEL}-git<<."
echo "zfs-${KERNEL}-git" >> "${PATH_TO_THE_PACKAGES_FILE}"
_echo_if_be_verbose " Adding package >>zfs-utils-git<<."
echo "zfs-utils-git" >> "${PATH_TO_THE_PACKAGES_FILE}"
fi
fi
#eo: adding package
echo ":: Finished adding packages and repository"
fi
}
function ask_for_more ()
{
if [[ ${ASK_TO_RUN_ISO} -eq 1 ]];
then
echo ":: Do you want to run the iso for testing? [y|N]"
read -r RUN_ISO
if [[ ${RUN_ISO} == "y" ]];
then
bash "${PATH_TO_THIS_SCRIPT}/run_iso.sh" "${ISO_FILE_PATH}"
fi
fi
if [[ ${ASK_TO_DUMP_ISO} -eq 1 ]];
then
echo ":: Do you want to dump the iso on a device? [y|N]"
read -r DUMP_ISO
if [[ ${DUMP_ISO} == "y" ]];
then
bash "${PATH_TO_THIS_SCRIPT}/dump_iso.sh" ${ISO_FILE_PATH}
fi
fi
if [[ ${ASK_TO_UPLOAD_ISO} -eq 1 ]];
then
echo ":: Do you want to upload the iso for testing? [y|N]"
read RUN_ISO
if [[ ${RUN_ISO} == "y" ]];
then
bash "${PATH_TO_THIS_SCRIPT}/upload_iso.sh" ${ISO_FILE_PATH}
fi
fi
}
####
# @param <string: PATH_TO_THE_WORK_DIRECTORY>
# @param <string: PATH_TO_THE_OUTPUT_DIRECTORY>
# @param <string: PATH_TO_THE_PROFILE_DIRECTORY>
# @param <string: ISO_FILE_PATH>
# @param <string: SHA512_FILE_PATH>
####
function build_archiso ()
{
_echo_if_be_verbose ":: Starting bulding archiso"
#bo: variable
local ISO_FILE_NAME
local ISO_FILE_PATH
local NUMBER_OF_ISO_FILES_AVAILABLE
local PATH_TO_THE_PROFILE_DIRECTORY
local PATH_TO_THE_OUTPUT_DIRECTORY
local PATH_TO_THE_WORK_DIRECTORY
local SHA512_FILE_PATH
ISO_FILE_PATH=${4:-""}
PATH_TO_THE_PROFILE_DIRECTORY=${3:-""}
PATH_TO_THE_OUTPUT_DIRECTORY=${2:-""}
PATH_TO_THE_WORK_DIRECTORY=${1:-""}
SHA512_FILE_PATH=${5:-""}
#eo: variable
#bo: argument validation
_exit_if_string_is_empty "PATH_TO_THE_WORK_DIRECTORY" "${PATH_TO_THE_WORK_DIRECTORY}"
_exit_if_string_is_empty "PATH_TO_THE_WORK_DIRECTORY" "${PATH_TO_THE_WORK_DIRECTORY}"
_exit_if_string_is_empty "PATH_TO_THE_WORK_DIRECTORY" "${PATH_TO_THE_WORK_DIRECTORY}"
_exit_if_string_is_empty "PATH_TO_THE_PROFILE_DIRECTORY" "${PATH_TO_THE_WORK_DIRECTORY}"
_exit_if_string_is_empty "ISO_FILE_PATH" "${ISO_FILE_PATH}"
_exit_if_string_is_empty "SHA512_FILE_PATH" "${SHA512_FILE_PATH}"
#eo: argument validation
#bo: environment setup
if [[ ! -d ${PATH_TO_THE_OUTPUT_DIRECTORY} ]];
then
_echo_if_be_verbose " PATH_TO_THE_OUTPUT_DIRECTORY >>${PATH_TO_THE_OUTPUT_DIRECTORY}<< does not exist."
_create_directory_or_exit "${PATH_TO_THE_OUTPUT_DIRECTORY}"
else
_echo_if_be_verbose " PATH_TO_THE_OUTPUT_DIRECTORY >>${PATH_TO_THE_OUTPUT_DIRECTORY}<< does exist."
fi
if [[ -d "${PATH_TO_THE_WORK_DIRECTORY}" ]];
then
_echo_if_be_verbose " PATH_TO_THE_WORK_DIRECTORY >>${PATH_TO_THE_WORK_DIRECTORY}<< does exist."
_remove_path_or_exit "${PATH_TO_THE_WORK_DIRECTORY}"
fi
_create_directory_or_exit "${PATH_TO_THE_WORK_DIRECTORY}"
#bo: environment setup
#begin of building
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
if [[ ${BE_VERBOSE} -gt 0 ]];
then
mkarchiso -v -w ${PATH_TO_THE_WORK_DIRECTORY} -o ${PATH_TO_THE_OUTPUT_DIRECTORY} ${PATH_TO_THE_PROFILE_DIRECTORY}
else
mkarchiso -w ${PATH_TO_THE_WORK_DIRECTORY} -o ${PATH_TO_THE_OUTPUT_DIRECTORY} ${PATH_TO_THE_PROFILE_DIRECTORY}
fi
exit_if_last_exit_code_is_not_zero ${?} "Execution of >>mkarchiso<< failed."
# Workaround to indicated build issue
# ref: https://github.com/stevleibelt/arch-linux-live-cd-iso-with-zfs/issues/18
if grep -q 'Bad return status for module build on kernel' build.sh.log;
then
echo ":: Build error detected."
echo " Removing invalid iso file"
# @todo sl90fyqo
echo " Dumping detected lines from file >>build.sh.log<<"
echo ""
cat build.sh.log | grep 'Bad return status for module build on kernel'
echo ""
exit 3
fi
fi
#end of building
#begin of renaming and hash generation
cd ${PATH_TO_THE_OUTPUT_DIRECTORY}
ISO_FILE_NAME=$(basename "${ISO_FILE_PATH}")
ISO_FILE_NAME=${ISO_FILE_NAME:0:-4} # remove >>.iso<< from file name
# We are searching for a file like archlinux-archzfs-linux-lts-2024.04.08-x86_64.iso
# we have a ISO_FILE_NAME like archlinux-archzfs-linux-lts.iso
# Searching for -20 should be safe enough for any future release years
NUMBER_OF_ISO_FILES_AVAILABLE=$(find -iname "${ISO_FILE_NAME}-20*.iso" -type f | wc -l)
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
if [[ ${NUMBER_OF_ISO_FILES_AVAILABLE} -eq 1 ]];
then
chmod -R 765 *
_echo_if_be_verbose " Moving >>${ISO_FILE_NAME}-*.iso<< to >>${ISO_FILE_PATH}<<."
mv ${ISO_FILE_NAME}-*.iso ${ISO_FILE_PATH}
sha512sum ${ISO_FILE_PATH} > ${SHA512_FILE_PATH}
#end of renaming and hash generation
_echo_if_be_verbose ""
_echo_if_be_verbose " Iso created in path:"
_echo_if_be_verbose " PATH_TO_THE_OUTPUT_DIRECTORY >>${PATH_TO_THE_OUTPUT_DIRECTORY}<<"
_echo_if_be_verbose " --------"
echo " Listing directory content, filterd by >>archzfs<<..."
ls -halt ${PATH_TO_THE_OUTPUT_DIRECTORY} | grep archzfs
_echo_if_be_verbose " --------"
_echo_if_be_verbose ":: Finished bulding archiso"
else
echo ":: Invalid amount of iso files found."
echo " Current path >>${PATH_TO_THE_OUTPUT_DIRECTORY}<<."
echo " Number of found >>${ISO_FILE_NAME}-20\*.iso<< files >>${NUMBER_OF_ISO_FILES_AVAILABLE}<<. Should be exact one iso file available."
exit 3
fi
fi
}
####
# @param <string: ISO_FILE_PATH>
# @param <string: SHA512_FILE_PATH>
####
function cleanup_build_path ()
{
_echo_if_be_verbose ":: Starting cleanup build path"
local ISO_FILE_PATH
local SHA512_FILE_PATH
ISO_FILE_PATH=${1:-""}
SHA512_FILE_PATH=${2:-""}
#bo: argument validation
_exit_if_string_is_empty "ISO_FILE_PATH" "${ISO_FILE_PATH}"
_exit_if_string_is_empty "SHA512_FILE_PATH" "${SHA512_FILE_PATH}"
#eo: argument validation
#begin of cleanup
if [[ -f ${ISO_FILE_PATH} ]];
then
if [[ ${IS_FORCED} -eq 1 ]];
then
_echo_if_be_verbose " Build is forced, existing build files will be removed automatically."
MOVE_EXISTING_BUILD_FILES="n"
else
echo ":: Older build detected"
echo ":: Do you want to move the files somewhere? [y|N] (n means overwriting, n is default)"
read MOVE_EXISTING_BUILD_FILES
fi
if [[ ${MOVE_EXISTING_BUILD_FILES} == "y" ]];
then
echo ":: Please input the path where you want to move the files (if the path does not exist, it will be created):"
read PATH_TO_MOVE_THE_EXISTING_BUILD_FILES
if [[ ! -d ${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES} ]];
then
_create_directory_or_exit "${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES}"
else
_echo_if_be_verbose " PATH_TO_MOVE_THE_EXISTING_BUILD_FILES >>${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES}<< exists."
fi
_echo_if_be_verbose ":: Moving files ..."
_echo_if_be_verbose " Moving >>${ISO_FILE_PATH}<< to >>${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES}<<."
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
mv -v ${ISO_FILE_PATH} ${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES}
fi
if [[ -f ${SHA512_FILE_PATH} ]];
then
_echo_if_be_verbose " Moving >>${SHA512_FILE_PATH}<< to >>${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES}<<."
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
mv -v ${SHA512_FILE_PATH} ${PATH_TO_MOVE_THE_EXISTING_BUILD_FILES}
fi
else
_echo_if_be_verbose " Moving skipped, >>${SHA512_FILE_PATH}<< does exist."
fi
else
_remove_file_path_or_exit "${ISO_FILE_PATH}"
#following lines prevent us from getting asked from mv to override the existing file
if [[ -f ${SHA512_FILE_PATH} ]];
then
_remove_file_path_or_exit "${SHA512_FILE_PATH}"
fi
fi
else
_echo_if_be_verbose " >>${ISO_FILE_PATH}<< does not exist."
#it can happen that the iso file does not exist but the sha512 file exists
if [[ -f ${SHA512_FILE_PATH} ]];
then
_remove_file_path_or_exit "${SHA512_FILE_PATH}"
fi
fi
#end of cleanup
_echo_if_be_verbose ":: Finished cleanup build path"
}
function dump_runtime_environment_variables ()
{
echo ":: Dumping runtime environment variables."
echo " ASK_TO_RUN_ISO >>${ASK_TO_RUN_ISO}<<."
echo " ASK_TO_DUMP_ISO >>${ASK_TO_DUMP_ISO}<<."
echo " ASK_TO_UPLOAD_ISO >>${ASK_TO_DUMP_ISO}<<."
echo " BE_VERBOSE >>${BE_VERBOSE}<<."
echo " BUILD_FILE_NAME >>${BUILD_FILE_NAME}<<."
echo " IS_DRY_RUN >>${IS_DRY_RUN}<<."
echo " IS_FORCED >>${IS_FORCED}<<."
echo " ISO_FILE_PATH >>${ISO_FILE_PATH}<<."
echo " KERNEL >>${KERNEL}<<."
echo " PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE >>${PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE}<<."
echo " PATH_TO_THE_DYNAMIC_DATA_DIRECTORY >>${PATH_TO_THE_DYNAMIC_DATA_DIRECTORY}<<."
echo " PATH_TO_THE_PROFILE_DIRECTORY >>${PATH_TO_THE_PROFILE_DIRECTORY}<<."
echo " PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE >>${PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE}<<."
echo " PATH_TO_THE_SOURCE_DATA_DIRECTORY >>${PATH_TO_THE_SOURCE_DATA_DIRECTORY}<<."
echo " REPO_INDEX >>${REPO_INDEX}<<."
echo " SHOW_HELP >>${SHOW_HELP}<<."
echo " SHA512_FILE_PATH >>${SHA512_FILE_PATH}<<."
echo " USE_GIT_PACKAGE >>${USE_GIT_PACKAGE}<<."
echo " USE_DKMS >>${USE_DKMS}<<."
echo " USE_OTHER_REPO_INDEX >>${USE_OTHER_REPO_INDEX}<<."
echo ""
}
####
# @param <int: last_exit_code>
# [@param <string: error_message>]
####
function exit_if_last_exit_code_is_not_zero ()
{
local LAST_EXIT_CODE
local LAST_COMMAND
local ERROR_MESSAGE
LAST_EXIT_CODE=${1:-1}
LAST_COMMAND="${@:2}"
ERROR_MESSAGE="${2:-'Something went wrong while building the image.'}"
if [[ ${LAST_EXIT_CODE} -ne 0 ]];
then
echo ":: Error"
echo " Last exit code >>${LAST_EXIT_CODE}<<."
# ref: https://intoli.com/blog/exit-on-errors-in-bash-scripts/
echo " Last command >>${LAST_COMMAND}<<."
echo " >>${ERROR_MESSAGE}<<."
exit ${LAST_EXIT_CODE}
dump_runtime_environment_variables
fi
}
####
# @param <string: output>
####
function _echo_if_be_verbose ()
{
if [[ ${BE_VERBOSE} -eq 1 ]];
then
echo "${1}"
fi
}
####
# @param <string: PATH_TO_THE_SOURCE_DATA_DIRECTORY>
# @param <string: PATH_TO_THE_PROFILE_DIRECTORY>
####
function evaluate_environment ()
{
_echo_if_be_verbose ":: Starting evaluating environment"
local FILE_PATH_TO_KEEP_THE_DIFF
local FILE_PATH_TO_THE_SOURCE_PACMAN_INIT_SERVICE
local FILE_PATH_TO_OUR_PACMAN_INIT_SERVICE
local FILE_PATH_TO_PACMAN_INIT_SERVICE_EXPECTED_DIFF
local PATH_TO_THE_PROFILE_DIRECTORY
local PATH_TO_THE_SOURCE_DATA_DIRECTORY
PATH_TO_THE_PROFILE_DIRECTORY=${2:-""}
PATH_TO_THE_SOURCE_DATA_DIRECTORY=${1:-""}
#bo: argument validation
_exit_if_string_is_empty "PATH_TO_THE_PROFILE_DIRECTORY" "${PATH_TO_THE_PROFILE_DIRECTORY}"
_exit_if_string_is_empty "PATH_TO_THE_SOURCE_DATA_DIRECTORY" "${PATH_TO_THE_SOURCE_DATA_DIRECTORY}"
#bo: argument validation
if [[ ! -d ${PATH_TO_THE_PROFILE_DIRECTORY} ]];
then
echo " Invalid path provided. >>${PATH_TO_THE_PROFILE_DIRECTORY}<< is not a directory."
exit 1
else
_echo_if_be_verbose " PATH_TO_THE_PROFILE_DIRECTORY >>${PATH_TO_THE_PROFILE_DIRECTORY}<< exists."
fi
if [[ ! -d ${PATH_TO_THE_SOURCE_DATA_DIRECTORY} ]];
then
echo " Invalid path provided. >>${PATH_TO_THE_SOURCE_DATA_DIRECTORY}<< is not a directory."
exit 2
else
_echo_if_be_verbose " PATH_TO_THE_SOURCE_DATA_DIRECTORY >>${PATH_TO_THE_SOURCE_DATA_DIRECTORY}<< exists."
fi
#begin of check if pacman-init.service file is still the same
FILE_PATH_TO_KEEP_THE_DIFF=$(mktemp)
FILE_PATH_TO_THE_SOURCE_PACMAN_INIT_SERVICE="/usr/share/archiso/configs/releng/airootfs/etc/systemd/system/pacman-init.service"
FILE_PATH_TO_OUR_PACMAN_INIT_SERVICE="${PATH_TO_THE_SOURCE_DATA_DIRECTORY}/pacman-init.service"
FILE_PATH_TO_PACMAN_INIT_SERVICE_EXPECTED_DIFF="${PATH_TO_THE_SOURCE_DATA_DIRECTORY}/pacman-init.service.expected_diff"
diff ${FILE_PATH_TO_THE_SOURCE_PACMAN_INIT_SERVICE} "${FILE_PATH_TO_OUR_PACMAN_INIT_SERVICE}" > ${FILE_PATH_TO_KEEP_THE_DIFF}
NUMBER_OF_LINES_BETWEEN_THE_TWO_DIFF_FILES=$(diff ${FILE_PATH_TO_KEEP_THE_DIFF} "${FILE_PATH_TO_PACMAN_INIT_SERVICE_EXPECTED_DIFF}" | wc -l)
if [[ ${NUMBER_OF_LINES_BETWEEN_THE_TWO_DIFF_FILES} -gt 0 ]];
then
echo " Unexpected runtime environment."
echo " The diff between the files >>${FILE_PATH_TO_THE_SOURCE_PACMAN_INIT_SERVICE}<< and >>${FILE_PATH_TO_OUR_PACMAN_INIT_SERVICE}<< results in an unexpected output."
echo " Dumping expected diff:"
echo "${FILE_PATH_TO_PACMAN_INIT_SERVICE_EXPECTED_DIFF}"
echo ""
echo " Dumping current diff:"
echo "${FILE_PATH_TO_KEEP_THE_DIFF}"
echo ""
echo " Please create an issue in >>https://github.com/stevleibelt/arch-linux-live-cd-iso-with-zfs/issues<<."
echo ""
echo " Will stop now."
echo ""
exit 2
else
_echo_if_be_verbose " Updating pacman-init.service"
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
cp "${FILE_PATH_TO_OUR_PACMAN_INIT_SERVICE}" "${PATH_TO_THE_PROFILE_DIRECTORY}/airootfs/etc/systemd/system/pacman-init.service"
fi
fi
#end of check if pacman-init.service file is still the same
_echo_if_be_verbose ":: Finished evaluating environment"
}
####
# @param <string: "${@}">
####
function auto_elevate_if_not_called_from_root ()
{
#begin of check if we are root
if [[ ${UID} -ne 0 ]];
then
#call this script (${0}) again with sudo with all provided arguments (${@})
_echo_if_be_verbose ":: Current user is not root. Restarting myself."
_echo_if_be_verbose " >>sudo \"${0}\" \"${@}\""
sudo "${0}" "${@}"
exit ${?}
fi
#end of check if we are root
}
####
# @param <string: PATH_TO_THE_SOURCE_PROFILE_DIRECTORY>
# @param <string: PATH_TO_THE_OUTPUT_DIRECTORY>
####
function setup_environment ()
{
_echo_if_be_verbose ":: Starting setup environment"
local PATH_TO_THE_DESTINATION_PROFILE_DIRECTORY
local PATH_TO_THE_OUTPUT_DIRECTORY
local PATH_TO_THE_SOURCE_PROFILE_DIRECTORY
local PROFILE_NAME
PATH_TO_THE_SOURCE_PROFILE_DIRECTORY=${1:-""}
PATH_TO_THE_OUTPUT_DIRECTORY=${2:-""}
#bo: argument validation
_exit_if_string_is_empty "PATH_TO_THE_SOURCE_PROFILE_DIRECTORY" "${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY}"
_exit_if_string_is_empty "PATH_TO_THE_OUTPUT_DIRECTORY" "${PATH_TO_THE_OUTPUT_DIRECTORY}"
#eo: argument validation
#bo: ensure package cache is up to date
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
_echo_if_be_verbose ":: Updating package cache"
pacman -Sy
fi
#eo: ensure package cache is up to date
#begin of check if archiso is installed
if [[ ! -d ${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY} ]];
then
_echo_if_be_verbose " No archiso package installed."
_echo_if_be_verbose " Provided path is not a directory >>${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY}<<."
_echo_if_be_verbose " We are going to install it now ..."
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
_echo_if_be_verbose ":: Archiso not installed, installing it."
pacman -S --noconfirm archiso
fi
else
_echo_if_be_verbose " >>${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY}<< exists."
fi
#end of check if archiso is installed
#bo: user input validation
if [[ ! -d ${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY} ]];
then
echo " Invalid source path for the profile provided >>${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY}<<."
exit 1
else
_echo_if_be_verbose " >>${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY}<< exists."
fi
if [[ ! -d ${PATH_TO_THE_OUTPUT_DIRECTORY} ]];
then
echo " Invalid output path provided >>${PATH_TO_THE_OUTPUT_DIRECTORY}<<."
exit 1
else
_echo_if_be_verbose " >>${PATH_TO_THE_OUTPUT_DIRECTORY}<< exists."
fi
#eo: user input validation
#begin of dynamic data directory exists
PROFILE_NAME=$(basename ${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY})
PATH_TO_THE_DESTINATION_PROFILE_DIRECTORY="${PATH_TO_THE_OUTPUT_DIRECTORY}/${PROFILE_NAME}"
if [[ -d ${PATH_TO_THE_DESTINATION_PROFILE_DIRECTORY} ]];
then
_echo_if_be_verbose " Previous profile data detected."
_echo_if_be_verbose " >>${PATH_TO_THE_DESTINATION_PROFILE_DIRECTORY}<< exists."
_echo_if_be_verbose " Cleaning up now ..."
_remove_path_or_exit "${PATH_TO_THE_DESTINATION_PROFILE_DIRECTORY}"
else
_echo_if_be_verbose " >>${PATH_TO_THE_DESTINATION_PROFILE_DIRECTORY}<< does not exist, no cleanup needed."
fi
#end of dynamic data directory exists
#begin of creating the output directory
if [[ ! -p ${PATH_TO_THE_OUTPUT_DIRECTORY} ]];
then
_create_directory_or_exit "${PATH_TO_THE_OUTPUT_DIRECTORY}"
else
_echo_if_be_verbose " >>${PATH_TO_THE_OUTPUT_DIRECTORY}<< exists."
fi
#end of creating the output directory
#begin of copying needed profile
_echo_if_be_verbose " Copying content off >>${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY}<< to >>${PATH_TO_THE_OUTPUT_DIRECTORY}<<."
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
cp -r ${PATH_TO_THE_SOURCE_PROFILE_DIRECTORY} "${PATH_TO_THE_OUTPUT_DIRECTORY}/"
fi
#end of copying needed profile
_echo_if_be_verbose ":: Finished setup environment"
}
####
# @param <string: path>
####
function _create_directory_or_exit ()
{
local DIRECTORY_PATH
DIRECTORY_PATH="${1}"
_echo_if_be_verbose " Creating directory path >>${DIRECTORY_PATH}<<."
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
/usr/bin/mkdir -p ${DIRECTORY_PATH}
fi
exit_if_last_exit_code_is_not_zero ${?} "Could not create directory path >>${DIRECTORY_PATH}<<."
}
####
# @param <string: PATH_TO_REMOVE>
####
function _remove_path_or_exit ()
{
local PATH_TO_REMOVE
PATH_TO_REMOVE="${1}"
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
_echo_if_be_verbose " Try to remove path >>${PATH_TO_REMOVE}<<."
if [[ -d "${PATH_TO_REMOVE}" ]];
then
/usr/bin/rm -fr ${PATH_TO_REMOVE}
exit_if_last_exit_code_is_not_zero ${?} "Could not remove path >>${PATH_TO_REMOVE}<<."
else
_echo_if_be_verbose " Path >>${PATH_TO_REMOVE}<< could not be removed because it does not exist."
fi
else
_echo_if_be_verbose " Would try to remove path >>${PATH_TO_REMOVE}<<."
fi
}
####
# @param <string: FILE_PATH_TO_REMOVE>
####
function _remove_file_path_or_exit ()
{
local FILE_PATH_TO_REMOVE
FILE_PATH_TO_REMOVE="${1}"
if [[ ${IS_DRY_RUN} -ne 1 ]];
then
_echo_if_be_verbose " Try to remove path >>${PATH_TO_REMOVE}<<."
if [[ -f "${FILE_PATH_TO_REMOVE}" ]];
then
/usr/bin/rm -f ${FILE_PATH_TO_REMOVE}
exit_if_last_exit_code_is_not_zero ${?} "Could not remove path >>${FILE_PATH_TO_REMOVE}<<."
else
_echo_if_be_verbose " Path >>${FILE_PATH_TO_REMOVE}<< could not be removed because it does not exist."
fi
else
_echo_if_be_verbose " Would try to remove path >>${PATH_TO_REMOVE}<<."
fi
}
####
# @param <string: VARIABLE_NAME>
# @param <string: VARIABLE_VALUE>
####
function _exit_if_string_is_empty ()
{
local VARIABLE_NAME
local VARIABLE_VALUE
VARIABLE_NAME="${1}"
VARIABLE_VALUE="${2}"
if [[ ${#VARIABLE_VALUE} -lt 1 ]];
then
echo " Empty >>${VARIABLE_NAME}<< provided."
exit 1
else
_echo_if_be_verbose " Valid >>${VARIABLE_NAME}<< provided, value has a string length of >>${#VARIABLE_VALUE}<<."
fi
}
#####
# @param <string: "${@}">
#####
function _main ()
{
if docker info > /dev/null 2>&1;
then
PATH_TO_THIS_SCRIPT=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
cd "${PATH_TO_THIS_SCRIPT}" || exit 11
_echo_if_be_verbose "Starting build in dedicated docker container"
docker compose run --rm archlinux-container /app/build.sh "${@}"
exit_if_last_exit_code_is_not_zero ${?} "Could not start docker container with: docker compose run --rm archlinux-container /app/build.sh" "${@}"
cd - || exit 12
else
local BUILD_FILE_NAME
local BUILD_WAS_SUCCESSFUL
local CURRENT_WORKING_DIRECTORY
local ISO_FILE_PATH
local PATH_TO_THIS_SCRIPT
local PATH_TO_THE_DYNAMIC_DATA_DIRECTORY
local PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE
local PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE
local PATH_TO_THE_OUTPUT_DIRECTORY
local PATH_TO_THE_PROFILE_DIRECTORY
local PATH_TO_THE_SOURCE_DATA_DIRECTORY
local SHA512_FILE_PATH
#@todo:
# * add support for dynamic user input
# -a|--add-script (add a script like a one we can maintain to easeup setup/installation of "our" archlinux)
# -l|--log-output 2>&1 | tee build.log
# -p|--package (archzfs-linux or what ever)
# * fix not working zfs embedding
#begin of main variables declaration
CURRENT_WORKING_DIRECTORY=$(pwd)
PATH_TO_THIS_SCRIPT=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE="${PATH_TO_THIS_SCRIPT}/.env.dist"
PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE="${PATH_TO_THIS_SCRIPT}/.env"
#begin of main variables declaration
#bo: user input
#we are storing all arguments for the case if the script needs to be re-executed as root/system user
local ALL_ARGUMENTS_TO_PASS
local ASK_TO_DUMP_ISO
local ASK_TO_RUN_ISO
local ASK_TO_UPLOAD_ISO
local BE_VERBOSE
local IS_DRY_RUN
local IS_FORCED
local KERNEL
local REPO_INDEX
local SHOW_HELP
local USE_DKMS
local USE_OTHER_REPO_INDEX
ALL_ARGUMENTS_TO_PASS="${@}"
ASK_TO_DUMP_ISO=1
ASK_TO_RUN_ISO=1