#!/usr/bin/env bash set -euo pipefail WORKDIR="$(pwd)/work" ROOTFS="$WORKDIR/rootfs" ISO="$WORKDIR/iso" rm -rf "$WORKDIR" mkdir -p "$ROOTFS" mkdir -p "$ISO/live" cleanup() { umount -R "$ROOTFS" 2>/dev/null || true umount -lf "$ROOTFS/dev/pts" 2>/dev/null || true umount -lf "$ROOTFS/dev/shm" 2>/dev/null || true umount -lf "$ROOTFS/dev" 2>/dev/null || true umount -lf "$ROOTFS/proc" 2>/dev/null || true umount -lf "$ROOTFS/sys" 2>/dev/null || true } trap cleanup EXIT echo "=== Extracting RootFS ===" tar --zstd -xf espos-openrc-rootfs.tar.zst -C "$ROOTFS" echo "=== Mounting pseudo filesystems ===" mount --bind /dev "$ROOTFS/dev" mount --bind /proc "$ROOTFS/proc" mount --bind /sys "$ROOTFS/sys" cleanup() { umount -lf "$ROOTFS/dev" 2>/dev/null || true umount -lf "$ROOTFS/proc" 2>/dev/null || true umount -lf "$ROOTFS/sys" 2>/dev/null || true } trap cleanup EXIT echo "=== Configuring Live User ===" chroot "$ROOTFS" bash <<'EOF' set -e apt update DEBIAN_FRONTEND=noninteractive apt install -y \ sudo \ live-boot \ live-config if ! id liveuser >/dev/null 2>&1; then useradd -m -s /bin/bash liveuser fi passwd -d liveuser echo "liveuser ALL=(ALL) NOPASSWD:ALL" \ > /etc/sudoers.d/liveuser chmod 440 /etc/sudoers.d/liveuser mkdir -p /etc/conf.d cat >/etc/conf.d/agetty.tty1 </dev/null || true umount -lf "$ROOTFS/dev/pts" 2>/dev/null || true umount -lf "$ROOTFS/dev/shm" 2>/dev/null || true umount -lf "$ROOTFS/dev" 2>/dev/null || true umount -lf "$ROOTFS/proc" 2>/dev/null || true umount -lf "$ROOTFS/sys" 2>/dev/null || true echo "=== Building SquashFS ===" mksquashfs \ "$ROOTFS" \ "$ISO/live/filesystem.squashfs" \ -comp zstd \ -e boot echo "=== Creating GRUB Layout ===" mkdir -p "$ISO/boot/grub" cat > "$ISO/boot/grub/grub.cfg" <