forked from picodotdev/alis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alis.sh
executable file
·1719 lines (1513 loc) · 58 KB
/
alis.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
set -e
# Arch Linux Install Script (alis) installs unattended, automated
# and customized Arch Linux system.
# Copyright (C) 2020 picodotdev
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This script is hosted at https://github.com/picodotdev/alis. For new features,
# improvements and bugs fill an issue in GitHub or make a pull request.
# Pull Request are welcome!
#
# If you test it in real hardware please send me an email to [email protected] with
# the machine description and tell me if somethig goes wrong or all works fine.
#
# Please, don't ask for support for this script in Arch Linux forums, first read
# the Arch Linux wiki [1], the Installation Guide [2] and the General
# Recomendations [3], later compare the commands with those of this script.
#
# [1] https://wiki.archlinux.org
# [2] https://wiki.archlinux.org/index.php/Installation_guide
# [3] https://wiki.archlinux.org/index.php/General_recommendations
# Usage:
# # loadkeys es
# # curl https://raw.githubusercontent.com/picodotdev/alis/master/download.sh | bash, curl https://raw.githubusercontent.com/picodotdev/alis/master/download.sh | bash -s -- -u [github user], or with URL shortener curl -sL https://bit.ly/2F3CATp | bash
# # vim alis.conf
# # ./alis.sh
# global variables (no configuration, don't edit)
ASCIINEMA=""
BIOS_TYPE=""
PARTITION_BOOT=""
PARTITION_ROOT=""
PARTITION_BOOT_NUMBER=""
PARTITION_ROOT_NUMBER=""
DEVICE_ROOT=""
DEVICE_LVM=""
LUKS_DEVICE_NAME="cryptroot"
LVM_VOLUME_GROUP="vg"
LVM_VOLUME_LOGICAL="root"
SWAPFILE="/swapfile"
BOOT_DIRECTORY=""
ESP_DIRECTORY=""
#PARTITION_BOOT_NUMBER=0
UUID_BOOT=""
UUID_ROOT=""
PARTUUID_BOOT=""
PARTUUID_ROOT=""
DEVICE_SATA=""
DEVICE_NVME=""
DEVICE_MMC=""
CPU_VENDOR=""
VIRTUALBOX=""
CMDLINE_LINUX_ROOT=""
CMDLINE_LINUX=""
CONF_FILE="alis.conf"
GLOBALS_FILE="alis-globals.conf"
LOG_FILE="alis.log"
ASCIINEMA_FILE="alis.asciinema"
RED='\033[0;31m'
GREEN='\033[0;32m'
LIGHT_BLUE='\033[1;34m'
NC='\033[0m'
function configuration_install() {
source alis.conf
}
function sanitize_variables() {
DEVICE=$(sanitize_variable "$DEVICE")
PARTITION_MODE=$(sanitize_variable "$PARTITION_MODE")
PARTITION_CUSTOMMANUAL_BOOT=$(sanitize_variable "$PARTITION_CUSTOMMANUAL_BOOT")
PARTITION_CUSTOMMANUAL_ROOT=$(sanitize_variable "$PARTITION_CUSTOMMANUAL_ROOT")
FILE_SYSTEM_TYPE=$(sanitize_variable "$FILE_SYSTEM_TYPE")
SWAP_SIZE=$(sanitize_variable "$SWAP_SIZE")
KERNELS=$(sanitize_variable "$KERNELS")
KERNELS_COMPRESSION=$(sanitize_variable "$KERNELS_COMPRESSION")
SYSTEMD_HOMED_STORAGE=$(sanitize_variable "$SYSTEMD_HOMED_STORAGE")
BOOTLOADER=$(sanitize_variable "$BOOTLOADER")
CUSTOM_SHELL=$(sanitize_variable "$CUSTOM_SHELL")
DESKTOP_ENVIRONMENT=$(sanitize_variable "$DESKTOP_ENVIRONMENT")
DISPLAY_DRIVER=$(sanitize_variable "$DISPLAY_DRIVER")
DISPLAY_DRIVER_HARDWARE_ACCELERATION_INTEL=$(sanitize_variable "$DISPLAY_DRIVER_HARDWARE_ACCELERATION_INTEL")
PACKAGES_PACMAN=$(sanitize_variable "$PACKAGES_PACMAN")
AUR=$(sanitize_variable "$AUR")
PACKAGES_AUR=$(sanitize_variable "$PACKAGES_AUR")
}
function sanitize_variable() {
VARIABLE=$1
VARIABLE=$(echo $VARIABLE | sed "s/![^ ]*//g") # remove disabled
VARIABLE=$(echo $VARIABLE | sed "s/ {2,}/ /g") # remove unnecessary white spaces
VARIABLE=$(echo $VARIABLE | sed 's/^[[:space:]]*//') # trim leading
VARIABLE=$(echo $VARIABLE | sed 's/[[:space:]]*$//') # trim trailing
echo "$VARIABLE"
}
function check_variables() {
check_variables_value "KEYS" "$KEYS"
check_variables_boolean "LOG" "$LOG"
check_variables_value "DEVICE" "$DEVICE"
check_variables_boolean "DEVICE_TRIM" "$DEVICE_TRIM"
check_variables_boolean "LVM" "$LVM"
check_variables_list "FILE_SYSTEM_TYPE" "$FILE_SYSTEM_TYPE" "ext4 btrfs xfs"
check_variables_equals "LUKS_PASSWORD" "LUKS_PASSWORD_RETYPE" "$LUKS_PASSWORD" "$LUKS_PASSWORD_RETYPE"
check_variables_list "PARTITION_MODE" "$PARTITION_MODE" "auto custom manual" "true"
if [ "$PARTITION_MODE" == "custom" ]; then
check_variables_value "PARTITION_CUSTOM_PARTED_UEFI" "$PARTITION_CUSTOM_PARTED_UEFI"
check_variables_value "PARTITION_CUSTOM_PARTED_BIOS" "$PARTITION_CUSTOM_PARTED_BIOS"
fi
if [ "$PARTITION_MODE" == "custom" -o "$PARTITION_MODE" == "manual" ]; then
check_variables_value "PARTITION_CUSTOMMANUAL_BOOT" "$PARTITION_CUSTOMMANUAL_BOOT"
check_variables_value "PARTITION_CUSTOMMANUAL_ROOT" "$PARTITION_CUSTOMMANUAL_ROOT"
fi
if [ "$LVM" == "true" ]; then
check_variables_list "PARTITION_MODE" "$PARTITION_MODE" "auto" "true"
fi
check_variables_value "PING_HOSTNAME" "$PING_HOSTNAME"
check_variables_value "PACMAN_MIRROR" "$PACMAN_MIRROR"
check_variables_list "KERNELS" "$KERNELS" "linux-lts linux-lts-headers linux-hardened linux-hardened-headers linux-zen linux-zen-headers" "false"
check_variables_list "KERNELS_COMPRESSION" "$KERNELS_COMPRESSION" "gzip bzip2 lzma xz lzop lz4 zstd" "false"
check_variables_value "TIMEZONE" "$TIMEZONE"
check_variables_boolean "REFLECTOR" "$REFLECTOR"
check_variables_value "PACMAN_MIRROR" "$PACMAN_MIRROR"
check_variables_value "LOCALES" "$LOCALES"
check_variables_value "LOCALE_CONF" "$LOCALE_CONF"
check_variables_value "LANG" "$LANG"
check_variables_value "KEYMAP" "$KEYMAP"
check_variables_value "HOSTNAME" "$HOSTNAME"
check_variables_value "USER_NAME" "$USER_NAME"
check_variables_value "USER_PASSWORD" "$USER_PASSWORD"
check_variables_equals "ROOT_PASSWORD" "ROOT_PASSWORD_RETYPE" "$ROOT_PASSWORD" "$ROOT_PASSWORD_RETYPE"
check_variables_equals "USER_PASSWORD" "USER_PASSWORD_RETYPE" "$USER_PASSWORD" "$USER_PASSWORD_RETYPE"
check_variables_boolean "SYSTEMD_HOMED" "$SYSTEMD_HOMED"
if [ "$SYSTEMD_HOMED" == "true" ]; then
check_variables_list "SYSTEMD_HOMED_STORAGE" "$SYSTEMD_HOMED_STORAGE" "directory fscrypt luks cifs subvolume" "true"
if [ "$SYSTEMD_HOMED_STORAGE" == "fscrypt" ]; then
check_variables_list "FILE_SYSTEM_TYPE" "$FILE_SYSTEM_TYPE" "ext4 f2fs" "true"
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "cifs" ]; then
check_variables_value "SYSTEMD_HOMED_CIFS_DOMAIN" "$SYSTEMD_HOMED_CIFS_DOMAIN"
check_variables_value "SYSTEMD_HOMED_CIFS_SERVICE" "$SYSTEMD_HOMED_CIFS_SERVICE"
fi
fi
check_variables_value "HOOKS" "$HOOKS"
check_variables_list "BOOTLOADER" "$BOOTLOADER" "grub refind systemd"
check_variables_list "CUSTOM_SHELL" "$CUSTOM_SHELL" "bash zsh dash fish"
check_variables_list "AUR" "$AUR" "aurman yay" "false"
check_variables_list "DESKTOP_ENVIRONMENT" "$DESKTOP_ENVIRONMENT" "gnome kde xfce mate cinnamon lxde i3-wm i3-gaps" "false"
check_variables_list "DISPLAY_DRIVER" "$DISPLAY_DRIVER" "intel amdgpu ati nvidia nvidia-lts nvidia-dkms nvidia-390xx nvidia-390xx-lts nvidia-390xx-dkms nouveau" "false"
check_variables_boolean "KMS" "$KMS"
check_variables_boolean "FASTBOOT" "$FASTBOOT"
check_variables_boolean "FRAMEBUFFER_COMPRESSION" "$FRAMEBUFFER_COMPRESSION"
check_variables_boolean "DISPLAY_DRIVER_DDX" "$DISPLAY_DRIVER_DDX"
check_variables_boolean "DISPLAY_DRIVER_HARDWARE_ACCELERATION" "$DISPLAY_DRIVER_HARDWARE_ACCELERATION"
check_variables_list "DISPLAY_DRIVER_HARDWARE_ACCELERATION_INTEL" "$DISPLAY_DRIVER_HARDWARE_ACCELERATION_INTEL" "intel-media-driver libva-intel-driver" "false"
check_variables_boolean "REBOOT" "$REBOOT"
}
function check_variables_value() {
NAME=$1
VALUE=$2
if [ -z "$VALUE" ]; then
echo "$NAME environment variable must have a value."
exit
fi
}
function check_variables_boolean() {
NAME=$1
VALUE=$2
check_variables_list "$NAME" "$VALUE" "true false"
}
function check_variables_list() {
NAME=$1
VALUE=$2
VALUES=$3
REQUIRED=$4
if [ "$REQUIRED" == "" -o "$REQUIRED" == "true" ]; then
check_variables_value "$NAME" "$VALUE"
fi
if [ "$VALUE" != "" -a -z "$(echo "$VALUES" | grep -F -w "$VALUE")" ]; then
echo "$NAME environment variable value [$VALUE] must be in [$VALUES]."
exit
fi
}
function check_variables_equals() {
NAME1=$1
NAME2=$2
VALUE1=$3
VALUE2=$4
if [ "$VALUE1" != "$VALUE2" ]; then
echo "$NAME1 and $NAME2 must be equal [$VALUE1, $VALUE2]."
exit
fi
}
function check_variables_size() {
NAME=$1
SIZE_EXPECT=$2
SIZE=$3
if [ "$SIZE_EXPECT" != "$SIZE" ]; then
echo "$NAME array size [$SIZE] must be [$SIZE_EXPECT]."
exit
fi
}
function warning() {
echo -e "${LIGHT_BLUE}Welcome to Arch Linux Install Script${NC}"
echo ""
echo -e "${RED}Warning"'!'"${NC}"
echo -e "${RED}This script deletes all partitions of the persistent${NC}"
echo -e "${RED}storage and continuing all your data in it will be lost.${NC}"
echo ""
read -p "Do you want to continue? [y/N] " yn
case $yn in
[Yy]* )
;;
[Nn]* )
exit
;;
* )
exit
;;
esac
}
function init() {
print_step "init()"
init_log
loadkeys $KEYS
}
function init_log() {
if [ "$LOG" == "true" ]; then
exec > >(tee -a $LOG_FILE)
exec 2> >(tee -a $LOG_FILE >&2)
fi
set -o xtrace
}
function facts() {
print_step "facts()"
if [ -d /sys/firmware/efi ]; then
BIOS_TYPE="uefi"
else
BIOS_TYPE="bios"
fi
if [ -f "$ASCIINEMA_FILE" ]; then
ASCIINEMA="true"
else
ASCIINEMA="false"
fi
DEVICE_SATA="false"
DEVICE_NVME="false"
DEVICE_MMC="false"
if [ -n "$(echo $DEVICE | grep "^/dev/[a-z]d[a-z]")" ]; then
DEVICE_SATA="true"
elif [ -n "$(echo $DEVICE | grep "^/dev/nvme")" ]; then
DEVICE_NVME="true"
elif [ -n "$(echo $DEVICE | grep "^/dev/mmc")" ]; then
DEVICE_MMC="true"
fi
if [ -n "$(lscpu | grep GenuineIntel)" ]; then
CPU_VENDOR="intel"
elif [ -n "$(lscpu | grep AuthenticAMD)" ]; then
CPU_VENDOR="amd"
fi
if [ -n "$(lspci | grep -i virtualbox)" ]; then
VIRTUALBOX="true"
fi
}
function checks() {
print_step "checks()"
check_facts
pacman -Sy
if [ -n "$PACKAGES_PACMAN" ]; then
pacman -Si $PACKAGES_PACMAN > /dev/null
fi
}
function check_facts() {
if [ "$BIOS_TYPE" == "bios" ]; then
check_variables_list "BOOTLOADER" "$BOOTLOADER" "grub"
fi
}
function prepare() {
print_step "prepare()"
configure_time
prepare_partition
configure_network
ask_passwords
}
function configure_time() {
timedatectl set-ntp true
}
function prepare_partition() {
if [ -d /mnt/boot ]; then
umount /mnt/boot
umount /mnt
fi
if [ -e "/dev/mapper/$LVM_VOLUME_GROUP-$LVM_VOLUME_LOGICAL" ]; then
umount "/dev/mapper/$LVM_VOLUME_GROUP-$LVM_VOLUME_LOGICAL"
fi
if [ -e "/dev/mapper/$LUKS_DEVICE_NAME" ]; then
cryptsetup close $LUKS_DEVICE_NAME
fi
partprobe $DEVICE
}
function configure_network() {
if [ -n "$WIFI_INTERFACE" ]; then
iwctl --passphrase "$WIFI_KEY" station $WIFI_INTERFACE connect $WIFI_ESSID
sleep 10
fi
# only on ping -c 1, packer gets stuck if -c 5
ping -c 1 -i 2 -W 5 -w 30 $PING_HOSTNAME
if [ $? -ne 0 ]; then
echo "Network ping check failed. Cannot continue."
exit
fi
}
function ask_passwords() {
if [ "$LUKS_PASSWORD" == "ask" ]; then
PASSWORD_TYPED="false"
while [ "$PASSWORD_TYPED" != "true" ]; do
read -sp 'Type LUKS password: ' LUKS_PASSWORD
echo ""
read -sp 'Retype LUKS password: ' LUKS_PASSWORD_RETYPE
echo ""
if [ "$LUKS_PASSWORD" == "$LUKS_PASSWORD_RETYPE" ]; then
PASSWORD_TYPED="true"
else
echo "LUKS password don't match. Please, type again."
fi
done
fi
if [ "$ROOT_PASSWORD" == "ask" ]; then
PASSWORD_TYPED="false"
while [ "$PASSWORD_TYPED" != "true" ]; do
read -sp 'Type root password: ' ROOT_PASSWORD
echo ""
read -sp 'Retype root password: ' ROOT_PASSWORD_RETYPE
echo ""
if [ "$ROOT_PASSWORD" == "$ROOT_PASSWORD_RETYPE" ]; then
PASSWORD_TYPED="true"
else
echo "Root password don't match. Please, type again."
fi
done
fi
if [ "$USER_PASSWORD" == "ask" ]; then
PASSWORD_TYPED="false"
while [ "$PASSWORD_TYPED" != "true" ]; do
read -sp 'Type user password: ' USER_PASSWORD
echo ""
read -sp 'Retype user password: ' USER_PASSWORD_RETYPE
echo ""
if [ "$USER_PASSWORD" == "$USER_PASSWORD_RETYPE" ]; then
PASSWORD_TYPED="true"
else
echo "User password don't match. Please, type again."
fi
done
fi
for I in ${!ADDITIONAL_USERS[@]}; do
VALUE=${ADDITIONAL_USERS[${I}]}
IFS='=' S=($VALUE)
USER=${S[0]}
PASSWORD=${S[1]}
PASSWORD_RETYPE=""
if [ "$PASSWORD" == "ask" ]; then
PASSWORD_TYPED="false"
while [ "$PASSWORD_TYPED" != "true" ]; do
read -sp "Type user ($USER) password: " PASSWORD
echo ""
read -sp "Retype user ($USER) password: " PASSWORD_RETYPE
echo ""
if [ "$PASSWORD" == "$PASSWORD_RETYPE" ]; then
PASSWORD_TYPED="true"
ADDITIONAL_USERS[${I}]="${USER}=${PASSWORD}"
else
echo "User ($USER) password don't match. Please, type again."
fi
done
fi
done
}
function partition() {
print_step "partition()"
# setup
if [ "$PARTITION_MODE" == "auto" ]; then
PARTITION_PARTED_UEFI="mklabel gpt mkpart ESP fat32 1MiB 512MiB mkpart root $FILE_SYSTEM_TYPE 512MiB 100% set 1 esp on"
PARTITION_PARTED_BIOS="mklabel msdos mkpart primary ext4 4MiB 512MiB mkpart primary $FILE_SYSTEM_TYPE 512MiB 100% set 1 boot on"
if [ "$BIOS_TYPE" == "uefi" ]; then
if [ "$DEVICE_SATA" == "true" ]; then
PARTITION_BOOT="${DEVICE}1"
PARTITION_ROOT="${DEVICE}2"
DEVICE_ROOT="${DEVICE}2"
fi
if [ "$DEVICE_NVME" == "true" ]; then
PARTITION_BOOT="${DEVICE}p1"
PARTITION_ROOT="${DEVICE}p2"
DEVICE_ROOT="${DEVICE}p2"
fi
if [ "$DEVICE_MMC" == "true" ]; then
PARTITION_BOOT="${DEVICE}p1"
PARTITION_ROOT="${DEVICE}p2"
DEVICE_ROOT="${DEVICE}p2"
fi
fi
if [ "$BIOS_TYPE" == "bios" ]; then
if [ "$DEVICE_SATA" == "true" ]; then
PARTITION_BOOT="${DEVICE}1"
PARTITION_ROOT="${DEVICE}2"
DEVICE_ROOT="${DEVICE}2"
fi
if [ "$DEVICE_NVME" == "true" ]; then
PARTITION_BOOT="${DEVICE}p1"
PARTITION_ROOT="${DEVICE}p2"
DEVICE_ROOT="${DEVICE}p2"
fi
if [ "$DEVICE_MMC" == "true" ]; then
PARTITION_BOOT="${DEVICE}p1"
PARTITION_ROOT="${DEVICE}p2"
DEVICE_ROOT="${DEVICE}p2"
fi
fi
elif [ "$PARTITION_MODE" == "custom" ]; then
PARTITION_PARTED_UEFI="$PARTITION_CUSTOM_PARTED_UEFI"
PARTITION_PARTED_BIOS="$PARTITION_CUSTOM_PARTED_BIOS"
fi
if [ "$PARTITION_MODE" == "custom" -o "$PARTITION_MODE" == "manual" ]; then
PARTITION_BOOT="$PARTITION_CUSTOMMANUAL_BOOT"
PARTITION_ROOT="$PARTITION_CUSTOMMANUAL_ROOT"
DEVICE_ROOT="${PARTITION_ROOT}"
fi
PARTITION_BOOT_NUMBER="$PARTITION_BOOT"
PARTITION_ROOT_NUMBER="$PARTITION_ROOT"
PARTITION_BOOT_NUMBER="${PARTITION_BOOT_NUMBER//\/dev\/sda/}"
PARTITION_BOOT_NUMBER="${PARTITION_BOOT_NUMBER//\/dev\/nvme0n1p/}"
PARTITION_BOOT_NUMBER="${PARTITION_BOOT_NUMBER//\/dev\/mmcblk0p/}"
PARTITION_ROOT_NUMBER="${PARTITION_ROOT_NUMBER//\/dev\/sda/}"
PARTITION_ROOT_NUMBER="${PARTITION_ROOT_NUMBER//\/dev\/nvme0n1p/}"
PARTITION_ROOT_NUMBER="${PARTITION_ROOT_NUMBER//\/dev\/mmcblk0p/}"
# partition
if [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
pacman -Sy --noconfirm f2fs-tools
fi
if [ "$PARTITION_MODE" == "auto" ]; then
sgdisk --zap-all $DEVICE
wipefs -a $DEVICE
fi
if [ "$PARTITION_MODE" == "auto" -o "$PARTITION_MODE" == "custom" ]; then
if [ "$BIOS_TYPE" == "uefi" ]; then
parted -s $DEVICE $PARTITION_PARTED_UEFI
if [ -n "$LUKS_PASSWORD" ]; then
sgdisk -t=$PARTITION_ROOT_NUMBER:8309 $DEVICE
elif [ "$LVM" == "true" ]; then
sgdisk -t=$PARTITION_ROOT_NUMBER:8e00 $DEVICE
fi
fi
if [ "$BIOS_TYPE" == "bios" ]; then
parted -s $DEVICE $PARTITION_PARTED_BIOS
fi
fi
# luks and lvm
if [ -n "$LUKS_PASSWORD" ]; then
echo -n "$LUKS_PASSWORD" | cryptsetup --key-size=512 --key-file=- luksFormat --type luks2 $PARTITION_ROOT
echo -n "$LUKS_PASSWORD" | cryptsetup --key-file=- open $PARTITION_ROOT $LUKS_DEVICE_NAME
sleep 5
fi
if [ "$LVM" == "true" ]; then
if [ -n "$LUKS_PASSWORD" ]; then
DEVICE_LVM="/dev/mapper/$LUKS_DEVICE_NAME"
else
DEVICE_LVM="$DEVICE_ROOT"
fi
pvcreate $DEVICE_LVM
vgcreate $LVM_VOLUME_GROUP $DEVICE_LVM
lvcreate -l 100%FREE -n $LVM_VOLUME_LOGICAL $LVM_VOLUME_GROUP
fi
if [ -n "$LUKS_PASSWORD" ]; then
DEVICE_ROOT="/dev/mapper/$LUKS_DEVICE_NAME"
fi
if [ "$LVM" == "true" ]; then
DEVICE_ROOT="/dev/mapper/$LVM_VOLUME_GROUP-$LVM_VOLUME_LOGICAL"
fi
# format
if [ "$BIOS_TYPE" == "uefi" ]; then
wipefs -a $PARTITION_BOOT
wipefs -a $DEVICE_ROOT
mkfs.fat -n ESP -F32 $PARTITION_BOOT
mkfs."$FILE_SYSTEM_TYPE" -L root $DEVICE_ROOT
fi
if [ "$BIOS_TYPE" == "bios" ]; then
wipefs -a $PARTITION_BOOT
wipefs -a $DEVICE_ROOT
mkfs."$FILE_SYSTEM_TYPE" -L boot $PARTITION_BOOT
mkfs."$FILE_SYSTEM_TYPE" -L root $DEVICE_ROOT
fi
PARTITION_OPTIONS="defaults"
if [ "$DEVICE_TRIM" == "true" ]; then
if [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
PARTITION_OPTIONS="$PARTITION_OPTIONS,noatime,nodiscard"
else
PARTITION_OPTIONS="$PARTITION_OPTIONS,noatime"
fi
fi
# mount
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
mount -o "$PARTITION_OPTIONS" "$DEVICE_ROOT" /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/var
btrfs subvolume create /mnt/snapshots
umount /mnt
mount -o "subvol=root,$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" /mnt
mkdir /mnt/{boot,home,var,snapshots}
mount -o "$PARTITION_OPTIONS" "$PARTITION_BOOT" /mnt/boot
mount -o "subvol=home,$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" /mnt/home
mount -o "subvol=var,$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" /mnt/var
mount -o "subvol=snapshots,$PARTITION_OPTIONS,compress=zstd" "$DEVICE_ROOT" /mnt/snapshots
else
mount -o "$PARTITION_OPTIONS" "$DEVICE_ROOT" /mnt
mkdir /mnt/boot
mount -o "$PARTITION_OPTIONS" "$PARTITION_BOOT" /mnt/boot
fi
# swap
if [ -n "$SWAP_SIZE" ]; then
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
truncate -s 0 /mnt$SWAPFILE
chattr +C /mnt$SWAPFILE
btrfs property set /mnt$SWAPFILE compression none
fi
dd if=/dev/zero of=/mnt$SWAPFILE bs=1M count=$SWAP_SIZE status=progress
chmod 600 /mnt$SWAPFILE
mkswap /mnt$SWAPFILE
fi
# 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)
}
function install() {
print_step "install()"
if [ -n "$PACMAN_MIRROR" ]; then
echo "Server=$PACMAN_MIRROR" > /etc/pacman.d/mirrorlist
fi
if [ "$REFLECTOR" == "true" ]; then
COUNTRIES=()
for COUNTRY in "${REFLECTOR_COUNTRIES[@]}"; do
COUNTRIES+=(--country "${COUNTRY}")
done
pacman -Sy --noconfirm reflector
reflector "${COUNTRIES[@]}" --latest 25 --age 24 --protocol https --completion-percent 100 --sort rate --save /etc/pacman.d/mirrorlist
fi
sed -i 's/#Color/Color/' /etc/pacman.conf
sed -i 's/#TotalDownload/TotalDownload/' /etc/pacman.conf
pacstrap /mnt base base-devel linux linux-firmware
sed -i 's/#Color/Color/' /mnt/etc/pacman.conf
sed -i 's/#TotalDownload/TotalDownload/' /mnt/etc/pacman.conf
}
function configuration() {
print_step "configuration()"
genfstab -U /mnt >> /mnt/etc/fstab
if [ -n "$SWAP_SIZE" ]; then
echo "# swap" >> /mnt/etc/fstab
echo "$SWAPFILE none swap defaults 0 0" >> /mnt/etc/fstab
echo "" >> /mnt/etc/fstab
fi
if [ "$DEVICE_TRIM" == "true" ]; then
if [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
sed -i 's/relatime/noatime,nodiscard/' /mnt/etc/fstab
else
sed -i 's/relatime/noatime/' /mnt/etc/fstab
fi
arch-chroot /mnt systemctl enable fstrim.timer
fi
arch-chroot /mnt ln -s -f $TIMEZONE /etc/localtime
arch-chroot /mnt hwclock --systohc
for LOCALE in "${LOCALES[@]}"; do
sed -i "s/#$LOCALE/$LOCALE/" /etc/locale.gen
sed -i "s/#$LOCALE/$LOCALE/" /mnt/etc/locale.gen
done
for VARIABLE in "${LOCALE_CONF[@]}"; do
#localectl set-locale "$VARIABLE"
echo -e "$VARIABLE" >> /mnt/etc/locale.conf
done
locale-gen
arch-chroot /mnt locale-gen
echo -e "$KEYMAP\n$FONT\n$FONT_MAP" > /mnt/etc/vconsole.conf
echo $HOSTNAME > /mnt/etc/hostname
OPTIONS=""
if [ -n "$KEYLAYOUT" ]; then
OPTIONS="$OPTIONS"$'\n'" Option \"XkbLayout\" \"$KEYLAYOUT\""
fi
if [ -n "$KEYMODEL" ]; then
OPTIONS="$OPTIONS"$'\n'" Option \"XkbModel\" \"$KEYMODEL\""
fi
if [ -n "$KEYVARIANT" ]; then
OPTIONS="$OPTIONS"$'\n'" Option \"XkbVariant\" \"$KEYVARIANT\""
fi
if [ -n "$KEYOPTIONS" ]; then
OPTIONS="$OPTIONS"$'\n'" Option \"XkbOptions\" \"$KEYOPTIONS\""
fi
arch-chroot /mnt mkdir -p "/etc/X11/xorg.conf.d/"
cat <<EOT > /mnt/etc/X11/xorg.conf.d/00-keyboard.conf
# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
$OPTIONS
EndSection
EOT
if [ -n "$SWAP_SIZE" ]; then
echo "vm.swappiness=10" > /mnt/etc/sysctl.d/99-sysctl.conf
fi
printf "$ROOT_PASSWORD\n$ROOT_PASSWORD" | arch-chroot /mnt passwd
}
function mkinitcpio_configuration() {
print_step "mkinitcpio_configuration()"
if [ "$KMS" == "true" ]; then
MODULES=""
case "$DISPLAY_DRIVER" in
"intel" )
MODULES="i915"
;;
"nvidia" | "nvidia-lts" | "nvidia-dkms" | "nvidia-390xx" | "nvidia-390xx-lts" | "nvidia-390xx-dkms" )
MODULES="nvidia nvidia_modeset nvidia_uvm nvidia_drm"
;;
"amdgpu" )
MODULES="amdgpu"
;;
"ati" )
MODULES="radeon"
;;
"nouveau" )
MODULES="nouveau"
;;
esac
arch-chroot /mnt sed -i "s/^MODULES=()/MODULES=($MODULES)/" /etc/mkinitcpio.conf
fi
if [ "$DISPLAY_DRIVER" == "intel" ]; then
OPTIONS=""
if [ "$FASTBOOT" == "true" ]; then
OPTIONS="$OPTIONS fastboot=1"
fi
if [ "$FRAMEBUFFER_COMPRESSION" == "true" ]; then
OPTIONS="$OPTIONS enable_fbc=1"
fi
if [ -n "$OPTIONS"]; then
echo "options i915 $OPTIONS" > /mnt/etc/modprobe.d/i915.conf
fi
fi
if [ "$LVM" == "true" ]; then
pacman_install "lvm2"
fi
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
pacman_install "btrfs-progs"
fi
if [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
pacman_install "f2fs-tools"
fi
if [ "$BOOTLOADER" == "systemd" ]; then
HOOKS=$(echo $HOOKS | sed 's/!systemd/systemd/')
HOOKS=$(echo $HOOKS | sed 's/!sd-vconsole/sd-vconsole/')
if [ "$LVM" == "true" ]; then
HOOKS=$(echo $HOOKS | sed 's/!sd-lvm2/sd-lvm2/')
fi
if [ -n "$LUKS_PASSWORD" ]; then
HOOKS=$(echo $HOOKS | sed 's/!sd-encrypt/sd-encrypt/')
fi
else
HOOKS=$(echo $HOOKS | sed 's/!udev/udev/')
HOOKS=$(echo $HOOKS | sed 's/!usr/usr/')
HOOKS=$(echo $HOOKS | sed 's/!keymap/keymap/')
HOOKS=$(echo $HOOKS | sed 's/!consolefont/consolefont/')
if [ "$LVM" == "true" ]; then
HOOKS=$(echo $HOOKS | sed 's/!lvm2/lvm2/')
fi
if [ -n "$LUKS_PASSWORD" ]; then
HOOKS=$(echo $HOOKS | sed 's/!encrypt/encrypt/')
fi
fi
HOOKS=$(sanitize_variable "$HOOKS")
arch-chroot /mnt sed -i "s/^HOOKS=(.*)$/HOOKS=($HOOKS)/" /etc/mkinitcpio.conf
if [ "$KERNELS_COMPRESSION" != "" ]; then
arch-chroot /mnt sed -i 's/^#COMPRESSION="'"$KERNELS_COMPRESSION"'"/COMPRESSION="'"$KERNELS_COMPRESSION"'"/' /etc/mkinitcpio.conf
fi
if [ "$KERNELS_COMPRESSION" == "bzip2" ]; then
pacman_install "bzip2"
fi
if [ "$KERNELS_COMPRESSION" == "lzma" -o "$KERNELS_COMPRESSION" == "xz" ]; then
pacman_install "xz"
fi
if [ "$KERNELS_COMPRESSION" == "lzop" ]; then
pacman_install "lzop"
fi
if [ "$KERNELS_COMPRESSION" == "lz4" ]; then
pacman_install "lz4"
fi
if [ "$KERNELS_COMPRESSION" == "zstd" ]; then
pacman_install "zstd"
fi
}
function display_driver() {
print_step "display_driver()"
PACKAGES_DRIVER=""
PACKAGES_DDX=""
PACKAGES_VULKAN=""
PACKAGES_HARDWARE_ACCELERATION=""
case "$DISPLAY_DRIVER" in
"nvidia" )
PACKAGES_DRIVER="nvidia"
;;
"nvidia-lts" )
PACKAGES_DRIVER="nvidia-lts"
;;
"nvidia-dkms" )
PACKAGES_DRIVER="nvidia-dkms"
;;
"nvidia-390xx" )
PACKAGES_DRIVER="nvidia-390xx"
;;
"nvidia-390xx-lts" )
PACKAGES_DRIVER="nvidia-390xx-lts"
;;
"nvidia-390xx-dkms" )
PACKAGES_DRIVER="nvidia-390xx-dkms"
;;
esac
if [ "$DISPLAY_DRIVER_DDX" == "true" ]; then
case "$DISPLAY_DRIVER" in
"intel" )
PACKAGES_DDX="xf86-video-intel"
;;
"amdgpu" )
PACKAGES_DDX="xf86-video-amdgpu"
;;
"ati" )
PACKAGES_DDX="xf86-video-ati"
;;
"nouveau" )
PACKAGES_DDX="xf86-video-nouveau"
;;
esac
fi
if [ "$VULKAN" == "true" ]; then
case "$DISPLAY_DRIVER" in
"intel" )
PACKAGES_VULKAN="vulkan-icd-loader vulkan-intel"
;;
"amdgpu" )
PACKAGES_VULKAN="vulkan-icd-loader vulkan-radeon"
;;
"ati" )
PACKAGES_VULKAN=""
;;
"nouveau" )
PACKAGES_VULKAN=""
;;
esac
fi
if [ "$DISPLAY_DRIVER_HARDWARE_ACCELERATION" == "true" ]; then
case "$DISPLAY_DRIVER" in
"intel" )
if [ -n "$DISPLAY_DRIVER_HARDWARE_ACCELERATION_INTEL" ]; then
PACKAGES_HARDWARE_ACCELERATION=$DISPLAY_DRIVER_HARDWARE_ACCELERATION_INTEL
fi
;;
"amdgpu" )
PACKAGES_HARDWARE_ACCELERATION="libva-mesa-driver"
;;
"ati" )
PACKAGES_HARDWARE_ACCELERATION="mesa-vdpau"
;;
"nouveau" )
PACKAGES_HARDWARE_ACCELERATION="libva-mesa-driver"
;;
esac
fi
pacman_install "mesa $PACKAGES_DRIVER $PACKAGES_DDX $PACKAGES_VULKAN $PACKAGES_HARDWARE_ACCELERATION"
}
function kernels() {
print_step "kernels()"
pacman_install "linux-headers"
if [ -n "$KERNELS" ]; then
pacman_install "$KERNELS"
fi
}
function mkinitcpio() {
print_step "mkinitcpio()"
arch-chroot /mnt mkinitcpio -P
}
function network() {
print_step "network()"
pacman_install "networkmanager"
arch-chroot /mnt systemctl enable NetworkManager.service
}
function virtualbox() {
print_step "virtualbox()"
if [ -z "$KERNELS" ]; then
pacman_install "virtualbox-guest-utils"
else
pacman_install "virtualbox-guest-utils virtualbox-guest-dkms"
fi
}
function users() {
print_step "users()"
create_user "$USER_NAME" "$USER_PASSWORD"
for U in ${ADDITIONAL_USERS[@]}; do
IFS='=' S=(${U})
USER=${S[0]}
PASSWORD=${S[1]}
create_user "${USER}" "${PASSWORD}"
done
arch-chroot /mnt sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers
pacman_install "xdg-user-dirs"
if [ "$SYSTEMD_HOMED" == "true" ]; then
cat <<EOT > "/mnt/etc/pam.d/nss-auth"
#%PAM-1.0
auth sufficient pam_unix.so try_first_pass nullok
auth sufficient pam_systemd_home.so
auth required pam_deny.so
account sufficient pam_unix.so
account sufficient pam_systemd_home.so
account required pam_deny.so
password sufficient pam_unix.so try_first_pass nullok sha512 shadow
password sufficient pam_systemd_home.so
password required pam_deny.so
EOT
cat <<EOT > "/mnt/etc/pam.d/system-auth"
#%PAM-1.0
auth substack nss-auth
auth optional pam_permit.so
auth required pam_env.so
account substack nss-auth
account optional pam_permit.so
account required pam_time.so
password substack nss-auth
password optional pam_permit.so
session required pam_limits.so
session optional pam_systemd_home.so
session required pam_unix.so
session optional pam_permit.so
EOT
fi
}
function create_user() {
USER=$1
PASSWORD=$2
if [ "$SYSTEMD_HOMED" == "true" ]; then
arch-chroot /mnt systemctl enable systemd-homed.service
create_user_homectl $USER $PASSWORD
# create_user_useradd $USER $PASSWORD
else
create_user_useradd $USER $PASSWORD
fi
}
function create_user_homectl() {
USER=$1
PASSWORD=$2
STORAGE=""
CIFS_DOMAIN=""
CIFS_USERNAME=""
CIFS_SERVICE=""
TZ=$(echo ${TIMEZONE} | sed "s/\/usr\/share\/zoneinfo\///g")
L=$(echo ${LOCALE_CONF[0]} | sed "s/LANG=//g")
IMAGE_PATH="/home/$USER.homedir"
HOME_PATH="/home/$USER"
if [ -n "$SYSTEMD_HOMED_STORAGE" ]; then
STORAGE="--storage=$SYSTEMD_HOMED_STORAGE"
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "cifs" ]; then
CIFS_DOMAIN="--cifs-domain=$SYSTEMD_HOMED_CIFS_DOMAIN"
CIFS_USERNAME="--cifs-user-name=$USER"
CIFS_SERVICE="--cifs-service=$SYSTEMD_HOMED_CIFS_SERVICE"
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "luks" ]; then
IMAGE_PATH="/home/$USER.home"