Files

119 lines
2.4 KiB
Bash

#!/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 <<CFG
agetty_options="--autologin liveuser --noclear"
CFG
EOF
echo "=== Copying Kernel ==="
KERNEL="$(ls "$ROOTFS"/boot/vmlinuz-* | head -n1)"
INITRD="$(ls "$ROOTFS"/boot/initrd.img-* | head -n1)"
cp "$KERNEL" "$ISO/live/vmlinuz"
cp "$INITRD" "$ISO/live/initrd"
echo "=== Unmounting file systems ==="
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
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" <<EOF
set timeout=5
menuentry "EspOS OpenRC Live" {
linux /live/vmlinuz boot=live quiet
initrd /live/initrd
}
EOF
echo "=== Creating ISO ==="
grub-mkrescue \
-o EspOS-OpenRC-Live.iso \
"$ISO"
echo "=== Done ==="
ls -lh EspOS-OpenRC-Live.iso