forked from jorgeluiscarrillo/arch-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·1486 lines (1363 loc) · 56.4 KB
/
setup
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
# Load the configuration file
init() {
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR"/etc/setup.conf
clear ; setfont Lat2-Terminus16.psfu.gz
dialog --title "Welcome to Arch Linux Installer" \
--ok-label "Begin Installation" --msgbox "Navigating the installer is \
easy.\nYou may select options using the ARROW keys and SPACE or \
ENTER.\nAlternate keys may also be used: '+', '-', and TAB." 7 70
}
# Proceed with installation only if there is an internet connection
check_connection() {
dialog --infobox "Checking internet connection..." 3 50
sleep 1
# Check if a web page is available
while ! ping -c1 google.com &>/dev/null; do
dialog --infobox "No internet connection available" 3 50
sleep 1
# Getting network interface
interfaces=($(iwctl device list | awk '{print $2}' | sed -n '5,$p'))
count=0
for ((i=0; i<${#interfaces[@]}; i++)); do
((count++))
interface_array=("${interface_array[@]}" "${count}" "${interfaces[i]}")
done
if [[ -z "$interfaces" ]]; then
echo "No network interfaces found."
else
network_interface=$(dialog --title "Network Interfaces" --menu "Select an interface:" 15 40 5 "${interface_array[@]}" 2>&1 >/dev/tty)
interface=${interfaces[$(($network_interface-1))]}
fi
# Getting wifi network to connect
iwctl station $interface scan
networks=($(iwctl station $interface get-networks | cut -d' ' -f6 | sed -n '5,$p' | tr -d '\n' ; iwctl station $interface get-networks | cut -d' ' -f7 | sed -n '5,$p'))
count=0
for ((i=0; i<${#networks[@]}; i++)); do
((count++))
network_array=("${network_array[@]}" "${count}" "${networks[i]}")
done
if [[ -z "$networks" ]]; then
echo "No network found."
else
network_interface=$(dialog --title "Network" --menu "Select a netowrk to connect:" 15 40 5 "${network_array[@]}" 2>&1 >/dev/tty)
network=${networks[$((network_interface-1))]}
fi
# Getting the wifi password
wifi_pass=$(dialog --title "Wifi Password" --clear --stdout --insecure --nocancel --passwordbox "SSID: ${network}" 10 20)
# Connecting to the wifi
dialog --infobox "Connecting to $network..." 3 50
iwctl --passphrase="$wifi_pass" station $interface connect $network
sleep 10
done
}
# Check and disable any active mountpoints
check_mountpoints() {
if mountpoint -q /mnt; then
dialog --infobox "Unmounting active mountpoints on $DISK..." 3 50
umount -R /mnt
fi
if free | awk '/^Swap:/ {exit !$2}'; then
swapoff -a
fi
}
# Check for LVM on the system to avoid conflicts
check_lvm_status() {
# Check for an existing volume group on the selected disk
if vgs --noheading --nosuffix -o pv_name | grep -q "$DISK"; then
vg_on_pv=$(pvs -o pv_name,vg_name | grep "$DISK" | awk '{print $2}')
dialog --title "WARNING: LVM Exists on $DISK" \
--yesno "A volume group ($vg_on_pv) was detected on the selected disk \
($DISK).\n\nIn order to proceed, the volume group ($vg_on_pv) needs to be \
removed and all data will be lost!\n\nAre you sure you want to remove the \
volume group '$vg_on_pv'?" 11 75
if [ $? -eq 0 ]; then
dialog --infobox "Removing $vg_on_pv from $DISK..." 3 50
vgchange -y -an "$vg_on_pv" &> /dev/null
vgremove -y "$vg_on_pv" &> /dev/null
else
dialog --title "ERROR: Unable to Partition $DISK" \
--msgbox "The installer can't proceed while LVM is active on \
$DISK.\n\nIf you have any active LVM devices, please make sure they are not in \
use and backup any data on the volume group before running the installer." 8 80
reset ; exit 1
fi
fi
# Check for a volume group with the same name on the system when creating LVM
if [ "$PARTITION_LAYOUT" != "Basic" ]; then
if vgs "$LVM_GROUP" &> /dev/null; then
dialog --title "WARNING: LVM Volume Group Exists" \
--yesno "A volume group with the name '$LVM_GROUP' already exists on \
your system.\n\nIn order to proceed, the volume group ($LVM_GROUP) needs to be \
overwritten and all data will be lost!\n\nAre you sure you want to overwrite \
the volume group '$LVM_GROUP'?" 11 80
if [ $? -eq 0 ]; then
dialog --infobox "Removing $LVM_GROUP from $DISK..." 3 50
vgchange -y -an "$LVM_GROUP" &> /dev/null
vgremove -y "$LVM_GROUP" &> /dev/null
else
dialog --title "ERROR: Unable to Partition $DISK" \
--msgbox "The installer can't partition the disk because a volume \
group with the name '$LVM_GROUP' already exists on your system.\n\nIf you have \
any active LVM devices, please make sure they are not in use and backup any \
data on the volume group before running the installer." 9 80
reset ; exit 1
fi
fi
fi
}
# Prompt the user to set their keyboard layout
set_keymap() {
while true; do
KEYMAP=$(dialog --title "Set the Keyboard Layout" --nocancel \
--default-item "us" --menu "Select a keymap that corresponds to your \
keyboard layout. Choose 'other' if your keymap is not listed. If you are \
unsure, the default is 'us' (United States/QWERTY).\n\nKeymap:" 23 57 10 \
"fr" "French" \
"de" "German" \
"gr" "Greek" \
"hu" "Hungarian" \
"it" "Italian" \
"pl" "Polish" \
"ru" "Russian" \
"es" "Spanish" \
"us" "United States" \
"us-acentos" "International US" \
"other" "View all available keymaps" 3>&1 1>&2 2>&3)
if [ "$KEYMAP" = "other" ]; then
keymaps=()
for map in $(localectl list-keymaps); do
keymaps+=("$map" "")
done
KEYMAP=$(dialog --title "Set the Keyboard Layout" --cancel-label "Back" \
--menu "Select a keymap that corresponds to your keyboard layout. The \
default is 'us' (United States/QWERTY)." 30 60 25 \
"${keymaps[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
break
fi
else
break
fi
done
dialog --infobox "Setting keymap to $KEYMAP..." 3 50
localectl set-keymap "$KEYMAP"
loadkeys "$KEYMAP"
}
# Prompt the user to set the system locale
set_locale() {
while true; do
LOCALE=$(dialog --title "Set the System Locale" --nocancel \
--default-item "en_US.UTF-8" --menu "Select a locale that corresponds \
to your language and region. The locale you select will define the language \
used by the system and other region specific information. Choose 'other' if \
your language and/or region is not listed. If you are unsure, the default is \
'en_US.UTF-8'.\n\nLocale:" 30 65 16 \
"zh_CN.UTF-8" "Chinese (Simplified)" \
"en_AU.UTF-8" "English (Australia)" \
"en_CA.UTF-8" "English (Canada)" \
"en_US.UTF-8" "English (United States)" \
"en_GB.UTF-8" "English (Great Britain)" \
"en_BE.UTF-8" "English (Belgium)" \
"fr_FR.UTF-8" "French (France)" \
"de_DE.UTF-8" "German (Germany)" \
"it_IT.UTF-8" "Italian (Italy)" \
"ja_JP.UTF-8" "Japanese (Japan)" \
"pt_BR.UTF-8" "Portuguese (Brazil)" \
"pt_PT.UTF-8" "Portuguese (Portugal)" \
"ru_RU.UTF-8" "Russian (Russia)" \
"es_MX.UTF-8" "Spanish (Mexico)" \
"es_ES.UTF-8" "Spanish (Spain)" \
"sv_SE.UTF-8" "Swedish (Sweden)" \
"other" "View all available locales" 3>&1 1>&2 2>&3)
if [ "$LOCALE" = "other" ]; then
locales=()
# Read each entry in /etc/locale.gen and remove comments and spaces
while read -r line; do
locales+=("$line" "")
done < <(grep -E "^#?[a-z].*UTF-8" /etc/locale.gen | sed -e 's/#//' -e 's/\s.*$//')
LOCALE=$(dialog --title "Set the System Locale" --cancel-label "Back" \
--menu "Select a locale that corresponds to your language and region. \
The locale you select will define the language used by the system and other
region specific information. If you are unsure, the default is \
'en_US.UTF-8'.\n\nLocale:" 30 65 16 \
"${locales[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
break
fi
else
break
fi
done
}
# Prompt the user to set the system time zone
set_timezone() {
utc_enabled=true
regions=()
for region in \
$(find /usr/share/zoneinfo -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
| grep -E -v '/$|posix|right' \
| sort); do
regions+=("$region" "")
done
regions+=("other" "")
while true; do
ZONE=$(dialog --title "Set the Time Zone" --nocancel \
--menu "Select your time zone.\nIf your region is not listed, select \
'other'.\n\nTime zone:" 27 50 17 \
"${regions[@]}" 3>&1 1>&2 2>&3)
if [ "$ZONE" != "other" ]; then
zone_regions=()
for zone_region in \
$(find /usr/share/zoneinfo/"${ZONE}" -mindepth 1 -maxdepth 1 -printf '%f\n' \
| sort); do
zone_regions+=("$zone_region" "")
done
SUBZONE=$(dialog --title "Set the Time Zone" --cancel-label "Back" \
--menu "Select your time zone.\n\nTime zone:" 27 50 17 \
"${zone_regions[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
if [ -d /usr/share/zoneinfo/"${ZONE}/${SUBZONE}" ]; then
subzone_regions=()
for subzone_region in \
$(find /usr/share/zoneinfo/"${ZONE}/${SUBZONE}" -mindepth 1 -maxdepth 1 -printf '%f\n' \
| sort); do
subzone_regions+=("$subzone_region" "")
done
SUBZONE_SUBREGION=$(dialog --title "Set the Time Zone" \
--cancel-label "Back" \
--menu "Select your time zone.\n\nTime zone:" 27 50 17 \
"${subzone_regions[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
ZONE="${ZONE}/${SUBZONE}/${SUBZONE_SUBREGION}"
break
fi
else
ZONE="${ZONE}/${SUBZONE}"
break
fi
fi
else
for other_region in \
$(find /usr/share/zoneinfo -mindepth 1 -maxdepth 1 -type f -printf '%f\n' \
| grep -E -v '/$|iso3166.tab|leapseconds|posixrules|tzdata.zi|zone.tab|zone1970.tab' \
| sort); do
other_regions+=("$other_region" "")
done
ZONE=$(dialog --title "Set the Time Zone" --cancel-label "Back" \
--menu "Select your time zone.\n\nTime zone:" 27 50 17 \
"${other_regions[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
ZONE="${ZONE}"
break
fi
fi
done
dialog --title "Set the Hardware Clock" --nocancel \
--yesno "Would you like to set the hardware clock from the system \
clock using UTC time?\nIf you select no, local time will be used \
instead.\n\nIf you are unsure, UTC time is the default." 8 85
if [ $? -ne 0 ]; then
utc_enabled=false
fi
}
# Prompt the user to set the system hostname
set_hostname() {
while true; do
HOST_NAME=$(dialog --title "Set the Hostname" --nocancel \
--inputbox "Please enter the hostname for this system.\n\nThe hostname \
is a single word that identifies your system to the network.\n\nHostname:" \
12 80 "arch" 3>&1 1>&2 2>&3)
# Hostname must be alpha-numeric and may contain a dash only in between
if printf "%s" "$HOST_NAME" | grep -Eoq "^[a-zA-Z0-9-]{1,63}$" \
&& [ "${HOST_NAME:0:1}" != "-" ] \
&& [ "${HOST_NAME: -1}" != "-" ]; then
break
else
dialog --title "ERROR: Invalid Hostname Format" \
--msgbox "You entered an invalid hostname.\n\nA valid hostname may \
contain only the numbers 0-9, upper and lowercase letters (A-Z and a-z), and \
the minus sign. It must be at most 63 characters long, and may not begin \
or end with a minus sign." 9 75
fi
done
}
# Prompt the user to create a password for the superuser account
set_root_passwd(){
inputs_match=false
while ! $inputs_match; do
input=$(dialog --title "Set the Root Password" --clear --stdout --nocancel \
--insecure --passwordbox "Please enter a password for 'root', the \
system administrative account.\n\nRoot password:" 10 75)
confirm_input=$(dialog --title "Set the Root Password" --clear --stdout \
--insecure --passwordbox "Re-enter password to verify:" 8 55)
if [ -z "$input" ]; then
dialog --title "ERROR: Empty Password" \
--msgbox "You are not allowed to have an empty password." 5 55
elif [ "$input" != "$confirm_input" ]; then
dialog --title "ERROR: Passwords Do No Match" \
--msgbox "The two passwords you entered did not match." 5 55
else
root_passwd="$input"
inputs_match=true
fi
done
}
# Prompt the user to create an unprivileged user account
create_user() {
while true; do
FULL_NAME=$(dialog --title "Create a User Account" --nocancel \
--inputbox "The installer will create a user account for you. This is \
the main user account that you will login to and use for non-administrative \
activities.\n\nPlease enter the real name for this user. This information \
will be used for any program that uses the user's real name such as email. \
Entering your full name here is recommended; however, it may be left \
blank.\n\nFull name for the new user:" 15 80 3>&1 1>&2 2>&3)
USER_NAME=$(dialog --title "Create a User Account" \
--cancel-label "Back" --inputbox "Please enter a username for the new \
account.\n\nThe username should start with a lower-case letter, which can be \
followed by any combination of numbers, more lower-case letters, or the dash \
symbol.\n\nUsername for your account:" 13 80 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
# Username must start with lowercase letter. May contain lowercase
# alpha-numerics and dashes
if printf "%s" "$USER_NAME" | grep -Eoq "^[a-z][a-z0-9-]*$" \
&& [ "${#USER_NAME}" -lt 33 ]; then
# The reserved_username file contains usernames that should be avoided
if grep -Fxq "$USER_NAME" "$DIR"/etc/reserved_usernames; then
dialog --title "ERROR: Reserved Username" \
--msgbox "The username you entered ($USER_NAME) is reserved for \
use by the system. Please select a different one." 6 70
else
inputs_match=false
while ! $inputs_match; do
input=$(dialog --title "Set the Password for $USER_NAME" --clear \
--stdout --nocancel --insecure --passwordbox "Please enter a \
password for '$USER_NAME'.\n\nChoose a password for the new user:" 10 70)
confirm_input=$(dialog --title "Set the Password for $USER_NAME" \
--clear --stdout --insecure \
--passwordbox "Re-enter password to verify:" 8 55)
if [ -z "$input" ]; then
dialog --title "ERROR: Empty Password" \
--msgbox "You are not allowed to have an empty password." 5 55
elif [ "$input" != "$confirm_input" ]; then
dialog --title "ERROR: Passwords Do No Match" \
--msgbox "The two passwords you entered did not match." 5 55
else
user_passwd="$input"
inputs_match=true
fi
done
break
fi
else
dialog --title "ERROR: Invalid Username Format" \
--msgbox "You entered an invalid username.\n\nThe username must \
start with a lower-case letter, which can be followed by any combination of \
numbers, more lower-case letters, or the dash symbol, and must be no more \
than 32 characters long." 9 80
fi
fi
done
dialog --title "Passwordless sudo" \
--yesno "Do you want to be able to use commands with sudo\n
without typing the password?" 6 57
if [ $? -ne 0 ]; then
passwordlles_sudo=true
fi
}
# Prepare the user's selected disk for partitioning
prepare_disk() {
SWAP="-"
swap_enabled=false
block_devices=()
# List all available block devices excluding 'rom' and 'loop'
for device in $(lsblk -d -n -p -r -e 7,11 -o NAME); do
device_size=$(lsblk -d -n -r -o SIZE "$device")
block_devices+=("$device" "$device_size")
done
check_mountpoints
while true; do
PARTITION_LAYOUT=$(dialog --title "Partition the Disks" \
--cancel-label "Exit to Menu" \
--menu "The installer will now automatically partition a disk for you. \
If you have no preference or are unsure about which partition layout to \
choose, the 'Basic' layout is the simplest and should be enough for most use \
cases.\n\nPartition layout:" 14 80 3 \
"Basic" "Use entire disk" \
"LVM" "Use entire disk and set up LVM" \
"Encrypted" "Use entire disk and set up encrypted LVM" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
dialog --title "Disk overview" --prgbox "This are the partitions on the disks on your system: \nKeep the name of the wanted installation disk in mind." "lsblk" 50 80
DISK=$(dialog --title "Set the Installation Disk" --cancel-label "Back" \
--menu "Select the disk for Arch Linux to be installed on. Note that \
the disk you select will be erased, but not until you have confirmed the \
changes.\n\nDisk to partition:" 16 55 5 \
"${block_devices[@]}" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
# NVME devices use nvme0n1p1, p2, p3 etc. for partition naming
# TODO: May need to be modified to support installing on other block
# devices (SD cards, USB?)
PREFIX=""
if [[ "$DISK" == *"nvme"* ]]; then
PREFIX="p"
fi
FILE_SYSTEM=$(dialog --title "Set the Filesystem for $DISK_ROOT" \
--nocancel --menu "Select the type of filesystem to use for the \
specified device. If you are unsure, 'ext4' is the default.\n\nFilesystem \
type:" 15 68 5 \
"ext4" "Ext4 journaling filesystem" \
"ext3" "Ext3 journaling filesystem" \
"ext2" "Standard Linux Ext2 filesystem" \
"btrfs" "Btrfs Copy-on-Write B-tree filesystem" \
"xfs" "SGI's journaling filesystem" 3>&1 1>&2 2>&3)
if [ "$FILE_SYSTEM" == "btrfs" ]; then
dialog --title "Snapper snapshots" \
--yesno "Would you like to enable snapper snapshots with a btrfs-grub menu?" 6 50
if [ $? - eq 0 ]; then
snapper=true
else
snapper=false
fi
fi
dialog --title "Create a Swap Partition" \
--yesno "Would you like to create an optional swap partition? If \
you are unsure, it is recommended to create one." 6 57
if [ $? -eq 0 ]; then
# Get the amount of RAM in the system to use as default swap size
mem_total=$(free --giga | awk '/^Mem:/{print $2}')
if [ "$mem_total" != "0" ]; then
mem_total="${mem_total}G"
else
mem_total=$(free --mega | awk '/^Mem:/{print $2}')
mem_total="${mem_total}M"
fi
while true; do
SWAP=$(dialog --title "Allocate Swap Space" \
--inputbox "Specify how much swap space to allocate. If you are \
unsure, the default is to have swap space equal to the amount of RAM in your \
system.\n\nSwap partition size (use 'M' for MiB or 'G' for GiB):" 11 80 \
"$mem_total" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
disk_size_bytes=$(lsblk -b -d -n -o SIZE "$DISK")
disk_size_mibs=$((disk_size_bytes/1024/1024))
disk_size_gibs=$((disk_size_mibs/1024))
swap_size=$(printf "%s" "$SWAP" | tr -c -d '[:digit:]')
# Input validation for swap size
if printf "%s" "$SWAP" | grep -Eoq "^[0-9]+[MG]$" \
&& [ "${swap_size:0:1}" != "0" ]; then
if [ "${SWAP: -1}" = "M" ] \
&& [ "$swap_size" -lt $((disk_size_mibs - 2048)) ]; then
swap_enabled=true
break
elif [ "${SWAP: -1}" = "G" ] \
&& [ "$swap_size" -lt $((disk_size_gibs - 2)) ]; then
swap_enabled=true
break
else
dialog --title "ERROR: Not Enough Disk Space" \
--msgbox "The amount you entered exceeds the amount of \
space available on the disk. Note that the installer sets aside an additional \
2 GiB to have enough space for the base installation." 8 60
fi
else
dialog --title "ERROR: Invalid Format" \
--msgbox "You entered an invalid format. Make sure to use \
'M' for 'MiB' or 'G' for 'GiB'." 6 60
fi
else
break
fi
done
fi
dialog --title "Selected disk overview" --prgbox "This are the partitions on the selected disk: $DISK" "lsblk $DISK" 20 80
dialog --title "Confirm the Partition Layout for $DISK" --defaultno \
--yesno "WARNING: All data on the selected disk will be lost! Make \
sure to review your changes before continuing.\n\nDisk to partition: \
$DISK\nPartition layout: $PARTITION_LAYOUT\nFilesystem type: \
$FILE_SYSTEM\nSwap size: $SWAP\n\nAre you sure you want to write the \
changes to the disk?" 13 60
if [ $? -eq 0 ]; then
check_lvm_status
dialog --infobox "Formatting $DISK..." 3 50
blkdiscard "$DISK" -f &> /dev/null
sgdisk --zap-all "$DISK" &> /dev/null
wipefs -a "$DISK" &> /dev/null
dialog --infobox "Partitioning $DISK..." 3 50
create_partition_label
case "$PARTITION_LAYOUT" in
"Basic") create_basic_layout ;;
"LVM") create_lvm_layout ;;
"Encrypted") create_encrypted_layout ;;
esac
break
else
main_menu
fi
fi
else
main_menu
fi
done
}
# Create a new partition label on the selected disk
create_partition_label() {
# UEFI systems use GPT partitioning and BIOS/CSM systems use MBR
if $UEFI; then
parted -s "$DISK" mklabel gpt &> /dev/null
else
parted -s "$DISK" mklabel msdos &> /dev/null
fi
if [ $? -ne 0 ]; then
dialog --title "ERROR: Unable to Partition $DISK" \
--msgbox "The installer encountered an error while partitioning \
$DISK.\n\nMake sure the disk you selected is not active before running the \
installer. If this error keeps occuring, please reboot your machine and try \
again." 8 80
reset ; exit 1
fi
}
# Partition the selected disk where everything is installed on one partition
create_basic_layout() {
if $UEFI; then
BOOT_PART="${DISK}${PREFIX}1"
ROOT_PART="${DISK}${PREFIX}2"
if $swap_enabled; then
SWAP_PART="${DISK}${PREFIX}3"
sgdisk -n 1:0:+512M -n 2:0:-"$SWAP" -n 3:-"$SWAP":-0 \
-t 1:ef00 -t 2:8300 -t 3:8200 "$DISK" &> /dev/null
mkswap "$SWAP_PART" &> /dev/null
swapon "$SWAP_PART"
else
sgdisk -n 1:0:+512M -n 2:0:0 -t 1:ef00 -t 2:8300 "$DISK" &> /dev/null
fi
mkfs.fat -F32 "$BOOT_PART" &> /dev/null
else
ROOT_PART="${DISK}${PREFIX}1"
if $swap_enabled; then
SWAP_PART="${DISK}${PREFIX}2"
echo -e "n\np\n1\n\n-${SWAP}\nn\np\n2\n\n\nt\n2\n82\nw" \
| fdisk "$DISK" &> /dev/null
mkswap "$SWAP_PART" &> /dev/null
swapon "$SWAP_PART"
else
echo -e "n\np\n1\n\n\nw" | fdisk "$DISK" &> /dev/null
fi
fi
case "$FILE_SYSTEM" in
btrfs)
mkfs."$FILE_SYSTEM" "$ROOT_PART" &> /dev/null
mount "$ROOT_PART" /mnt
btrfs sub cr /mnt/@ &> /dev/null
btrfs sub cr /mnt/@.snapshots &> /dev/null
umount /mnt
if [ $? -eq 0 ]; then
mounted=true
fi
mount -o subvol=/@,defaults,noatime,compress=zstd "$ROOT_PART" /mnt
mount -o subvol=/@.snapshots,defaults,noatime,compress=zstd -m "$ROOT_PART" /mnt/.snapshots
BASE_PACKAGES+=('btrfs-progs')
btrfs subvol set-default 256 / ;;
xfs) mkfs."$FILE_SYSTEM" -f "$ROOT_PART" &> /dev/null ;;
*) mkfs."$FILE_SYSTEM" "$ROOT_PART" &> /dev/null ;;
esac
if [ "$FILE_SYSTEM" != "btrfs" ]; then
mount "$ROOT_PART" /mnt
if [ $? -eq 0 ]; then
mounted=true
fi
fi
if $UEFI; then
mkdir /mnt/boot/efi
mount -o defaults,noatime -m "$BOOT_PART" /mnt/boot/efi
fi
}
# Partition the selected disk and configure LVM
create_lvm_layout() {
if $UEFI; then
BOOT_PART="${DISK}${PREFIX}1"
ROOT_PART="${DISK}${PREFIX}2"
sgdisk -n 1:0:+512M -n 2:0:0 -t 1:ef00 -t 2:8e00 "$DISK" &> /dev/null
mkfs.fat -F32 "$BOOT_PART" &> /dev/null
else
ROOT_PART="${DISK}${PREFIX}1"
echo -e "n\np\n1\n\n\nt\n8e\nw" | fdisk "$DISK" &> /dev/null
fi
dialog --infobox "Configuring LVM on $ROOT_PART..." 3 50
pvcreate -y "$ROOT_PART" &> /dev/null
vgcreate -y "$LVM_GROUP" "$ROOT_PART" &> /dev/null
if $swap_enabled; then
lvcreate -y -L "$SWAP" "$LVM_GROUP" -n "$LVM_SWAP" &> /dev/null
lvcreate -y -l 100%FREE "$LVM_GROUP" -n "$LVM_ROOT" &> /dev/null
mkswap "/dev/${LVM_GROUP}/${LVM_SWAP}" &> /dev/null
swapon "/dev/${LVM_GROUP}/${LVM_SWAP}"
else
lvcreate -y -l 100%FREE "$LVM_GROUP" -n "$LVM_ROOT" &> /dev/null
fi
case "$FILE_SYSTEM" in
btrfs|xfs) mkfs."$FILE_SYSTEM" -f "/dev/${LVM_GROUP}/${LVM_ROOT}" &> /dev/null ;;
*) mkfs."$FILE_SYSTEM" "/dev/${LVM_GROUP}/${LVM_ROOT}" &> /dev/null ;;
esac
mount "/dev/${LVM_GROUP}/${LVM_ROOT}" /mnt
if [ $? -eq 0 ]; then
mounted=true
fi
if $UEFI; then
mkdir /mnt/boot
mount "$BOOT_PART" /mnt/boot
fi
}
# Partition the selected disk and set up root disk encryption (LVM on LUKS)
create_encrypted_layout() {
# /boot is left unencrypted
BOOT_PART="${DISK}${PREFIX}1"
ROOT_PART="${DISK}${PREFIX}2"
if $UEFI; then
sgdisk -n 1:0:+512M -n 2:0:0 -t 1:ef00 -t 2:8e00 "$DISK" &> /dev/null
mkfs.fat -F32 "$BOOT_PART" &> /dev/null
else
echo -e "n\np\n1\n\n+512M\nn\np\n2\n\n\nt\n2\n8e\nw" | fdisk "$DISK" &> /dev/null
mkfs.ext4 "$BOOT_PART" &> /dev/null
fi
inputs_match=false
while ! $inputs_match; do
input=$(dialog --title "Encrypt $ROOT_PART" --clear --stdout \
--insecure --passwordbox "Enter a passphrase to encrypt \
$ROOT_PART.\n\nThe overall strength of the encryption process depends \
strongly on this passphrase, therefore you should set a passphrase that is \
not easy to guess.\n\nNote that the passphrase you enter will be required \
each time on boot.\n\nEncryption passphrase:" 15 80)
if [ $? -eq 0 ]; then
confirm_input=$(dialog --title "Encrypt $ROOT_PART" --clear --stdout \
--insecure --passwordbox "Re-enter passphrase to verify:" 8 55)
if [ -z "$input" ]; then
dialog --title "ERROR: Empty Passphrase" \
--msgbox "You are not allowed to have an empty passphrase." 5 55
elif [ "$input" != "$confirm_input" ]; then
dialog --title "ERROR: Passphrases Do No Match" \
--msgbox "The two passphrases you entered did not match." 5 55
elif [ "${#input}" -lt 8 ]; then
dialog --title "WARNING: Weak Passphrase" --defaultno \
--yesno "The passphrase you entered is less than 8 characters which \
is considered insecure.\n\nContinue using a weak passphrase?" 8 60
if [ $? -eq 0 ]; then
inputs_match=true
fi
else
inputs_match=true
fi
else
dialog --title "Revert Partition Changes" --defaultno \
--yesno "Are you sure you want to cancel the encryption \
process? If you choose yes, you will be returned to the partition menu." 7 65
if [ $? -eq 0 ]; then
prepare_disk
fi
fi
done
dialog --infobox "Encrypting $ROOT_PART..." 3 50
printf "%s" "$input" | cryptsetup luksFormat "$ROOT_PART" - &> /dev/null
printf "%s" "$input" | cryptsetup open "$ROOT_PART" "$CRYPT_DEVICE_NAME" -
dialog --infobox "Configuring LVM on $ROOT_PART..." 3 50
pvcreate -y "/dev/mapper/${CRYPT_DEVICE_NAME}" &> /dev/null
vgcreate -y "$LVM_GROUP" "/dev/mapper/${CRYPT_DEVICE_NAME}" &> /dev/null
if $swap_enabled; then
lvcreate -y -L "$SWAP" "$LVM_GROUP" -n "$LVM_SWAP" &> /dev/null
lvcreate -y -l 100%FREE "$LVM_GROUP" -n "$LVM_ROOT" &> /dev/null
mkswap "/dev/mapper/${LVM_GROUP}-${LVM_SWAP}" &> /dev/null
swapon "/dev/mapper/${LVM_GROUP}-${LVM_SWAP}"
else
lvcreate -y -l 100%FREE "$LVM_GROUP" -n "$LVM_ROOT" &> /dev/null
fi
case "$FILE_SYSTEM" in
btrfs|xfs) mkfs."$FILE_SYSTEM" -f "/dev/mapper/${LVM_GROUP}-${LVM_ROOT}" &> /dev/null ;;
*) mkfs."$FILE_SYSTEM" "/dev/mapper/${LVM_GROUP}-${LVM_ROOT}" &> /dev/null ;;
esac
mount "/dev/mapper/${LVM_GROUP}-${LVM_ROOT}" /mnt
if [ $? -eq 0 ]; then
mounted=true
fi
mkdir /mnt/boot
mount "$BOOT_PART" /mnt/boot
}
# Use the reflector script to update the pacman mirror list
update_mirrorlist() {
dialog --title "Update the Mirror List" \
--yesno "Would you like to update the Arch Linux mirror list?\n\nUpdating \
the mirror list will speed up the download of packages. If you select no, \
your download speed may be affected." 8 70
if [ $? -eq 0 ]; then
dialog --infobox "Updating pacman mirror list..." 3 50
# Sort the 50 most recently synchronized HTTPS mirrors by download speed
reflector --latest 50 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
# Enable parallel downloads
sed -i "s/#ParallelDownloads = 5/ParallelDownloads = 5/g" /etc/pacman.conf
fi
}
# Prompt the user to install the base packages for the system
configure_install() {
bluetooth_enabled=false
dm_enabled=false
multilib=false
DESKTOP_PACKAGES=()
if $UEFI; then
DESKTOP_PACKAGES+=('efibootmgr')
dialog --title "Enable OS-prober" \
--yesno "Would you like to enable OS-prober?\n\n It \
allows you to boot into other systems on your computer from the grub." 9 70
if [ $? -eq 0 ]; then
os_prober=true
DESKTOP_PACKAGES+=('os-prober')
fi
fi
kernel=$(dialog --title "Set the kernel type" --nocancel \
--default-item "linux-zen" --menu "Select the kernel type \
that you want. If you are unsure, the default is 'linux-zen' (Zen Kernel).\n\nKernel:" 15 57 10 \
"linux" "Stable" \
"linux-lts" "Longterm" \
"linux-zen" "Zen kernel" \
"linux-hardened" "Hardened" \
"linux-rt" "Realtime kernel" 3>&1 1>&2 2>&3)
DESKTOP_PACKAGES+=($kernel)
if [ "$PARTITION_LAYOUT" = "LVM" ]; then
DESKTOP_PACKAGES+=('lvm2')
elif [ "$PARTITION_LAYOUT" = "Encrypted" ]; then
DESKTOP_PACKAGES+=('lvm2' 'cryptsetup')
fi
if [ "$FILE_SYSTEM" = "btrfs" ]; then
DESKTOP_PACKAGES+=('btrfs-progs')
elif [ "$FILE_SYSTEM" = "xfs" ]; then
DESKTOP_PACKAGES+=('xfsprogs')
fi
if [ "$architecture" = "x86_64" ]; then
dialog --title "Enable multilib" \
--yesno "Would you like to enable the 'multilib' repository?\n\nBy \
default, Arch only includes 64-bit software in its repositories. The \
'multilib' repository contains 32-bit software that is compatible on a 64-bit \
system (e.g. wine, steam, etc)." 9 70
if [ $? -eq 0 ]; then
multilib=true
fi
fi
while true; do
DESKTOP=$(dialog --title "Choose your Graphical Environment" --no-cancel \
--menu "Select the style of graphical environment you wish to \
use.\n\nGraphical environment:" 15 75 3 \
"Desktop Environment" "Traditional complete graphical user interface" \
"Window Manager" "Standalone minimal graphical user interface" \
"HyDE" "Hyprland with hyprdots from prasanthrangan" \
"None" "Command-line only interface" 3>&1 1>&2 2>&3)
if [ "$DESKTOP" = "Desktop Environment" ]; then
GUI=$(dialog --title "Select a Desktop Environment" \
--cancel-label "Back" \
--menu "Select a desktop environment to install:" 20 65 8 \
"Budgie" "Modern GNOME based desktop" \
"Cinnamon" "Traditional desktop experience" \
"GNOME" "Modern simplicity focused desktop" \
"KDE Plasma" "Full featured QT based desktop" \
"LXDE" "Lightweight and efficient desktop" \
"LXQT" "Lightweight and efficient QT based desktop" \
"MATE" "Continuation of the GNOME 2 desktop" \
"Xfce" "Lightweight and modular desktop" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
break
fi
elif [ "$DESKTOP" = "Window Manager" ]; then
GUI=$(dialog --title "Select a Window Manager" \
--cancel-label "Back" \
--menu "Select a window manager to install:" 13 75 6 \
"awesome" "Highly configurable, dynamic window manager" \
"bspwm" "Tiling window manager based on binary space partitioning" \
"Fluxbox" "Stacking window manager based on Blackbox" \
"i3" "Dynamic tiling window manager inspired by wmii" \
"Openbox" "Highly configurable, stacking window manager" \
"xmonad" "Dynamic tiling window manager configured in Haskell" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
break
fi
elif [ "$DESKTOP" = "HyDE" ]; then
GUI=$(dialog --title "Hypdrots version" \
--cancel-label "Back" \
--menu "Select a Hyprland version to install:" 13 75 6 \
"prasanthrangan" "The original Hyde dots files by prasanthrangan" \
"sitolam" "The forked version of Hyde dots files by sitolam" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
break
fi
else
break
fi
done
if [ "$DESKTOP" != "None" ] && [ "$DESKTOP" != "HyDE" ]; then
DESKTOP_PACKAGES+=("${DESKTOP_DEFAULTS[@]}")
case "$GUI" in
"Budgie") DESKTOP_PACKAGES+=('budgie-desktop' 'gnome-control-center')
dialog --title "Install Extras" --yesno "Would you like to \
install the 'gnome' group?\n\nIt contains additional utilities and \
applications that integrate well with the Budgie desktop." 8 60
if [ $? -eq 0 ]; then
DESKTOP_PACKAGES+=('gnome')
fi
xinit_config="export XDG_CURRENT_DESKTOP=Budgie:GNOME ; exec budgie-desktop"
;;
"Cinnamon") DESKTOP_PACKAGES+=('cinnamon' 'cinnamon-translations' 'nemo-fileroller')
xinit_config="exec cinnamon-session"
;;
"GNOME") DESKTOP_PACKAGES+=('gnome')
dialog --title "Install Extras" --yesno "Would you like to \
install the 'gnome-extra' group?\n\nIt contains additional utilities and \
applications that integrate well with the GNOME desktop." 8 60
if [ $? -eq 0 ]; then
DESKTOP_PACKAGES+=('gnome-extra')
fi
xinit_config="exec gnome-session"
;;
"KDE Plasma") DESKTOP_PACKAGES+=('plasma')
dialog --title "Install Extras" --yesno "Would you like \
to install the 'kde-applications' group?\n\nIt contains additional utilities \
and applications that integrate well with the Plasma desktop." 8 60
if [ $? -eq 0 ]; then
DESKTOP_PACKAGES+=('kde-applications')
fi
xinit_config="exec startkde"
;;
"LXDE") DESKTOP_PACKAGES+=('lxde')
xinit_config="exec startlxde"
;;
"LXQT") DESKTOP_PACKAGES+=('lxqt' 'breeze-icons')
xinit_config="exec startlxqt"
;;
"MATE") DESKTOP_PACKAGES+=('mate' 'gtk-engines' 'gtk-engine-murrine')
dialog --title "Install Extras" --yesno "Would you like to \
install the 'mate-extra' group?\n\nIt contains additional utilities and \
applications that integrate well with the MATE desktop." 8 60
if [ $? -eq 0 ]; then
DESKTOP_PACKAGES+=('mate-extra')
fi
xinit_config="exec mate-session"
;;
"Xfce") DESKTOP_PACKAGES+=('xfce4')
dialog --title "Install Extras" --yesno "Would you like to \
install the 'xfce4-goodies' group?\n\nIt contains additional utilities and \
applications that integrate well with the Xfce desktop." 8 60
if [ $? -eq 0 ]; then
DESKTOP_PACKAGES+=('xfce4-goodies')
fi
xinit_config="exec startxfce4"
;;
"awesome") DESKTOP_PACKAGES+=('awesome')
xinit_config="exec awesome"
;;
"bspwm") DESKTOP_PACKAGES+=('bspwm' 'sxhkd')
xinit_config="sxhkd & ; exec bspwm"
;;
"Fluxbox") DESKTOP_PACKAGES+=('fluxbox')
xinit_config="exec startfluxbox"
;;
"i3") DESKTOP_PACKAGES+=('i3')
xinit_config="exec i3"
;;
"Openbox") DESKTOP_PACKAGES+=('openbox')
xinit_config="exec openbox-session"
;;
"xmonad") DESKTOP_PACKAGES+=('xmonad' 'xmonad-contrib')
xinit_config="exec xmonad"
;;
esac
# GNOME already has networkmanager applet built-in. Plasma uses plasma-nm
if [ "$GUI" != "GNOME" ]; then
if [ "$GUI" = "KDE Plasma" ]; then
DESKTOP_PACKAGES+=('plasma-nm')
elif [ "$DESKTOP" != "HyDE"]; then
DESKTOP_PACKAGES+=('network-manager-applet' 'gnome-keyring')
fi
fi
# Check for available bluetooth devices
if $bluetooth; then
dialog --title "Enable Bluetooth" \
--yesno "The installer has detected Bluetooth support on your \
system.\n\nWould you like to install and enable the Bluetooth service?" 7 65
if [ $? -eq 0 ]; then
bluetooth_enabled=true
DESKTOP_PACKAGES+=('bluez' 'bluez-utils' 'pulseaudio-bluetooth')
dialog --title "Install Bluetooth Manager" \
--yesno "Would you like to install a graphical Bluetooth \
manager?\n\nThe utility that best integrates with the desktop environment \
you selected will be installed." 8 60
if [ $? -eq 0 ]; then
case "$GUI" in
"Budgie"|"GNOME") DESKTOP_PACKAGES+=('gnome-bluetooth') ;;
"Cinnamon") DESKTOP_PACKAGES+=('blueberry') ;;
"KDE Plasma") DESKTOP_PACKAGES+=('bluedevil') ;;
*) DESKTOP_PACKAGES+=('blueman') ;;
esac
fi
fi
fi
if [ $GUI != "prasanthrangan" ]; then
dialog --title "Install a Display Manager" \
--yesno "Would you like to install a graphical login manager?\n\nIf you \
select no, 'xinit' will be installed so you can manually start Xorg with the\
'startx' command." 8 60
if [ $? -eq 0 ]; then
DM=$(dialog --title "Install a Display Manager" \
--menu "Select a display manager to install:" 10 50 3 \
"gdm" "GNOME Display Manager" \
"lightdm" "Lightweight Display Manager" \
"sddm" "Simple Desktop Display Manager" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
dm_enabled=true
case "$DM" in
"gdm") DESKTOP_PACKAGES+=('gdm') ;;
"lightdm") DESKTOP_PACKAGES+=('lightdm' 'lightdm-gtk-greeter' 'lightdm-gtk-greeter-settings') ;;
"sddm") DESKTOP_PACKAGES+=('sddm') ;;
esac
else
DESKTOP_PACKAGES+=('xorg-xinit')
dialog --title "xinit" \
--msgbox "No display manager selected. Installing 'xorg-xinit'. The \
installer will create a xinitrc file for you.\n\nYou will need to use the \
'startx' command to start the graphical environment once you login." 9 57
fi
else
DESKTOP_PACKAGES+=('xorg-xinit')
dialog --title "xinit" \
--msgbox "No display manager selected. Installing 'xorg-xinit'. The \
installer will create a xinitrc file for you.\n\nYou will need to use the \
'startx' command to start the graphical environment once you login." 9 57
fi