-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup.sh
executable file
·1013 lines (801 loc) · 30.1 KB
/
setup.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/bash
################################################
##### Time
################################################
# References:
# https://wiki.archlinux.org/title/System_time#Time_zone
# https://wiki.archlinux.org/title/Systemd-timesyncd
# Enable systemd-timesyncd
systemctl enable systemd-timesyncd.service
# Set timezone
ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
hwclock --systohc --utc
################################################
##### Locale and keymap
################################################
# Set locale
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
echo "LANG=\"en_US.UTF-8\"" > /etc/locale.conf
locale-gen
# Set keymap
echo "KEYMAP=us" > /etc/vconsole.conf
################################################
##### Hostname
################################################
# Set hostname
echo ${NEW_HOSTNAME} > /etc/hostname
# Set /etc/hosts
tee /etc/hosts << EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 ${NEW_HOSTNAME}.localdomain ${NEW_HOSTNAME}
EOF
################################################
##### Pacman
################################################
# References:
# https://wiki.archlinux.org/title/Pacman/Package_signing#Initializing_the_keyring
if [ ${STEAM_NATIVE} = "yes" ]; then
# Enable multilib repository
sed -i '/#\[multilib\]/{N;s/#\[multilib\]\n#Include = \/etc\/pacman.d\/mirrorlist/\[multilib\]\nInclude = \/etc\/pacman.d\/mirrorlist/}' /etc/pacman.conf
fi
# Always ignore amdvlk packages
# sed -i '/^#IgnorePkg/s/^#//' /etc/pacman.conf
# sed -i '/^IgnorePkg/s/$/ amdvlk lib32-amdvlk/' /etc/pacman.conf
# Force pacman to refresh the package lists
pacman -Syyu --noconfirm
# Initialize Pacman's keyring
pacman-key --init
pacman-key --populate
# Configure Pacman
sed -i "s|^#Color|Color|g" /etc/pacman.conf
sed -i "s|^#VerbosePkgLists|VerbosePkgLists|g" /etc/pacman.conf
sed -i "s|^#ParallelDownloads.*|ParallelDownloads = 5|g" /etc/pacman.conf
sed -i "/ParallelDownloads = 5/a ILoveCandy" /etc/pacman.conf
# Upgrade system
pacman -Syy
################################################
##### Common applications
################################################
# Install common applications
pacman -S --noconfirm \
coreutils \
htop \
git \
p7zip \
unzip \
unrar \
lm_sensors \
upower \
nano \
wget \
openssh \
fwupd \
zstd \
lzop \
man-db \
man-pages \
e2fsprogs \
util-linux \
rsync \
jq \
yq \
lazygit \
ripgrep \
fd \
gptfdisk \
bc \
cpupower \
procps-ng \
gawk \
fzf \
findutils \
net-tools
# Add AppImage support
pacman -S --noconfirm fuse3
# Updater helper
tee /usr/local/bin/update-all << EOF
#!/usr/bin/bash
################################################
##### System and firmware
################################################
# Update keyring
sudo pacman -Sy --noconfirm archlinux-keyring
# Update all packages
paru -Syyu
# Update firmware
sudo fwupdmgr refresh
sudo fwupdmgr update
################################################
##### Flatpaks
################################################
# Update Flatpak apps
flatpak update -y
flatpak uninstall -y --unused
EOF
chmod +x /usr/local/bin/update-all
################################################
##### zram (swap)
################################################
# References:
# https://wiki.archlinux.org/title/Zram#Using_zram-generator
# https://wiki.archlinux.org/title/swap#Swappiness
# https://wiki.archlinux.org/title/Improving_performance#zram_or_zswap
# https://wiki.gentoo.org/wiki/Zram
# https://www.reddit.com/r/Fedora/comments/mzun99/new_zram_tuning_benchmarks/
# https://github.com/systemd/zram-generator
# Install zram generator
pacman -S --noconfirm zram-generator
# Configure zram generator
tee /etc/systemd/zram-generator.conf << EOF
[zram0]
zram-size = ram / 4
compression-algorithm = zstd
EOF
# Daemon reload
systemctl daemon-reload
# Enable zram on boot
systemctl start /dev/zram0
# Set page cluster
echo 'vm.page-cluster=0' > /etc/sysctl.d/99-page-cluster.conf
# Set swappiness
echo 'vm.swappiness=10' > /etc/sysctl.d/99-swappiness.conf
# Set vfs cache pressure
echo 'vm.vfs_cache_pressure=50' > /etc/sysctl.d/99-vfs-cache-pressure.conf
################################################
##### Tweaks
################################################
# References:
# https://github.com/CryoByte33/steam-deck-utilities/blob/main/docs/tweak-explanation.md
# https://wiki.cachyos.org/configuration/general_system_tweaks/
# https://gitlab.com/cscs/maxperfwiz/-/blob/master/maxperfwiz?ref_type=heads
# Set reverse path filtering to strict mode
tee /etc/sysctl.d/99-reverse-path-filtering.conf << EOF
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.all.rp_filter=1
EOF
# Enable trim operations
systemctl enable fstrim.timer
# Sysctl tweaks
COMPUTER_MEMORY=$(echo $(vmstat -sS M | head -n1 | awk '{print $1;}'))
MEMORY_BY_CORE=$(echo $(( $(vmstat -s | head -n1 | awk '{print $1;}')/$(nproc) )))
BEST_KEEP_FREE=$(echo "scale=0; "$MEMORY_BY_CORE"*0.058" | bc | awk '{printf "%.0f\n", $1}')
tee /etc/sysctl.d/99-performance-tweaks.conf << EOF
kernel.nmi_watchdog=0
kernel.split_lock_mitigate=0
vm.compaction_proactiveness=0
vm.page_lock_unfairness=1
$(if [[ ${COMPUTER_MEMORY} > 13900 ]]; then echo "vm.dirty_bytes=419430400"; fi)
$(if [[ ${COMPUTER_MEMORY} > 13900 ]]; then echo "vm.dirty_background_bytes=209715200"; fi)
$(if [[ $(cat /sys/block/*/queue/rotational) == 0 ]]; then echo "vm.dirty_expire_centisecs=500"; else echo "vm.dirty_expire_centisecs=3000"; fi)
$(if [[ $(cat /sys/block/*/queue/rotational) == 0 ]]; then echo "vm.dirty_writeback_centisecs=250"; else echo "vm.dirty_writeback_centisecs=1500"; fi)
vm.min_free_kbytes=${BEST_KEEP_FREE}
EOF
# Udev tweaks
tee /etc/udev/rules.d/99-performance-tweaks.rules << 'EOF'
ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="none"
ACTION=="add|change", KERNEL=="sd[a-z]|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"
EOF
# Hugepage Defragmentation - default: 1
# Transparent Hugepages - default: always
# Shared Memory in Transparent Hugepages - default: never
tee /etc/systemd/system/kernel-tweaks.service << 'EOF'
[Unit]
Description=Set kernel tweaks
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/usr/bin/bash -c 'echo always > /sys/kernel/mm/transparent_hugepage/enabled'
ExecStart=/usr/bin/bash -c 'echo advise > /sys/kernel/mm/transparent_hugepage/shmem_enabled'
ExecStart=/usr/bin/bash -c 'echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag'
[Install]
WantedBy=multi-user.target
EOF
systemctl enable kernel-tweaks.service
# Disable watchdog timer drivers
# sudo dmesg | grep -e sp5100 -e iTCO -e wdt -e tco
tee /etc/modprobe.d/disable-watchdog-drivers.conf << 'EOF'
blacklist sp5100_tco
blacklist iTCO_wdt
blacklist iTCO_vendor_support
EOF
# Disable broadcast messages
tee /etc/systemd/system/disable-broadcast-messages.service << 'EOF'
[Unit]
Description=Disable broadcast messages
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/usr/bin/busctl set-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager EnableWallMessages b false
[Install]
WantedBy=multi-user.target
EOF
systemctl enable disable-broadcast-messages.service
################################################
##### Users
################################################
# References:
# https://wiki.archlinux.org/title/XDG_Base_Directory
# Install ZSH and dependencies
pacman -S --noconfirm zsh
# Set root password and shell
echo "root:${NEW_USER_PASSWORD}" | chpasswd
chsh -s /usr/bin/zsh
# Setup user
useradd -m -G wheel -s /usr/bin/zsh ${NEW_USER}
echo "${NEW_USER}:${NEW_USER_PASSWORD}" | chpasswd
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
# Create XDG user directories
pacman -S --noconfirm xdg-user-dirs
sudo -u ${NEW_USER} xdg-user-dirs-update
# Create common directories and configure them
mkdir -p \
/home/${NEW_USER}/.local/share/applications \
/home/${NEW_USER}/.local/share/themes \
/home/${NEW_USER}/.local/share/fonts \
/home/${NEW_USER}/.config/autostart \
/home/${NEW_USER}/.config/environment.d \
/home/${NEW_USER}/.config/autostart \
/home/${NEW_USER}/.config/systemd/user \
/home/${NEW_USER}/.icons \
/home/${NEW_USER}/Projects
# Create SSH directory and config file
mkdir -p /home/${NEW_USER}/.ssh
chown 700 /home/${NEW_USER}/.ssh
tee /home/${NEW_USER}/.ssh/config << EOF
Host *
ServerAliveInterval 60
EOF
# Create zsh configs directory
mkdir -p /home/${NEW_USER}/.zshrc.d
# Configure ZSH
curl https://raw.githubusercontent.com/gjpin/arch-linux/main/configs/zsh/.zshrc -o /home/${NEW_USER}/.zshrc
# Configure powerlevel10k zsh theme
curl https://raw.githubusercontent.com/gjpin/arch-linux/main/configs/zsh/.p10k.zsh -o /home/${NEW_USER}/.p10k.zsh
################################################
##### Networking
################################################
# References:
# https://wiki.archlinux.org/title/NetworkManager#Using_iwd_as_the_Wi-Fi_backend
# https://wiki.archlinux.org/title/Firewalld
# https://wiki.archlinux.org/title/nftables
# Install and configure firewalld
pacman -S --noconfirm firewalld
systemctl enable firewalld.service
# Set default zone to home
firewall-offline-cmd --set-default-zone=home
# Disable firewall-applet
sed -i '/^Exec/d' /etc/xdg/autostart/firewall-applet.desktop
chattr +i /etc/xdg/autostart/firewall-applet.desktop
# Install and enable NetworkManager
pacman -S --noconfirm networkmanager
systemctl enable NetworkManager.service
# Install bind tools
pacman -S --noconfirm bind
# Install nftables
pacman -S --noconfirm iptables-nft --ask 4
################################################
##### initramfs
################################################
# References:
# https://wiki.archlinux.org/title/RAID#Configure_mkinitcpio
# Configure mkinitcpio
sed -i "s|MODULES=()|MODULES=(ext4${MKINITCPIO_MODULES})|" /etc/mkinitcpio.conf
sed -i "s|^HOOKS.*|HOOKS=(systemd autodetect keyboard sd-vconsole modconf block $(if [ ${RAID0} = "yes" ]; then echo "mdadm_udev"; fi) sd-encrypt filesystems fsck)|" /etc/mkinitcpio.conf
sed -i "s|#COMPRESSION=\"zstd\"|COMPRESSION=\"zstd\"|" /etc/mkinitcpio.conf
sed -i "s|#COMPRESSION_OPTIONS=()|COMPRESSION_OPTIONS=(-2)|" /etc/mkinitcpio.conf
# Re-create initramfs image
mkinitcpio -P
################################################
##### systemd-boot
################################################
# References:
# https://wiki.archlinux.org/title/systemd-boot
# https://wiki.archlinux.org/title/RAID#RAID0_layout
# https://wiki.archlinux.org/title/CPU_frequency_scaling#amd_pstate
# Install systemd-boot to the ESP
bootctl install
# systemd-boot upgrade hook
mkdir -p /etc/pacman.d/hooks
tee /etc/pacman.d/hooks/95-systemd-boot.hook << 'EOF'
[Trigger]
Type = Package
Operation = Upgrade
Target = systemd
[Action]
Description = Gracefully upgrading systemd-boot...
When = PostTransaction
Exec = /usr/bin/systemctl restart systemd-boot-update.service
EOF
# systemd-boot configuration
tee /boot/loader/loader.conf << 'EOF'
default arch.conf
timeout 0
console-mode max
editor no
EOF
tee /boot/loader/entries/arch.conf << EOF
title Arch Linux
linux /vmlinuz-linux
initrd /${CPU_MICROCODE}.img
initrd /initramfs-linux.img
options $(if [ ${RAID0} = "yes" ]; then echo "raid0.default_layout=2"; fi) rd.luks.name=$(if [ ${RAID0} = "no" ]; then blkid -s UUID -o value /dev/nvme0n1p2; elif [ ${RAID0} = "yes" ]; then blkid -s UUID -o value /dev/md/ArchArray;fi)=system root=/dev/mapper/system ${AMD_SCALING_DRIVER} zswap.enabled=0 nowatchdog quiet loglevel=3 systemd.show_status=auto rd.udev.log_level=3 vt.global_cursor_default=0 splash rw
EOF
tee /boot/loader/entries/arch-lts.conf << EOF
title Arch Linux LTS
linux /vmlinuz-linux-lts
initrd /${CPU_MICROCODE}.img
initrd /initramfs-linux-lts.img
options $(if [ ${RAID0} = "yes" ]; then echo "raid0.default_layout=2"; fi) rd.luks.name=$(if [ ${RAID0} = "no" ]; then blkid -s UUID -o value /dev/nvme0n1p2; elif [ ${RAID0} = "yes" ]; then blkid -s UUID -o value /dev/md/ArchArray;fi)=system root=/dev/mapper/system ${AMD_SCALING_DRIVER} zswap.enabled=0 nowatchdog quiet loglevel=3 systemd.show_status=auto rd.udev.log_level=3 vt.global_cursor_default=0 splash rw
EOF
################################################
##### Unlock LUKS with TPM2
################################################
# References:
# https://wiki.archlinux.org/title/Trusted_Platform_Module#systemd-cryptenroll
# Install TPM2-tools
pacman -S --noconfirm tpm2-tools tpm2-tss
# Configure initramfs to unlock the encrypted volume
sed -i "s|=system|& rd.luks.options=$(if [ ${RAID0} = "no" ]; then blkid -s UUID -o value /dev/nvme0n1p2; elif [ ${RAID0} = "yes" ]; then blkid -s UUID -o value /dev/md/ArchArray;fi)=tpm2-device=auto|" /boot/loader/entries/arch.conf
sed -i "s|=system|& rd.luks.options=$(if [ ${RAID0} = "no" ]; then blkid -s UUID -o value /dev/nvme0n1p2; elif [ ${RAID0} = "yes" ]; then blkid -s UUID -o value /dev/md/ArchArray;fi)=tpm2-device=auto|" /boot/loader/entries/arch-lts.conf
################################################
##### Secure boot
################################################
# References:
# https://github.com/Foxboron/sbctl
# https://wiki.archlinux.org/title/Unified_Extensible_Firmware_Interface/Secure_Boot#Using_your_own_keys
# Install sbctl
pacman -S --noconfirm sbctl
# Create secure boot signing keys
sbctl create-keys
# Enroll keys to EFI
sbctl enroll-keys --tpm-eventlog
# Sign files with secure boot keys
sbctl sign -s /boot/EFI/BOOT/BOOTX64.EFI
sbctl sign -s /boot/EFI/systemd/systemd-bootx64.efi
sbctl sign -s /boot/vmlinuz-linux
sbctl sign -s /boot/vmlinuz-linux-lts
################################################
##### Paru
################################################
# References:
# https://github.com/Morganamilo/paru
# (Temporary - reverted at cleanup) Allow $NEW_USER to run pacman without password
echo "${NEW_USER} ALL=NOPASSWD:/usr/bin/pacman" >> /etc/sudoers
# Install paru
git clone https://aur.archlinux.org/paru-bin.git
chown -R ${NEW_USER}:${NEW_USER} paru-bin
cd paru-bin
sudo -u ${NEW_USER} makepkg -si --noconfirm
cd ..
rm -rf paru-bin
################################################
##### AppArmor
################################################
# References:
# https://wiki.archlinux.org/title/AppArmor
# https://wiki.archlinux.org/title/Audit_framework
# https://github.com/roddhjav/apparmor.d
# https://apparmor.pujol.io/
# Install AppArmor
pacman -S --noconfirm apparmor
# Enable AppArmor service
systemctl enable apparmor.service
# Enable AppArmor as default security model
sed -i "s|/system|& lsm=landlock,lockdown,yama,integrity,apparmor,bpf|" /boot/loader/entries/arch.conf
sed -i "s|/system|& lsm=landlock,lockdown,yama,integrity,apparmor,bpf|" /boot/loader/entries/arch-lts.conf
# Enable caching AppArmor profiles
sed -i "s|^#write-cache|write-cache|g" /etc/apparmor/parser.conf
sed -i "s|^#Optimize=compress-fast|Optimize=compress-fast|g" /etc/apparmor/parser.conf
# Install and enable Audit Framework
pacman -S --noconfirm audit
systemctl enable auditd.service
# Install AppArmor.d profiles
sudo -u ${NEW_USER} paru -S apparmor.d-git
# Configure AppArmor.d
mkdir -p /etc/apparmor.d/tunables/xdg-user-dirs.d/apparmor.d.d
tee /etc/apparmor.d/tunables/xdg-user-dirs.d/apparmor.d.d/local << 'EOF'
@{XDG_PROJECTS_DIR}+="Projects" ".devtools"
@{XDG_GAMES_DIR}+="Games"
EOF
################################################
##### ffmpeg
################################################
# References:
# https://wiki.archlinux.org/title/FFmpeg#Installation
# Install ffmpeg
pacman -S --noconfirm ffmpeg
################################################
##### GPU
################################################
# References:
# https://wiki.archlinux.org/title/intel_graphics
# https://wiki.archlinux.org/title/AMDGPU
# https://wiki.archlinux.org/title/Hardware_video_acceleration
# https://wiki.archlinux.org/title/Vulkan
# Install GPU drivers related packages
pacman -S --noconfirm mesa vulkan-icd-loader vulkan-mesa-layers ${GPU_PACKAGES}
# Install 32-bit packages
if [ ${STEAM_NATIVE} = "yes" ]; then
pacman -S --noconfirm lib32-mesa lib32-vulkan-icd-loader lib32-vulkan-mesa-layers
if lspci | grep "VGA" | grep "Intel" > /dev/null; then
pacman -S --noconfirm lib32-vulkan-intel
elif lspci | grep "VGA" | grep "AMD" > /dev/null; then
pacman -S --noconfirm lib32-vulkan-radeon lib32-libva
fi
fi
# Override VA-API driver via environment variable
tee -a /etc/environment << EOF
# VA-API
${LIBVA_ENV_VAR}
EOF
# Set env vars for AMDGPU
if lspci | grep "VGA" | grep "AMD" > /dev/null; then
tee -a /etc/environment << EOF
# Vulkan
AMD_VULKAN_ICD=RADV
# VDPAU
VDPAU_DRIVER=radeonsi
EOF
elif lspci | grep "VGA" | grep "Intel" > /dev/null; then
tee -a /etc/environment << EOF
# VDPAU
VDPAU_DRIVER=va_gl
EOF
fi
# Install VA-API tools
pacman -S --noconfirm libva-utils
# Install VDPAU tools
pacman -S --noconfirm vdpauinfo
# Install Vulkan tools
pacman -S --noconfirm vulkan-tools
################################################
##### systemd
################################################
# References:
# https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html
# Configure default timeout to stop system units
mkdir -p /etc/systemd/system.conf.d
tee /etc/systemd/system.conf.d/default-timeout.conf << EOF
[Manager]
DefaultTimeoutStopSec=5s
EOF
# Configure default timeout to stop user units
mkdir -p /etc/systemd/user.conf.d
tee /etc/systemd/user.conf.d/default-timeout.conf << EOF
[Manager]
DefaultTimeoutStopSec=5s
EOF
################################################
##### GStreamer
################################################
# References:
# https://wiki.archlinux.org/title/GStreamer
# Install GStreamer
pacman -S --noconfirm \
gstreamer \
gst-libav \
gst-plugins-base \
gst-plugins-good \
gst-plugins-bad \
gst-plugins-ugly \
gst-plugin-pipewire \
gstreamer-vaapi
################################################
##### PipeWire
################################################
# References:
# https://wiki.archlinux.org/title/PipeWire
# Install PipeWire and WirePlumber
pacman -S --noconfirm \
pipewire \
pipewire-alsa \
pipewire-jack \
pipewire-pulse \
libpulse \
wireplumber --ask 4
# Enable PipeWire's user service
chown -R ${NEW_USER}:${NEW_USER} /home/${NEW_USER}
sudo -u ${NEW_USER} systemctl --user enable pipewire-pulse.service
################################################
##### Syncthing
################################################
# References:
# https://wiki.archlinux.org/title/syncthing
# Install Syncthing
pacman -S --noconfirm syncthing
# Enable Syncthing's user service
chown -R ${NEW_USER}:${NEW_USER} /home/${NEW_USER}
sudo -u ${NEW_USER} systemctl --user enable syncthing.service
################################################
##### Podman
################################################
# References:
# https://wiki.archlinux.org/title/Podman
# https://wiki.archlinux.org/title/Buildah
# https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md
# Install Podman and dependencies
pacman -S --noconfirm podman passt netavark aardvark-dns
# Install Buildah
pacman -S --noconfirm buildah
# Enable unprivileged ping
echo 'net.ipv4.ping_group_range=0 165535' > /etc/sysctl.d/99-unprivileged-ping.conf
# Create docker/podman alias
tee /home/${NEW_USER}/.zshrc.d/podman << EOF
alias docker=podman
EOF
# Re-enable unqualified search registries
tee -a /etc/containers/registries.conf.d/10-unqualified-search-registries.conf << EOF
unqualified-search-registries = ['docker.io']
EOF
tee -a /etc/containers/registries.conf.d/01-registries.conf << EOF
[[registry]]
location = "docker.io"
EOF
################################################
##### Virtualization
################################################
# References:
# https://wiki.archlinux.org/title/Libvirt
# https://wiki.archlinux.org/title/QEMU
# https://wiki.archlinux.org/title/Virt-Manager
# Install QEMU and dependencies
pacman -S --noconfirm libvirt qemu-desktop dnsmasq virt-manager
# Add user to libvirt group
gpasswd -a ${NEW_USER} libvirt
# Enable libvirtd service
systemctl enable libvirtd.service
# Use as a normal user
# sed -i "s|^#unix_sock_group = \"libvirt\"|unix_sock_group = \"libvirt\"|g" /etc/libvirt/libvirtd.conf
# sed -i "s|^#unix_sock_rw_perms = \"0770\"|unix_sock_rw_perms = \"0770\"|g" /etc/libvirt/libvirtd.conf
# sed -i "s|^#user = \"libvirt-qemu\"|user = \"${NEW_USER}\"|g" /etc/libvirt/qemu.conf
# sed -i "s|^#group = \"libvirt-qemu\"|group = \"${NEW_USER}\"|g" /etc/libvirt/qemu.conf
################################################
##### Kubernetes / Cloud
################################################
# References:
# https://minikube.sigs.k8s.io/docs/drivers/kvm2/
# https://wiki.archlinux.org/title/Minikube
# Install and configure minikube
pacman -S --noconfirm minikube
mkdir -p /home/${NEW_USER}/.minikube/config
tee /home/${NEW_USER}/.minikube/config/config.json << 'EOF'
{
"container-runtime": "containerd",
"driver": "kvm2"
}
EOF
# Install k8s applications
pacman -S --noconfirm kubectl helm k9s kubectx cilium-cli talosctl
# Kubernetes aliases and autocompletion
tee /home/${NEW_USER}/.zshrc.d/kubernetes << 'EOF'
# Aliases
alias k="kubectl"
alias kx="kubectx"
alias kn="kubens"
# Autocompletion
autoload -Uz compinit
compinit
source <(kubectl completion zsh)
EOF
# Install OpenTofu
pacman -S --noconfirm opentofu
################################################
##### Development (languages, LSP, neovim)
################################################
# Set git configurations
sudo -u ${NEW_USER} git config --global init.defaultBranch main
# Create dev tools directory
mkdir -p /home/${NEW_USER}/.devtools
# Install NodeJS and npm
pacman -S --noconfirm nodejs npm
# Change npm's default directory
# https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
mkdir /home/${NEW_USER}/.devtools/npm-global
chown -R ${NEW_USER}:${NEW_USER} /home/${NEW_USER}/.devtools/npm-global
sudo -u ${NEW_USER} npm config set prefix "/home/${NEW_USER}/.devtools/npm-global"
tee /home/${NEW_USER}/.zshrc.d/npm << 'EOF'
export PATH=$HOME/.devtools/npm-global/bin:$PATH
EOF
# Install Python uv
pacman -S --noconfirm uv
tee /home/${NEW_USER}/.zshrc.d/python << 'EOF'
# uv shell autocompletion
eval "$(uv generate-shell-completion zsh)"
eval "$(uvx --generate-shell-completion zsh)"
EOF
# Install Go
pacman -S --noconfirm go go-tools gopls
mkdir -p /home/${NEW_USER}/.devtools/go
tee /home/${NEW_USER}/.zshrc.d/go << 'EOF'
export GOPATH="$HOME/.devtools/go"
EOF
# Install language servers
pacman -S --noconfirm \
bash-language-server \
eslint-language-server \
python-lsp-server \
typescript-language-server \
vue-language-server \
vscode-css-languageserver \
vscode-html-languageserver \
vscode-json-languageserver \
yaml-language-server
# Install C++ development related packages
pacman -S --noconfirm llvm clang lld mold scons
# Install rust
pacman -S --noconfirm rust
################################################
##### Neovim
################################################
# Install Neovim and set as default editor
pacman -S --noconfirm neovim
tee /home/${NEW_USER}/.zshrc.d/neovim << 'EOF'
# Set neovim alias
alias vi=nvim
alias vim=nvim
# Set preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
export VISUAL='vim'
else
export EDITOR='nvim'
export VISUAL='nvim'
fi
EOF
# Install LazyVim
# https://www.lazyvim.org/installation
git clone https://github.com/LazyVim/starter /home/${NEW_USER}/.config/nvim
rm -rf /home/${NEW_USER}/.config/nvim/.git
# Install arctic.nvim (Dark Modern) color scheme in neovim
# https://github.com/rockyzhang24/arctic.nvim/tree/v2
# https://www.lazyvim.org/plugins/colorscheme
tee /home/${NEW_USER}/.config/nvim/lua/plugins/colorscheme.lua << 'EOF'
return {
{
"gjpin/arctic.nvim",
branch = "v2",
dependencies = { "rktjmp/lush.nvim" }
},
{
"LazyVim/LazyVim",
opts = {
colorscheme = "arctic",
}
}
}
EOF
################################################
##### Power management
################################################
# References:
# https://wiki.archlinux.org/title/Power_management
# https://wiki.archlinux.org/title/CPU_frequency_scaling#cpupower
# https://gitlab.com/corectrl/corectrl/-/wikis/Setup
# https://wiki.archlinux.org/title/AMDGPU#Performance_levels
# Apply power managament configurations according to device type
if [[ $(cat /sys/class/dmi/id/chassis_type) -eq 10 ]]; then
# Enable audio power saving features
echo 'options snd_hda_intel power_save=1' > /etc/modprobe.d/audio_powersave.conf
# Enable wifi (iwlwifi) power saving features
echo 'options iwlwifi power_save=1' > /etc/modprobe.d/iwlwifi.conf
# Rebuild initramfs
mkinitcpio -P
else
if lspci | grep "VGA" | grep "AMD" > /dev/null; then
# Install corectrl
pacman -S --noconfirm corectrl
# Launch CoreCtrl on session startup
cp /usr/share/applications/org.corectrl.CoreCtrl.desktop /home/${NEW_USER}/.config/autostart/org.corectrl.CoreCtrl.desktop
# Don't ask for user password
curl https://raw.githubusercontent.com/gjpin/arch-linux/main/configs/corectrl/90-corectrl.rules -o /etc/polkit-1/rules.d/90-corectrl.rules
sed -i "s/your-user-group/${NEW_USER}/" /etc/polkit-1/rules.d/90-corectrl.rules
# Full AMD GPU controls
sed -i "s|/system|& amdgpu.ppfeaturemask=0xffffffff|" /boot/loader/entries/arch.conf
sed -i "s|/system|& amdgpu.ppfeaturemask=0xffffffff|" /boot/loader/entries/arch-lts.conf
# Import corectrl configs and profiles
mkdir -p /home/${NEW_USER}/.config/corectrl/profiles
curl https://raw.githubusercontent.com/gjpin/arch-linux/main/configs/corectrl/corectrl.ini -o /home/${NEW_USER}/.config/corectrl/corectrl.ini
curl https://raw.githubusercontent.com/gjpin/arch-linux/main/configs/corectrl/profiles/_global_.ccpro -o /home/${NEW_USER}/.config/corectrl/profiles/_global_.ccpro
fi
fi
# Install and enable thermald if CPU is Intel
if [[ $(cat /proc/cpuinfo | grep vendor | uniq) =~ "GenuineIntel" ]]; then
pacman -S --noconfirm thermald
systemctl enable thermald.service
fi
# Install and enable power profiles daemon
pacman -S --noconfirm power-profiles-daemon
systemctl enable power-profiles-daemon.service
################################################
##### VSCode
################################################
# Install VSCode
sudo -u ${NEW_USER} paru -S --noconfirm visual-studio-code-bin
# (Temporary - reverted at cleanup) Install Virtual framebuffer X server. Required to install VSCode extensions without a display server
pacman -S --noconfirm xorg-server-xvfb
# Install VSCode extensions
sudo -u ${NEW_USER} xvfb-run code --install-extension golang.Go
sudo -u ${NEW_USER} xvfb-run code --install-extension ms-python.python
sudo -u ${NEW_USER} xvfb-run code --install-extension redhat.vscode-yaml
sudo -u ${NEW_USER} xvfb-run code --install-extension esbenp.prettier-vscode
sudo -u ${NEW_USER} xvfb-run code --install-extension dbaeumer.vscode-eslint
sudo -u ${NEW_USER} xvfb-run code --install-extension hashicorp.terraform
# Import VSCode settings
mkdir -p /home/${NEW_USER}/.config/Code/User
curl https://raw.githubusercontent.com/gjpin/arch-linux/main/configs/vscode/settings.json -o /home/${NEW_USER}/.config/Code/User/settings.json
################################################
##### Fonts
################################################
# Install fonts
pacman -S --noconfirm \
noto-fonts \
noto-fonts-emoji \
noto-fonts-cjk \
noto-fonts-extra \
ttf-liberation \
otf-cascadia-code \
otf-commit-mono-nerd \
ttf-firacode-nerd \
ttf-hack-nerd \
ttf-noto-nerd \
ttf-sourcecodepro-nerd \
ttf-ubuntu-nerd \
ttf-ubuntu-mono-nerd \
ttf-hack \
inter-font \
cantarell-fonts \
otf-font-awesome
################################################
##### Electron
################################################
# Enable Wayland for electron apps and improve font rendering
tee /home/${NEW_USER}/.config/electron-flags.conf << EOF
--disable-font-subpixel-positioning
--enable-features=WaylandWindowDecorations
--ozone-platform-hint=auto
EOF
################################################
##### Desktop Environment
################################################
# Enable bluetooth
systemctl enable bluetooth.service
# Install and configure desktop environment
if [ ${DESKTOP_ENVIRONMENT} = "plasma" ]; then
/install-arch/plasma.sh
elif [ ${DESKTOP_ENVIRONMENT} = "gnome" ]; then
/install-arch/gnome.sh
fi
# Hide applications from menus
APPLICATIONS=('assistant' 'avahi-discover' 'designer' 'electron' 'electron21' 'htop' 'linguist' 'lstopo' 'nvim' 'org.kde.kuserfeedback-console' 'qdbusviewer' 'qt5ct' 'qv4l2' 'qvidcap' 'bssh' 'bvnc' 'mpv')
for APPLICATION in "${APPLICATIONS[@]}"
do
# Create a local copy of the desktop files and append properties
cp /usr/share/applications/${APPLICATION}.desktop /home/${NEW_USER}/.local/share/applications/${APPLICATION}.desktop 2>/dev/null || :
if test -f "/home/${NEW_USER}/.local/share/applications/${APPLICATION}.desktop"; then
echo "NoDisplay=true" >> /home/${NEW_USER}/.local/share/applications/${APPLICATION}.desktop
echo "Hidden=true" >> /home/${NEW_USER}/.local/share/applications/${APPLICATION}.desktop
echo "NotShowIn=KDE;GNOME;" >> /home/${NEW_USER}/.local/share/applications/${APPLICATION}.desktop
fi
done
################################################
##### Gaming
################################################
# Install and configure gaming with Flatpak
if [ ${GAMING} = "yes" ]; then
/install-arch/gaming.sh
fi