forked from picodotdev/alis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alis.sh
executable file
·1971 lines (1758 loc) · 69.5 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 -eu
# Arch Linux Install Script (alis) installs unattended, automated
# and customized Arch Linux system.
# Copyright (C) 2022 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
# Script to install an Arch Linux system.
#
# Usage:
# # loadkeys es
# # curl https://raw.githubusercontent.com/picodotdev/alis/master/download.sh | bash
# # vim alis.conf
# # ./alis.sh
function init_config() {
local COMMONS_FILE="alis-commons.sh"
source "$COMMONS_FILE"
source "$COMMONS_CONF_FILE"
source "$ALIS_CONF_FILE"
}
function sanitize_variables() {
DEVICE=$(sanitize_variable "$DEVICE")
PARTITION_MODE=$(sanitize_variable "$PARTITION_MODE")
PARTITION_CUSTOM_PARTED_UEFI=$(sanitize_variable "$PARTITION_CUSTOM_PARTED_UEFI")
PARTITION_CUSTOM_PARTED_BIOS=$(sanitize_variable "$PARTITION_CUSTOM_PARTED_BIOS")
FILE_SYSTEM_TYPE=$(sanitize_variable "$FILE_SYSTEM_TYPE")
SWAP_SIZE=$(sanitize_variable "$SWAP_SIZE")
KERNELS=$(sanitize_variable "$KERNELS")
KERNELS_COMPRESSION=$(sanitize_variable "$KERNELS_COMPRESSION")
KERNELS_PARAMETERS=$(sanitize_variable "$KERNELS_PARAMETERS")
AUR_PACKAGE=$(sanitize_variable "$AUR_PACKAGE")
DISPLAY_DRIVER=$(sanitize_variable "$DISPLAY_DRIVER")
DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION_INTEL=$(sanitize_variable "$DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION_INTEL")
SYSTEMD_HOMED_STORAGE=$(sanitize_variable "$SYSTEMD_HOMED_STORAGE")
SYSTEMD_HOMED_STORAGE_LUKS_TYPE=$(sanitize_variable "$SYSTEMD_HOMED_STORAGE_LUKS_TYPE")
BOOTLOADER=$(sanitize_variable "$BOOTLOADER")
CUSTOM_SHELL=$(sanitize_variable "$CUSTOM_SHELL")
DESKTOP_ENVIRONMENT=$(sanitize_variable "$DESKTOP_ENVIRONMENT")
DISPLAY_MANAGER=$(sanitize_variable "$DISPLAY_MANAGER")
SYSTEMD_UNITS=$(sanitize_variable "$SYSTEMD_UNITS")
for I in "${BTRFS_SUBVOLUMES_MOUNTPOINTS[@]}"; do
IFS=',' 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
IFS='=' 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
}
function check_variables() {
check_variables_value "KEYS" "$KEYS"
check_variables_boolean "LOG_TRACE" "$LOG_TRACE"
check_variables_boolean "LOG_FILE" "$LOG_FILE"
check_variables_value "DEVICE" "$DEVICE"
if [ "$DEVICE" == "auto" ]; then
local DEVICE_BOOT=$(lsblk -oMOUNTPOINT,PKNAME -P -M | grep 'MOUNTPOINT="/run/archiso/bootmnt"' | sed 's/.*PKNAME="\(.*\)".*/\1/')
if [ -n "$DEVICE_BOOT" ]; then
local DEVICE_BOOT="/dev/$DEVICE_BOOT"
fi
local DEVICE_DETECTED="false"
if [ -e "/dev/sda" -a "$DEVICE_BOOT" != "/dev/sda" ]; then
if [ "$DEVICE_DETECTED" == "true" ]; then
echo "Auto device is ambigous, detected $DEVICE and /dev/sda."
exit 1
fi
DEVICE_DETECTED="true"
DEVICE_SDA="true"
DEVICE="/dev/sda"
fi
if [ -e "/dev/nvme0n1" -a "$DEVICE_BOOT" != "/dev/nvme0n1" ]; then
if [ "$DEVICE_DETECTED" == "true" ]; then
echo "Auto device is ambigous, detected $DEVICE and /dev/nvme0n1."
exit 1
fi
DEVICE_DETECTED="true"
DEVICE_NVME="true"
DEVICE="/dev/nvme0n1"
fi
if [ -e "/dev/vda" -a "$DEVICE_BOOT" != "/dev/vda" ]; then
if [ "$DEVICE_DETECTED" == "true" ]; then
echo "Auto device is ambigous, detected $DEVICE and /dev/vda."
exit 1
fi
DEVICE_DETECTED="true"
DEVICE_VDA="true"
DEVICE="/dev/vda"
fi
if [ -e "/dev/mmcblk0" -a "$DEVICE_BOOT" != "/dev/mmcblk0" ]; then
if [ "$DEVICE_DETECTED" == "true" ]; then
echo "Auto device is ambigous, detected $DEVICE and /dev/mmcblk0."
exit 1
fi
DEVICE_DETECTED="true"
DEVICE_MMC="true"
DEVICE="/dev/mmcblk0"
fi
fi
check_variables_boolean "DEVICE_TRIM" "$DEVICE_TRIM"
check_variables_boolean "LVM" "$LVM"
check_variables_equals "LUKS_PASSWORD" "LUKS_PASSWORD_RETYPE" "$LUKS_PASSWORD" "$LUKS_PASSWORD_RETYPE"
check_variables_list "FILE_SYSTEM_TYPE" "$FILE_SYSTEM_TYPE" "ext4 btrfs xfs f2fs reiserfs" "true" "true"
check_variables_size "BTRFS_SUBVOLUME_ROOT" ${#BTRFS_SUBVOLUME_ROOT[@]} 3
check_variables_list "BTRFS_SUBVOLUME_ROOT" "${BTRFS_SUBVOLUME_ROOT[2]}" "/" "true" "true"
if [ -n "$SWAP_SIZE" ]; then
check_variables_size "BTRFS_SUBVOLUME_SWAP" ${#BTRFS_SUBVOLUME_SWAP[@]} 3
fi
for I in "${BTRFS_SUBVOLUMES_MOUNTPOINTS[@]}"; do
IFS=',' SUBVOLUME=($I)
check_variables_size "SUBVOLUME" ${#SUBVOLUME[@]} 3
done
check_variables_list "PARTITION_MODE" "$PARTITION_MODE" "auto custom manual" "true" "true"
check_variables_value "PARTITION_BOOT_NUMBER" "$PARTITION_BOOT_NUMBER"
check_variables_value "PARTITION_ROOT_NUMBER" "$PARTITION_ROOT_NUMBER"
check_variables_equals "WIFI_KEY" "WIFI_KEY_RETYPE" "$WIFI_KEY" "$WIFI_KEY_RETYPE"
check_variables_value "PING_HOSTNAME" "$PING_HOSTNAME"
check_variables_boolean "REFLECTOR" "$REFLECTOR"
check_variables_value "PACMAN_MIRROR" "$PACMAN_MIRROR"
check_variables_boolean "PACMAN_PARALLEL_DOWNLOADS" "$PACMAN_PARALLEL_DOWNLOADS"
check_variables_list "KERNELS" "$KERNELS" "linux-lts linux-lts-headers linux-hardened linux-hardened-headers linux-zen linux-zen-headers" "false" "false"
check_variables_list "KERNELS_COMPRESSION" "$KERNELS_COMPRESSION" "gzip bzip2 lzma xz lzop lz4 zstd" "false" "true"
check_variables_list "AUR_PACKAGE" "$AUR_PACKAGE" "paru-bin yay-bin paru yay aurman" "true" "true"
check_variables_list "DISPLAY_DRIVER" "$DISPLAY_DRIVER" "auto intel amdgpu ati nvidia nvidia-lts nvidia-dkms nvidia-470xx-dkms nvidia-390xx-dkms nvidia-340xx-dkms nouveau" "false" "true"
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_VIDEO_ACCELERATION" "$DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION"
check_variables_list "DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION_INTEL" "$DISPLAY_DRIVER_HARDWARE_VIDEO_ACCELERATION_INTEL" "intel-media-driver libva-intel-driver" "false" "true"
check_variables_value "TIMEZONE" "$TIMEZONE"
check_variables_value "LOCALES" "$LOCALES"
check_variables_value "LOCALE_CONF" "$LOCALE_CONF"
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"
check_variables_list "SYSTEMD_HOMED_STORAGE" "$SYSTEMD_HOMED_STORAGE" "auto luks subvolume directory fscrypt cifs" "true" "true"
check_variables_list "SYSTEMD_HOMED_STORAGE_LUKS_TYPE" "$SYSTEMD_HOMED_STORAGE_LUKS_TYPE" "auto ext4 btrfs xfs" "true" "true"
if [ "$SYSTEMD_HOMED" == "true" ]; then
if [ "$SYSTEMD_HOMED_STORAGE" == "fscrypt" ]; then
check_variables_list "FILE_SYSTEM_TYPE" "$FILE_SYSTEM_TYPE" "ext4 f2fs" "true" "true"
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "cifs" ]; then
check_variables_value "SYSTEMD_HOMED_CIFS[\"domain]\"" "${SYSTEMD_HOMED_CIFS_DOMAIN["domain"]}"
check_variables_value "SYSTEMD_HOMED_CIFS[\"service\"]" "${SYSTEMD_HOMED_CIFS_SERVICE["size"]}"
fi
fi
check_variables_value "HOOKS" "$HOOKS"
check_variables_list "BOOTLOADER" "$BOOTLOADER" "auto grub refind systemd" "true" "true"
check_variables_list "CUSTOM_SHELL" "$CUSTOM_SHELL" "bash zsh dash fish" "true" "true"
check_variables_list "DESKTOP_ENVIRONMENT" "$DESKTOP_ENVIRONMENT" "gnome kde xfce mate cinnamon lxde i3-wm i3-gaps deepin budgie bspwm awesome qtile openbox leftwm dusk" "false" "true"
check_variables_list "DISPLAY_MANAGER" "$DISPLAY_MANAGER" "auto gdm sddm lightdm lxdm" "true" "true"
check_variables_boolean "PACKAGES_MULTILIB" "$PACKAGES_MULTILIB"
check_variables_boolean "PACKAGES_INSTALL" "$PACKAGES_INSTALL"
check_variables_boolean "PROVISION" "$PROVISION"
check_variables_boolean "VAGRANT" "$VAGRANT"
check_variables_boolean "REBOOT" "$REBOOT"
}
function warning() {
echo -e "${BLUE}Welcome to Arch Linux Install Script${NC}"
echo ""
echo -e "${RED}Warning"'!'"${NC}"
echo -e "${RED}This script can delete all partitions of the persistent${NC}"
echo -e "${RED}storage and continuing all your data can be lost.${NC}"
echo ""
echo -e "Install device: $DEVICE."
echo -e "Mount points: ${PARTITION_MOUNT_POINTS[@]}."
echo ""
#if [ "$WARNING_CONFIRM" == "true" ]; then
# read -p "Do you want to continue? [y/N] " yn
#else
# yn="y"
# sleep 2
#fi
#case $yn in
# [Yy]* )
# ;;
# [Nn]* )
# exit 0
# ;;
# * )
# exit 0
# ;;
#esac
}
function init() {
print_step "init()"
init_log_trace "$LOG_TRACE"
init_log_file "$LOG_FILE" "$ALIS_LOG_FILE"
loadkeys "$KEYS"
}
function facts() {
print_step "facts()"
facts_commons
if [ -n "$(echo "$DEVICE" | grep "^/dev/sd[a-z]")" ]; then
DEVICE_SDA="true"
elif [ -n "$(echo "$DEVICE" | grep "^/dev/nvme")" ]; then
DEVICE_NVME="true"
elif [ -n "$(echo "$DEVICE" | grep "^/dev/vd[a-z]")" ]; then
DEVICE_VDA="true"
elif [ -n "$(echo "$DEVICE" | grep "^/dev/mmc")" ]; then
DEVICE_MMC="true"
fi
if [ "$DISPLAY_DRIVER" == "auto" ]; then
case "$GPU_VENDOR" in
"intel" )
DISPLAY_DRIVER="intel"
;;
"amd" )
DISPLAY_DRIVER="amdgpu"
;;
"nvidia" )
DISPLAY_DRIVER="nvidia"
;;
esac
fi
case "$AUR_PACKAGE" in
"aurman" )
AUR_COMMAND="aurman"
;;
"yay" )
AUR_COMMAND="yay"
;;
"paru" )
AUR_COMMAND="paru"
;;
"yay-bin" )
AUR_COMMAND="yay"
;;
"paru-bin" | *)
AUR_COMMAND="paru"
;;
esac
if [ "$BOOTLOADER" == "auto" ]; then
if [ "$BIOS_TYPE" == "uefi" ]; then
BOOTLOADER="systemd"
elif [ "$BIOS_TYPE" == "bios" ]; then
BOOTLOADER="grub"
fi
fi
}
function checks() {
print_step "checks()"
check_facts
}
function check_facts() {
if [ "$BIOS_TYPE" == "bios" ]; then
check_variables_list "BOOTLOADER" "$BOOTLOADER" "grub" "true" "true"
fi
}
function prepare() {
print_step "prepare()"
configure_reflector
configure_time
prepare_partition
ask_passwords
configure_network
}
function configure_reflector() {
if [ "$REFLECTOR" == "false" ]; then
if systemctl is-active --quiet reflector.service; then
systemctl stop reflector.service
fi
fi
}
function configure_time() {
timedatectl set-ntp true
}
function prepare_partition() {
set +e
mountpoint -q ${MNT_DIR}/boot
if [ $? == 0 ]; then
umount ${MNT_DIR}/boot
fi
mountpoint -q ${MNT_DIR}
if [ $? == 0 ]; then
umount ${MNT_DIR}
fi
lvs $LVM_VOLUME_GROUP-$LVM_VOLUME_LOGICAL
if [ $? == 0 ]; then
lvchange -an "$LVM_VOLUME_GROUP/$LVM_VOLUME_LOGICAL"
fi
vgs $LVM_VOLUME_GROUP
if [ $? == 0 ]; then
vgchange -an $LVM_VOLUME_GROUP
fi
if [ -e "/dev/mapper/$LUKS_DEVICE_NAME" ]; then
cryptsetup status $LUKS_DEVICE_NAME | grep -qi "is active"
if [ $? == 0 ]; then
cryptsetup close $LUKS_DEVICE_NAME
fi
fi
set -e
}
function ask_passwords() {
if [ "$LUKS_PASSWORD" == "ask" ]; then
local 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
local PASSWORD_TYPED="true"
else
echo "LUKS password don't match. Please, type again."
fi
done
fi
if [ -n "$WIFI_INTERFACE" -a "$WIFI_KEY" == "ask" ]; then
local PASSWORD_TYPED="false"
while [ "$PASSWORD_TYPED" != "true" ]; do
read -sp 'Type WIFI key: ' WIFI_KEY
echo ""
read -sp 'Retype WIFI key: ' WIFI_KEY_RETYPE
echo ""
if [ "$WIFI_KEY" == "$WIFI_KEY_RETYPE" ]; then
local PASSWORD_TYPED="true"
else
echo "WIFI key don't match. Please, type again."
fi
done
fi
if [ "$ROOT_PASSWORD" == "ask" ]; then
local 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
local PASSWORD_TYPED="true"
else
echo "Root password don't match. Please, type again."
fi
done
fi
if [ "$USER_PASSWORD" == "ask" ]; then
local 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
local PASSWORD_TYPED="true"
else
echo "User password don't match. Please, type again."
fi
done
fi
for I in ${!ADDITIONAL_USERS[@]}; do
local VALUE=${ADDITIONAL_USERS[${I}]}
IFS='=' local S=($VALUE)
local USER=${S[0]}
local PASSWORD=${S[1]}
local PASSWORD_RETYPE=""
if [ "$PASSWORD" == "ask" ]; then
local 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
local 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()"
partprobe -s $DEVICE
# setup
partition_setup
# partition
if [ "$PARTITION_MODE" == "auto" ]; then
sgdisk --zap-all $DEVICE
sgdisk -o $DEVICE
wipefs -a -f $DEVICE
partprobe -s $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
partprobe -s $DEVICE
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
if [ "$PARTITION_MODE" == "auto" ]; then
set +e
lvs $LVM_VOLUME_GROUP-$LVM_VOLUME_LOGICAL
if [ $? == 0 ]; then
lvremove -y $LVM_VOLUME_GROUP/$LVM_VOLUME_LOGICAL
fi
vgs $LVM_VOLUME_GROUP
if [ $? == 0 ]; then
vgremove -y $LVM_VOLUME_GROUP
fi
pvs $DEVICE_LVM
if [ $? == 0 ]; then
pvremove -y $DEVICE_LVM
fi
set -e
pvcreate -y $DEVICE_LVM
vgcreate -y $LVM_VOLUME_GROUP $DEVICE_LVM
lvcreate -y -l 100%FREE -n $LVM_VOLUME_LOGICAL $LVM_VOLUME_GROUP
fi
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
# Delete patition filesystem in case is reinstalling in an already existing system
# Not fail on error
wipefs -a -f $PARTITION_BOOT || true
wipefs -a -f $DEVICE_ROOT || true
## boot
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
if [ "$FILE_SYSTEM_TYPE" == "reiserfs" ]; then
mkfs."$FILE_SYSTEM_TYPE" -f -l root $DEVICE_ROOT
elif [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
mkfs."$FILE_SYSTEM_TYPE" -l root $DEVICE_ROOT
else
mkfs."$FILE_SYSTEM_TYPE" -L root $DEVICE_ROOT
fi
## mountpoint
for I in "${PARTITION_MOUNT_POINTS[@]}"; do
if [[ "$I" =~ ^!.* ]]; then
continue
fi
IFS='=' PARTITION_MOUNT_POINT=($I)
if [ "${PARTITION_MOUNT_POINT[1]}" == "/boot" -o "${PARTITION_MOUNT_POINT[1]}" == "/" ]; then
continue
fi
local PARTITION_DEVICE="$(partition_device "${DEVICE}" "${PARTITION_MOUNT_POINT[0]}")"
if [ "$FILE_SYSTEM_TYPE" == "reiserfs" ]; then
mkfs."$FILE_SYSTEM_TYPE" -f $PARTITION_DEVICE
elif [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
mkfs."$FILE_SYSTEM_TYPE" $PARTITION_DEVICE
else
mkfs."$FILE_SYSTEM_TYPE" $PARTITION_DEVICE
fi
done
# options
partition_options
# 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=',' SUBVOLUME=($I)
if [ ${SUBVOLUME[0]} == "swap" -a -z "$SWAP_SIZE" ]; then
continue
fi
btrfs subvolume create "${MNT_DIR}/${SUBVOLUME[1]}"
done
umount ${MNT_DIR}
fi
# mount
partition_mount
# swap
if [ -n "$SWAP_SIZE" ]; then
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
SWAPFILE="${BTRFS_SUBVOLUME_SWAP[2]}${SWAPFILE}"
truncate -s 0 ${MNT_DIR}${SWAPFILE}
chattr +C ${MNT_DIR}${SWAPFILE}
btrfs property set ${MNT_DIR}${SWAPFILE} compression none
fi
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
# 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()"
local COUNTRIES=()
pacman -Sy --noconfirm archlinux-keyring
if [ -n "$PACMAN_MIRROR" ]; then
echo "Server = $PACMAN_MIRROR" > /etc/pacman.d/mirrorlist
fi
if [ "$REFLECTOR" == "true" ]; then
for COUNTRY in "${REFLECTOR_COUNTRIES[@]}"; do
local 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
if [ "$PACMAN_PARALLEL_DOWNLOADS" == "true" ]; then
sed -i 's/#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
else
sed -i 's/#ParallelDownloads\(.*\)/#ParallelDownloads\1\nDisableDownloadTimeout/' /etc/pacman.conf
fi
local PACKAGES=()
if [ "$LVM" == "true" ]; then
local PACKAGES+=("lvm2")
fi
if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then
local PACKAGES+=("btrfs-progs")
fi
if [ "$FILE_SYSTEM_TYPE" == "xfs" ]; then
local PACKAGES+=("xfsprogs")
fi
if [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
local PACKAGES+=("f2fs-tools")
fi
if [ "$FILE_SYSTEM_TYPE" == "reiserfs" ]; then
local PACKAGES+=("reiserfsprogs")
fi
pacstrap ${MNT_DIR} base base-devel linux linux-firmware "${PACKAGES[@]}"
sed -i 's/#Color/Color/' ${MNT_DIR}/etc/pacman.conf
if [ "$PACMAN_PARALLEL_DOWNLOADS" == "true" ]; then
sed -i 's/#ParallelDownloads/ParallelDownloads/' ${MNT_DIR}/etc/pacman.conf
else
sed -i 's/#ParallelDownloads\(.*\)/#ParallelDownloads\1\nDisableDownloadTimeout/' ${MNT_DIR}/etc/pacman.conf
fi
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
}
function configuration() {
print_step "configuration()"
genfstab -U ${MNT_DIR} >> ${MNT_DIR}/etc/fstab
if [ -n "$SWAP_SIZE" ]; then
echo "# swap" >> ${MNT_DIR}/etc/fstab
echo "${SWAPFILE} none swap defaults 0 0" >> ${MNT_DIR}/etc/fstab
echo "" >> ${MNT_DIR}/etc/fstab
fi
if [ "$DEVICE_TRIM" == "true" ]; then
if [ "$FILE_SYSTEM_TYPE" == "f2fs" ]; then
sed -i 's/relatime/noatime,nodiscard/' ${MNT_DIR}/etc/fstab
else
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
local OPTIONS=""
if [ -n "$KEYLAYOUT" ]; then
local OPTIONS="$OPTIONS"$'\n'" Option \"XkbLayout\" \"$KEYLAYOUT\""
fi
if [ -n "$KEYMODEL" ]; then
local OPTIONS="$OPTIONS"$'\n'" Option \"XkbModel\" \"$KEYMODEL\""
fi
if [ -n "$KEYVARIANT" ]; then
local OPTIONS="$OPTIONS"$'\n'" Option \"XkbVariant\" \"$KEYVARIANT\""
fi
if [ -n "$KEYOPTIONS" ]; then
local OPTIONS="$OPTIONS"$'\n'" Option \"XkbOptions\" \"$KEYOPTIONS\""
fi
arch-chroot ${MNT_DIR} mkdir -p "/etc/X11/xorg.conf.d/"
cat <<EOT > ${MNT_DIR}/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_DIR}/etc/sysctl.d/99-sysctl.conf
fi
printf "$ROOT_PASSWORD\n$ROOT_PASSWORD" | arch-chroot ${MNT_DIR} passwd
}
function mkinitcpio_configuration() {
print_step "mkinitcpio_configuration()"
if [ "$KMS" == "true" ]; then
local MKINITCPIO_KMS_MODULES=""
case "$DISPLAY_DRIVER" in
"intel" )
local MKINITCPIO_KMS_MODULES="i915"
;;
"amdgpu" )
local MKINITCPIO_KMS_MODULES="amdgpu"
;;
"ati" )
local MKINITCPIO_KMS_MODULES="radeon"
;;
"nvidia" | "nvidia-lts" | "nvidia-dkms" )
local MKINITCPIO_KMS_MODULES="nvidia nvidia_modeset nvidia_uvm nvidia_drm"
;;
"nouveau" )
local MKINITCPIO_KMS_MODULES="nouveau"
;;
esac
local MODULES="$MODULES $MKINITCPIO_KMS_MODULES"
fi
if [ "$DISPLAY_DRIVER" == "intel" ]; then
local OPTIONS=""
if [ "$FASTBOOT" == "true" ]; then
local OPTIONS="$OPTIONS fastboot=1"
fi
if [ "$FRAMEBUFFER_COMPRESSION" == "true" ]; then
local OPTIONS="$OPTIONS enable_fbc=1"
fi
if [ -n "$OPTIONS" ]; then
echo "options i915 $OPTIONS" > ${MNT_DIR}/etc/modprobe.d/i915.conf
fi
fi
if [ "$LVM" == "true" ]; then
HOOKS=$(echo $HOOKS | sed 's/!lvm2/lvm2/')
fi
if [ "$BOOTLOADER" == "systemd" ]; then
HOOKS=$(echo $HOOKS | sed 's/!systemd/systemd/')
HOOKS=$(echo $HOOKS | sed 's/!sd-vconsole/sd-vconsole/')
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 [ -n "$LUKS_PASSWORD" ]; then
HOOKS=$(echo $HOOKS | sed 's/!encrypt/encrypt/')
fi
fi
HOOKS=$(sanitize_variable "$HOOKS")
MODULES=$(sanitize_variable "$MODULES")
arch-chroot ${MNT_DIR} sed -i "s/^HOOKS=(.*)$/HOOKS=($HOOKS)/" /etc/mkinitcpio.conf
arch-chroot ${MNT_DIR} sed -i "s/^MODULES=(.*)/MODULES=($MODULES)/" /etc/mkinitcpio.conf
if [ "$KERNELS_COMPRESSION" != "" ]; then
arch-chroot ${MNT_DIR} 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 users() {
print_step "users()"
local USERS_GROUPS="wheel,storage,optical"
create_user "$USER_NAME" "$USER_PASSWORD" "$USERS_GROUPS"
for U in ${ADDITIONAL_USERS[@]}; do
IFS='=' local S=(${U})
local USER=${S[0]}
local PASSWORD=${S[1]}
create_user "$USER" "$PASSWORD" "$USERS_GROUPS"
done
arch-chroot ${MNT_DIR} sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
pacman_install "xdg-user-dirs"
if [ "$SYSTEMD_HOMED" == "true" ]; then
arch-chroot ${MNT_DIR} systemctl enable systemd-homed.service
cat <<EOT > "${MNT_DIR}/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_DIR}/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() {
local USER=$1
local PASSWORD=$2
local USERS_GROUPS=$3
if [ "$SYSTEMD_HOMED" == "true" ]; then
create_user_homectl "$USER" "$PASSWORD" "$USERS_GROUPS"
else
create_user_useradd "$USER" "$PASSWORD" "$USERS_GROUPS"
fi
}
function create_user_homectl() {
local USER=$1
local PASSWORD=$2
local USER_GROUPS=$3
local STORAGE="--storage=directory"
local IMAGE_PATH="--image-path=${MNT_DIR}/home/$USER"
local FS_TYPE=""
local CIFS_DOMAIN=""
local CIFS_USERNAME=""
local CIFS_SERVICE=""
local TZ=$(echo ${TIMEZONE} | sed "s/\/usr\/share\/zoneinfo\///g")
local L=$(echo ${LOCALE_CONF[0]} | sed "s/LANG=//g")
if [ "$SYSTEMD_HOMED_STORAGE" != "auto" ]; then
local STORAGE="--storage="$SYSTEMD_HOMED_STORAGE""
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "luks" -a "$SYSTEMD_HOMED_STORAGE_LUKS_TYPE" != "auto" ]; then
local FS_TYPE="--fs-type="$SYSTEMD_HOMED_STORAGE_LUKS_TYPE""
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "luks" ]; then
local IMAGE_PATH="--image-path="${MNT_DIR}/home/$USER.home""
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "cifs" ]; then
local CIFS_DOMAIN="--cifs-domain="${SYSTEMD_HOMED_CIFS_DOMAIN["domain"]}""
local CIFS_USERNAME="--cifs-user-name="$USER""
local CIFS_SERVICE="--cifs-service="${SYSTEMD_HOMED_CIFS_SERVICE["service"]}""
fi
if [ "$SYSTEMD_HOMED_STORAGE" == "luks" -a "$SYSTEMD_HOMED_STORAGE_LUKS_TYPE" == "auto" ]; then
pacman_install "btrfs-progs"
fi
systemctl start systemd-homed.service
sleep 10 # #151 avoid Operation on home <USER> failed: Transport endpoint is not conected.
homectl create "$USER" --enforce-password-policy=no --timezone="$TZ" --language="$L" $STORAGE $IMAGE_PATH $FS_TYPE $CIFS_DOMAIN $CIFS_USERNAME $CIFS_SERVICE -G "$USER_GROUPS"
sleep 10 # #151 avoid Operation on home <USER> failed: Transport endpoint is not conected.
cp -a "/var/lib/systemd/home/." "${MNT_DIR}/var/lib/systemd/home/"
}
function create_user_useradd() {
local USER=$1
local PASSWORD=$2
local USER_GROUPS=$3
arch-chroot ${MNT_DIR} useradd -m -G "$USER_GROUPS" -s /bin/bash $USER
printf "$USER_PASSWORD\n$USER_PASSWORD" | arch-chroot ${MNT_DIR} passwd $USER
}
function user_add_groups() {
local USER="$1"
local USER_GROUPS="$2"
if [ "$SYSTEMD_HOMED" == "true" ]; then
homectl update "$USER" -G "$USER_GROUPS"
else
arch-chroot ${MNT_DIR} usermod -a -G "$USER_GROUPS" "$USER"
fi
}
function user_add_groups_lightdm() {
arch-chroot ${MNT_DIR} groupadd -r "autologin"
user_add_groups "$USER_NAME" "autologin"
for U in ${ADDITIONAL_USERS[@]}; do
IFS='=' local S=(${U})
local USER=${S[0]}
user_add_groups "$USER" "autologin"
done
}
function display_driver() {
print_step "display_driver()"
local PACKAGES_DRIVER_PACMAN="true"
local PACKAGES_DRIVER=""
local PACKAGES_DRIVER_MULTILIB=""
local PACKAGES_DDX=""
local PACKAGES_VULKAN=""
local PACKAGES_VULKAN_MULTILIB=""
local PACKAGES_HARDWARE_ACCELERATION=""
local PACKAGES_HARDWARE_ACCELERATION_MULTILIB=""
case "$DISPLAY_DRIVER" in
"intel" )
local PACKAGES_DRIVER_MULTILIB="lib32-mesa"
;;
"amdgpu" )
local PACKAGES_DRIVER_MULTILIB="lib32-mesa"
;;
"ati" )
local PACKAGES_DRIVER_MULTILIB="lib32-mesa"
;;
"nvidia" )
local PACKAGES_DRIVER="nvidia"
local PACKAGES_DRIVER_MULTILIB="lib32-nvidia-utils"
;;
"nvidia-lts" )
local PACKAGES_DRIVER="nvidia-lts"
local PACKAGES_DRIVER_MULTILIB="lib32-nvidia-utils"
;;
"nvidia-dkms" )
local PACKAGES_DRIVER="nvidia-dkms"
local PACKAGES_DRIVER_MULTILIB="lib32-nvidia-utils"
;;
"nvidia-470xx-dkms" )
local PACKAGES_DRIVER_PACMAN="false"
local PACKAGES_DRIVER="nvidia-470xx-dkms"
local PACKAGES_DRIVER_MULTILIB="lib32-nvidia-utils"
;;
"nvidia-390xx-dkms" )
local PACKAGES_DRIVER_PACMAN="false"
local PACKAGES_DRIVER="nvidia-390xx-dkms"
local PACKAGES_DRIVER_MULTILIB="lib32-nvidia-utils"
;;