-
Notifications
You must be signed in to change notification settings - Fork 3
/
installer.sh
executable file
·1714 lines (1502 loc) · 83 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
# Debug simulator: MODE=debug ./installer.sh
# Custom gum: GUM=/usr/bin/gum ./installer.sh
# 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)
# SCRIPT
VERSION='1.6.4'
# GUM
GUM_VERSION="0.13.0"
# ENVIRONMENT
SCRIPT_CONFIG="./installer.conf"
SCRIPT_LOG="./installer.log"
# 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
# ---------------------------------------------------------------------------------------------------
# Loop properties step to update screen if user edit properties
while (true); do
gum_header # Show welcome screen
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'
echo
gum_title "Arch OS Properties"
# Ask for load & remove existing config file
if [ -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
rm -f "$SCRIPT_CONFIG" && gum_info "installer.conf successfully removed"
gum_warn "Please restart Arch OS Installer..."
exit 0
fi
# Source installer.conf if exists
properties_source && gum_info "installer.conf successfully loaded"
# Selectors
until select_preset; do :; done
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
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
until select_enable_desktop; do :; done
# Print success
gum_info "installer.conf successfully initialized"
# Edit properties?
if gum_confirm "Edit installer.conf manually?"; then
log_info "Edit installer.conf manually..."
local gum_header="Save with CTRL + D or ESC and cancel with CTRL + C"
if gum_write --height=10 --width=100 --header=" ${gum_header}" --value="$(cat "$SCRIPT_CONFIG")" >"${SCRIPT_CONFIG}.new"; then
mv "${SCRIPT_CONFIG}.new" "${SCRIPT_CONFIG}" && properties_source
gum_info "installer.conf successfully edited"
gum_confirm "Change Password?" && until select_password --force && properties_source; do :; done
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 "Canceled"
fi
fi
######################################################
break # Exit properties step and continue installation
######################################################
done
# ---------------------------------------------------------------------------------------------------
# Start installation in 5 seconds?
gum_confirm "Start Arch OS Installation?" || trap_gum_exit
echo && gum_title "Arch OS Installation"
local spin_title="Arch OS Installation starts in 5 seconds. Press CTRL + C to cancel..."
gum_spin --title="$spin_title" -- sleep 5 || trap_gum_exit # CTRL + C pressed
SECONDS=0 # Messure execution time of installation
# Executors
exec_init_installation
exec_prepare_disk
exec_pacstrap_core
exec_enable_multilib
exec_install_bootsplash
exec_install_aur_helper
exec_install_housekeeping
exec_install_shell_enhancement
exec_install_desktop
exec_install_graphics_driver
exec_install_archos_manager
exec_install_vm_support
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 [ "$MODE" != "debug" ]; then
cp -f "$SCRIPT_CONFIG" "/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="false"
local do_unmount="false"
gum_confirm "Reboot to Arch OS now?" && do_reboot="true" && do_unmount="true"
[ "$do_reboot" = "false" ] && gum_confirm "Unmount Arch OS from /mnt?" && do_unmount="true"
# Unmount
if [ "$do_unmount" = "true" ] && [ "$MODE" != "debug" ]; then
swapoff -a
umount -A -R /mnt
[ "$ARCH_OS_ENCRYPTION_ENABLED" = "true" ] && cryptsetup close cryptroot
fi
# Reboot
[ "$do_reboot" = "true" ] && [ "$MODE" != "debug" ] && gum_warn "Rebooting..." && reboot
exit 0
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# 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_SHELL_ENHANCEMENT_ENABLED='${ARCH_OS_SHELL_ENHANCEMENT_ENABLED}'"
echo "ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED='${ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED}'"
echo "ARCH_OS_HOUSEKEEPING_ENABLED='${ARCH_OS_HOUSEKEEPING_ENABLED}'"
echo "ARCH_OS_MANAGER_ENABLED='${ARCH_OS_MANAGER_ENABLED}'"
echo "ARCH_OS_DESKTOP_ENABLED='${ARCH_OS_DESKTOP_ENABLED}'"
echo "ARCH_OS_DESKTOP_SLIM_ENABLED='${ARCH_OS_DESKTOP_SLIM_ENABLED}'"
echo "ARCH_OS_DESKTOP_GRAPHICS_DRIVER='${ARCH_OS_DESKTOP_GRAPHICS_DRIVER}'"
echo "ARCH_OS_DESKTOP_KEYBOARD_LAYOUT='${ARCH_OS_DESKTOP_KEYBOARD_LAYOUT}'"
echo "ARCH_OS_DESKTOP_KEYBOARD_MODEL='${ARCH_OS_DESKTOP_KEYBOARD_MODEL}'"
echo "ARCH_OS_DESKTOP_KEYBOARD_VARIANT='${ARCH_OS_DESKTOP_KEYBOARD_VARIANT}'"
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
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# SELECTORS
# ////////////////////////////////////////////////////////////////////////////////////////////////////
select_preset() {
if [ ! -f "$SCRIPT_CONFIG" ]; then
local preset options
options=("desktop" "core" "custom")
preset=$(gum_choose --header "+ Choose Preset:" "${options[@]}") || trap_gum_exit_confirm
[ -z "$preset" ] && return 1 # Check if new value is null
# Default presets
ARCH_OS_HOSTNAME="arch-os"
ARCH_OS_KERNEL="linux-zen"
ARCH_OS_VM_SUPPORT_ENABLED="true"
ARCH_OS_SHELL_ENHANCEMENT_FISH_ENABLED="true"
ARCH_OS_ECN_ENABLED="true"
ARCH_OS_DESKTOP_KEYBOARD_MODEL="pc105"
# Set microcode
grep -E "GenuineIntel" &>/dev/null <<<"$(lscpu)" && ARCH_OS_MICROCODE="intel-ucode"
grep -E "AuthenticAMD" &>/dev/null <<<"$(lscpu)" && ARCH_OS_MICROCODE="amd-ucode"
# 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_AUR_HELPER='none'
ARCH_OS_DESKTOP_GRAPHICS_DRIVER="none"
fi
# Desktop preset
if [ "$preset" = "desktop" ]; then
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_AUR_HELPER='paru-bin'
ARCH_OS_MANAGER_ENABLED='true'
fi
# Write properties
properties_generate && gum_info "Preset is set to ${preset}"
fi
}
# ---------------------------------------------------------------------------------------------------
select_username() {
if [ -z "$ARCH_OS_USERNAME" ]; then
local user_input
user_input=$(gum_input --header "+ Enter Username (mandatory)") || 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_info "Username is set to ${ARCH_OS_USERNAME}"
}
# ---------------------------------------------------------------------------------------------------
select_password() { # --force
if [ "$1" = "--force" ] || [ -z "$ARCH_OS_PASSWORD" ]; then
local user_password user_password_check
user_password=$(gum_input --password --header "+ Enter Password (mandatory)") || 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
[ "$user_password" != "$user_password_check" ] && gum_fail "Passwords not identical" && return 1
ARCH_OS_PASSWORD="$user_password" && properties_generate # Set value and generate properties file
fi
gum_info "Password is set to *******"
}
# ---------------------------------------------------------------------------------------------------
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)" --value "$tz_auto") || trap_gum_exit_confirm
[ -z "$user_input" ] && return 1 # Check if new value is null
[ ! -f "/usr/share/zoneinfo/${user_input}" ] && gum_fail "Timezone '${user_input}' is not supported" && return 1
ARCH_OS_TIMEZONE="$user_input" && properties_generate # Set property and generate properties file
fi
gum_info "Timezone is set to ${ARCH_OS_TIMEZONE}"
}
# ---------------------------------------------------------------------------------------------------
# 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_info "Language is set to ${ARCH_OS_LOCALE_LANG}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Keyboard is set to ${ARCH_OS_VCONSOLE_KEYMAP}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Disk is set to ${ARCH_OS_DISK}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Disk Encryption is set to ${ARCH_OS_ENCRYPTION_ENABLED}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Core Tweaks is set to ${ARCH_OS_CORE_TWEAKS_ENABLED}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Bootsplash is set to ${ARCH_OS_BOOTSPLASH_ENABLED}"
}
# ---------------------------------------------------------------------------------------------------
select_enable_desktop() {
local user_input options
# Select desktop environment
if [ -z "$ARCH_OS_DESKTOP_ENABLED" ]; then
gum_confirm "Enable 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_info "Desktop Environment is set to ${ARCH_OS_DESKTOP_ENABLED}"
# Return if desktop disabled
[ "$ARCH_OS_DESKTOP_ENABLED" = "false" ] && return 0
# Slim Mode
if [ -z "$ARCH_OS_DESKTOP_SLIM_ENABLED" ]; then
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_info "Desktop Slim Mode is set to ${ARCH_OS_DESKTOP_SLIM_ENABLED}"
# Keyboard layout
if [ -z "$ARCH_OS_DESKTOP_KEYBOARD_LAYOUT" ]; then
user_input=$(gum_input --header "+ Enter Desktop Keyboard Layout (mandatory)" --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"
user_input=$(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_input"
properties_generate
fi
gum_info "Desktop Keyboard Layout is set to ${ARCH_OS_DESKTOP_KEYBOARD_LAYOUT}"
[ -n "$ARCH_OS_DESKTOP_KEYBOARD_VARIANT" ] && gum_info "Desktop Keyboard Variant is set to ${ARCH_OS_DESKTOP_KEYBOARD_VARIANT}"
# Graphics driver
if [ -z "$ARCH_OS_DESKTOP_GRAPHICS_DRIVER" ] || [ "$ARCH_OS_DESKTOP_GRAPHICS_DRIVER" = "none" ]; then
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_info "Desktop Graphics Driver is set to ${ARCH_OS_DESKTOP_GRAPHICS_DRIVER}"
return 0
}
# ---------------------------------------------------------------------------------------------------
select_enable_aur() {
if [ -z "$ARCH_OS_AUR_HELPER" ]; then
gum_confirm "Enable AUR Helper?"
local user_confirm=$?
[ $user_confirm = 130 ] && {
trap_gum_exit_confirm
return 1
}
local user_input
[ $user_confirm = 1 ] && user_input="none"
[ $user_confirm = 0 ] && user_input="paru-bin"
ARCH_OS_AUR_HELPER="$user_input" && properties_generate # Set value and generate properties file
fi
gum_info "AUR Helper is set to ${ARCH_OS_AUR_HELPER}"
}
# ---------------------------------------------------------------------------------------------------
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_info "32 Bit Support is set to ${ARCH_OS_MULTILIB_ENABLED}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Housekeeping is set to ${ARCH_OS_HOUSEKEEPING_ENABLED}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Shell Enhancement is set to ${ARCH_OS_SHELL_ENHANCEMENT_ENABLED}"
}
# ---------------------------------------------------------------------------------------------------
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_info "Arch OS Manager is set to ${ARCH_OS_MANAGER_ENABLED}"
}
# ////////////////////////////////////////////////////////////////////////////////////////////////////
# EXECUTORS (SUB PROCESSES)
# ////////////////////////////////////////////////////////////////////////////////////////////////////
exec_init_installation() {
local process_name="Initialize Installation"
process_init "$process_name"
(
[ "$MODE" = "debug" ] && 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"
(
[ "$MODE" = "debug" ] && 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 System"
process_init "$process_name"
(
[ "$MODE" = "debug" ] && 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'
echo 'swap-priority = 100'
echo 'fs-type = swap'
} >/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 '127.0.0.1 localhost'
echo '::1 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
process_return 0
) &>"$PROCESS_LOG" &
process_capture $! "$process_name"
}
# ---------------------------------------------------------------------------------------------------
exec_install_desktop() {
local process_name="Install Desktop Environment"
if [ "$ARCH_OS_DESKTOP_ENABLED" = "true" ]; then
process_init "$process_name"
(
[ "$MODE" = "debug" ] && sleep 1 && process_return 0 # If debug mode then return
# GNOME base packages
local packages=(gnome gnome-tweaks gnome-browser-connector gnome-themes-extra power-profiles-daemon rygel cups gnome-epub-thumbnailer)
[ "$ARCH_OS_DESKTOP_SLIM_ENABLED" = "false" ] && packages+=(gnome-firmware file-roller)
# GNOME wayland screensharing, flatpak & pipewire support
packages+=(xdg-utils xdg-desktop-portal xdg-desktop-portal-gtk xdg-desktop-portal-gnome flatpak-xdg-utils)
# Audio (Pipewire replacements + session manager)
packages+=(pipewire pipewire-alsa pipewire-pulse pipewire-jack wireplumber)
[ "$ARCH_OS_MULTILIB_ENABLED" = "true" ] && packages+=(lib32-pipewire lib32-pipewire-jack)
# Networking & Access
packages+=(samba gvfs gvfs-mtp gvfs-smb gvfs-nfs gvfs-afc gvfs-goa gvfs-gphoto2 gvfs-google gvfs-dnssd gvfs-wsdd)
# Utils (https://wiki.archlinux.org/title/File_systems)
packages+=(fwupd bash-completion git dhcp net-tools inetutils nfs-utils f2fs-tools udftools dosfstools ntfs-3g exfat-utils p7zip zip unzip unrar tar)
# Certificates
packages+=(ca-certificates)
# Codecs (https://wiki.archlinux.org/title/Codecs_and_containers)
packages+=(ffmpeg ffmpegthumbnailer gstreamer gst-libav gst-plugin-pipewire gst-plugins-good gst-plugins-bad gst-plugins-ugly libdvdcss libheif webp-pixbuf-loader)
packages+=(a52dec faac faad2 flac jasper lame libdca libdv libmad libmpeg2 libtheora libvorbis libxv wavpack x264 xvidcore libdvdnav libdvdread openh264)
[ "$ARCH_OS_MULTILIB_ENABLED" = "true" ] && packages+=(lib32-gstreamer lib32-gst-plugins-good)
# Optimization
packages+=(gamemode)
[ "$ARCH_OS_MULTILIB_ENABLED" = "true" ] && packages+=(lib32-gamemode)
# Fonts
packages+=(noto-fonts noto-fonts-emoji ttf-firacode-nerd ttf-liberation ttf-dejavu)
# Theming
packages+=(adw-gtk-theme)
# Install packages
chroot_pacman_install "${packages[@]}"
# Force remove packages
if [ "$ARCH_OS_DESKTOP_SLIM_ENABLED" = "true" ]; then
chroot_pacman_remove gnome-calendar || true
chroot_pacman_remove gnome-maps || true
chroot_pacman_remove gnome-contacts || true
chroot_pacman_remove gnome-font-viewer || true
chroot_pacman_remove gnome-characters || true
chroot_pacman_remove gnome-clocks || true
chroot_pacman_remove gnome-connections || true
chroot_pacman_remove gnome-music || true
chroot_pacman_remove gnome-weather || true
chroot_pacman_remove gnome-calculator || true
chroot_pacman_remove gnome-logs || true
chroot_pacman_remove gnome-text-editor || true
chroot_pacman_remove gnome-disk-utility || true
chroot_pacman_remove simple-scan || true
chroot_pacman_remove baobab || true
chroot_pacman_remove totem || true
chroot_pacman_remove snapshot || true
chroot_pacman_remove loupe || true
chroot_pacman_remove epiphany || true
#chroot_pacman_remove evince || true # Need for sushi
fi
# Add user to gamemode group
arch-chroot /mnt gpasswd -a "$ARCH_OS_USERNAME" gamemode
# Enable GNOME auto login
mkdir -p /mnt/etc/gdm
[ -f /mnt/etc/gdm/custom.conf ] && mv /mnt/etc/gdm/custom.conf /mnt/etc/gdm/custom.conf.bak
#grep -qrnw /mnt/etc/gdm/custom.conf -e "AutomaticLoginEnable" || sed -i "s/^\[security\]/AutomaticLoginEnable=True\nAutomaticLogin=${ARCH_OS_USERNAME}\n\n\[security\]/g" /mnt/etc/gdm/custom.conf
{
echo "[daemon]"
echo "WaylandEnable=True"
echo ""
echo "AutomaticLoginEnable=True"
echo "AutomaticLogin=${ARCH_OS_USERNAME}"
echo ""
echo "[debug]"
echo "Enable=False"
} >/mnt/etc/gdm/custom.conf
# Set git-credential-libsecret in ~/.gitconfig
arch-chroot /mnt /usr/bin/runuser -u "$ARCH_OS_USERNAME" -- git config --global credential.helper /usr/lib/git-core/git-credential-libsecret
# GnuPG integration (https://wiki.archlinux.org/title/GNOME/Keyring#GnuPG_integration)
mkdir -p "/mnt/home/${ARCH_OS_USERNAME}/.gnupg"
echo 'pinentry-program /usr/bin/pinentry-gnome3' >"/mnt/home/${ARCH_OS_USERNAME}/.gnupg/gpg-agent.conf"
# Set environment
mkdir -p "/mnt/home/${ARCH_OS_USERNAME}/.config/environment.d/"
# shellcheck disable=SC2016
{
echo '# SSH AGENT'
echo 'SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gcr/ssh' # Set gcr sock (https://wiki.archlinux.org/title/GNOME/Keyring#Setup_gcr)
echo ''
echo '# PATH'
echo 'PATH="${PATH}:${HOME}/.local/bin"'
echo 'PATH="${PATH}:/var/lib/flatpak/exports/bin"'
echo ''
echo '# XDG'
echo 'XDG_CONFIG_HOME="${HOME}/.config"'
echo 'XDG_DATA_HOME="${HOME}/.local/share"'
echo 'XDG_STATE_HOME="${HOME}/.local/state"'
echo 'XDG_CACHE_HOME="${HOME}/.cache" '
} >"/mnt/home/${ARCH_OS_USERNAME}/.config/environment.d/00-arch.conf"
# Samba
mkdir -p "/mnt/etc/samba/"
{
echo "[global]"
echo " workgroup = WORKGROUP"
echo " log file = /var/log/samba/%m"
} >/mnt/etc/samba/smb.conf
# Set X11 keyboard layout in /etc/X11/xorg.conf.d/00-keyboard.conf
mkdir -p /mnt/etc/X11/xorg.conf.d/
{
echo 'Section "InputClass"'
echo ' Identifier "system-keyboard"'
echo ' MatchIsKeyboard "yes"'
echo ' Option "XkbLayout" "'"${ARCH_OS_DESKTOP_KEYBOARD_LAYOUT}"'"'
echo ' Option "XkbModel" "'"${ARCH_OS_DESKTOP_KEYBOARD_MODEL}"'"'
echo ' Option "XkbVariant" "'"${ARCH_OS_DESKTOP_KEYBOARD_VARIANT}"'"'
echo 'EndSection'
} >/mnt/etc/X11/xorg.conf.d/00-keyboard.conf
# Enable Arch OS Desktop services
arch-chroot /mnt systemctl enable gdm.service # GNOME
arch-chroot /mnt systemctl enable bluetooth.service # Bluetooth
arch-chroot /mnt systemctl enable avahi-daemon # Network browsing service
arch-chroot /mnt systemctl enable power-profiles-daemon # Power daemon
arch-chroot /mnt systemctl enable cups.socket # Printer
arch-chroot /mnt systemctl enable smb.service # Samba
arch-chroot /mnt systemctl enable nmb.service # Samba
arch-chroot /mnt systemctl enable gpm.service # TTY Mouse Support
arch-chroot /mnt /usr/bin/runuser -u "$ARCH_OS_USERNAME" -- systemctl enable --user pipewire.service # Pipewire
arch-chroot /mnt /usr/bin/runuser -u "$ARCH_OS_USERNAME" -- systemctl enable --user pipewire-pulse.service # Pipewire
arch-chroot /mnt /usr/bin/runuser -u "$ARCH_OS_USERNAME" -- systemctl enable --user wireplumber.service # Pipewire
arch-chroot /mnt /usr/bin/runuser -u "$ARCH_OS_USERNAME" -- systemctl enable --user gcr-ssh-agent.socket # GCR ssh-agent
# Create users applications dir
mkdir -p "/mnt/home/${ARCH_OS_USERNAME}/.local/share/applications"
# Create UEFI Boot desktop entry
#{
# echo '[Desktop Entry]'
# echo 'Name=Reboot to UEFI'
# echo 'Icon=system-reboot'
# echo 'Exec=systemctl reboot --firmware-setup'
# echo 'Type=Application'
# echo 'Terminal=false'
#} >"/mnt/home/${ARCH_OS_USERNAME}/.local/share/applications/systemctl-reboot-firmware.desktop"
# Hide desktop Aaplications icons
echo -e '[Desktop Entry]\nType=Application\nHidden=true' >"/mnt/home/${ARCH_OS_USERNAME}/.local/share/applications/bssh.desktop"
echo -e '[Desktop Entry]\nType=Application\nHidden=true' >"/mnt/home/${ARCH_OS_USERNAME}/.local/share/applications/bvnc.desktop"
echo -e '[Desktop Entry]\nType=Application\nHidden=true' >"/mnt/home/${ARCH_OS_USERNAME}/.local/share/applications/avahi-discover.desktop"
echo -e '[Desktop Entry]\nType=Application\nHidden=true' >"/mnt/home/${ARCH_OS_USERNAME}/.local/share/applications/qv4l2.desktop"