forked from Kron4ek/Conty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-arch-bootstrap.sh
More file actions
executable file
·273 lines (216 loc) · 7.8 KB
/
create-arch-bootstrap.sh
File metadata and controls
executable file
·273 lines (216 loc) · 7.8 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
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
#!/usr/bin/env bash
# Dependencies: curl tar gzip grep coreutils
# Root rights are required
source settings.sh
check_command_available() {
for cmd in "$@"; do
if ! command -v "$cmd" >&-; then
echo "$cmd is required!"
exit 1
fi
done
}
check_command_available curl gzip grep sha256sum
if [ $EUID != 0 ]; then
echo "Root rights are required!"
exit 1
fi
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
bootstrap="${script_dir}"/root.x86_64
mount_chroot () {
mount --bind "${bootstrap}" "${bootstrap}"
mount -t proc /proc "${bootstrap}"/proc
mount --bind /sys "${bootstrap}"/sys
mount --make-rslave "${bootstrap}"/sys
mount --bind /dev "${bootstrap}"/dev
mount --bind /dev/pts "${bootstrap}"/dev/pts
mount --bind /dev/shm "${bootstrap}"/dev/shm
mount --make-rslave "${bootstrap}"/dev
rm -f "${bootstrap}"/etc/resolv.conf
cp /etc/resolv.conf "${bootstrap}"/etc/resolv.conf
cp "${script_dir}"/settings.sh "${bootstrap}"/conty_settings.sh
mkdir -p "${bootstrap}"/run/shm
}
unmount_chroot () {
umount -l "${bootstrap}"
umount "${bootstrap}"/proc
umount "${bootstrap}"/sys
umount "${bootstrap}"/dev/pts
umount "${bootstrap}"/dev/shm
umount "${bootstrap}"/dev
}
run_in_chroot () {
if [ -n "${CHROOT_AUR}" ]; then
chroot --userspec=aur:aur "${bootstrap}" /usr/bin/env LANG=en_US.UTF-8 TERM=xterm PATH="/bin:/sbin:/usr/bin:/usr/sbin" "$@"
else
chroot "${bootstrap}" /usr/bin/env LANG=en_US.UTF-8 TERM=xterm PATH="/bin:/sbin:/usr/bin:/usr/sbin" "$@"
fi
}
install_packages () {
source /conty_settings.sh
echo "Checking if packages are present in the repos, please wait..."
declare -a bad_pkglist
mapfile -t bad_pkglist < <(comm -23 \
<(printf '%s\n' "${PACKAGES[@]}" | sort -u) \
<(pacman -Slq | sort -u))
if [ "${#bad_pkglist[@]}" -gt 0 ]; then
echo "These packages are not available in arch repositories: " "${bad_pkglist[@]}"
exit 1
fi
for i in {1..10}; do
if pacman --noconfirm --needed -S "${PACKAGES[@]}" || [ "$?" -gt 127 ]; then
break
fi
done
}
install_aur_packages () {
cd /home/aur
echo "Checking if packages are present in the AUR, please wait..."
for p in ${aur_pkgs}; do
if ! yay -a -G "${p}" &>/dev/null; then
bad_aur_pkglist="${bad_aur_pkglist} ${p}"
fi
done
if [ -n "${bad_aur_pkglist}" ]; then
echo ${bad_aur_pkglist} > /home/aur/bad_aur_pkglist.txt
fi
for i in {1..10}; do
if yes | yay --needed --removemake --builddir /home/aur -a -S ${aur_pkgs}; then
break
fi
done
}
generate_pkg_licenses_file () {
pacman -Qi | grep -E '^Name|Licenses' | cut -d ":" -f 2 | paste -d ' ' - - > /pkglicenses.txt
}
generate_localegen () {
printf '%s\n' "${LOCALES[@]}" > locale.gen
}
generate_mirrorlist () {
printf '%s\n' "$MIRRORLIST" > mirrorlist
}
cd "${script_dir}" || exit 1
curl -#LO "$BOOTSTRAP_SHA256SUM_FILE_URL"
for link in "${BOOTSTRAP_DOWNLOAD_URLS[@]}"; do
echo "Downloading Arch Linux bootstrap from $link"
curl -#LO "$link"
echo "Verifying the integrity of the bootstrap"
if sha256sum --ignore-missing -c sha256sums.txt &>/dev/null; then
bootstrap_is_good=1
break
fi
echo "Download failed, trying again with different mirror"
done
if [ -z "${bootstrap_is_good}" ]; then
echo "Bootstrap download failed or its checksum is incorrect"
exit 1
fi
# Unmount first just in case
unmount_chroot
rm -rf "${bootstrap}"
tar xf archlinux-bootstrap-x86_64.tar.zst
rm archlinux-bootstrap-x86_64.tar.zst sha256sums.txt
mount_chroot
generate_localegen
if command -v reflector 1>/dev/null; then
echo "Generating mirrorlist..."
reflector --connection-timeout 10 --download-timeout 10 --protocol https --score 10 --sort rate --save mirrorlist
reflector_used=1
else
generate_mirrorlist
fi
rm "${bootstrap}"/etc/locale.gen
mv locale.gen "${bootstrap}"/etc/locale.gen
rm "${bootstrap}"/etc/pacman.d/mirrorlist
mv mirrorlist "${bootstrap}"/etc/pacman.d/mirrorlist
{
echo
echo "[multilib]"
echo "Include = /etc/pacman.d/mirrorlist"
} >> "${bootstrap}"/etc/pacman.conf
run_in_chroot pacman-key --init
run_in_chroot pacman-key --populate archlinux
# Add Chaotic-AUR repo
run_in_chroot pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
run_in_chroot pacman-key --lsign-key 3056513887B78AEB
if ! run_in_chroot pacman --noconfirm -U \
'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst' \
'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'; then
echo "Seems like Chaotic-AUR keyring or mirrorlist is currently unavailable"
echo "Please try again later"
exit 1
fi
{
echo
echo "[chaotic-aur]"
echo "Include = /etc/pacman.d/chaotic-mirrorlist"
} >> "${bootstrap}"/etc/pacman.conf
# Do not install unneeded files (man pages and Nvidia firmwares)
sed -i 's/#NoExtract =/NoExtract = usr\/lib\/firmware\/nvidia\/\* usr\/share\/man\/\*/' "${bootstrap}"/etc/pacman.conf
run_in_chroot pacman -Sy archlinux-keyring --noconfirm
run_in_chroot pacman -Su --noconfirm
if [ -n "$ENABLE_ALHP_REPO" ]; then
run_in_chroot pacman --noconfirm --needed -S alhp-keyring alhp-mirrorlist
sed -i "s/#\[multilib\]/#/" "${bootstrap}"/etc/pacman.conf
sed -i "s/\[core\]/\[core-x86-64-v${ALHP_FEATURE_LEVEL}\]\nInclude = \/etc\/pacman.d\/alhp-mirrorlist\n\n\[extra-x86-64-v${ALHP_FEATURE_LEVEL}\]\nInclude = \/etc\/pacman.d\/alhp-mirrorlist\n\n\[core\]/" "${bootstrap}"/etc/pacman.conf
sed -i "s/\[multilib\]/\[multilib-x86-64-v${ALHP_FEATURE_LEVEL}\]\nInclude = \/etc\/pacman.d\/alhp-mirrorlist\n\n\[multilib\]/" "${bootstrap}"/etc/pacman.conf
run_in_chroot pacman -Syu --noconfirm
fi
date -u +"%d-%m-%Y %H:%M (DMY UTC)" > "${bootstrap}"/version
# These packages are required for the self-update feature to work properly
run_in_chroot pacman --noconfirm --needed -S base reflector squashfs-tools fakeroot
# Regenerate the mirrorlist with reflector if reflector was not used before
if [ -z "${reflector_used}" ]; then
echo "Generating mirrorlist..."
run_in_chroot reflector --connection-timeout 10 --download-timeout 10 --protocol https --score 10 --sort rate --save /etc/pacman.d/mirrorlist
run_in_chroot pacman -Syu --noconfirm
fi
export -f install_packages
if ! run_in_chroot bash -c install_packages; then
unmount_chroot
exit 1
fi
if [ "${#AUR_PACKAGES[@]}" -ne 0 ]; then
run_in_chroot pacman --noconfirm --needed -S base-devel yay
run_in_chroot useradd -m -G wheel aur
echo "%wheel ALL=(ALL:ALL) NOPASSWD: ALL" >> "${bootstrap}"/etc/sudoers
for p in "${AUR_PACKAGES[@]}"; do
aur_pkgs="${aur_pkgs} aur/${p}"
done
export aur_pkgs
export -f install_aur_packages
CHROOT_AUR=1 HOME=/home/aur run_in_chroot bash -c install_aur_packages
mv "${bootstrap}"/home/aur/bad_aur_pkglist.txt "${bootstrap}"/opt
rm -rf "${bootstrap}"/home/aur
fi
run_in_chroot locale-gen
echo "Generating package info, please wait..."
# Generate a list of installed packages
run_in_chroot pacman -Q > "${bootstrap}"/pkglist.x86_64.txt
# Generate a list of licenses of installed packages
export -f generate_pkg_licenses_file
run_in_chroot bash -c generate_pkg_licenses_file
unmount_chroot
# Clear pacman package cache
rm -f "${bootstrap}"/var/cache/pacman/pkg/*
# Create some empty files and directories
# This is needed for bubblewrap to be able to bind real files/dirs to them
# later in the conty-start.sh script
mkdir "${bootstrap}"/media
mkdir "${bootstrap}"/initrd
mkdir -p "${bootstrap}"/usr/share/steam/compatibilitytools.d
touch "${bootstrap}"/etc/asound.conf
touch "${bootstrap}"/etc/localtime
chmod 755 "${bootstrap}"/root
# Enable full font hinting
rm -f "${bootstrap}"/etc/fonts/conf.d/10-hinting-slight.conf
ln -s /usr/share/fontconfig/conf.avail/10-hinting-full.conf "${bootstrap}"/etc/fonts/conf.d
clear
echo "Done"
if [ -f "${bootstrap}"/opt/bad_aur_pkglist.txt ]; then
echo
echo "These packages are either not in the AUR or yay failed to download their"
echo "PKGBUILDs:"
cat "${bootstrap}"/opt/bad_aur_pkglist.txt
rm "${bootstrap}"/opt/bad_aur_pkglist.txt
fi