This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·151 lines (120 loc) · 4.81 KB
/
setup
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
#!/bin/bash
# Sets up the system without any user interaction.
# All the variables that is needed will be sourced from /info
# shellcheck disable=SC2154
set -euo pipefail
user_setup() {
prompt "Setting up the user $AI_USER" work
# https://wiki.archlinux.org/title/users_and_groups
out useradd -m -G wheel "$AI_USER"
echo "$AI_USER:$AI_PASS" | chpasswd
prompt "Setting up the root password" work
echo "root:$AI_ROOT_PASS" | chpasswd
}
system_setup() {
local timeZ
prompt "Setting up the system" work
# https://wiki.archlinux.org/title/systemd-timesyncd
# https://wiki.archlinux.org/title/systemd-resolved
# https://wiki.archlinux.org/title/iwd
out systemctl enable systemd-timesyncd systemd-resolved iwd
out ln -sf ../run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
echo "[General]
EnableNetworkConfiguration=true" >/etc/iwd/main.conf
# Set up the timezone and clock
prompt "Setting up the timezone" work
timeZ="$(curl -s "http://worldtimeapi.org/api/ip.txt" | awk '/timezone/{print $2}')"
out ln -sf /usr/share/zoneinfo/"$timeZ" /etc/localtime
out hwclock --systohc # Write the current software clock time to the hardware clock
prompt "Setting up the locale: $AI_LOCALE" work
out sed -i "/$AI_LOCALE/s/^#//g" /etc/locale.gen
out locale-gen
echo -e "LANG=$AI_LOCALE\nLANGUAGE=$AI_LOCALE" >/etc/locale.conf
# Setup hostname
prompt "Setting up the hostname: $AI_HOSTNAME" work
echo "$AI_HOSTNAME" >/etc/hostname
echo -e "127.0.0.1\tlocalhost
::1\tlocalhost
127.0.0.1 $AI_HOSTNAME.localdomain $AI_HOSTNAME" >/etc/hosts
}
trim_setup() {
prompt "Enabling auto-trimming of SSDs" work
out systemctl enable fstrim.timer
}
hibernation_setup() {
local swapUUID
swapUUID=$(blkid -s UUID -o value "$AI_SWAP_PART")
prompt "Adding mkinitcpio resume hook" work
sed "/^[^#]/ s/\<filesystems\>/& resume/" /etc/mkinitcpio.conf # Add the resume hook after the filesystems mkinitcpio hook
prompt "Modifying kernel parameters to allow for hibernation" work
printf "resume=UUID=%s" "$swapUUID" >/boot/loader/entries/arch.conf
printf "resume=UUID=%s" "$swapUUID" >/boot/loader/entries/arch-fallback.conf
prompt "Regenerating the initramfs" work
out mkinitcpio -p linux
}
# https://wiki.archlinux.org/index.php/Makepkg#Parallel_compilation
makepkg_parallel() {
local marchFlag mtuneFlag
prompt "Enabling parallel compilation and compression" work
sed -i '/#BUILDDIR=/c\BUILDDIR=\/tmp\/makepkg/' /etc/makepkg.conf # build in memory
sed -i '/MAKEFLAGS=/c\MAKEFLAGS="-j$(nproc)"' /etc/makepkg.conf # build with all cores
sed -i 's/COMPRESSXZ=(xz/COMPRESSXZ=(xz --threads=0/' /etc/makepkg.conf # compress with all threads
sed -i 's/COMPRESSZST=(zstd/COMPRESSZST=(zstd --threads=0/' /etc/makepkg.conf # compress with all threads
prompt "Enabling safe architecture-specific optimizations" work
sed -i 's/#RUSTFLAGS="/RUSTFLAGS="-C target-cpu=native /' /etc/makepkg.conf # enable safe rust optimizations
marchFlag="$(grep -o "\-march\S*" /etc/makepkg.conf)"
mtuneFlag="$(grep -o "\-mtune\S*" /etc/makepkg.conf)"
[[ -n ${marchFlag:-} ]] && sed -i "s/$marchFlag//" /etc/makepkg.conf
[[ -n ${mtuneFlag:-} ]] && sed -i "s/$mtuneFlag//" /etc/makepkg.conf
sed -i 's/CFLAGS="/CFLAGS="-march=native /' /etc/makepkg.conf # enable safe gcc optimizations
}
bl_setup() {
out bootctl install
out systemctl enable systemd-boot-update
# man loader.conf
echo "default arch.conf
timeout 4
console-mode max
editor no" >/boot/loader/loader.conf
# https://uapi-group.org/specifications/specs/boot_loader_specification/#type-1-boot-loader-specification-entries
echo 'title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root="LABEL=ROOT_PARTITION" rw' >/boot/loader/entries/arch.conf
echo 'title Arch Linux (fallback initramfs)
linux /vmlinuz-linux
initrd /initramfs-linux-fallback.img
options root="LABEL=ROOT_PARTITION" rw' >/boot/loader/entries/arch-fallback.conf
}
# Sets up yay
yay_setup() {
prompt "Installing yay" work
out cd /home/"$AI_USER"/
out su -c \"git clone https://aur.archlinux.org/yay.git\" "$AI_USER"
out cd yay
out su -c \"makepkg -s\" "$AI_USER"
out pacman -U --needed --noconfirm -- *.zst
cd ..
rm -rf yay/
cd /
}
main() {
# /info is written by the install script
# shellcheck disable=SC1091
source /info
source /sharedfuncs
# Shred file since it contains sensative info
shred -n25 -u /info
user_setup
system_setup
bl_setup
[[ -n ${AI_OPT_HIBERNATION:-} ]] && hibernation_setup
# Doing this before installaing yay might make the installation faster
[[ -n ${AI_OPT_MAKEPKG:-} ]] && makepkg_parallel
[[ -n ${AI_OPT_YAY:-} ]] && yay_setup
[[ -n ${AI_OPT_SSD_TRIM:-} ]] && trim_setup
# Move files to $HOME
mv "$AI_LOG_FILE" /home/"$AI_USER"/
prompt "Log files have been dropped in /home/$AI_USER/" green
}
main "$@"