diff --git a/autoinstall/build-iso.sh b/autoinstall/build-iso.sh index f79ee56..432196d 100644 --- a/autoinstall/build-iso.sh +++ b/autoinstall/build-iso.sh @@ -1,70 +1,44 @@ #!/usr/bin/env bash # ───────────────────────────────────────────────────────────── # Cezen AI Suite — Custom ISO Builder -# Runs on macOS using Docker. Produces a bootable USB image. +# Runs directly on Ubuntu 22.04 (run on the server) # -# Usage: bash autoinstall/build-iso.sh -# Output: autoinstall/cezen-ai-ubuntu2204.iso +# Usage: +# cd ~/aipackage +# bash autoinstall/build-iso.sh # -# Requirements: -# - Docker Desktop running on your MacBook -# - ~6 GB free disk space (ISO download + work) +# Output: ~/aipackage/autoinstall/cezen-ai-ubuntu2204.iso +# Then copy the ISO to a USB stick or burn it. # ───────────────────────────────────────────────────────────── set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +WORK_DIR="/tmp/cezen-iso-work" +ORIGINAL_ISO="/tmp/ubuntu-22.04.5-live-server-amd64.iso" OUTPUT_ISO="$SCRIPT_DIR/cezen-ai-ubuntu2204.iso" -UBUNTU_ISO_URL="https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso" +UBUNTU_URL="https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso" echo "╔══════════════════════════════════════════╗" echo "║ Cezen AI — ISO Builder ║" echo "╚══════════════════════════════════════════╝" echo "" -# Check Docker is running -if ! docker info &>/dev/null; then - echo "ERROR: Docker is not running. Start Docker Desktop and try again." - exit 1 -fi -echo "✓ Docker is running" - -# Check autoinstall files exist -if [ ! -f "$SCRIPT_DIR/user-data" ] || [ ! -f "$SCRIPT_DIR/meta-data" ]; then - echo "ERROR: user-data or meta-data not found in $SCRIPT_DIR" - exit 1 -fi -echo "✓ Autoinstall files found" - -echo "" -echo "→ Building ISO inside Docker container (Ubuntu 22.04)..." -echo " This will take 5–15 minutes depending on internet speed." -echo "" - -docker run --rm \ - -v "$SCRIPT_DIR:/autoinstall" \ - -v "$REPO_ROOT:/repo" \ - ubuntu:22.04 \ - bash -c ' -set -e - -# Install tools -export DEBIAN_FRONTEND=noninteractive +# ── Install build tools ──────────────────────── +echo "→ Installing build tools..." apt-get update -qq -apt-get install -y -qq xorriso wget isolinux rsync +apt-get install -y -qq xorriso wget isolinux +echo "✓ Tools ready" -WORK_DIR="/tmp/iso-work" -ORIGINAL_ISO="/tmp/ubuntu-22.04.5-live-server-amd64.iso" -UBUNTU_URL="https://releases.ubuntu.com/22.04.5/ubuntu-22.04.5-live-server-amd64.iso" - -# Download Ubuntu ISO if not already cached -if [ ! -f "$ORIGINAL_ISO" ]; then +# ── Download Ubuntu ISO ──────────────────────── +if [ -f "$ORIGINAL_ISO" ]; then + echo "✓ Ubuntu ISO already downloaded" +else echo "→ Downloading Ubuntu 22.04.5 Server ISO (~1.8 GB)..." - wget -q --show-progress -O "$ORIGINAL_ISO" "$UBUNTU_URL" + wget --show-progress -O "$ORIGINAL_ISO" "$UBUNTU_URL" + echo "✓ Downloaded" fi -echo "✓ Ubuntu ISO ready" -# Extract ISO contents +# ── Extract ISO ──────────────────────────────── echo "→ Extracting ISO..." rm -rf "$WORK_DIR" mkdir -p "$WORK_DIR" @@ -72,47 +46,46 @@ xorriso -osirrox on \ -indev "$ORIGINAL_ISO" \ -extract / "$WORK_DIR" 2>/dev/null chmod -R u+w "$WORK_DIR" -echo "✓ ISO extracted" +echo "✓ Extracted" -# Inject autoinstall files +# ── Inject autoinstall files ─────────────────── echo "→ Injecting autoinstall config..." mkdir -p "$WORK_DIR/nocloud" -cp /autoinstall/user-data "$WORK_DIR/nocloud/user-data" -cp /autoinstall/meta-data "$WORK_DIR/nocloud/meta-data" +cp "$SCRIPT_DIR/user-data" "$WORK_DIR/nocloud/user-data" +cp "$SCRIPT_DIR/meta-data" "$WORK_DIR/nocloud/meta-data" +echo "✓ user-data and meta-data injected" -# Modify GRUB to auto-select install with autoinstall +# ── Patch GRUB ──────────────────────────────── +echo "→ Patching GRUB config..." GRUB_CFG="$WORK_DIR/boot/grub/grub.cfg" - -# Backup original cp "$GRUB_CFG" "$GRUB_CFG.orig" -# Set default to first entry and zero timeout +# Set 5 second countdown then auto-install sed -i "s/set timeout=.*/set timeout=5/" "$GRUB_CFG" sed -i "s/set timeout_style=.*/set timeout_style=countdown/" "$GRUB_CFG" -# Add autoinstall + nocloud parameters to the first linux line -# This patches the "Install Ubuntu Server" entry +# Add autoinstall params to the first linux kernel line sed -i "/^\s*linux.*vmlinuz/s/$/ autoinstall quiet ds=nocloud;s=\/cdrom\/nocloud\//" "$GRUB_CFG" +echo "✓ GRUB patched" -echo "✓ GRUB config patched" - -# Get original ISO metadata for repacking +# ── Get EFI partition info for repacking ─────── MBR_TEMPLATE=$(mktemp) dd if="$ORIGINAL_ISO" bs=1 count=432 of="$MBR_TEMPLATE" 2>/dev/null -# Get EFI partition info -EFI_START=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk "{print \$2}") -EFI_SIZE=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk "{print \$4}") +EFI_START=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk '{print $2}') +EFI_SIZE=$(fdisk -l "$ORIGINAL_ISO" 2>/dev/null | grep "EFI" | awk '{print $4}') -echo "→ Repacking ISO..." +# ── Repack ISO ───────────────────────────────── +echo "→ Repacking ISO (this takes ~2 minutes)..." xorriso -as mkisofs \ -r \ -V "Cezen_AI_Ubuntu2204" \ - -o /autoinstall/cezen-ai-ubuntu2204.iso \ + -o "$OUTPUT_ISO" \ --grub2-mbr "$MBR_TEMPLATE" \ -partition_offset 16 \ --mbr-force-bootable \ - -append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b "$WORK_DIR/boot/grub/efi.img" \ + -append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b \ + "$WORK_DIR/boot/grub/efi.img" \ -appended_part_as_gpt \ -iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \ -c "/boot.catalog" \ @@ -127,18 +100,17 @@ xorriso -as mkisofs \ -boot-load-size 4 \ "$WORK_DIR" 2>/dev/null -echo "✓ ISO built successfully" -ls -lh /autoinstall/cezen-ai-ubuntu2204.iso -' - echo "" echo "╔══════════════════════════════════════════════════════╗" -echo "║ ISO built: autoinstall/cezen-ai-ubuntu2204.iso ║" -echo "║ ║" -echo "║ Flash to USB: ║" -echo "║ sudo dd if=autoinstall/cezen-ai-ubuntu2204.iso \ ║" -echo "║ of=/dev/diskX bs=4m status=progress ║" -echo "║ (replace /dev/diskX with your USB drive) ║" +echo "║ Done! ║" echo "╚══════════════════════════════════════════════════════╝" echo "" -echo "→ To find your USB drive: diskutil list" +ls -lh "$OUTPUT_ISO" +echo "" +echo "→ Copy to your MacBook:" +echo " scp user@172.16.10.180:~/aipackage/autoinstall/cezen-ai-ubuntu2204.iso ." +echo "" +echo "→ Flash to USB on MacBook:" +echo " diskutil list # find USB e.g. /dev/disk4" +echo " diskutil unmountDisk /dev/disk4" +echo " sudo dd if=cezen-ai-ubuntu2204.iso of=/dev/disk4 bs=4m status=progress"