-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
1666 lines (1551 loc) · 56.8 KB
/
common.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
#!/usr/bin/env bash
# shellcheck disable=SC2034,SC2001,SC2155,SC2153,SC2143
# SC2034: foo appears unused. Verify it or export it.
# SC2001: See if you can use ${variable//search/replace} instead.
# SC2155 Declare and assign separately to avoid masking return values
# SC2153: Possible Misspelling: MYVARIABLE may not be assigned. Did you mean MY_VARIABLE?
# SC2143: Use grep -q instead of comparing output with [ -n .. ].
# @description Common functions for the system installation.
# @author ssnow
# @version 1.0.0
# @date 2024-02-20
# @license GPLv3
set -eu
# set variables
BOOT_DIRECTORY=/boot
ESP_DIRECTORY=/boot
UUID_BOOT=$(blkid -s UUID -o value "$PARTITION_BOOT")
UUID_ROOT=$(blkid -s UUID -o value "$PARTITION_ROOT")
PARTUUID_BOOT=$(blkid -s PARTUUID -o value "$PARTITION_BOOT")
PARTUUID_ROOT=$(blkid -s PARTUUID -o value "$PARTITION_ROOT")
# @description Ask for installation information.
# @return 0 on success, 1 on failure
ask_for_installation_info() {
local script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
local project_root="$( cd "$script_dir/.." && pwd )"
local executable_path="$project_root/installation_info/installation_info"
print_message DEBUG "Current directory: $(pwd)"
print_message DEBUG "Script directory: $script_dir"
print_message DEBUG "Project root: $project_root"
print_message DEBUG "Executable path: $executable_path"
if [ ! -f "$executable_path" ]; then
print_message ERROR "installation_info file not found at $executable_path"
return 1
fi
if [ ! -x "$executable_path" ]; then
print_message ERROR "installation_info is not executable at $executable_path"
chmod +x "$executable_path"
print_message DEBUG "Made $executable_path executable"
fi
print_message DEBUG "Current PATH: $PATH"
print_message DEBUG "Current working directory: $(pwd)"
print_message DEBUG "Executable permissions: $(ls -l "$executable_path")"
print_message DEBUG "Executable file type: $(file "$executable_path")"
print_message DEBUG "Environment variables:"
print_message DEBUG "USERNAME=$USERNAME"
print_message DEBUG "USER_PASSWORD=$USER_PASSWORD"
print_message DEBUG "HOSTNAME=$HOSTNAME"
print_message DEBUG "TIMEZONE=$TIMEZONE"
print_message DEBUG "Attempting to run installation_info program"
print_message DEBUG "Command: $executable_path -interactive=false"
# Explicitly set environment variables
export USERNAME="$(sanitize "${USERNAME:-user}")"
export USER_PASSWORD="$(sanitize "${USER_PASSWORD:-changeme}")" # Set a default password
export HOSTNAME="$(sanitize "${HOSTNAME:-arch}")"
export TIMEZONE="$(sanitize "${TIMEZONE:-America/Toronto}")"
print_message DEBUG "Environment variables after setting defaults:"
print_message DEBUG "USERNAME=$USERNAME"
print_message DEBUG "USER_PASSWORD=$USER_PASSWORD"
print_message DEBUG "HOSTNAME=$HOSTNAME"
print_message DEBUG "TIMEZONE=$TIMEZONE"
# Check if we need to run in interactive mode
if [ -z "$USERNAME" ] || [ -z "$USER_PASSWORD" ] || [ -z "$HOSTNAME" ] || [ -z "$TIMEZONE" ]; then
print_message DEBUG "Running installation_info in interactive mode"
"$executable_path" -interactive=true
else
print_message DEBUG "Running installation_info in non-interactive mode"
"$executable_path" -interactive=false
fi
exit_code=$?
print_message DEBUG "installation_info exit code: $exit_code"
if [ $exit_code -ne 0 ]; then
print_message ERROR "Failed to run installation_info program. Exit code: $exit_code"
return 1
fi
print_message DEBUG "Trying to execute directly from shell"
bash -c "$executable_path -interactive=false"
print_message DEBUG "Direct execution exit code: $?"
print_message DEBUG "Checking library dependencies"
ldd_output=$(ldd "$executable_path" 2>&1) || true
if [[ $ldd_output == *"not a dynamic executable"* ]]; then
print_message DEBUG "The executable is statically linked (this is normal for Go programs)"
else
print_message DEBUG "Library dependencies: $ldd_output"
fi
print_message DEBUG "Running strace on installation_info"
strace "$executable_path" -interactive=false || true
print_message SUCCESS "Installation information collected successfully!"
return 0
}
sanitize_variable() {
local VARIABLE="$1"
local VARIABLE=$(echo "$VARIABLE" | sed "s/![^ ]*//g") # remove disabled
local VARIABLE=$(echo "$VARIABLE" | sed -r "s/ {2,}/ /g") # remove unnecessary white spaces
local VARIABLE=$(echo "$VARIABLE" | sed 's/^[[:space:]]*//') # trim leading
local VARIABLE=$(echo "$VARIABLE" | sed 's/[[:space:]]*$//') # trim trailing
echo "$VARIABLE"
}
trim_variable() {
local VARIABLE="$1"
local VARIABLE=$(echo "$VARIABLE" | sed 's/^[[:space:]]*//') # trim leading
local VARIABLE=$(echo "$VARIABLE" | sed 's/[[:space:]]*$//') # trim trailing
echo "$VARIABLE"
}
wipe_disk() {
local DEVICE="$1"
local PARTITION_MODE="$2"
if [ "$PARTITION_MODE" == "auto" ]; then
sgdisk --zap-all "$DEVICE"
sgdisk -o "$DEVICE"
wipefs -a -f "$DEVICE"
partprobe -s "$DEVICE"
fi
}
boot_partition() {
local PARTITION_BOOT="$1"
local BIOS_TYPE="$2"
if [ "$BIOS_TYPE" == "uefi" ]; then
mkfs.fat -n ESP -F32 "$PARTITION_BOOT"
fi
if [ "$BIOS_TYPE" == "bios" ]; then
mkfs.ext4 -L boot "$PARTITION_BOOT"
fi
}
root_partition() {
local DEVICE_ROOT="$1"
local FILE_SYSTEM_TYPE="$2"
if [ "$FILE_SYSTEM_TYPE" == "ext4|btrfs" ]; then
mkfs."$FILE_SYSTEM_TYPE" -L root "$DEVICE_ROOT"
fi
}
home_partition() {
local DEVICE_HOME="$1"
local FILE_SYSTEM_TYPE="$2"
if [ "$FILE_SYSTEM_TYPE" == "ext4|btrfs" ]; then
mkfs."$FILE_SYSTEM_TYPE" -L home "$DEVICE_HOME"
fi
}
swap_partition() {
local DEVICE_SWAP="$1"
local SWAP_SIZE="$2"
fallocate -l "$SWAP_SIZE" "$DEVICE_SWAP"
}
partition_mount() {
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
# mount subvolumes
mount -o "subvol=${BTRFS_SUBVOLUME_ROOT[1]},$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" "${MNT_DIR}"
mkdir -p "${MNT_DIR}"/boot
mount -o "$PARTITION_OPTIONS_BOOT" "$PARTITION_BOOT" "${MNT_DIR}"/boot
for I in "${BTRFS_SUBVOLUMES_MOUNTPOINTS[@]}"; do
IFS=',' read -ra SUBVOLUME <<< "$I"
if [ "${SUBVOLUME[0]}" == "root" ]; then
continue
fi
if [ "${SUBVOLUME[0]}" == "swap" ] && [ -z "$SWAP_SIZE" ]; then
continue
fi
if [ "${SUBVOLUME[0]}" == "swap" ]; then
mkdir -p "${MNT_DIR}${SUBVOLUME[2]}"
chmod 0755 "${MNT_DIR}${SUBVOLUME[2]}"
else
mkdir -p "${MNT_DIR}${SUBVOLUME[2]}"
fi
mount -o "subvol=${SUBVOLUME[1]},$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" "${MNT_DIR}${SUBVOLUME[2]}"
done
else
# root
mount -o "$PARTITION_OPTIONS" "$DEVICE_ROOT" "${MNT_DIR}"
# boot
mkdir -p "${MNT_DIR}"/boot
mount -o "$PARTITION_OPTIONS_BOOT" "$PARTITION_BOOT" "${MNT_DIR}"/boot
# mount points
for I in "${PARTITION_MOUNT_POINTS[@]}"; do
if [[ "$I" =~ ^!.* ]]; then
continue
fi
IFS='=' read -ra PARTITION_MOUNT_POINT <<< "$I"
if [ "${PARTITION_MOUNT_POINT[1]}" == "/boot" ] || [ "${PARTITION_MOUNT_POINT[1]}" == "/" ]; then
continue
fi
local PARTITION_DEVICE="$(partition_device "${DEVICE}" "${PARTITION_MOUNT_POINT[0]}")"
mkdir -p "${MNT_DIR}${PARTITION_MOUNT_POINT[1]}"
mount -o "$PARTITION_OPTIONS" "${PARTITION_DEVICE}" "${MNT_DIR}${PARTITION_MOUNT_POINT[1]}"
done
fi
}
create_subvolumes() {
# create
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
# create subvolumes
mount -o "$PARTITION_OPTIONS" "$DEVICE_ROOT" "${MNT_DIR}"
for I in "${BTRFS_SUBVOLUMES_MOUNTPOINTS[@]}"; do
IFS=',' read -ra SUBVOLUME <<< "$I"
if [ "${SUBVOLUME[0]}" == "swap" ] && [ -z "$SWAP_SIZE" ]; then
continue
fi
btrfs subvolume create "${MNT_DIR}/${SUBVOLUME[1]}"
done
umount "${MNT_DIR}"
fi
}
swap_file() {
# swap
if [ -n "$SWAP_SIZE" ]; then
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
SWAPFILE="${BTRFS_SUBVOLUME_SWAP[2]}$SWAPFILE"
chattr +C "${MNT_DIR}"
btrfs filesystem mkswapfile --size "${SWAP_SIZE}m" --uuid clear "${MNT_DIR}${SWAPFILE}"
swapon "${MNT_DIR}${SWAPFILE}"
else
dd if=/dev/zero of="${MNT_DIR}$SWAPFILE" bs=1M count="$SWAP_SIZE" status=progress
chmod 600 "${MNT_DIR}${SWAPFILE}"
mkswap "${MNT_DIR}${SWAPFILE}"
fi
fi
}
install() {
print_step "install()"
local COUNTRIES=()
local PACKAGES=()
pacman -Sy --noconfirm reflector
reflector "${COUNTRIES[@]}" --latest 25 --age 24 --protocol https --completion-percent 100 --sort rate --save /etc/pacman.d/mirrorlist
sed -i 's/#Color/Color/' /etc/pacman.conf
sed -i 's/#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
PACKAGES=()
if [ "$LVM" == "true" ]; then
local PACKAGES+=("lvm2")
fi
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
local PACKAGES+=("btrfs-progs")
fi
if [ "$FILE_SYSTEM_TYPE" == "ext4" ]; then
local PACKAGES+=("e2fsprogs")
fi
pacstrap "${MNT_DIR}" base base-devel linux linux-firmware "${PACKAGES[@]}"
sed -i 's/#ParallelDownloads/ParallelDownloads/' "${MNT_DIR}"/etc/pacman.conf
if [ "$REFLECTOR" == "true" ]; then
pacman_install "reflector"
cat <<EOT > "${MNT_DIR}/etc/xdg/reflector/reflector.conf"
${COUNTRIES[@]}
--latest 25
--age 24
--protocol https
--completion-percent 100
--sort rate
--save /etc/pacman.d/mirrorlist
EOT
arch-chroot "${MNT_DIR}" reflector "${COUNTRIES[@]}" --latest 25 --age 24 --protocol https --completion-percent 100 --sort rate --save /etc/pacman.d/mirrorlist
arch-chroot "${MNT_DIR}" systemctl enable reflector.timer
fi
if [ "$PACKAGES_MULTILIB" == "true" ]; then
sed -z -i 's/#\[multilib\]\n#/[multilib]\n/' "${MNT_DIR}"/etc/pacman.conf
fi
}
configuration() {
print_step "configuration()"
if [ "$GPT_AUTOMOUNT" != "true" ]; then
genfstab -U "${MNT_DIR}" >> "${MNT_DIR}/etc/fstab"
cat <<EOT >> "${MNT_DIR}/etc/fstab"
# efivars
efivarfs /sys/firmware/efi/efivars efivarfs ro,nosuid,nodev,noexec 0 0
EOT
if [ -n "$SWAP_SIZE" ]; then
cat <<EOT >> "${MNT_DIR}/etc/fstab"
# swap
$SWAPFILE none swap defaults 0 0
EOT
fi
fi
if [ "$DEVICE_TRIM" == "true" ]; then
if [ "$GPT_AUTOMOUNT" != "true" ]; then
sed -i 's/relatime/noatime/' "${MNT_DIR}"/etc/fstab
fi
arch-chroot "${MNT_DIR}" systemctl enable fstrim.timer
fi
arch-chroot "${MNT_DIR}" ln -s -f "$TIMEZONE" /etc/localtime
arch-chroot "${MNT_DIR}" hwclock --systohc
for LOCALE in "${LOCALES[@]}"; do
sed -i "s/#$LOCALE/$LOCALE/" /etc/locale.gen
sed -i "s/#$LOCALE/$LOCALE/" "${MNT_DIR}"/etc/locale.gen
done
for VARIABLE in "${LOCALE_CONF[@]}"; do
#localectl set-locale "$VARIABLE"
echo -e "$VARIABLE" >> "${MNT_DIR}"/etc/locale.conf
done
locale-gen
arch-chroot "${MNT_DIR}" locale-gen
echo -e "$KEYMAP\n$FONT\n$FONT_MAP" > "${MNT_DIR}"/etc/vconsole.conf
echo "$HOSTNAME" > "${MNT_DIR}"/etc/hostname
if [ -n "$SWAP_SIZE" ]; then
echo "vm.swappiness=10" > "${MNT_DIR}"/etc/sysctl.d/99-sysctl.conf
fi
printf "%s\n%s" "$ROOT_PASSWORD" "$ROOT_PASSWORD" | arch-chroot "${MNT_DIR}" passwd
}
provision() {
print_step "provision()"
(cd "$PROVISION_DIRECTORY" && cp -vr --parents . "${MNT_DIR}")
}
end() {
local REBOOT="$1"
printf "\n"
printf "%s\n" "${GREEN}Arch Linux installed successfully"'!'"${NC}"
printf "\n"
if [ "$REBOOT" == "true" ]; then
REBOOT="true"
set +e
for (( i = 15; i >= 1; i-- )); do
read -r -s -n 1 -t 1 -p "Rebooting in $i seconds... Press Esc key to abort or press R key to reboot now."$'\n' KEY
local CODE="$?"
if [ "$CODE" != "0" ]; then
continue
fi
if [ "$KEY" == $'\e' ]; then
REBOOT="false"
break
elif [ "$KEY" == "r" ] || [ "$KEY" == "R" ]; then
REBOOT="true"
break
fi
done
fi
if [ "$REBOOT" == 'true' ]; then
printf "%s\n" "${GREEN}Rebooting...${NC}"
printf "\n"
copy_logs
do_reboot
else
copy_logs
fi
}
copy_logs() {
local ESCAPED_LUKS_PASSWORD=${LUKS_PASSWORD//[.[\*^$()+?{|]/[\\&]}
local ESCAPED_ROOT_PASSWORD=${ROOT_PASSWORD//[.[\*^$()+?{|]/[\\&]}
local ESCAPED_USER_PASSWORD=${USER_PASSWORD//[.[\*^$()+?{|]/[\\&]}
if [ -f "$ALIS_CONF_FILE" ]; then
local SOURCE_FILE="$ALIS_CONF_FILE"
local FILE="${MNT_DIR}/var/log/arch-install/$ALIS_CONF_FILE"
mkdir -p "${MNT_DIR}"/var/log/arch-install/
cp "$SOURCE_FILE" "$FILE"
chown root:root "$FILE"
chmod 600 "$FILE"
if [ -n "$ESCAPED_LUKS_PASSWORD" ]; then
sed -i "s/${ESCAPED_LUKS_PASSWORD}/******/g" "$FILE"
fi
if [ -n "$ESCAPED_ROOT_PASSWORD" ]; then
sed -i "s/${ESCAPED_ROOT_PASSWORD}/******/g" "$FILE"
fi
if [ -n "$ESCAPED_USER_PASSWORD" ]; then
sed -i "s/${ESCAPED_USER_PASSWORD}/******/g" "$FILE"
fi
fi
}
sanitize() {
DEVICE=$(sanitize "$DEVICE")
PARTITION_MODE=$(sanitize "$PARTITION_MODE")
PARTITION_CUSTOM_PARTED_UEFI=$(sanitize "$PARTITION_CUSTOM_PARTED_UEFI")
PARTITION_CUSTOM_PARTED_BIOS=$(sanitize "$PARTITION_CUSTOM_PARTED_BIOS")
FILE_SYSTEM_TYPE=$(sanitize "$FILE_SYSTEM_TYPE")
SWAP_SIZE=$(sanitize "$SWAP_SIZE")
KERNELS=$(sanitize "$KERNELS")
KERNELS_COMPRESSION=$(sanitize "$KERNELS_COMPRESSION")
KERNELS_PARAMETERS=$(sanitize "$KERNELS_PARAMETERS")
AUR_PACKAGE=$(sanitize "$AUR_PACKAGE")
DISPLAY_DRIVER=$(sanitize "$DISPLAY_DRIVER")
DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION_INTEL=$(sanitize "$DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION_INTEL")
SYSTEMD_HOMED_STORAGE=$(sanitize "$SYSTEMD_HOMED_STORAGE")
SYSTEMD_HOMED_STORAGE_LUKS_TYPE=$(sanitize "$SYSTEMD_HOMED_STORAGE_LUKS_TYPE")
BOOTLOADER=$(sanitize "$BOOTLOADER")
CUSTOM_SHELL=$(sanitize "$CUSTOM_SHELL")
DESKTOP_ENVIRONMENT=$(sanitize "$DESKTOP_ENVIRONMENT")
DISPLAY_MANAGER=$(sanitize "$DISPLAY_MANAGER")
SYSTEMD_UNITS=$(sanitize "$SYSTEMD_UNITS")
for I in "${BTRFS_SUBVOLUMES_MOUNTPOINTS[@]}"; do
IFS=',' read -ra SUBVOLUME <<< "$I"
if [ "${SUBVOLUME[0]}" == "root" ]; then
BTRFS_SUBVOLUME_ROOT=("${SUBVOLUME[@]}")
elif [ "${SUBVOLUME[0]}" == "swap" ]; then
BTRFS_SUBVOLUME_SWAP=("${SUBVOLUME[@]}")
fi
done
for I in "${PARTITION_MOUNT_POINTS[@]}"; do #SC2153
IFS='=' read -ra PARTITION_MOUNT_POINT <<< "$I"
if [ "${PARTITION_MOUNT_POINT[1]}" == "/boot" ]; then
PARTITION_BOOT_NUMBER="${PARTITION_MOUNT_POINT[0]}"
elif [ "${PARTITION_MOUNT_POINT[1]}" == "/" ]; then
PARTITION_ROOT_NUMBER="${PARTITION_MOUNT_POINT[0]}"
fi
done
}
cleanup() {
local exit_code=$?
print_message INFO "Performing cleanup..."
# Restore original configuration files if backups exist
[ -f "/mnt/etc/mkinitcpio.conf.bak" ] && mv "/mnt/etc/mkinitcpio.conf.bak" "/mnt/etc/mkinitcpio.conf"
[ -f "/mnt/etc/default/grub.bak" ] && mv "/mnt/etc/default/grub.bak" "/mnt/etc/default/grub"
# Remove any partial boot entries
if [ "$BOOTLOADER" == "systemd" ]; then
rm -f "/mnt$ESP_DIRECTORY/loader/entries/arch-*.conf"
fi
# Log the exit status
if [ $exit_code -ne 0 ]; then
print_message ERROR "Script exited with error code $exit_code"
# You could add more detailed logging or error reporting here
fi
print_message INFO "Cleanup completed"
exit $exit_code
}
select_default_kernel {
local kernellist
local kernels
local option
if [ "$(stat -c "%u" /boot)" -eq 0 ]; then
show_info "'/boot' owned by root. Searching as root:"
mapfile -t kernellist < \
<(sudo find /boot -maxdepth 1 -name 'vmlinuz-*' -type f -print0 |
xargs -0 -I _ basename _ |
sed -e "s/^vmlinuz-//g")
else
mapfile -t kernellist < \
<(find /boot -maxdepth 1 -name 'vmlinuz-*' -type f -print0 |
xargs -0 -I _ basename _ |
sed -e "s/^vmlinuz-//g")
fi
kernels=("Back" "${kernellist[@]}")
show_question "Select a default kernel:"
select option in "${kernels[@]}"; do
case "${option}" in
Back)
break
;;
linux | linux-lts | linux-zen | linux-hardened | linux-rt | linux-rt-lts)
KERNEL="${option}"
set_default_kernel
break
;;
*)
show_error "Invalid option ${option@Q}."
break
;;
esac
done
}
set_default_kernel {
local grubdefault="/etc/default/grub"
local grubcfg="/boot/grub/grub.cfg"
local mksdbootcfg="${DIR}/utils/sdboot-mkconfig"
show_info "Setting default boot kernel to ${KERNEL}."
if [ -f "${grubdefault}" ]; then
sudo sed -i "s/^GRUB_DEFAULT=.*$/GRUB_DEFAULT='Advanced options for Arch Linux>Arch Linux, with Linux ${KERNEL}'/g" ${grubdefault}
sudo grub-mkconfig -o ${grubcfg}
fi
if [[ "$(sudo bootctl is-installed)" = yes ]]; then
local sdbootcfg
sdbootcfg="$(bootctl -p)/loader/loader.conf"
if ! [ -f "$(bootctl -p)/loader/entries/${KERNEL}.conf" ]; then
sudo "${mksdbootcfg}" "${KERNEL}"
fi
sudo sed -i "s/^default\(\s\+\)\(.*\)/default\1${KERNEL}.conf/g" "${sdbootcfg}"
fi
}
select_plymouth_theme {
if command -v plymouth-set-default-theme > /dev/null; then
show_info "Select Plymouth theme:"
local choice
local choices
mapfile -t choices < <(plymouth-set-default-theme -l)
select choice in Back default "${choices[@]}"; do
set_plymouth_theme "${choice}"
break
done
else
show_warning "'plymouth-set-default-theme' executable not found. Skipping."
fi
}
set_plymouth_theme {
local theme="${1:-default}"
if command -v plymouth-set-default-theme > /dev/null; then
case "${theme}" in
Back)
return
;;
default)
sudo plymouth-set-default-theme -r -R
;;
breeze-text)
show_warning "WARNING: ${theme@Q} not working as of 03/07/2024."
;;
*)
sudo plymouth-set-default-theme -R "${theme}"
;;
esac
else
show_warning "'plymouth-set-default-theme' executable not found. Skipping."
fi
}
select_icon_theme {
show_question "Select an icon theme:"
local options=(
"Back"
"Adwaita"
"Breeze"
"Breeze-Dark"
"Papirus"
"ePapirus"
"ePapirus-Dark"
"Papirus-Light"
"Papirus-Dark"
"Papirus-Adapta"
"Papirus-Adapta-Nokto")
local option
select option in "${options[@]}"; do
case "${option}" in
"Back")
return
;;
"Adwaita")
if [ -d /usr/share/icons/Adwaita ]; then
ICONTHEME="Adwaita"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Breeze")
if [ -d /usr/share/icons/breeze ]; then
ICONTHEME="breeze"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Breeze-Dark")
if [ -d /usr/share/icons/breeze-dark ]; then
ICONTHEME="breeze-dark"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Papirus")
if [ -d /usr/share/icons/Papirus ] ||
[ -d /usr/local/share/icons/Papirus ] ||
[ -d "${HOME}/.local/share/icons/Papirus" ] ||
[ -d "${HOME}/.icons/Papirus" ]; then
ICONTHEME="Papirus"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"ePapirus")
if [ -d /usr/share/icons/ePapirus ] ||
[ -d /usr/local/share/icons/ePapirus ] ||
[ -d "${HOME}/.local/share/icons/ePapirus" ] ||
[ -d "${HOME}/.icons/ePapirus" ]; then
ICONTHEME="ePapirus"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"ePapirus-Dark")
if [ -d /usr/share/icons/ePapirus-Dark ] ||
[ -d /usr/local/share/icons/ePapirus-Dark ] ||
[ -d "${HOME}/.local/share/icons/ePapirus-Dark" ] ||
[ -d "${HOME}/.icons/ePapirus-Dark" ]; then
ICONTHEME="ePapirus-Dark"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Papirus-Light")
if [ -d /usr/share/icons/Papirus-Light ] ||
[ -d /usr/local/share/icons/Papirus-Light ] ||
[ -d "${HOME}/.local/share/icons/Papirus-Light" ] ||
[ -d "${HOME}/.icons/Papirus-Light" ]; then
ICONTHEME="Papirus-Light"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Papirus-Dark")
if [ -d /usr/share/icons/Papirus-Dark ] ||
[ -d /usr/local/share/icons/Papirus-Dark ] ||
[ -d "${HOME}/.local/share/icons/Papirus-Dark" ] ||
[ -d "${HOME}/.icons/Papirus-Dark" ]; then
ICONTHEME="Papirus-Dark"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Papirus-Adapta")
if [ -d /usr/share/icons/Papirus-Adapta ] ||
[ -d /usr/local/share/icons/Papirus-Adapta ] ||
[ -d "${HOME}/.local/share/icons/Papirus-Adapta" ] ||
[ -d "${HOME}/.icons/Papirus-Adapta" ]; then
ICONTHEME="Papirus-Adapta"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
"Papirus-Adapta-Nokto")
if [ -d /usr/share/icons/Papirus-Adapta-Nokto ] ||
[ -d /usr/local/share/icons/Papirus-Adapta-Nokto ] ||
[ -d "${HOME}/.local/share/icons/Papirus-Adapta-Nokto" ] ||
[ -d "${HOME}/.icons/Papirus-Adapta-Nokto" ]; then
ICONTHEME="Papirus-Adapta-Nokto"
break
else
show_warning "${option@Q} icons are not installed."
fi
;;
*)
show_warning "Invalid option ${option@Q}."
;;
esac
done
set_icon_theme
set_lightdm_theme
}
select_plasma_theme {
show_question "Select a Plasma theme:"
local options=(
"Back"
"Arc"
"Arc-Dark"
"Arc-Darker"
"Breeze"
"Breeze-dark"
"Breeze-twilight"
"Materia"
"Materia-dark"
"Materia-light")
local option
select option in "${options[@]}"; do
case "${option}" in
"Back")
return
;;
"Arc")
if [ -d /usr/share/plasma/look-and-feel/com.github.sudorook.arc/ ] ||
[ -d /usr/local/share/plasma/look-and-feel/com.github.sudorook.arc/ ]; then
PLASMATHEME="Arc"
GTKTHEME="Arc"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Arc-Darker")
if [ -d /usr/share/plasma/look-and-feel/com.github.sudorook.arc-darker ] ||
[ -d /usr/local/share/plasma/look-and-feel/com.github.sudorook.arc-darker ]; then
PLASMATHEME="Arc-Darker"
GTKTHEME="Arc-Dark"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Arc-Dark")
if [ -d /usr/share/plasma/look-and-feel/com.github.sudorook.arc-dark ] ||
[ -d /usr/local/share/plasma/look-and-feel/com.github.sudorook.arc-dark ]; then
PLASMATHEME="Arc-Dark"
GTKTHEME="Arc-Dark"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Breeze")
if [ -d /usr/share/plasma/look-and-feel/org.kde.breeze.desktop ] ||
[ -d /usr/local/share/plasma/look-and-feel/org.kde.breeze.desktop ]; then
PLASMATHEME="breeze"
GTKTHEME="Breeze"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Breeze-dark")
if [ -d /usr/share/plasma/look-and-feel/org.kde.breezedark.desktop ] ||
[ -d /usr/local/share/plasma/look-and-feel/org.kde.breezedark.desktop ]; then
PLASMATHEME="breeze-dark"
GTKTHEME="Breeze"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Breeze-twilight")
if [ -d /usr/share/plasma/look-and-feel/org.kde.breezetwilight.desktop ] ||
[ -d /usr/local/share/plasma/look-and-feel/org.kde.breezetwilight.desktop ]; then
PLASMATHEME="breeze-twilight"
GTKTHEME="Breeze"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia")
if [ -d /usr/share/plasma/desktoptheme/Materia ] ||
[ -d /usr/local/share/plasma/desktoptheme/Materia ]; then
PLASMATHEME="Materia"
GTKTHEME="Materia"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia-light")
if [ -d /usr/share/plasma/desktoptheme/Materia-light ] ||
[ -d /usr/local/share/plasma/desktoptheme/Materia-light ]; then
PLASMATHEME="Materia-light"
GTKTHEME="Materia-light"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia-dark")
if [ -d /usr/share/plasma/desktoptheme/Materia-dark ] ||
[ -d /usr/local/share/plasma/desktoptheme/Materia-dark ]; then
PLASMATHEME="Materia-dark"
GTKTHEME="Materia-dark"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
*)
show_warning "Invalid option ${option@Q}."
;;
esac
done
set_plasma_theme
set_gtk_theme
set_sddm_theme
}
select_gtk_theme {
show_question "Select a GTK theme:"
local options=(
"Back"
"Adwaita"
"Adwaita-dark"
"Arc"
"Arc-Darker"
"Arc-Dark"
"Arc-Lighter"
"Adapta"
"Adapta-Eta"
"Adapta-Nokto"
"Adapta-Nokto-Eta"
"Materia"
"Materia-compact"
"Materia-dark"
"Materia-dark-compact"
"Materia-light"
"Materia-light-compact"
"Plata"
"Plata-Compact"
"Plata-Lumine"
"Plata-Lumine-Compact"
"Plata-Noir"
"Plata-Noir-Compact")
local option
select option in "${options[@]}"; do
case "${option}" in
"Back")
return
;;
"Adwaita")
if [ -d /usr/share/themes/Adwaita ]; then
GTKTHEME="Adwaita"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Adwaita-dark")
if [ -d /usr/share/themes/Adwaita-dark ]; then
GTKTHEME="Adwaita-dark"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Arc")
if [ -d /usr/share/themes/Arc ] ||
[ -d /usr/local/share/themes/Arc ] ||
[ -d "${HOME}/.local/share/themes/Arc" ] ||
[ -d "${HOME}/.themes/Arc" ]; then
GTKTHEME="Arc"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Arc-Darker")
if [ -d /usr/share/themes/Arc-Darker ] ||
[ -d /usr/local/share/themes/Arc-Darker ] ||
[ -d "${HOME}/.local/share/themes/Arc-Darker" ] ||
[ -d "${HOME}/.themes/Arc-Darker" ]; then
GTKTHEME="Arc-Darker"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Arc-Dark")
if [ -d /usr/share/themes/Arc-Dark ] ||
[ -d /usr/local/share/themes/Arc-Dark ] ||
[ -d "${HOME}/.local/share/themes/Arc-Dark" ] ||
[ -d "${HOME}/.themes/Arc-Dark" ]; then
GTKTHEME="Arc-Dark"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Arc-Lighter")
if [ -d /usr/share/themes/Arc-Lighter ] ||
[ -d /usr/local/share/themes/Arc-Lighter ] ||
[ -d "${HOME}/.local/share/themes/Arc-Lighter" ] ||
[ -d "${HOME}/.themes/Arc-Lighter" ]; then
GTKTHEME="Arc-Lighter"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Adapta")
if [ -d /usr/share/themes/Adapta ] ||
[ -d /usr/local/share/themes/Adapta ] ||
[ -d "${HOME}/.local/share/themes/Adapta" ] ||
[ -d "${HOME}/.themes/Adapta" ]; then
GTKTHEME="Adapta"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Adapta-Eta")
if [ -d /usr/share/themes/Adapta-Eta ] ||
[ -d /usr/local/share/themes/Adapta-Eta ] ||
[ -d "${HOME}/.local/share/themes/Adapta-Eta" ] ||
[ -d "${HOME}/.themes/Adapta-Eta" ]; then
GTKTHEME="Adapta-Eta"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Adapta-Nokto")
if [ -d /usr/share/themes/Adapta-Nokto ] ||
[ -d /usr/local/share/themes/Adapta-Nokto ] ||
[ -d "${HOME}/.local/share/themes/Adapta-Nokto" ] ||
[ -d "${HOME}/.themes/Adapta-Nokto" ]; then
GTKTHEME="Adapta-Nokto"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Adapta-Nokto-Eta")
if [ -d /usr/share/themes/Adapta-Nokto-Eta ] ||
[ -d /usr/local/share/themes/Adapta-Nokto-Eta ] ||
[ -d "${HOME}/.local/share/themes/Adapta-Nokto-Eta" ] ||
[ -d "${HOME}/.themes/Adapta-Nokto-Eta" ]; then
GTKTHEME="Adapta-Nokto-Eta"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia")
if [ -d /usr/share/themes/Materia ] ||
[ -d /usr/local/share/themes/Materia ] ||
[ -d "${HOME}/.local/share/themes/Materia" ] ||
[ -d "${HOME}/.themes/Materia" ]; then
GTKTHEME="Materia"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia-compact")
if [ -d /usr/share/themes/Materia-compact ] ||
[ -d /usr/local/share/themes/Materia-compact ] ||
[ -d "${HOME}/.local/share/themes/Materia-compact" ] ||
[ -d "${HOME}/.themes/Materia-compact" ]; then
GTKTHEME="Materia-compact"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia-light")
if [ -d /usr/share/themes/Materia-light ] ||
[ -d /usr/local/share/themes/Materia-light ] ||
[ -d "${HOME}/.local/share/themes/Materia-light" ] ||
[ -d "${HOME}/.themes/Materia-light" ]; then
GTKTHEME="Materia-light"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia-light-compact")
if [ -d /usr/share/themes/Materia-light-compact ] ||
[ -d /usr/local/share/themes/Materia-light-compact ] ||
[ -d "${HOME}/.local/share/themes/Materia-light-compact" ] ||
[ -d "${HOME}/.themes/Materia-light-compact" ]; then
GTKTHEME="Materia-light-compact"
break
else
show_warning "${option@Q} theme is not installed."
fi
;;
"Materia-dark")
if [ -d /usr/share/themes/Materia-dark ] ||
[ -d /usr/local/share/themes/Materia-dark ] ||
[ -d "${HOME}/.local/share/themes/Materia-dark" ] ||
[ -d "${HOME}/.themes/Materia-dark" ]; then