Repository navigation
Expand file tree
/
Copy pathinit-root
More file actions
executable file
·146 lines (116 loc) · 3.79 KB
/
Copy pathinit-root
File metadata and controls
executable file
·146 lines (116 loc) · 3.79 KB
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
#!/usr/bin/env bash
#
# This will initialize an Arch Linux system with all the essentials.
# The script should be run during the chroot step of the installation.
#
(($(id -u) > 0)) && echo "Must be root" && exit 1
ping -c 2 8.8.8.8 &> /dev/null || {
echo "Network connection is required to continue"
exit 1
}
# Copy contents of root folder to /
cp -rf ./__root/* /
# Make sudoers files world unreadable
chmod o-rwx /etc/sudoers.d/*
# Filesystem optimizations (for SSDs)
sed -i "s/relatime/noatime/g" /etc/fstab
systemctl enable fstrim.timer
# Prevent system OOM
systemctl enable systemd-oomd.service
# Generate locales
locale-gen
# Configure the network
systemctl enable systemd-networkd.service
systemctl enable systemd-resolved.service
read -r -p "Will you be using Wi-Fi? (y/N) " wifi
[[ "${wifi,,}" == "y" ]] && {
pacman -S --noconfirm --needed iwd
systemctl enable iwd.service
}
read -r -p "Will you be using WireGuard? (y/N) " wg
[[ "${wg,,}" == "y" ]] && pacman -S --noconfirm --needed wireguard-tools systemd-resolvconf
read -r -p "Will you be using Bluetooth? (y/N) " bluetooth
[[ "${bluetooth,,}" == "y" ]] && {
pacman -S --noconfirm --needed bluez bluez-utils
systemctl enable bluetooth.service
}
# Set the hostname
read -r -p "Set hostname: " hostname
echo "${hostname,,}" > /etc/hostname
printf "Hostname set to %s." "${hostname,,}"
cat << EOF > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 ${hostname}
EOF
# Enable CPU frequency scaling
pacman -S --noconfirm --needed power-profiles-daemon
systemctl enable power-profiles-daemon.service
# Create the default user 1000 if he doesn't exist
getent passwd 1000 &> /dev/null || {
read -r -p "Create the default user with sudo access. Username: " username
useradd -m -G wheel -s /usr/bin/bash "${username,,}"
passwd "${username,,}"
printf "Created user %s." "${username,,}"
}
# Use realtime privileges for user 1000 (pro audio)
pacman -S --noconfirm --needed realtime-privileges
gpasswd -a "$(getent passwd 1000 | cut -d ":" -f 1)" realtime
# Configure the time
read -r -p "Configure timezone (default: UTC) " timezone
tz_file="/usr/share/zoneinfo/${timezone:-UTC}"
if [ -f "${tz_file}" ]; then
ln -sf "${tz_file}" /etc/localtime
else
printf "Timezone %s not found. Setting /etc/localtime to UTC instead.\n" "${timezone}"
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
fi
systemctl enable systemd-timesyncd.service
hwclock --systohc
# Regenerate initramfs image because of the added custom config
mkinitcpio -P
# Bootloader
read -r -p "Set up bootloader? Only run this if you have ESP mounted to /boot (y/N) " bootloader
if [[ "${bootloader,,}" == "y" ]]; then
mkdir -p /boot/loader/entries
chmod -R o-rwx /boot
bootctl install
systemctl enable systemd-boot-update.service
cat << EOF > /boot/loader/loader.conf
default arch
timeout 3
editor no
console-mode max
EOF
printf "\nPartition UUIDs:\n"
uuids=()
i=0
for disk in /dev/disk/by-uuid/*; do
link=$(readlink -f "$disk")
uuid=${disk##*/}
printf " %d) %s -> %s\n" $i "$link" "$uuid"
uuids+=("$uuid")
((i++))
done
printf "\nFound %d devices.\n" $i
((i--))
while true; do
read -r -p "Select your root partition: (0-${i}) " selected
if [[ ! $selected =~ ^[0-9]+$ ]]; then continue; fi
if ! ((selected >= 0 && selected <= i)); then continue; fi
read -r -p "Use ${uuids[$selected]}? (y/N) " ok
if [[ "${ok,,}" == "y" ]]; then break; fi
done
cat << EOF > /boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=UUID=${uuids[$selected]} rw mitigations=off
EOF
fi # /bootloader
echo "Set the root password"
passwd
echo "Done. Now exit chroot and run:"
echo " ln -sf ../run/systemd/resolve/stub-resolv.conf /mnt/etc/resolv.conf"
echo " umount -R /mnt"
echo " reboot"