2019-02-14 17:32:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euxo pipefail
|
|
|
|
|
|
|
|
[ $(id -u) -eq 0 ] || exec sudo bash $0 "$@"
|
|
|
|
|
2023-05-22 09:59:33 +00:00
|
|
|
[ -e /usr/share/devtools/pacman.conf.d/extra.conf ] || {
|
2022-07-17 11:53:42 +00:00
|
|
|
echo "Missing 'devtools' on this system. Please 'pacman -S devtools'."
|
|
|
|
exit 1
|
2019-02-14 17:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Packages required for the minimal system
|
|
|
|
packages=(
|
2022-07-27 21:11:25 +00:00
|
|
|
archlinux-keyring
|
2022-07-17 11:53:42 +00:00
|
|
|
awk
|
|
|
|
gzip
|
|
|
|
pacman
|
|
|
|
sed
|
|
|
|
systemd
|
2019-02-14 17:32:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# In case more packages were passed add them to the package list
|
|
|
|
if [ $# -gt 0 ]; then
|
2022-07-17 11:53:42 +00:00
|
|
|
packages+=("$@")
|
2019-02-14 17:32:04 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Build in a tempdir
|
|
|
|
tmpdir=$(mktemp -d)
|
|
|
|
function rm_temp() {
|
2022-07-17 11:53:42 +00:00
|
|
|
umount ${tmpdir}
|
|
|
|
rm -rf ${tmpdir}
|
2019-02-14 17:32:04 +00:00
|
|
|
}
|
|
|
|
trap rm_temp EXIT
|
|
|
|
|
2022-07-17 11:53:42 +00:00
|
|
|
# Create a bind-mount to avoid side-effects on the host system
|
|
|
|
mount --bind ${tmpdir} ${tmpdir}
|
|
|
|
|
2019-02-14 17:32:04 +00:00
|
|
|
# Pacstrap the requested packages
|
2023-05-22 09:59:33 +00:00
|
|
|
env -i pacstrap -C /usr/share/devtools/pacman.conf.d/extra.conf -c -G -M ${tmpdir} "${packages[@]}"
|
2019-02-14 17:32:04 +00:00
|
|
|
|
|
|
|
# Add local configurations
|
|
|
|
cp --recursive --preserve=timestamps --backup --suffix=.pacnew rootfs/* ${tmpdir}/
|
|
|
|
|
|
|
|
# Initialize locales and pacman-keys
|
2022-07-17 11:53:42 +00:00
|
|
|
arch-chroot ${tmpdir} bash -ex <<EOF
|
|
|
|
# Generate locales
|
|
|
|
locale-gen
|
|
|
|
|
|
|
|
# Initialize pacman-key keyring
|
|
|
|
pacman-key --init
|
|
|
|
pacman-key --populate archlinux
|
|
|
|
|
|
|
|
# Stop agent to free /dev mount
|
|
|
|
export GNUPGHOME=/etc/pacman.d/gnupg
|
|
|
|
gpgconf --kill gpg-agent
|
2022-07-17 12:07:54 +00:00
|
|
|
|
|
|
|
# Give the agent some time to die
|
|
|
|
sleep 5
|
2022-07-17 11:53:42 +00:00
|
|
|
EOF
|
2019-02-14 17:32:04 +00:00
|
|
|
|
|
|
|
# Pack rootfs
|
|
|
|
tar --numeric-owner --xattrs --acls --exclude-from=exclude -C ${tmpdir} -c . -f archlinux.tar
|