AnotterKiosk/build_raspberry_pi.sh

86 lines
2.7 KiB
Bash
Raw Normal View History

2023-06-29 22:14:05 +02:00
#!/bin/bash
2023-06-29 22:34:26 +02:00
# *sigh*, some docker containers don't seem to have sbin in their PATH
export PATH=$PATH:/usr/sbin
2023-06-29 22:14:05 +02:00
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
BUILD_DIR="${SCRIPT_DIR}/work/root/"
2023-06-29 23:47:30 +02:00
# cleanup any previous build attempts
2023-06-29 22:14:05 +02:00
umount -fl "${BUILD_DIR}" || true
losetup -D /dev/loop0 || true
rm -rf "${BUILD_DIR}" || true
mkdir -p "${BUILD_DIR}"
2023-06-29 23:47:30 +02:00
# download a modern RaspiOS build
2023-06-29 22:14:05 +02:00
if [ ! -f raspios.img.xz ]
then
wget -O raspios.img.xz "https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2023-05-03/2023-05-03-raspios-bullseye-arm64-lite.img.xz"
echo "bf982e56b0374712d93e185780d121e3f5c3d5e33052a95f72f9aed468d58fa7 raspios.img.xz" | sha256sum --check --status
2023-06-29 22:37:01 +02:00
if [ $? -ne 0 ]
then
2023-06-29 22:14:05 +02:00
echo "downloaded raspios does not match checksum";
return -1;
fi
fi
rm -f raspios.img
xz -kd raspios.img.xz
# Repartition image
2023-06-29 23:00:37 +02:00
export LIBGUESTFS_BACKEND_SETTINGS=force_tcg
2023-06-29 22:14:05 +02:00
truncate -r raspios.img raspikiosk.img
truncate -s +3G raspikiosk.img
virt-resize --expand /dev/sda2 raspios.img raspikiosk.img
rm -f raspios.img
# Setup loop device for Raspberry Pi image (with partition scanning)
sudo losetup -P /dev/loop0 raspikiosk.img
# Mount partitions
sudo mount /dev/loop0p2 "${BUILD_DIR}"
sudo mount /dev/loop0p1 "${BUILD_DIR}/boot"
# Copy the (raspberry pi-specific) skeleton files
2023-06-29 23:09:37 +02:00
sudo rsync -a "${SCRIPT_DIR}/raspberry_pi_skeleton/." "${BUILD_DIR}"
sudo rsync -a "${SCRIPT_DIR}/kiosk_skeleton/." "${BUILD_DIR}/kiosk_skeleton"
2023-06-29 22:14:05 +02:00
2023-06-29 23:47:30 +02:00
# Make fstab read-only
sed -i 's/vfat defaults/vfat ro,defaults/g' "${BUILD_DIR}/etc/fstab"
sed -i 's/ext4 defaults/ext4 ro,defaults/g' "${BUILD_DIR}/etc/fstab"
# Include git repo version info
echo -n "AnotterKiosk repository version: " > "${BUILD_DIR}/version-info"
git describe --abbrev=4 --dirty --always --tags >> "${BUILD_DIR}/version-info"
echo >> "${BUILD_DIR}/version-info"
2023-06-29 22:14:05 +02:00
# Mount system partitions (from the build host)
2023-06-29 23:28:05 +02:00
sudo mount proc -t proc -o nosuid,noexec,nodev "${BUILD_DIR}/proc/"
sudo mount sys -t sysfs -o nosuid,noexec,nodev,ro "${BUILD_DIR}/sys/"
sudo mount devpts -t devtmpfs -o mode=0755,nosuid "${BUILD_DIR}/dev/"
2023-06-29 22:14:05 +02:00
2023-06-29 23:47:30 +02:00
# Raspbian currently ships only Debian 11. Let's upgrade to 12.
2023-06-29 22:14:05 +02:00
sudo chroot "${BUILD_DIR}" /raspberry_pi_bullseye.sh
2023-06-29 23:47:30 +02:00
# and then actually install everything.
2023-06-29 22:14:05 +02:00
sudo chroot "${BUILD_DIR}" /kiosk_skeleton/build.sh
sudo rm -r "${BUILD_DIR}/kiosk_skeleton"
sudo rm "${BUILD_DIR}/raspberry_pi_bullseye.sh"
2023-06-29 23:47:30 +02:00
cp "${BUILD_DIR}/version-info" raspikiosk.version
2023-06-29 22:14:05 +02:00
sudo umount -fl "${BUILD_DIR}/proc"
sudo umount -fl "${BUILD_DIR}/sys"
sudo umount -fl "${BUILD_DIR}/dev"
sudo umount "${BUILD_DIR}/proc"
sudo umount "${BUILD_DIR}/sys"
sudo umount "${BUILD_DIR}/dev"
sudo umount "${BUILD_DIR}/boot"
sudo umount "${BUILD_DIR}"
sudo losetup -D /dev/loop0