This commit is contained in:
Zsolt Alföldi
2026-02-25 18:53:59 +01:00
parent 573d727305
commit 561044e548
3 changed files with 26 additions and 27 deletions

41
build-iso.sh Normal file → Executable file
View File

@@ -19,7 +19,7 @@
set -euo pipefail
UBUNTU_ISO="${UBUNTU_ISO:-}"
UBUNTU_VERSION="24.04"
UBUNTU_VERSION="24.04.4"
UBUNTU_ISO_URL="https://releases.ubuntu.com/${UBUNTU_VERSION}/ubuntu-${UBUNTU_VERSION}-live-server-amd64.iso"
WORK_DIR="$(mktemp -d /tmp/autoinstall-build.XXXXXX)"
OUTPUT_ISO="autoinstall-$(date +%Y%m%d-%H%M).iso"
@@ -81,19 +81,27 @@ if grep -qE '\$\{[A-Z_]+\}' "$RENDERED_FILE"; then
fi
info "Template rendered."
# ── Get Ubuntu ISO ─────────────────────────────────────────────────────────────
if [[ -z "$UBUNTU_ISO" ]]; then
if [[ -n "$UBUNTU_ISO" ]]; then
# User provided a path — validate it exists
[[ -f "$UBUNTU_ISO" ]] || error "ISO not found: $UBUNTU_ISO"
info "Using provided ISO: $UBUNTU_ISO"
else
# Auto mode — use default name, download if missing
# UBUNTU_ISO="ubuntu-${UBUNTU_VERSION}-desktop-amd64.iso"
UBUNTU_ISO="ubuntu-${UBUNTU_VERSION}-live-server-amd64.iso"
if [[ ! -f "$UBUNTU_ISO" ]]; then
info "Downloading Ubuntu ${UBUNTU_VERSION} server ISO..."
curl -L --progress-bar -o "$UBUNTU_ISO" "$UBUNTU_ISO_URL"
curl -L --fail --progress-bar -o "$UBUNTU_ISO" "$UBUNTU_ISO_URL" ||
{
rm -f "$UBUNTU_ISO"
error "Download failed (check URL or network): $UBUNTU_ISO_URL"
}
else
info "Found cached ISO: $UBUNTU_ISO"
fi
fi
[[ -f "$UBUNTU_ISO" ]] || error "ISO not found: $UBUNTU_ISO"
# ── Extract ISO ────────────────────────────────────────────────────────────────
# ── Extract ISO + MBR template ────────────────────────────────────────────────
info "Extracting ISO..."
xorriso -osirrox on -indev "$UBUNTU_ISO" -extract / "$WORK_DIR/iso" 2>/dev/null
chmod -R u+w "$WORK_DIR/iso"
@@ -106,15 +114,6 @@ cp "$RENDERED_FILE" "$NOCLOUD_DIR/user-data"
cp "$POST_INSTALL_SCRIPT" "$NOCLOUD_DIR/post-install.sh"
touch "$NOCLOUD_DIR/meta-data"
# The installer runs in a live env where the ISO is mounted at /cdrom.
# post-install.sh lands at /cdrom/nocloud/post-install.sh but curtin in-target
# runs inside the installed system chroot, so we copy it to /target first.
# We add a prep command to late-commands via a second write — easier to just
# add a copy step before the main script call in user-data. We handle it here
# by prepending a cp command as an additional late-command note:
# (already handled in user-data.tmpl with: curtin in-target -- bash /post-install.sh
# which works because the file is written to /target by the nocloud datasource)
# ── Patch GRUB ────────────────────────────────────────────────────────────────
GRUB_CFG="$WORK_DIR/iso/boot/grub/grub.cfg"
if [[ -f "$GRUB_CFG" ]]; then
@@ -125,18 +124,6 @@ fi
# ── Repack ISO ─────────────────────────────────────────────────────────────────
info "Repacking ISO → $OUTPUT_ISO ..."
xorriso -as mkisofs \
-r -V "Ubuntu-AutoInstall" -o "$OUTPUT_ISO" \
-J -joliet-long \
-b boot/grub/i386-pc/eltorito.img -c boot.catalog \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--grub2-boot-info \
--grub2-mbr "$WORK_DIR/iso/boot/grub/i386-pc/boot_hybrid.img" \
-eltorito-alt-boot \
-e --interval:appended_partition_2:all:: -no-emul-boot \
-append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b "$WORK_DIR/iso/boot/grub/efi.img" \
-iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
"$WORK_DIR/iso" 2>/dev/null
info "Done! ✓"
echo ""