forked from Kron4ek/Conty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-arch-bootstrap.sh
executable file
·429 lines (351 loc) · 13.5 KB
/
create-arch-bootstrap.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
#!/usr/bin/env bash
# Dependencies: curl tar gzip grep coreutils
# Root rights are required
########################################################################
# Package groups
audio_pkgs="alsa-lib lib32-alsa-lib alsa-plugins lib32-alsa-plugins libpulse \
lib32-libpulse jack2 lib32-jack2 alsa-tools alsa-utils pipewire lib32-pipewire wireplumber"
video_pkgs="mesa lib32-mesa vulkan-radeon lib32-vulkan-radeon \
vulkan-icd-loader lib32-vulkan-icd-loader vulkan-mesa-layers \
lib32-vulkan-mesa-layers libva-mesa-driver lib32-libva-mesa-driver \
mesa-utils vulkan-tools libva-utils lib32-mesa-utils"
# rocm-hip-sdk rocm-opencl-sdk"
wine_pkgs="wine-staging winetricks-git wine-nine wineasio \
giflib lib32-giflib libpng lib32-libpng libldap lib32-libldap \
gnutls lib32-gnutls mpg123 lib32-mpg123 openal lib32-openal \
v4l-utils lib32-v4l-utils libpulse lib32-libpulse alsa-plugins \
lib32-alsa-plugins alsa-lib lib32-alsa-lib libjpeg-turbo \
lib32-libjpeg-turbo libxcomposite lib32-libxcomposite libxinerama \
lib32-libxinerama libxslt lib32-libxslt libva lib32-libva gtk3-classic \
lib32-gtk3 vulkan-icd-loader lib32-vulkan-icd-loader sdl2 lib32-sdl2 \
vkd3d lib32-vkd3d libgphoto2 ffmpeg gst-plugins-good gst-plugins-bad \
gst-plugins-ugly gst-plugins-base lib32-gst-plugins-good \
lib32-gst-plugins-base gst-libav wget faudio lib32-faudio"
devel_pkgs="base-devel git nano"
# Packages to install
# You can add packages that you want and remove packages that you don't need
# Apart from packages from the official Arch repos, you can also specify
# packages from the Chaotic-AUR repo
export packagelist="${audio_pkgs} ${video_pkgs} ${wine_pkgs} ${devel_pkgs} \
zsh fish lxterminal htop minizip \
eza bat aria2 wget wl-clipboard sqlitebrowser \
xorg-server-xephyr xorg-xwayland wayland lib32-wayland \
qt5-wayland qt6-wayland libdbusmenu-qt5 libdbusmenu-qt6 \
libdbusmenu-gtk3 libdbusmenu-gtk2 appmenu-gtk-module \
ttf-meslo-nerd-font-powerlevel10k ttf-ibm-plex ttf-ms-fonts \
whitesur-kde-theme-git whitesur-icon-theme-git whitesur-cursor-theme-git \
whitesur-gtk-theme-git adwaita-icon-theme \
steam steam-native-runtime protontricks-git \
xdg-desktop-portal-kde plasma-browser-integration \
peazip-qt5 p7zip unrar unarchiver lzop lrzip arj \
spotify-adblock-git qtscrcpy scrcpy \
masterpdfeditor-free exifcleaner-bin \
teams-for-linux onedrive-abraunegg onedrivegui onedriver \
gamemode lib32-gamemode mangohud-git lib32-mangohud-git \
bottles itch-setup-bin lutris anime-games-launcher-bin \
pcsx2-git ppsspp rpcs3-git duckstation-git vita3k-avx-git \
melonds-git ryujinx-git yuzu-early-access citra-canary-git \
gimp-git curtail anydesk-bin vlc-wayland-git \
firejail firetools discord discord-rpc-git \
rustdesk-nightly tesseract-data-eng tesseract-data-ind tesseract-data-jpn tesseract-data-jpn_vert"
# If you want to install AUR packages, specify them in this variable
export aur_packagelist=" \
gamescope-plus wine-ge-custom-opt \
monterey-kde-theme-git \
thorium-browser-bin junction sgdboop-bin \
thcrap-steam-proton-wrapper-git \
obs-studio-amf mpv-discordrpc mpv-discord-git 4kvideodownloaderplus"
# ALHP is a repository containing packages from the official Arch Linux
# repos recompiled with -O3, LTO and optimizations for modern CPUs for
# better performance
#
# When this repository is enabled, most of the packages from the official
# Arch Linux repos will be replaced with their optimized versions from ALHP
#
# Set this variable to true, if you want to enable this repository
enable_alhp_repo="false"
# Feature levels for ALHP. Available feature levels are 2 and 3
# For level 2 you need a CPU with SSE4.2 instructions
# For level 3 you need a CPU with AVX2 instructions
alhp_feature_level="2"
########################################################################
if [ $EUID != 0 ]; then
echo "Root rights are required!"
exit 1
fi
if ! command -v curl 1>/dev/null; then
echo "curl is required!"
exit 1
fi
if ! command -v gzip 1>/dev/null; then
echo "gzip is required!"
exit 1
fi
if ! command -v grep 1>/dev/null; then
echo "grep is required!"
exit 1
fi
if ! command -v sha256sum 1>/dev/null; then
echo "sha256sum is required!"
exit 1
fi
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
mount_chroot () {
# First unmount just in case
umount -Rl "${bootstrap}"
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
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 () {
echo "Checking if packages are present in the repos, please wait..."
for p in ${packagelist}; do
if pacman -Sp "${p}" &>/dev/null; then
good_pkglist="${good_pkglist} ${p}"
else
bad_pkglist="${bad_pkglist} ${p}"
fi
done
if [ -n "${bad_pkglist}" ]; then
echo ${bad_pkglist} > /opt/bad_pkglist.txt
fi
for i in {1..10}; do
if pacman --noconfirm --needed -S ${good_pkglist}; then
good_install=1
break
fi
done
if [ -z "${good_install}" ]; then
echo > /opt/pacman_failed.txt
fi
}
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 yay --needed --noconfirm --removemake --builddir /home/aur -a -S ${aur_pkgs}; then
break
fi
done
}
generate_localegen () {
cat <<EOF > locale.gen
ar_EG.UTF-8 UTF-8
en_US.UTF-8 UTF-8
en_GB.UTF-8 UTF-8
en_CA.UTF-8 UTF-8
en_SG.UTF-8 UTF-8
es_MX.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
fr_FR.UTF-8 UTF-8
ru_RU.UTF-8 UTF-8
ru_UA.UTF-8 UTF-8
es_ES.UTF-8 UTF-8
de_DE.UTF-8 UTF-8
pt_BR.UTF-8 UTF-8
it_IT.UTF-8 UTF-8
id_ID.UTF-8 UTF-8
ja_JP.UTF-8 UTF-8
bg_BG.UTF-8 UTF-8
pl_PL.UTF-8 UTF-8
da_DK.UTF-8 UTF-8
ko_KR.UTF-8 UTF-8
tr_TR.UTF-8 UTF-8
hu_HU.UTF-8 UTF-8
cs_CZ.UTF-8 UTF-8
bn_IN UTF-8
hi_IN UTF-8
EOF
}
generate_mirrorlist () {
cat <<EOF > mirrorlist
Server = https://mirror1.sl-chat.ru/archlinux/\$repo/os/\$arch
Server = https://mirror3.sl-chat.ru/archlinux/\$repo/os/\$arch
Server = https://us.mirrors.cicku.me/archlinux/\$repo/os/\$arch
Server = https://mirror.osbeck.com/archlinux/\$repo/os/\$arch
Server = https://md.mirrors.hacktegic.com/archlinux/\$repo/os/\$arch
Server = https://geo.mirror.pkgbuild.com/\$repo/os/\$arch
Server = https://mirror.qctronics.com/archlinux/\$repo/os/\$arch
Server = https://arch.mirror.constant.com/\$repo/os/\$arch
Server = https://america.mirror.pkgbuild.com/\$repo/os/\$arch
Server = https://mirror.tmmworkshop.com/archlinux/\$repo/os/\$arch
EOF
}
cd "${script_dir}" || exit 1
bootstrap="${script_dir}"/root.x86_64
curl -#LO 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
curl -#LO 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
if [ ! -s chaotic-keyring.pkg.tar.zst ] || [ ! -s 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
bootstrap_urls=("mirror.f4st.host" \
"arch.hu.fo" \
"mirror.cyberbits.eu" \
"mirror.osbeck.com" \
"mirror.lcarilla.de" \
"mirror.moson.org")
echo "Downloading Arch Linux bootstrap"
for link in "${bootstrap_urls[@]}"; do
curl -#LO "https://${link}/archlinux/iso/latest/archlinux-bootstrap-x86_64.tar.zst"
curl -#LO "https://${link}/archlinux/iso/latest/sha256sums.txt"
if [ -s sha256sums.txt ]; then
grep bootstrap-x86_64 sha256sums.txt > sha256.txt
echo "Verifying the integrity of the bootstrap"
if sha256sum -c sha256.txt &>/dev/null; then
bootstrap_is_good=1
break
fi
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
rm -rf "${bootstrap}"
tar xf archlinux-bootstrap-x86_64.tar.zst
rm archlinux-bootstrap-x86_64.tar.zst sha256sums.txt sha256.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 7 --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
echo "keyserver hkps://keyserver.ubuntu.com" >> "${bootstrap}"/etc/pacman.d/gnupg/gpg.conf
run_in_chroot pacman-key --populate archlinux
# Add Chaotic-AUR repo
run_in_chroot pacman-key --recv-key 3056513887B78AEB
run_in_chroot pacman-key --lsign-key 3056513887B78AEB
mv chaotic-keyring.pkg.tar.zst chaotic-mirrorlist.pkg.tar.zst "${bootstrap}"/opt
run_in_chroot pacman --noconfirm -U /opt/chaotic-keyring.pkg.tar.zst /opt/chaotic-mirrorlist.pkg.tar.zst
rm "${bootstrap}"/opt/chaotic-keyring.pkg.tar.zst "${bootstrap}"/opt/chaotic-mirrorlist.pkg.tar.zst
{
echo
echo "[chaotic-aur]"
echo "Include = /etc/pacman.d/chaotic-mirrorlist"
} >> "${bootstrap}"/etc/pacman.conf
# The ParallelDownloads feature of pacman
# Speeds up packages installation, especially when there are many small packages to install
sed -i 's/#ParallelDownloads = 5/ParallelDownloads = 3/g' "${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 [ "${enable_alhp_repo}" = "true" ]; then
if [ "${alhp_feature_level}" -gt 2 ]; then
alhp_feature_level=3
else
alhp_feature_level=2
fi
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 7 --sort rate --save /etc/pacman.d/mirrorlist
fi
export -f install_packages
run_in_chroot bash -c install_packages
if [ -f "${bootstrap}"/opt/pacman_failed.txt ]; then
unmount_chroot
echo "Pacman failed to install some packages"
exit 1
fi
if [ -n "${aur_packagelist}" ]; 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_packagelist}; 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
# Generate a list of installed packages
run_in_chroot pacman -Q > "${bootstrap}"/pkglist.x86_64.txt
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 -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_pkglist.txt ]; then
echo
echo "These packages are not in the repos and have not been installed:"
cat "${bootstrap}"/opt/bad_pkglist.txt
rm "${bootstrap}"/opt/bad_pkglist.txt
fi
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