#!/usr/bin/env bash # Builds the Fennec OS installer ISO (UEFI, x86-64) for a USB stick. # Run as root inside WSL Debian: # sudo bash /mnt/g/source/smartfox/image/build-iso.sh # Writes image/out/smartfox-installer.iso (in the source tree, so Rufus on # Windows can pick it up). Rufus: "ISO image mode", GPT, UEFI, FAT32. # Raw writers (Etcher, dd) work too: the ISO carries a GPT with an ESP holding # the UKI, so UEFI firmware sees the stick as bootable. # # SKIP_BUILD=1 reuses the last Fennec OS image instead of running build.sh. # Don't do that after booting it in run-qemu.sh: the VM writes into that file. set -euo pipefail SRC="$(cd "$(dirname "$0")/.." && pwd)" WORK="${SMARTFOX_WORK:-/root/smartfox}" OUT_DIR="$SRC/image/out" if [ "${SKIP_BUILD:-0}" != 1 ]; then bash "$SRC/image/build.sh" else echo "== sync installer sources" rsync -a --delete --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r "$SRC/image/installer/" "$WORK/image/installer/" \ --exclude /mkosi.output --exclude /mkosi.cache fi RAW="$WORK/image/mkosi.output/smartfox.raw" [ -f "$RAW" ] || { echo "missing $RAW"; exit 1; } for tool in xorriso mcopy mkfs.vfat zstd; do command -v "$tool" >/dev/null || { apt-get update -qq && apt-get install -y -qq xorriso mtools dosfstools zstd; break; } done echo "== installer (mkosi)" cd "$WORK/image/installer" chmod +x mkosi.postinst.chroot mkosi.extra/usr/bin/sf-install mkdir -p mkosi.cache mkosi -f build UKI="$WORK/image/installer/mkosi.output/smartfox-installer.efi" [ -f "$UKI" ] || { echo "missing $UKI"; exit 1; } echo "== payload" STAGE="$WORK/image/iso" rm -rf "$STAGE" mkdir -p "$STAGE/tree/EFI/BOOT" "$STAGE/tree/smartfox" cp "$UKI" "$STAGE/tree/EFI/BOOT/BOOTX64.EFI" stat -c %s "$RAW" >"$STAGE/tree/smartfox/smartfox.size" echo "Fennec OS $(grep -m1 '^version' "$WORK/Cargo.toml" | cut -d'"' -f2) · $(date +%Y-%m-%d)" >"$STAGE/tree/smartfox/version" zstd -T0 -10 -q "$RAW" -o "$STAGE/tree/smartfox/smartfox.raw.zst" # Rufus puts the files on FAT32: no single file may reach 4 GiB. [ "$(stat -c %s "$STAGE/tree/smartfox/smartfox.raw.zst")" -lt 4294967296 ] || { echo "payload too big for FAT32"; exit 1; } echo "== EFI boot image" EFI_IMG="$STAGE/efiboot.img" size_kb=$(( $(stat -c %s "$UKI") / 1024 + 4096 )) mkfs.vfat -C -n SFBOOT "$EFI_IMG" "$size_kb" >/dev/null mmd -i "$EFI_IMG" ::/EFI ::/EFI/BOOT mcopy -i "$EFI_IMG" "$UKI" ::/EFI/BOOT/BOOTX64.EFI echo "== iso" ISO="$STAGE/smartfox-installer.iso" xorriso -as mkisofs \ -iso-level 3 -full-iso9660-filenames -joliet -joliet-long -rational-rock \ -volid FENNEC_OS -appid "Fennec OS installer" \ -partition_offset 16 \ -append_partition 2 C12A7328-F81F-11D2-BA4B-00A0C93EC93B "$EFI_IMG" -appended_part_as_gpt \ -e --interval:appended_partition_2:all:: -no-emul-boot \ -o "$ISO" "$STAGE/tree" 2>&1 | grep -v '^xorriso : UPDATE' || true [ -f "$ISO" ] || { echo "xorriso failed"; exit 1; } mkdir -p "$OUT_DIR" cp "$ISO" "$OUT_DIR/smartfox-installer.iso" ls -lh "$OUT_DIR/smartfox-installer.iso" echo "Rufus: válaszd ki az ISO-t, Partíciós séma: GPT, Cél: UEFI, majd ISO kép mód."