-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstaller.sh
executable file
·2160 lines (1881 loc) · 106 KB
/
installer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC1090
#########################################################
# ARCH OS INSTALLER | Automated Arch Linux Installer TUI
#########################################################
# SOURCE: https://github.com/murkl/arch-os
# AUTOR: murkl
# ORIGIN: Germany
# LICENCE: GPL 2.0
# CONFIG
set -o pipefail # A pipeline error results in the error status of the entire pipeline
set -e # Terminate if any command exits with a non-zero
set -E # ERR trap inherited by shell functions (errtrace)
# ENVIRONMENT
: "${DEBUG:=false}" # DEBUG=true ./installer.sh
: "${GUM:=./gum}" # GUM=/usr/bin/gum ./installer.sh
: "${FORCE:=false}" # FORCE=true ./installer.sh
# SCRIPT
VERSION='1.8.0'
# GUM
GUM_VERSION="0.13.0"
# ENVIRONMENT
SCRIPT_CONFIG="./installer.conf"
SCRIPT_LOG="./installer.log"
# INIT
INIT_FILENAME="initialize"
# TEMP
SCRIPT_TMP_DIR="$(mktemp -d "./.tmp.XXXXX")"
ERROR_MSG="${SCRIPT_TMP_DIR}/installer.err"
PROCESS_LOG="${SCRIPT_TMP_DIR}/process.log"
PROCESS_RET="${SCRIPT_TMP_DIR}/process.ret"
# COLORS
COLOR_WHITE=251
COLOR_GREEN=36
COLOR_PURPLE=212
COLOR_YELLOW=221
COLOR_RED=9
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# MAIN
# ////////////////////////////////////////////////////////////////////////////////////////////////////
main() {
# Clear logfile
[ -f "$SCRIPT_LOG" ] && mv -f "$SCRIPT_LOG" "${SCRIPT_LOG}.old"
# Check gum binary or download
gum_init
# Traps (error & exit)
trap 'trap_exit' EXIT
trap 'trap_error ${FUNCNAME} ${LINENO}' ERR
# Print version to logfile
log_info "Arch OS ${VERSION}"
# Start recovery
[[ "$1" = "--recovery"* ]] && {
start_recovery
exit $? # Exit after recovery
}
# ---------------------------------------------------------------------------------------------------
# Loop properties step to update screen if user edit properties
while (true); do
print_header "Arch OS Installer" # Show landig page
gum_white 'Please make sure you have:' && echo
gum_white '• Backed up your important data'
gum_white '• A stable internet connection'
gum_white '• Secure Boot disabled'
gum_white '• Boot Mode set to UEFI'
# Ask for load & remove existing config file
if [ "$FORCE" = "false" ] && [ -f "$SCRIPT_CONFIG" ] && ! gum_confirm "Load existing installer.conf?"; then
gum_confirm "Remove existing installer.conf?" || trap_gum_exit # If not want remove config > exit script
echo && gum_title "Properties File"
mv -f "$SCRIPT_CONFIG" "${SCRIPT_CONFIG}.old" && gum_info "installer.conf was moved to installer.conf.old"
gum_warn "Please restart Arch OS Installer..."
echo && exit 0
fi
echo # Print new line
# Source installer.conf if exists or select preset
until properties_preset_source; do :; done
# Selectors
echo && gum_title "Core Setup"
until select_username; do :; done
until select_password; do :; done
until select_timezone; do :; done
until select_language; do :; done
until select_keyboard; do :; done
until select_disk; do :; done
echo && gum_title "Desktop Setup"
until select_enable_desktop_environment; do :; done
until select_enable_desktop_driver; do :; done
until select_enable_desktop_slim; do :; done
until select_enable_desktop_keyboard; do :; done
echo && gum_title "Feature Setup"
until select_enable_encryption; do :; done
until select_enable_core_tweaks; do :; done
until select_enable_bootsplash; do :; done
until select_enable_multilib; do :; done
until select_enable_aur; do :; done
until select_enable_housekeeping; do :; done
until select_enable_shell_enhancement; do :; done
until select_enable_manager; do :; done
# Print success
echo && gum_info "Properties successfully initialized"
# Open Advanced Properties?
if [ "$FORCE" = "false" ] && gum_confirm --negative="Skip" "Open Advanced Setup?"; then
local header_txt="• Save with CTRL + D or ESC and cancel with CTRL + C"
if gum_write --show-line-numbers --prompt "> " --height=10 --width=180 --header="${header_txt}" --value="$(cat "$SCRIPT_CONFIG")" >"${SCRIPT_CONFIG}.new"; then
mv "${SCRIPT_CONFIG}.new" "${SCRIPT_CONFIG}" && properties_source
gum_info "Properties successfully saved"
gum_confirm "Change Password?" && until select_password --change && properties_source; do :; done
echo && ! gum_spin --title="Reload Properties in 3 seconds..." -- sleep 3 && trap_gum_exit
continue # Restart properties step to refresh properties screen
else
rm -f "${SCRIPT_CONFIG}.new" # Remove tmp properties
gum_warn "Advanced Setup canceled"
fi
fi
######################################################
break # Exit properties step and continue installation
######################################################
done
# ---------------------------------------------------------------------------------------------------
# Start installation in 5 seconds?
if [ "$FORCE" = "false" ]; then
gum_confirm "Start Arch OS Installation?" || trap_gum_exit
fi
local spin_title="Arch OS Installation starts in 5 seconds. Press CTRL + C to cancel..."
echo && ! gum_spin --title="$spin_title" -- sleep 5 && trap_gum_exit # CTRL + C pressed
gum_title "Arch OS Installation"
SECONDS=0 # Messure execution time of installation
# Executors
exec_init_installation
exec_prepare_disk
exec_pacstrap_core
exec_enable_multilib
exec_install_aur_helper
exec_install_bootsplash
exec_install_housekeeping
exec_install_shell_enhancement
exec_install_desktop
exec_install_graphics_driver
exec_install_archos_manager
exec_install_vm_support
exec_finalize_arch_os
exec_cleanup_installation
# Calc installation duration
duration=$SECONDS # This is set before install starts
duration_min="$((duration / 60))"
duration_sec="$((duration % 60))"
# Print duration time info
local finish_txt="Installation successful in ${duration_min} minutes and ${duration_sec} seconds"
echo && gum_green --bold "$finish_txt"
log_info "$finish_txt"
# Copy installer files to users home
if [ "$DEBUG" = "false" ]; then
cp -f "$SCRIPT_CONFIG" "/mnt/home/${ARCH_OS_USERNAME}/installer.conf"
sed -i "1i\# Arch OS Version: ${VERSION}" "/mnt/home/${ARCH_OS_USERNAME}/installer.conf"
cp -f "$SCRIPT_LOG" "/mnt/home/${ARCH_OS_USERNAME}/installer.log"
arch-chroot /mnt chown -R "$ARCH_OS_USERNAME":"$ARCH_OS_USERNAME" "/home/${ARCH_OS_USERNAME}/installer.conf"
arch-chroot /mnt chown -R "$ARCH_OS_USERNAME":"$ARCH_OS_USERNAME" "/home/${ARCH_OS_USERNAME}/installer.log"
fi
wait # Wait for sub processes
# ---------------------------------------------------------------------------------------------------
# Show reboot & unmount promt
local do_reboot do_unmount do_chroot
# Default values
do_reboot="false"
do_chroot="false"
do_unmount="false"
# Force values
if [ "$FORCE" = "true" ]; then
do_reboot="false"
do_chroot="false"
do_unmount="true"
fi
# Reboot promt
[ "$FORCE" = "false" ] && gum_confirm "Reboot to Arch OS now?" && do_reboot="true" && do_unmount="true"
# Unmount
[ "$FORCE" = "false" ] && [ "$do_reboot" = "false" ] && gum_confirm "Unmount Arch OS from /mnt?" && do_unmount="true"
[ "$do_unmount" = "true" ] && echo && gum_warn "Unmounting Arch OS from /mnt..."
if [ "$DEBUG" = "false" ] && [ "$do_unmount" = "true" ]; then
swapoff -a
umount -A -R /mnt
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ] && cryptsetup close cryptroot
fi
# Do reboot
[ "$FORCE" = "false" ] && [ "$do_reboot" = "true" ] && gum_warn "Rebooting to Arch OS..." && [ "$DEBUG" = "false" ] && reboot
# Chroot
[ "$FORCE" = "false" ] && [ "$do_unmount" = "false" ] && gum_confirm "Chroot to new Arch OS?" && do_chroot="true"
if [ "$do_chroot" = "true" ] && echo && gum_warn "Chrooting Arch OS at /mnt..."; then
gum_warn "!! YOUR ARE NOW ON YOUR NEW ARCH OS SYSTEM !!"
gum_warn ">> Leave with command 'exit'"
[ "$DEBUG" = "false" ] && arch-chroot /mnt </dev/tty
wait # Wait for subprocesses
gum_warn "Please reboot manually..."
fi
# Print warning
[ "$do_unmount" = "false" ] && [ "$do_chroot" = "false" ] && echo && gum_warn "Arch OS is still mounted at /mnt"
gum_info "Exit" && exit 0
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# RECOVERY
# ////////////////////////////////////////////////////////////////////////////////////////////////////
start_recovery() {
print_header "Arch OS Recovery"
local recovery_boot_partition recovery_root_partition user_input items options
local recovery_mount_dir="/mnt/recovery"
local recovery_crypt_label="cryptrecovery"
recovery_unmount() {
set +e
swapoff -a &>/dev/null
umount -A -R "$recovery_mount_dir" &>/dev/null
cryptsetup close "$recovery_crypt_label" &>/dev/null
set -e
}
# Select disk
mapfile -t items < <(lsblk -I 8,259,254 -d -o KNAME,SIZE -n)
# size: $(lsblk -d -n -o SIZE "/dev/${item}")
options=() && for item in "${items[@]}"; do options+=("/dev/${item}"); done
user_input=$(gum_choose --header "+ Select Arch OS Disk" "${options[@]}") || exit 130
gum_title "Recovery"
[ -z "$user_input" ] && log_fail "Disk is empty" && exit 1 # Check if new value is null
user_input=$(echo "$user_input" | awk -F' ' '{print $1}') # Remove size from input
[ ! -e "$user_input" ] && log_fail "Disk does not exists" && exit 130
[[ "$user_input" = "/dev/nvm"* ]] && recovery_boot_partition="${user_input}p1" || recovery_boot_partition="${user_input}1"
[[ "$user_input" = "/dev/nvm"* ]] && recovery_root_partition="${user_input}p2" || recovery_root_partition="${user_input}2"
# Check encryption
if lsblk -ndo FSTYPE "$recovery_root_partition" 2>/dev/null | grep -q "crypto_LUKS"; then
recovery_encryption_enabled="true"
gum_warn "The disk $user_input is encrypted with LUKS"
else
recovery_encryption_enabled="false"
gum_info "The disk $user_input is not encrypted"
fi
# Check archiso
[ "$(cat /proc/sys/kernel/hostname)" != "archiso" ] && gum_fail "You must execute the Recovery from Arch ISO!" && exit 130
# Make sure everything is unmounted
recovery_unmount
# Create mount dir
mkdir -p "$recovery_mount_dir"
mkdir -p "$recovery_mount_dir/boot"
# Mount disk
if [ "$recovery_encryption_enabled" = "true" ]; then
# Encryption password
recovery_encryption_password=$(gum_input --password --header "+ Enter Encryption Password") || exit 130
# Open encrypted Disk
echo -n "$recovery_encryption_password" | cryptsetup open "$recovery_root_partition" "$recovery_crypt_label" &>/dev/null || {
gum_fail "Wrong encryption password"
exit 130
}
# Mount encrypted disk
mount "/dev/mapper/${recovery_crypt_label}" "$recovery_mount_dir"
mount "$recovery_boot_partition" "$recovery_mount_dir/boot"
else
# Mount unencrypted disk
mount "$recovery_root_partition" "$recovery_mount_dir"
mount "$recovery_boot_partition" "$recovery_mount_dir/boot"
fi
# Chroot
gum_green "!! YOUR ARE NOW ON YOUR RECOVERY SYSTEM !!"
gum_yellow ">> Leave with command 'exit'"
arch-chroot "$recovery_mount_dir" </dev/tty
wait && recovery_unmount
gum_green ">> Exit Recovery"
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# PROPERTIES
# ////////////////////////////////////////////////////////////////////////////////////////////////////
properties_source() {
[ ! -f "$SCRIPT_CONFIG" ] && return 1
set -a # Load properties file and auto export variables
source "$SCRIPT_CONFIG"
set +a
return 0
}
properties_generate() {
{ # Write properties to installer.conf
echo "ARCH_OS_HOSTNAME='${ARCH_OS_HOSTNAME}'"
echo "ARCH_OS_USERNAME='${ARCH_OS_USERNAME}'"
echo "ARCH_OS_DISK='${ARCH_OS_DISK}'"
echo "ARCH_OS_BOOT_PARTITION='${ARCH_OS_BOOT_PARTITION}'"
echo "ARCH_OS_ROOT_PARTITION='${ARCH_OS_ROOT_PARTITION}'"
echo "ARCH_OS_ENCRYPTION_ENABLED='${ARCH_OS_ENCRYPTION_ENABLED}'"
echo "ARCH_OS_TIMEZONE='${ARCH_OS_TIMEZONE}'"
echo "ARCH_OS_LOCALE_LANG='${ARCH_OS_LOCALE_LANG}'"
echo "ARCH_OS_LOCALE_GEN_LIST=(${ARCH_OS_LOCALE_GEN_LIST[*]@Q})"
echo "ARCH_OS_REFLECTOR_COUNTRY='${ARCH_OS_REFLECTOR_COUNTRY}'"
echo "ARCH_OS_VCONSOLE_KEYMAP='${ARCH_OS_VCONSOLE_KEYMAP}'"
echo "ARCH_OS_VCONSOLE_FONT='${ARCH_OS_VCONSOLE_FONT}'"
echo "ARCH_OS_KERNEL='${ARCH_OS_KERNEL}'"
echo "ARCH_OS_MICROCODE='${ARCH_OS_MICROCODE}'"
echo "ARCH_OS_CORE_TWEAKS_ENABLED='${ARCH_OS_CORE_TWEAKS_ENABLED}'"
echo "ARCH_OS_MULTILIB_ENABLED='${ARCH_OS_MULTILIB_ENABLED}'"
echo "ARCH_OS_AUR_HELPER='${ARCH_OS_AUR_HELPER}'"
echo "ARCH_OS_BOOTSPLASH_ENABLED='${ARCH_OS_BOOTSPLASH_ENABLED}'"
echo "ARCH_OS_HOUSEKEEPING_ENABLED='${ARCH_OS_HOUSEKEEPING_ENABLED}'"
echo "ARCH_OS_MANAGER_ENABLED='${ARCH_OS_MANAGER_ENABLED}'"
echo "ARCH_OS_SHELL_ENHANCEMENT_ENABLED='${ARCH_OS_SHELL_ENHANCEMENT_ENABLED}'"
echo "ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED='${ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED}'"
echo "ARCH_OS_DESKTOP_ENABLED='${ARCH_OS_DESKTOP_ENABLED}'"
echo "ARCH_OS_DESKTOP_GRAPHICS_DRIVER='${ARCH_OS_DESKTOP_GRAPHICS_DRIVER}'"
echo "ARCH_OS_DESKTOP_EXTRAS_ENABLED='${ARCH_OS_DESKTOP_EXTRAS_ENABLED}'"
echo "ARCH_OS_DESKTOP_SLIM_ENABLED='${ARCH_OS_DESKTOP_SLIM_ENABLED}'"
echo "ARCH_OS_DESKTOP_KEYBOARD_MODEL='${ARCH_OS_DESKTOP_KEYBOARD_MODEL}'"
echo "ARCH_OS_DESKTOP_KEYBOARD_LAYOUT='${ARCH_OS_DESKTOP_KEYBOARD_LAYOUT}'"
echo "ARCH_OS_DESKTOP_KEYBOARD_VARIANT='${ARCH_OS_DESKTOP_KEYBOARD_VARIANT}'"
echo "ARCH_OS_SAMBA_SHARE_ENABLED='${ARCH_OS_SAMBA_SHARE_ENABLED}'"
echo "ARCH_OS_VM_SUPPORT_ENABLED='${ARCH_OS_VM_SUPPORT_ENABLED}'"
echo "ARCH_OS_ECN_ENABLED='${ARCH_OS_ECN_ENABLED}'"
} >"$SCRIPT_CONFIG" # Write properties to file
}
properties_preset_source() {
# Default presets
[ -z "$ARCH_OS_HOSTNAME" ] && ARCH_OS_HOSTNAME="arch-os"
[ -z "$ARCH_OS_KERNEL" ] && ARCH_OS_KERNEL="linux-zen"
[ -z "$ARCH_OS_DESKTOP_EXTRAS_ENABLED" ] && ARCH_OS_DESKTOP_EXTRAS_ENABLED='true'
[ -z "$ARCH_OS_SAMBA_SHARE_ENABLED" ] && ARCH_OS_SAMBA_SHARE_ENABLED="true"
[ -z "$ARCH_OS_VM_SUPPORT_ENABLED" ] && ARCH_OS_VM_SUPPORT_ENABLED="true"
[ -z "$ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED" ] && ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED="true"
[ -z "$ARCH_OS_ECN_ENABLED" ] && ARCH_OS_ECN_ENABLED="true"
[ -z "$ARCH_OS_DESKTOP_KEYBOARD_MODEL" ] && ARCH_OS_DESKTOP_KEYBOARD_MODEL="pc105"
# Set microcode
[ -z "$ARCH_OS_MICROCODE" ] && grep -E "GenuineIntel" &>/dev/null <<<"$(lscpu)" && ARCH_OS_MICROCODE="intel-ucode"
[ -z "$ARCH_OS_MICROCODE" ] && grep -E "AuthenticAMD" &>/dev/null <<<"$(lscpu)" && ARCH_OS_MICROCODE="amd-ucode"
# Load properties or select preset
if [ -f "$SCRIPT_CONFIG" ]; then
properties_source
gum join "$(gum_green --bold "• ")" "$(gum_white "Setup preset loaded from: ")" "$(gum_white --bold "installer.conf")"
else
# Select preset
local preset options
options=("desktop - GNOME Desktop Environment (default)" "core - Minimal Arch Linux TTY Environment" "none - No pre-selection")
preset=$(gum_choose --header "+ Choose Setup Preset" "${options[@]}") || trap_gum_exit_confirm
[ -z "$preset" ] && return 1 # Check if new value is null
preset="$(echo "$preset" | awk '{print $1}')"
# Core preset
if [[ $preset == core* ]]; then
ARCH_OS_DESKTOP_ENABLED='false'
ARCH_OS_MULTILIB_ENABLED='false'
ARCH_OS_HOUSEKEEPING_ENABLED='false'
ARCH_OS_SHELL_ENHANCEMENT_ENABLED='false'
ARCH_OS_BOOTSPLASH_ENABLED='false'
ARCH_OS_MANAGER_ENABLED='false'
ARCH_OS_DESKTOP_GRAPHICS_DRIVER="none"
ARCH_OS_AUR_HELPER='none'
fi
# Desktop preset
if [[ $preset == desktop* ]]; then
ARCH_OS_DESKTOP_EXTRAS_ENABLED='true'
ARCH_OS_SAMBA_SHARE_ENABLED='true'
ARCH_OS_CORE_TWEAKS_ENABLED="true"
ARCH_OS_BOOTSPLASH_ENABLED='true'
ARCH_OS_DESKTOP_ENABLED='true'
ARCH_OS_MULTILIB_ENABLED='true'
ARCH_OS_HOUSEKEEPING_ENABLED='true'
ARCH_OS_SHELL_ENHANCEMENT_ENABLED='true'
ARCH_OS_MANAGER_ENABLED='true'
ARCH_OS_AUR_HELPER='paru'
fi
# Write properties
properties_source
gum join "$(gum_green --bold "• ")" "$(gum_white "Setup preset loaded for: ")" "$(gum_white --bold "$preset")"
fi
return 0
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# SELECTORS
# ////////////////////////////////////////////////////////////////////////////////////////////////////
select_username() {
if [ -z "$ARCH_OS_USERNAME" ]; then
local user_input
user_input=$(gum_input --header "+ Enter Username") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
ARCH_OS_USERNAME="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Username" "$ARCH_OS_USERNAME"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_password() { # --change
if [ "$1" = "--change" ] || [ -z "$ARCH_OS_PASSWORD" ]; then
local user_password user_password_check
user_password=$(gum_input --password --header "+ Enter Password") || trap_gum_exit_confirm
[ -z "$user_password" ] && return 1 # Check if new value is null
user_password_check=$(gum_input --password --header "+ Enter Password again") || trap_gum_exit_confirm
[ -z "$user_password_check" ] && return 1 # Check if new value is null
if [ "$user_password" != "$user_password_check" ]; then
gum_confirm --affirmative="Ok" --negative="" "The passwords are not identical"
return 1
fi
ARCH_OS_PASSWORD="$user_password" && properties_generate # Set value and generate properties file
fi
[ "$1" = "--change" ] && gum_info "Password successfully changed"
[ "$1" != "--change" ] && gum_property "Password" "*******"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_timezone() {
if [ -z "$ARCH_OS_TIMEZONE" ]; then
local tz_auto user_input
tz_auto="$(curl -s http://ip-api.com/line?fields=timezone)"
user_input=$(gum_input --header "+ Enter Timezone (auto-detected)" --value "$tz_auto") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
if [ ! -f "/usr/share/zoneinfo/${user_input}" ]; then
gum_confirm --affirmative="Ok" --negative="" "Timezone '${user_input}' is not supported"
return 1
fi
ARCH_OS_TIMEZONE="$user_input" && properties_generate # Set property and generate properties file
fi
gum_property "Timezone" "$ARCH_OS_TIMEZONE"
return 0
}
# ---------------------------------------------------------------------------------------------------
# shellcheck disable=SC2001
select_language() {
if [ -z "$ARCH_OS_LOCALE_LANG" ] || [ -z "${ARCH_OS_LOCALE_GEN_LIST[*]}" ]; then
local user_input items options filter
# Fetch available options (list all from /usr/share/i18n/locales and check if entry exists in /etc/locale.gen)
mapfile -t items < <(basename -a /usr/share/i18n/locales/* | grep -v "@") # Create array without @ files
# Add only available locales (!!! intense command !!!)
options=() && for item in "${items[@]}"; do grep -q -e "^$item" -e "^#$item" /etc/locale.gen && options+=("$item"); done
# shellcheck disable=SC2002
[ -r /root/.zsh_history ] && filter=$(cat /root/.zsh_history | grep 'loadkeys' | head -n 2 | tail -n 1 | cut -d';' -f2 | cut -d' ' -f2 | cut -d'-' -f1)
# Select locale
user_input=$(gum_filter --value="$filter" --header "+ Choose Language" "${options[@]}") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
ARCH_OS_LOCALE_LANG="$user_input" # Set property
# Set locale.gen properties (auto generate ARCH_OS_LOCALE_GEN_LIST)
ARCH_OS_LOCALE_GEN_LIST=() && while read -r locale_entry; do
ARCH_OS_LOCALE_GEN_LIST+=("$locale_entry")
# Remove leading # from matched lang in /etc/locale.gen and add entry to array
done < <(sed "/^#${ARCH_OS_LOCALE_LANG}/s/^#//" /etc/locale.gen | grep "$ARCH_OS_LOCALE_LANG")
# Add en_US fallback (every language) if not already exists in list
[[ "${ARCH_OS_LOCALE_GEN_LIST[*]}" != *'en_US.UTF-8 UTF-8'* ]] && ARCH_OS_LOCALE_GEN_LIST+=('en_US.UTF-8 UTF-8')
properties_generate # Generate properties file (for ARCH_OS_LOCALE_LANG & ARCH_OS_LOCALE_GEN_LIST)
fi
gum_property "Language" "$ARCH_OS_LOCALE_LANG"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_keyboard() {
if [ -z "$ARCH_OS_VCONSOLE_KEYMAP" ]; then
local user_input items options filter
mapfile -t items < <(command localectl list-keymaps)
options=() && for item in "${items[@]}"; do options+=("$item"); done
# shellcheck disable=SC2002
[ -r /root/.zsh_history ] && filter=$(cat /root/.zsh_history | grep 'loadkeys' | head -n 2 | tail -n 1 | cut -d';' -f2 | cut -d' ' -f2 | cut -d'-' -f1)
user_input=$(gum_filter --value="$filter" --header "+ Choose Keyboard" "${options[@]}") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
ARCH_OS_VCONSOLE_KEYMAP="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Keyboard" "$ARCH_OS_VCONSOLE_KEYMAP"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_disk() {
if [ -z "$ARCH_OS_DISK" ] || [ -z "$ARCH_OS_BOOT_PARTITION" ] || [ -z "$ARCH_OS_ROOT_PARTITION" ]; then
local user_input items options
mapfile -t items < <(lsblk -I 8,259,254 -d -o KNAME,SIZE -n)
# size: $(lsblk -d -n -o SIZE "/dev/${item}")
options=() && for item in "${items[@]}"; do options+=("/dev/${item}"); done
user_input=$(gum_choose --header "+ Choose Disk" "${options[@]}") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
user_input=$(echo "$user_input" | awk -F' ' '{print $1}') # Remove size from input
[ ! -e "$user_input" ] && log_fail "Disk does not exists" && return 1
ARCH_OS_DISK="$user_input" # Set property
[[ "$ARCH_OS_DISK" = "/dev/nvm"* ]] && ARCH_OS_BOOT_PARTITION="${ARCH_OS_DISK}p1" || ARCH_OS_BOOT_PARTITION="${ARCH_OS_DISK}1"
[[ "$ARCH_OS_DISK" = "/dev/nvm"* ]] && ARCH_OS_ROOT_PARTITION="${ARCH_OS_DISK}p2" || ARCH_OS_ROOT_PARTITION="${ARCH_OS_DISK}2"
properties_generate # Generate properties file
fi
gum_property "Disk" "$ARCH_OS_DISK"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_encryption() {
if [ -z "$ARCH_OS_ENCRYPTION_ENABLED" ]; then
gum_confirm "Enable Disk Encryption?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_ENCRYPTION_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Disk Encryption" "$ARCH_OS_ENCRYPTION_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_core_tweaks() {
if [ -z "$ARCH_OS_CORE_TWEAKS_ENABLED" ]; then
gum_confirm "Enable Core Tweaks?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_CORE_TWEAKS_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Core Tweaks" "$ARCH_OS_CORE_TWEAKS_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_bootsplash() {
if [ -z "$ARCH_OS_BOOTSPLASH_ENABLED" ]; then
gum_confirm "Enable Bootsplash?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_BOOTSPLASH_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Bootsplash" "$ARCH_OS_BOOTSPLASH_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_desktop_environment() {
if [ -z "$ARCH_OS_DESKTOP_ENABLED" ]; then
local user_input
gum_confirm "Enable GNOME Desktop Environment?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_DESKTOP_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Desktop Environment" "$ARCH_OS_DESKTOP_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_desktop_slim() {
if [ "$ARCH_OS_DESKTOP_ENABLED" = "true" ]; then
if [ -z "$ARCH_OS_DESKTOP_SLIM_ENABLED" ]; then
local user_input
gum_confirm "Enable Desktop Slim Mode? (GNOME Core Apps only)" --affirmative="No (default)" --negative="Yes"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
[ $user_confirm = 1 ] && user_input="true"
[ $user_confirm = 0 ] && user_input="false"
ARCH_OS_DESKTOP_SLIM_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Desktop Slim Mode" "$ARCH_OS_DESKTOP_SLIM_ENABLED"
fi
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_desktop_keyboard() {
if [ "$ARCH_OS_DESKTOP_ENABLED" = "true" ]; then
if [ -z "$ARCH_OS_DESKTOP_KEYBOARD_LAYOUT" ]; then
local user_input user_input2
user_input=$(gum_input --header "+ Enter Desktop Keyboard Layout" --placeholder "e.g. 'us' or 'de'...") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
ARCH_OS_DESKTOP_KEYBOARD_LAYOUT="$user_input"
gum_property "Desktop Keyboard" "$ARCH_OS_DESKTOP_KEYBOARD_LAYOUT"
user_input2=$(gum_input --header "+ Enter Desktop Keyboard Variant (optional)" --placeholder "e.g. 'nodeadkeys' or leave empty...") || trap_gum_exit_confirm
ARCH_OS_DESKTOP_KEYBOARD_VARIANT="$user_input2"
properties_generate
else
gum_property "Desktop Keyboard" "$ARCH_OS_DESKTOP_KEYBOARD_LAYOUT"
fi
[ -n "$ARCH_OS_DESKTOP_KEYBOARD_VARIANT" ] && gum_property "Desktop Keyboard Variant" "$ARCH_OS_DESKTOP_KEYBOARD_VARIANT"
fi
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_desktop_driver() {
if [ "$ARCH_OS_DESKTOP_ENABLED" = "true" ]; then
if [ -z "$ARCH_OS_DESKTOP_GRAPHICS_DRIVER" ] || [ "$ARCH_OS_DESKTOP_GRAPHICS_DRIVER" = "none" ]; then
local user_input options
options=("mesa" "intel_i915" "nvidia" "amd" "ati")
user_input=$(gum_choose --header "+ Choose Desktop Graphics Driver (default: mesa)" "${options[@]}") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
ARCH_OS_DESKTOP_GRAPHICS_DRIVER="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Desktop Graphics Driver" "$ARCH_OS_DESKTOP_GRAPHICS_DRIVER"
fi
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_aur() {
if [ -z "$ARCH_OS_AUR_HELPER" ]; then
local user_input options
options=("paru" "paru-bin" "paru-git" "none")
user_input=$(gum_choose --header "+ Choose AUR Helper (default: paru)" "${options[@]}") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
ARCH_OS_AUR_HELPER="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "AUR Helper" "$ARCH_OS_AUR_HELPER"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_multilib() {
if [ -z "$ARCH_OS_MULTILIB_ENABLED" ]; then
gum_confirm "Enable 32 Bit Support?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_MULTILIB_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "32 Bit Support" "$ARCH_OS_MULTILIB_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_housekeeping() {
if [ -z "$ARCH_OS_HOUSEKEEPING_ENABLED" ]; then
gum_confirm "Enable Housekeeping?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_HOUSEKEEPING_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Housekeeping" "$ARCH_OS_HOUSEKEEPING_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_shell_enhancement() {
if [ -z "$ARCH_OS_SHELL_ENHANCEMENT_ENABLED" ]; then
gum_confirm "Enable Shell Enhancement?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_SHELL_ENHANCEMENT_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Shell Enhancement" "$ARCH_OS_SHELL_ENHANCEMENT_ENABLED"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_manager() {
if [ -z "$ARCH_OS_MANAGER_ENABLED" ]; then
gum_confirm "Enable Arch OS Manager?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="false"
[ $user_confirm = 0 ] && user_input="true"
ARCH_OS_MANAGER_ENABLED="$user_input" && properties_generate # Set value and generate properties file
fi
gum_property "Arch OS Manager" "$ARCH_OS_MANAGER_ENABLED"
return 0
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# EXECUTORS (SUB PROCESSES)
# ////////////////////////////////////////////////////////////////////////////////////////////////////
exec_init_installation() {
local process_name="Initialize Installation"
process_init "$process_name"
(
[ "$DEBUG" = "true" ] && sleep 1 && process_return 0 # If debug mode then return
# Check installation prerequisites
[ ! -d /sys/firmware/efi ] && log_fail "BIOS not supported! Please set your boot mode to UEFI." && exit 1
log_info "UEFI detected"
bootctl status | grep "Secure Boot" | grep -q "disabled" || { log_fail "You must disable Secure Boot in UEFI to continue installation" && exit 1; }
log_info "Secure Boot: disabled"
[ "$(cat /proc/sys/kernel/hostname)" != "archiso" ] && log_fail "You must execute the Installer from Arch ISO!" && exit 1
log_info "Arch ISO detected"
log_info "Waiting for Reflector from Arch ISO..."
# This mirrorlist will copied to new Arch system during installation
while timeout 180 tail --pid=$(pgrep reflector) -f /dev/null &>/dev/null; do sleep 1; done
pgrep reflector &>/dev/null && log_fail "Reflector timeout after 180 seconds" && exit 1
rm -f /var/lib/pacman/db.lck # Remove pacman lock file if exists
timedatectl set-ntp true # Set time
# Make sure everything is unmounted before start install
swapoff -a || true
if [[ "$(umount -f -A -R /mnt 2>&1)" == *"target is busy"* ]]; then
# If umount is busy execute fuser
fuser -km /mnt || true
umount -f -A -R /mnt || true
fi
wait # Wait for sub process
cryptsetup close cryptroot || true
vgchange -an || true
# Temporarily disable ECN (prevent traffic problems with some old routers)
[ "$ARCH_OS_ECN_ENABLED" = "false" ] && sysctl net.ipv4.tcp_ecn=0
pacman -Sy --noconfirm archlinux-keyring # Update keyring
process_return 0
) &>"$PROCESS_LOG" &
process_capture $! "$process_name"
}
# ---------------------------------------------------------------------------------------------------
exec_prepare_disk() {
local process_name="Prepare Disk"
process_init "$process_name"
(
[ "$DEBUG" = "true" ] && sleep 1 && process_return 0 # If debug mode then return
# Wipe and create partitions
wipefs -af "$ARCH_OS_DISK" # Remove All Filesystem Signatures
sgdisk --zap-all "$ARCH_OS_DISK" # Remove the Partition Table
sgdisk -o "$ARCH_OS_DISK" # Create new GPT partition table
sgdisk -n 1:0:+1G -t 1:ef00 -c 1:boot --align-end "$ARCH_OS_DISK" # Create partition /boot efi partition: 1 GiB
sgdisk -n 2:0:0 -t 2:8300 -c 2:root --align-end "$ARCH_OS_DISK" # Create partition / partition: Rest of space
partprobe "$ARCH_OS_DISK" # Reload partition table
# Disk encryption
if [ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ]; then
log_info "Enable Disk Encryption for ${ARCH_OS_ROOT_PARTITION}"
echo -n "$ARCH_OS_PASSWORD" | cryptsetup luksFormat "$ARCH_OS_ROOT_PARTITION"
echo -n "$ARCH_OS_PASSWORD" | cryptsetup open "$ARCH_OS_ROOT_PARTITION" cryptroot
fi
# Format disk
mkfs.fat -F 32 -n BOOT "$ARCH_OS_BOOT_PARTITION"
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ] && mkfs.ext4 -F -L ROOT /dev/mapper/cryptroot
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "false" ] && mkfs.ext4 -F -L ROOT "$ARCH_OS_ROOT_PARTITION"
# Mount disk to /mnt
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ] && mount -v /dev/mapper/cryptroot /mnt
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "false" ] && mount -v "$ARCH_OS_ROOT_PARTITION" /mnt
mkdir -p /mnt/boot
mount -v "$ARCH_OS_BOOT_PARTITION" /mnt/boot
# Return
process_return 0
) &>"$PROCESS_LOG" &
process_capture $! "$process_name"
}
# ---------------------------------------------------------------------------------------------------
exec_pacstrap_core() {
local process_name="Pacstrap Arch OS Core"
process_init "$process_name"
(
[ "$DEBUG" = "true" ] && sleep 1 && process_return 0 # If debug mode then return
# Core packages
local packages=("$ARCH_OS_KERNEL" base sudo linux-firmware zram-generator networkmanager)
# Add microcode package
[ -n "$ARCH_OS_MICROCODE" ] && [ "$ARCH_OS_MICROCODE" != "none" ] && packages+=("$ARCH_OS_MICROCODE")
# Install core packages and initialize an empty pacman keyring in the target
pacstrap -K /mnt "${packages[@]}"
# Generate /etc/fstab
genfstab -U /mnt >>/mnt/etc/fstab
# Set timezone & system clock
arch-chroot /mnt ln -sf "/usr/share/zoneinfo/${ARCH_OS_TIMEZONE}" /etc/localtime
arch-chroot /mnt hwclock --systohc # Set hardware clock from system clock
{ # Create swap (zram-generator with zstd compression)
# https://wiki.archlinux.org/title/Zram#Using_zram-generator
echo '[zram0]'
echo 'zram-size = ram / 2'
echo 'compression-algorithm = zstd'
} >/mnt/etc/systemd/zram-generator.conf
{ # Optimize swap on zram (https://wiki.archlinux.org/title/Zram#Optimizing_swap_on_zram)
echo 'vm.swappiness = 180'
echo 'vm.watermark_boost_factor = 0'
echo 'vm.watermark_scale_factor = 125'
echo 'vm.page-cluster = 0'
} >/mnt/etc/sysctl.d/99-vm-zram-parameters.conf
# Set console keymap in /etc/vconsole.conf
echo "KEYMAP=$ARCH_OS_VCONSOLE_KEYMAP" >/mnt/etc/vconsole.conf
[ -n "$ARCH_OS_VCONSOLE_FONT" ] && echo "FONT=$ARCH_OS_VCONSOLE_FONT" >>/mnt/etc/vconsole.conf
# Set & Generate Locale
echo "LANG=${ARCH_OS_LOCALE_LANG}.UTF-8" >/mnt/etc/locale.conf
for ((i = 0; i < ${#ARCH_OS_LOCALE_GEN_LIST[@]}; i++)); do sed -i "s/^#${ARCH_OS_LOCALE_GEN_LIST[$i]}/${ARCH_OS_LOCALE_GEN_LIST[$i]}/g" "/mnt/etc/locale.gen"; done
arch-chroot /mnt locale-gen
# Set hostname & hosts
echo "$ARCH_OS_HOSTNAME" >/mnt/etc/hostname
{
echo '# <ip> <hostname.domain.org> <hostname>'
echo '127.0.0.1 localhost.localdomain localhost'
echo '::1 localhost.localdomain localhost'
} >/mnt/etc/hosts
# Create initial ramdisk from /etc/mkinitcpio.conf
# https://wiki.archlinux.org/title/Mkinitcpio#Common_hooks
# https://wiki.archlinux.org/title/Microcode#mkinitcpio
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ] && sed -i "s/^HOOKS=(.*)$/HOOKS=(base systemd keyboard autodetect microcode modconf sd-vconsole block sd-encrypt filesystems fsck)/" /mnt/etc/mkinitcpio.conf
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "false" ] && sed -i "s/^HOOKS=(.*)$/HOOKS=(base systemd keyboard autodetect microcode modconf sd-vconsole block filesystems fsck)/" /mnt/etc/mkinitcpio.conf
arch-chroot /mnt mkinitcpio -P
# Install Bootloader to /boot (systemdboot)
arch-chroot /mnt bootctl --esp-path=/boot install # Install systemdboot to /boot
# Kernel args
# Zswap should be disabled when using zram (https://github.com/archlinux/archinstall/issues/881)
# Silent boot: https://wiki.archlinux.org/title/Silent_boot
local kernel_args=()
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ] && kernel_args+=("rd.luks.name=$(blkid -s UUID -o value "${ARCH_OS_ROOT_PARTITION}")=cryptroot" "root=/dev/mapper/cryptroot")
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "false" ] && kernel_args+=("root=PARTUUID=$(lsblk -dno PARTUUID "${ARCH_OS_ROOT_PARTITION}")")
kernel_args+=('rw' 'init=/usr/lib/systemd/systemd' 'zswap.enabled=0')
[ "$ARCH_OS_CORE_TWEAKS_ENABLED" = "true" ] && kernel_args+=('nowatchdog')
[ "$ARCH_OS_BOOTSPLASH_ENABLED" = "true" ] || [ "$ARCH_OS_CORE_TWEAKS_ENABLED" = "true" ] && kernel_args+=('quiet' 'splash' 'vt.global_cursor_default=0')
{ # Create Bootloader config
echo 'default arch.conf'
echo 'console-mode auto'
echo 'timeout 0'
echo 'editor yes'
} >/mnt/boot/loader/loader.conf
{ # Create default boot entry
echo 'title Arch OS'
echo "linux /vmlinuz-${ARCH_OS_KERNEL}"
echo "initrd /initramfs-${ARCH_OS_KERNEL}.img"
echo "options ${kernel_args[*]}"
} >/mnt/boot/loader/entries/arch.conf
{ # Create fallback boot entry
echo 'title Arch OS (Fallback)'
echo "linux /vmlinuz-${ARCH_OS_KERNEL}"
echo "initrd /initramfs-${ARCH_OS_KERNEL}-fallback.img"
echo "options ${kernel_args[*]}"
} >/mnt/boot/loader/entries/arch-fallback.conf
# Create new user
arch-chroot /mnt useradd -m -G wheel -s /bin/bash "$ARCH_OS_USERNAME"
# Create user dirs
mkdir -p "/mnt/home/${ARCH_OS_USERNAME}/.config"
mkdir -p "/mnt/home/${ARCH_OS_USERNAME}/.local/share"
arch-chroot /mnt chown -R "$ARCH_OS_USERNAME":"$ARCH_OS_USERNAME" "/home/${ARCH_OS_USERNAME}"
# Allow users in group wheel to use sudo
sed -i 's^# %wheel ALL=(ALL:ALL) ALL^%wheel ALL=(ALL:ALL) ALL^g' /mnt/etc/sudoers
# Change passwords
printf "%s\n%s" "${ARCH_OS_PASSWORD}" "${ARCH_OS_PASSWORD}" | arch-chroot /mnt passwd
printf "%s\n%s" "${ARCH_OS_PASSWORD}" "${ARCH_OS_PASSWORD}" | arch-chroot /mnt passwd "$ARCH_OS_USERNAME"
# Enable services
arch-chroot /mnt systemctl enable NetworkManager # Network Manager
arch-chroot /mnt systemctl enable fstrim.timer # SSD support
arch-chroot /mnt systemctl enable [email protected] # Swap (zram-generator)
arch-chroot /mnt systemctl enable systemd-oomd.service # Out of memory killer (swap is required)
arch-chroot /mnt systemctl enable systemd-boot-update.service # Auto bootloader update
arch-chroot /mnt systemctl enable systemd-timesyncd.service # Sync time from internet after boot
# Make some Arch OS tweaks
if [ "$ARCH_OS_CORE_TWEAKS_ENABLED" = "true" ]; then
# Add password feedback
echo -e "\n## Enable sudo password feedback\nDefaults pwfeedback" >>/mnt/etc/sudoers
# Configure pacman parrallel downloads, colors, eyecandy
sed -i 's/^#ParallelDownloads/ParallelDownloads/' /mnt/etc/pacman.conf
sed -i 's/^#Color/Color\nILoveCandy/' /mnt/etc/pacman.conf
# Disable watchdog modules
mkdir -p /mnt/etc/modprobe.d/
echo 'blacklist sp5100_tco' >>/mnt/etc/modprobe.d/blacklist-watchdog.conf
echo 'blacklist iTCO_wdt' >>/mnt/etc/modprobe.d/blacklist-watchdog.conf
# Disable debug packages when using makepkg
sed -i '/OPTIONS=.*!debug/!s/\(OPTIONS=.*\)debug/\1!debug/' /mnt/etc/makepkg.conf
# Set max VMAs (need for some apps/games)
#echo vm.max_map_count=1048576 >/mnt/etc/sysctl.d/vm.max_map_count.conf
# Reduce shutdown timeout
#sed -i "s/^\s*#\s*DefaultTimeoutStopSec=.*/DefaultTimeoutStopSec=10s/" /mnt/etc/systemd/system.conf
fi
# Return