androot/rootfsbuilder/archlinux-arm64.sh

58 lines
2.1 KiB
Bash
Raw Normal View History

2023-11-07 17:23:39 +01:00
#!/bin/bash
set -euo pipefail
shopt -s inherit_errexit
if [ ! "${UID}" == "0" ]; then
echo ":: Error: root user required"
exit 1
fi
DISTRIBUTION=archlinux
ARCH=arm64
echo ":: Generating rootfs for ${DISTRIBUTION}-${ARCH}"
if [ -f "./${DISTRIBUTION}-${ARCH}.tar.gz" ]; then
echo ":: Removing ${DISTRIBUTION}-${ARCH}.tar.gz"
rm -rf "./${DISTRIBUTION}-${ARCH}.tar.gz"
fi
if [ -f "./${DISTRIBUTION}-${ARCH}.tar" ]; then
echo ":: Removing ${DISTRIBUTION}-${ARCH}.tar"
rm -rf "./${DISTRIBUTION}-${ARCH}.tar"
fi
if [ -d "./${DISTRIBUTION}-${ARCH}" ]; then
echo ":: Removing ${DISTRIBUTION}-${ARCH}"
rm -rf "./${DISTRIBUTION}-${ARCH}"
fi
if [ -f "./${DISTRIBUTION}-${ARCH}-rootfs.tar" ]; then
echo ":: Removing ${DISTRIBUTION}-${ARCH}-rootfs.tar"
rm -rf "./${DISTRIBUTION}-${ARCH}-rootfs.tar"
fi
mkdir -p "./${DISTRIBUTION}-${ARCH}"
cd "./${DISTRIBUTION}-${ARCH}"
echo ":: Downloading rootfs"
wget "http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz" -O "../${DISTRIBUTION}-${ARCH}-rootfs.tar.gz"
echo ":: Decompressing rootfs"
bsdtar -xpf "../${DISTRIBUTION}-${ARCH}-rootfs.tar.gz" -C "."
rm -rf "../${DISTRIBUTION}-${ARCH}-rootfs.tar.gz"
echo ":: Binding"
mount --bind /dev "./dev"
mount --bind /dev/pts "./dev/pts"
mount --bind /dev/shm "./dev/shm"
mount --bind /sys "./sys"
mount --bind /proc "./proc"
mount --bind /run "./run"
echo ":: Removing packages"
cp "$(which qemu-aarch64-static)" "./bin/qemu-aarch64-static"
echo -e "pacman -R --noconfirm dhcpcd linux-aarch64 nano net-tools netctl openssh vi which\npacman -R \$(pacman -Qdtq) --recursive --unneeded --noconfirm" > "./clean.sh"
chmod +x "./clean.sh"
chroot . /bin/qemu-aarch64-static /bin/bash -c /clean.sh
echo ":: Removing files"
rm -rf "./clean.sh" "./bin/qemu-aarch64-static" "./boot/*"
echo ":: Unmounting"
bash -c "umount ./{dev/pts,dev/shm,dev,sys,proc,run};exit 0"
echo ":: Archiving rootfs"
tar --acls -cpf "../${DISTRIBUTION}-${ARCH}.tar" ./*
cd ..
rm -rf "./${DISTRIBUTION}-${ARCH}"
echo ":: Compressing rootfs"
gzip --best ${DISTRIBUTION}-${ARCH}.tar
rm -rf "./${DISTRIBUTION}-${ARCH}.tar"
echo ":: Generated rootfs for ${DISTRIBUTION}-${ARCH}"