-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLFSInstaller.sh
1074 lines (985 loc) · 28.8 KB
/
LFSInstaller.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
#================================================================
# HEADER
#================================================================
# Script Name : LFSInstaller.sh
# Description : Interactive LFS Installer
# Author : Eliaz Simon
# Date : 2024-10-13
# Version : 1.0
# Usage : ./LFSInstaller.sh
# Notes :
# Dependencies :
#================================================================
# MIT License
# Copyright (c) 2024 Eliaz Simon
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the Software), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#================================================================
# Capture the current time
current_time=$(date +"%T")
# Capture the current date
current_date=$(date +"%Y-%m-%d")
# Capture the current year
current_year=$(date +"%Y")
#################################################################
# ANSI Color Code Escape Sequences #
#################################################################
# Colors
BLACK="\e[30m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
MAGENTA="\e[35m"
CYAN="\e[36m"
LIGHT_GRAY="\e[37m"
GRAY="\e[90m"
LIGHT_RED="\e[91m"
LIGHT_GREEN="\e[92m"
LIGHT_YELLOW="\e[93m"
LIGHT_BLUE="\e[94m"
LIGHT_MAGENTA="\e[95m"
LIGHT_CYAN="\e[96m"
# Background Colors
BLACK_BG="\e[40m"
RED_BG="\e[41m"
GREEN_BG="\e[42m"
YELLOW_BG="\e[43m"
BLUE_BG="\e[44m"
MAGENTA_BG="\e[45m"
CYAN_BG="\e[46m"
WHITE_BG="\e[47m"
# Bold
BOLD_BLACK="\e[1;30m"
BOLD_RED="\e[1;31m"
BOLD_GREEN="\e[1;32m"
BOLD_YELLOW="\e[1;33m"
BOLD_BLUE="\e[1;34m"
BOLD_MAGENTA="\e[1;35m"
BOLD_CYAN="\e[1;36m"
BOLD_LIGHT_GRAY="\e[1;37m"
BOLD_GRAY="\e[1;90m"
BOLD_LIGHT_RED="\e[1;91m"
BOLD_LIGHT_GREEN="\e[1;92m"
BOLD_LIGHT_YELLOW="\e[1;93m"
BOLD_LIGHT_BLUE="\e[1;94m"
BOLD_LIGHT_MAGENTA="\e[1;95m"
BOLD_LIGHT_CYAN="\e[1;96m"
BOLD_WHITE="\e[1;97m"
# Italic
ITALIC_BLACK="\e[3;30m"
ITALIC_RED="\e[3;31m"
ITALIC_GREEN="\e[3;32m"
ITALIC_YELLOW="\e[3;33m"
ITALIC_BLUE="\e[3;34m"
ITALIC_MAGENTA="\e[3;35m"
ITALIC_CYAN="\e[3;36m"
ITALIC_LIGHT_GRAY="\e[3;37m"
ITALIC_GRAY="\e[3;90m"
ITALIC_LIGHT_RED="\e[3;91m"
ITALIC_LIGHT_GREEN="\e[3;92m"
ITALIC_LIGHT_YELLOW="\e[3;93m"
ITALIC_LIGHT_BLUE="\e[3;94m"
ITALIC_LIGHT_MAGENTA="\e[3;95m"
ITALIC_LIGHT_CYAN="\e[3;96m"
ITALIC_WHITE="\e[3;97m"
# Styles
BOLD="\e[1m"
ITALIC="\e[3m"
ENDCOLOR="\e[0m"
#================================================================
# FUNCTION: info
# DESCRIPTION:
# Prints info message using the provided parameter.
# PARAMETERS:
# $1 - A message
# RETURNS:
# None
#================================================================
info() {
if [[ "$VERBOSE" = true ]]; then
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${GREEN}INFO${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}$1${ENDCOLOR}\n"
fi
}
#================================================================
# FUNCTION: bold_info
# DESCRIPTION:
# Prints bold info message using the provided parameter.
# PARAMETERS:
# $1 - A message
# RETURNS:
# None
#================================================================
bold_info() {
if [[ "$VERBOSE" = true ]]; then
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${BOLD_GREEN}INFO${ENDCOLOR}${WHITE}]${ENDCOLOR} ${BOLD_WHITE}$1${ENDCOLOR}\n"
fi
}
#================================================================
# FUNCTION: success
# DESCRIPTION:
# Prints success message using the provided parameter.
# $1 - A message
# RETURNS:
# None
#================================================================
success() {
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${BOLD_GREEN}SUCCESS${ENDCOLOR}${WHITE}]${ENDCOLOR} ${BOLD_WHITE}$1${ENDCOLOR}\n"
}
#================================================================
# FUNCTION: warning
# DESCRIPTION:
# Prints warning message using the provided parameter.
# PARAMETERS:
# $1 - A message
# RETURNS:
# None
#================================================================
warning() {
if [[ "$VERBOSE" = true ]]; then
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${YELLOW}WARNING${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}$1${ENDCOLOR}\n"
fi
}
#================================================================
# FUNCTION: bold_warning
# DESCRIPTION:
# Prints bold warning message using the provided parameter.
# PARAMETERS:
# $1 - A message
# RETURNS:
# None
#================================================================
bold_warning() {
if [[ "$VERBOSE" = true ]]; then
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${BOLD_YELLOW}WARNING${ENDCOLOR}${WHITE}]${ENDCOLOR} ${BOLD_WHITE}$1${ENDCOLOR}\n"
fi
}
#================================================================
# FUNCTION: error
# DESCRIPTION:
# Prints error message using the provided parameter.
# PARAMETERS:
# $1 - A message
# RETURNS:
# None
#================================================================
error() {
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${RED}ERROR${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}$1${ENDCOLOR}\n"
}
#================================================================
# FUNCTION: bold_error
# DESCRIPTION:
# Prints bold error message using the provided parameter.
# PARAMETERS:
# $1 - A message
# RETURNS:
# None
#================================================================
bold_error() {
local message=$1
printf "${WHITE}[${ENDCOLOR}${CYAN}$current_time${ENDCOLOR}${WHITE}]${ENDCOLOR} ${WHITE}[${ENDCOLOR}${BOLD_RED}ERROR${ENDCOLOR}${WHITE}]${ENDCOLOR} ${BOLD_WHITE}$1${ENDCOLOR}\n"
}
#================================================================
# FUNCTION: check_file
# DESCRIPTION:
# Checks if target file exists
# PARAMETERS:
# None
# RETURNS:
# 0 - Target file exists on the host machine.
# 1 - Target file does not exist on the host machine.
#================================================================
check_file() {
local $TARGET_FILE="$1"
if [[ -e "$TARGET_FILE" ]]; then
info "$TARGET_FILE exists in your host machine."
return 0
else
error "$TARGET_FILE does not exist on the host machine."
return 1
fi
}
#================================================================
# FUNCTION: verify_mount_point
# DESCRIPTION:
# Scans if "/mnt/lfs" is mounted to the host machine that is listed in /proc/mounts.
# PARAMETERS:
# None
# RETURNS:
# 0 - Returns true if mount point is mounted on device
# 1 - Returns false if mount point is not mounted
#================================================================
verify_mount_point() {
# MOUNT_POINT="/mnt/lfs"
if grep -qs /mnt/lfs /proc/mounts; then
# DEVICE=$(grep "$MOUNT_POINT" /proc/mounts | awk '{print $1}')
return 0
else
return 1
fi
}
#================================================================
# FUNCTION: verify_partition
# DESCRIPTION:
# Checks if partition exists which scans from /proc/partitions.
# PARAMETERS:
# $1 - Target partition
# RETURNS:
# 0 - Returns true if target partition is listed on /proc/partitions.
# 1 - Returns false if target partition is not listed on /proc/partition
#================================================================
verify_partition() {
local PARTITION=$1
local PARTITION_NAME=$(basename "$PARTITION")
if grep -wq "$PARTITION_NAME" /proc/partitions; then
return 0
else
return 1
fi
}
#================================================================
# FUNCTION: select_partition
# DESCRIPTION:
# Retrieves user input of an available target partition.
# PARAMETERS:
# None
# RETURNS:
# 0 - Returns true if such partition exist.
# 1 - Returns false if such partition does not exist.
#================================================================
select_partition() {
read -p "Specify the partition: " PARTITION
AVAILABLE_PARTITION=$(verify_partition "$PARTITION")
if [ $? -eq 0 ]; then
echo "$PARTITION"
return 0
else
return 1
fi
}
#================================================================
# FUNCTION: mount
# DESCRIPTION:
# Mounts target partition to /mnt/lfs mount point
# PARAMETERS:
# None
# RETURNS:
# 0 - Target partition is mounted to /mnt/lfs mount point.
# 1 - Target partition is failed mounting to /mnt/lfs mount point.
#================================================================
mount() {
if verify_mount_point; then
success "/mnt/lfs is already mounted."
exit 0
fi
if [[ -z $PARTITION ]]; then
PARTITION=$(select_partition)
if [ $? -eq 1 ]; then
error "Unavailable partition for mounting"
exit 1
fi
fi
if [ ! -d /mnt/lfs ]; then
info "Creating /mnt/lfs directory..."
mkdir -pv /mnt/lfs
if [ $? -ne 0 ]; then
error "Failed to create /mnt/lfs directory."
exit 1
fi
fi
info "Mounting partition $PARTITION to /mnt/lfs..."
sudo mount -v -t ext4 $PARTITION /mnt/lfs
if [ $? -ne 0 ]; then
error "Failed to mount $PARTITION to /mnt/lfs"
exit 1
fi
info "Creating /mnt/lfs/home directory..."
if [ ! -d /mnt/lfs/home ]; then
info "Creating /mnt/lfs/home directory..."
mkdir -v /mnt/lfs/home
if [ $? -ne 0 ]; then
error "Failed to create /mnt/lfs/home directory."
exit 1
fi
fi
sudo mount -v -t ext4 $PARTITION /mnt/lfs/home
if [ $? -ne 0 ]; then
error "Failed to mount $PARTITION to /mnt/lfs/home"
exit 1
fi
bold_info "Creating Virtual File System directories"
virtual_file_system=("dev" "proc" "sys" "run")
for vfs in "${virtual_file_system[@]}"; do
if [ ! -d /mnt/lfs/$vfs ]; then
info "Creating /mnt/lfs/$vfs directory..."
mkdir -v /mnt/lfs/$vfs
if [ $? -ne 0 ]; then
error "Failed to create /mnt/lfs/$vfs directory."
exit 1
fi
fi
done
bold_info "Mounting Virtual Kernel File Systems"
sudo mount -v --bind /dev/ /mnt/lfs/dev
if [ $? -ne 0 ]; then
error "Failed to mount /dev to /mnt/lfs/dev"
exit 1
fi
sudo mount -vt devpts devpts -o gid=5,mode=0620 /mnt/lfs/dev/pts
if [ $? -ne 0 ]; then
error "Failed to mount /dev/pts to /mnt/lfs/dev/pts"
exit 1
fi
sudo mount -vt proc proc /mnt/lfs/proc
if [ $? -ne 0 ]; then
error "Failed to mount proc to /mnt/lfs/proc"
exit 1
fi
sudo mount -vt sysfs sysfs /mnt/lfs/sys
if [ $? -ne 0 ]; then
error "Failed to mount sysfs to /mnt/lfs/sys"
exit 1
fi
sudo mount -vt tmpfs tmpfs /mnt/lfs/run
if [ $? -ne 0 ]; then
error "Failed to mount tmpfs to /mnt/lfs/run"
exit 1
fi
if [ -h /mnt/lfs/dev/shm ]; then
install -v -d -m 1777 /mnt/lfs$(realpath /dev/shm)
if [ $? -ne 0 ]; then
error "Failed to create directory and installation on /mnt/lfs$(realpath /dev/shm) path"
exit 1
fi
else
sudo mount -vt tmpfs -o nosuid,nodev tmpfs /mnt/lfs/dev/shm
if [ $? -ne 0 ]; then
error "Failed to mount tmpfs to /mnt/lfs/dev/shm"
exit 1
fi
fi
if verify_mount_point; then
success "$PARTITION mounted on /mnt/lfs"
exit 0
else
error "Mounting Failed: $PARTITION is not mounted on /mnt/lfs"
exit 1
fi
}
#================================================================
# FUNCTION: unmount
# DESCRIPTION:
# Unmounts target partition from LFS mount point.
# PARAMETERS:
# None
# RETURNS:
# 0 - LFS mountpoint is successfully unmounted from partition.
# 1 - LFS mountpoint failed to be unmounted from partition.
#================================================================
unmount() {
if [ ! verify_mount_point ]; then
success "/mnt/lfs is already not mounted."
exit 0
fi
bold_info "Unmounting Virtual File Systems"
info "Unmounting /mnt/lfs/dev/pts"
umount -v /mnt/lfs/dev/pts
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/dev/pts"
exit 1
fi
info "Unmounting /mnt/lfs/dev/shm"
mountpoint -q /mnt/lfs/dev/shm && umount -v /mnt/lfs/dev/shm
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/dev/shm"
exit 1
fi
info "Unmounting /mnt/lfs/dev"
umount -v /mnt/lfs/dev
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/dev"
exit 1
fi
info "Unmounting /mnt/lfs/run"
umount -v /mnt/lfs/run
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/run"
exit 1
fi
info "Unmounting /mnt/lfs/proc"
umount -v /mnt/lfs/proc
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/proc"
exit 1
fi
info "Unmounting /mnt/lfs/sys"
umount -v /mnt/lfs/sys
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/sys"
exit 1
fi
bold_info "Unmounting LFS filesystem"
info "Unmounting /mnt/lfs/home"
umount -v /mnt/lfs/home
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs/home"
exit 1
fi
info "Unmounting /mnt/lfs"
umount -v /mnt/lfs
if [ $? -ne 0 ]; then
error "Failed to unmount /mnt/lfs"
exit 1
fi
verify_mount_point
if [ $? -eq 1 ]; then
success "/mnt/lfs is successfully unmounted."
exit 0
else
error "/mnt/lfs failed to be unmounted."
exit 1
fi
}
#================================================================
# FUNCTION: chroot
# DESCRIPTION:
# Enters chroot environment as an isolated machine
# PARAMETERS:
# None
# RETURNS:
# 1 - LFS mount point is not mounted to partition
#================================================================
chroot() {
verify_mount_point
if [ $? -ne 0 ]; then
error "/mnt/lfs is not mounted."
exit 1
fi
export LFS=/mnt/lfs
chroot "$LFS" /usr/bin/env -i \
HOME=/root \
TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/usr/bin:/usr/sbin \
MAKEFLAGS="-j$(nproc)" \
TESTSUITEFLAGS="-j$(nproc)" \
/bin/bash --login
}
#================================================================
# FUNCTION: display_version_list
# DESCRIPTION:
# Prints LFS Release Build Version list
# PARAMETERS:
# None
# RETURNS:
# None
#================================================================
display_version_list() {
for i in "${!VERSION_LIST[@]}"; do
echo "$((i + 1)). ${VERSION_LIST[i]}"
done
exit 0
}
#================================================================
# FUNCTION: install
# DESCRIPTION:
# Performs LFS Installation that is generated from install script
# if user is currently root and that the installation script exists
# in order to perform installation.
# PARAMETERS:
# None
# RETURNS:
# 1 - User is not root to perform the following installation.
#================================================================
install() {
if [[ "$EUID" -ne 0 ]]; then
warning "You must run this script as a root user to perform such action."
exit 1
fi
if [ "$INSTALL_TYPE" == "s" ] || [ "$INSTALL_TYPE" == "single" ]; then
CHECK_COMMAND=$(check_file "install.sh")
check_file "install.sh"
if [ $CHECK_COMMAND -eq 0 ]; then
info "Initializing single installation script..."
sudo ./$TARGET_INSTALLATION_FILE
exit 0
fi
fi
if [ "$INSTALL_TYPE" == "p" ] || [ "$INSTALL_TYPE" == "phase" ]; then
MISSING_PHASE_FILE=false
PHASE_FILES=("phase1.sh" "phase2.sh" "phase3.sh" "phase4.sh")
for phase_file in ${PHASE_FILES[@]}; do
CHECK_PHASE_COMMAND=$(check phase_file)
if [ $CHECK_PHASE_COMMAND -eq 1 ]; then
error "$phase_file installation script does not exist in your phase installation"
MISSING_PHASE_FILE=true
fi
done
if [[ "$MISSING_PHASE_FILE" == "true" ]]; then
error "Unable to proceed with installation due to missing phase installation script(s)."
exit 1
fi
fi
exit 1
}
#================================================================
# FUNCTION: create_partition
# DESCRIPTION:
# Scans disk management tools from host machine for the user to create
# partition if no partition is available on host machine.
# PARAMETERS:
# None
# RETURNS:
# 1 - Disk management tools is not available on the host machine.
#================================================================
create_partition() {
disk_tools=("cfdisk" "fdisk" "parted" "lsblk" "gparted" "gdisk")
selected_tools=()
echo "Scanning for disk management tools..."
for tool in "${disk_tools[@]}"; do
if command -v "$tool" &> /dev/null; then
echo "$tool is installed."
selected_tools+=("$tool")
fi
done
if [ ${#selected_tools[@]} -eq 0 ]; then
error "No disk management tools found."
exit 1
fi
echo "Please select the tools you want to use from the following list:"
for i in "${!selected_tools[@]}"; do
echo "$((i + 0)). ${selected_tools[i]}"
done
read -p "Enter the number of the disk management tool you want to select: " user_input
if [[ "$user_input" =~ ^[0-9]+$ ]] && [ "$user_input" -ge 0 ] && [ "$user_input" -lt "${#selected_tools[@]}" ]; then
tool="${selected_tools[user_input]}"
echo "You selected: $tool"
case $tool in
"fdisk")
sudo "$tool" $PARTITION
;;
esac
if [[ ! "$tool" == "fdisk" ]]; then
sudo "$tool"
fi
echo "Operation completed."
else
echo "Error: Invalid selection: $user_input"
fi
}
#================================================================
# FUNCTION: create_script
# DESCRIPTION:
# Creates LFS installation script from user's input
# PARAMETERS:
# None
# RETURNS:
# None
#================================================================
create_script() {
if [ -z "$PARTITION" ]; then
PARTITION=$(select_partition)
if [ $? -eq 0 ]; then
bold_info "Partition: $PARTITION"
else
error "Partition not selected"
exit 1
fi
fi
if [ -z "$SWAP_PARTITION" ]; then
SWAP=false
while true; do
read -p "Do you want to use swap partition during LFS installation (Y/n): " answer
case "$answer" in
[Yy]* )
SWAP=true
break
;;
[Nn]* )
break
;;
* )
error "Please answer Y or n."
;;
esac
done
if [ "$SWAP" = true ]; then
SWAP_PARTITION=$(select_partition)
if [ $? -eq 0 ]; then
bold_info "Swap Partition: $SWAP_PARTITION"
else
error "Swap partition not selected"
exit 1
fi
fi
fi
if [ -z "$VERSION" ]; then
match_found=0
for ver in "${VERSION_LIST[@]}"; do
if [ "$VERSION" = "$ver" ]; then
match_found=1
break
fi
done
if [ "$match_found" -eq 0 ]; then
display_version_list
while true; do
read -p "Enter the number corresponding to your choice (1-23): " -a answer
case "$answer" in
1 )
VERSION="${VERSION_LIST[0]}"
break
;;
2 )
VERSION="${VERSION_LIST[1]}"
break
;;
3 )
VERSION="${VERSION_LIST[2]}"
break
;;
4 )
VERSION="${VERSION_LIST[3]}"
break
;;
5 )
VERSION="${VERSION_LIST[4]}"
break
;;
6 )
VERSION="${VERSION_LIST[5]}"
break
;;
7 )
VERSION="${VERSION_LIST[6]}"
break
;;
8 )
VERSION="${VERSION_LIST[7]}"
break
;;
9 )
VERSION="${VERSION_LIST[8]}"
break
;;
10 )
VERSION="${VERSION_LIST[9]}"
break
;;
11 )
VERSION="${VERSION_LIST[10]}"
break
;;
12 )
VERSION="${VERSION_LIST[11]}"
break
;;
13 )
VERSION="${VERSION_LIST[12]}"
break
;;
14 )
VERSION="${VERSION_LIST[13]}"
break
;;
15 )
VERSION="${VERSION_LIST[14]}"
break
;;
16 )
VERSION="${VERSION_LIST[15]}"
break
;;
17 )
VERSION="${VERSION_LIST[16]}"
break
;;
18 )
VERSION="${VERSION_LIST[17]}"
break
;;
19 )
VERSION="${VERSION_LIST[18]}"
break
;;
20 )
VERSION="${VERSION_LIST[19]}"
break
;;
21 )
VERSION="${VERSION_LIST[20]}"
break
;;
22 )
VERSION="${VERSION_LIST[21]}"
break
;;
23 )
VERSION="${VERSION_LIST[22]}"
break
;;
* )
error "You must select the version"
break
;;
esac
done
bold_info "Version: $VERSION"
fi
fi
if [ -z "$INSTALL_TYPE" ]; then
INSTALL_VALUES=("single" "phase")
match_found=0
for install in "${INSTALL_VALUES[@]}"; do
if [ "$INSTALL_TYPE" = "$install" ]; then
match_found=1
break
fi
done
if [ "$match_found" -eq 0 ]; then
while true; do
echo "The LFS Installation allows you to choose two types of installation:"
echo ""
echo "1. Single Script Installation"
echo "The script will merge all scripts, with addition of dependencies but it requires overviewing"
echo "of how your script can be installed."
echo ""
echo "2. Phases Script Installation"
echo "The following installation will be broken down into phases, allowing more control over the process"
echo "and allowing your to install components manually."
echo ""
echo "The following phases follow as such"
echo " Phase 1 - Build Preparation"
echo " Phase 2 - Cross Toolchain"
echo " Phase 3 - Chroot"
echo " Phase 4 - System Configuration"
echo ""
# Prompt the user
read -p "Enter your choice (1 or 2): " answer
# Convert the answer to lowercase for easier comparison
case "$answer" in
1)
bold_info "Installation Type: Single Script Installation"
INSTALL_TYPE="single"
break
;;
2 )
bold_info "Installation Type: Phase-by-Phase Installation"
INSTALL_TYPE="phase"
break
;;
* )
error "Invalid option. Please run the script again and choose 1 or 2."
;;
esac
done
fi
fi
if [ -z "$DISTRIB_CODENAME" ]; then
echo "DISTRIB CODENAME"
echo ""
echo "The codename refers to the specific release of the Linux distribution."
echo ""
echo "It is usually found in system files like /etc/lsb-release."
echo ""
while true; do
read -p "Enter the name of your specific release: " distrib_codename
if [[ -z "$distrib_codename" ]]; then
error "The distribution codename is empty. Please try again."
else
bold_info "Distribution Codename: $distrib_codename"
DISTRIB_CODENAME="$distrib_codename"
break
fi
done
fi
if [ -z "$VERSION_CODENAME" ]; then
echo "VERSION CODENAME"
echo ""
echo "This is term represent the codename of the distributed version, which can be found in files like /etc/os-release."
echo ""
while true; do
read -p "Enter the name of your codename of the distributed version: " version_codename
if [[ -z "$version_codename" ]]; then
error "The version codename is empty. Please try again."
else
bold_info "Version Codename: $version_codename"
VERSION_CODENAME="$version_codename"
break
fi
done
fi
./generate-installer.sh \
"$PARTITION" \
"$SWAP_PARTITION" \
"$DISTRIB_CODENAME" \
"$VERSION_CODENAME" \
"$INSTALL_TYPE" \
"$VERSION" \
"$VERBOSE"
exit 0
}
#================================================================
# FUNCTION: usage
# DESCRIPTION:
# Prints default usage information.
# PARAMETERS:
# None
# RETURNS:
# None
#================================================================
usage() {
echo "LFSInstaller"
echo " "
echo "Linux From Scratch Script Template Installation Generator"
echo "It is recommended that you execute this script as a root user."
echo " "
echo "Usage: ./LFSInstaller.sh [modes] [options] [others]"
echo " "
exit 0
}
#================================================================
# FUNCTION: help
# DESCRIPTION:
# Prints default help information.
# PARAMETERS:
# None
# RETURNS:
# None
#================================================================
help() {
echo "LFSInstaller"
echo " "
echo "Linux From Scratch Script Template Installation Generator"
echo "It is recommended that you execute this script as a root user."
echo ""
echo "Usage: ./LFSInstaller.sh [modes] [options] [others]"
echo ""
echo "Modes: "
printf " ${BOLD}-c, --create${ENDCOLOR} Generates LFS installation script\n"
printf " ${BOLD}-i, --install${ENDCOLOR} Starts LFS Installation script\n"
printf " ${BOLD}-it, --install-type${ENDCOLOR} Specifies installation type\n"
printf " ${BOLD}--create-partition${ENDCOLOR} Specifies new device blocks of partition\n"
printf " ${BOLD}-m, --mount${ENDCOLOR} Mounts LFS to a target partition\n"
printf " ${BOLD}-um, --unmount${ENDCOLOR} Unmounts LFS from a target partition\n"
printf " ${BOLD}--chroot${ENDCOLOR} Enters chroot environment on an isolated machine\n"
echo ""
echo "Options:"
printf " ${BOLD}-v, --version${ENDCOLOR} Specifies LFS Release Build Version\n"
printf " ${BOLD}-p, --partition${ENDCOLOR} Specifies partition\n"
printf " ${BOLD}-s, --swap${ENDCOLOR} Enables SWAP partition\n"
printf " ${BOLD}-sp, --swap-partition${ENDCOLOR} Specifies SWAP partition\n"
printf " ${BOLD}-vc, --version-codename${ENDCOLOR} Specifies version codename\n"
printf " ${BOLD}-dc, --distrib-codename${ENDCOLOR} Specifies distrib codename\n"
echo " "
echo "Others:"
printf " ${BOLD}-h, --help${ENDCOLOR} Show help message\n"
printf " ${BOLD}-u, --usage${ENDCOLOR} Show usage information\n"
printf " ${BOLD}--version-list${ENDCOLOR} Show list of LFS Release Builds\n"
printf " ${BOLD}--verbose${ENDCOLOR} Enable verbose mode\n"
echo " "
echo "Examples:"
printf " ${BOLD}./LFSInstaller -m${ENDCOLOR} Initialize mounting procedure\n"
printf " ${BOLD}./LFSInstaller -c${ENDCOLOR} Creates standard installation script in interactive mode (if no values have passed)\n"
printf " ${BOLD}./LFSInstaller --partition=/dev/sda1 --install-type=phase -c${ENDCOLOR} Creates installation script, on the /dev/sda1 partition, which will create shell script as phases.\n"
printf " ${BOLD}./LFSInstaller --version=9.0 -c${ENDCOLOR} Creates installation script that uses the release build version 9.0\n"
exit 0
}
VERSION_LIST=("9.0-rc1" "9.0" "9.1-rc1" "9.1" "10.0-rc1" "10.0" "10.1-rc1" "10.1" "11.0-rc1"
"11.0-rc2" "11.0-rc3" "11.0" "11.1-rc1" "11.1" "11.2-rc1" "11.3-rc1" "11.3" "12.0-rc1" "12.0" "12.1-rc1"
"12.1" "12.2-rc1" "12.2")
PARTITION=""
SWAP_PARTITION=""
VERSION_CODENAME=""
DISTRIB_CODENAME=""
INSTALL_TYPE=""