#!/usr/bin/env bash # iso-install-test.sh — valida el lazo COMPLETO de instalación desde el medio live (refinamiento #1): # (1) arma un ISO instalador (iso-image.sh INSTALLER=1 AUTO_INSTALL=/dev/vda) con el payload de disco # (kernel + GRUB MBR + /usr/bin/takana-install) bundleado; # (2) lo bootea con un disco EN BLANCO ⇒ el /init desatendido corre takana-install y apaga; # (3) bootea ESE disco SOLO (sin ISO, sin -kernel) ⇒ el producto instalado arranca y sirve SSH. # Cierra el lazo "ISO live → disco instalado → bootea solo", lo que hace la distro distribuible. # # Uso: PRODUCT= ./scripts/iso-install-test.sh # Vars: KERNEL MEM (def 4096) KVM (def 1) DISK_MB (def 4096) INSTALL_DEADLINE (def 180) BOOT_DEADLINE (def 90) set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT" KERNEL="${KERNEL:-$(ls store/*-linux/boot/bzImage 2>/dev/null | head -1)}" MEM="${MEM:-4096}"; KVM="${KVM:-1}"; DISK_MB="${DISK_MB:-4096}" INSTALL_DEADLINE="${INSTALL_DEADLINE:-180}"; BOOT_DEADLINE="${BOOT_DEADLINE:-90}" WORK="$ROOT/work/iso-install-test"; ISO="$WORK/installer.iso"; TGT="$WORK/target.img" ILOG="$WORK/install.log"; BLOG="$WORK/diskboot.log" mkdir -p "$WORK" if [ -n "${PRODUCT:-}" ]; then PDIR=$(ls -d store/"${PRODUCT#b3:}"*-product-rootfs 2>/dev/null | head -1) else PDIR=$(ls -dt store/*-product-rootfs 2>/dev/null | head -1) fi [ -n "$PDIR" ] && [ -d "$PDIR" ] || { echo "no encuentro product-rootfs"; exit 1; } [ -n "$KERNEL" ] && [ -e "$KERNEL" ] || { echo "no encuentro kernel"; exit 1; } echo "==> product-rootfs: $PDIR" accel=(); if [ "$KVM" = 1 ] && [ -w /dev/kvm ]; then accel=(-enable-kvm -cpu host); fi echo "==> (1) armando ISO instalador (INSTALLER=1, AUTO_INSTALL=/dev/vda)" ROOTFS="$PDIR" ISO="$ISO" KERNEL="$KERNEL" INSTALLER=1 AUTO_INSTALL=/dev/vda ./scripts/iso-image.sh >/dev/null echo " ISO: $(du -h "$ISO" | cut -f1)" echo "==> (2) boot del instalador con disco EN BLANCO ${DISK_MB}M (auto-instala y apaga)" rm -f "$TGT"; truncate -s "${DISK_MB}M" "$TGT" timeout "$INSTALL_DEADLINE" qemu-system-x86_64 -m "$MEM" -no-reboot -nographic "${accel[@]}" \ -drive file="$TGT",format=raw,if=virtio -cdrom "$ISO" -boot d > "$ILOG" 2>&1 || true if ! grep -q "TAKANA-INSTALL-OK" "$ILOG"; then echo "✗ la instalación NO terminó OK — ver $ILOG" >&2 grep -iE "TAKANA-INSTALL-FAIL|takana-install:|no apareció|error" "$ILOG" | head; exit 1 fi echo " ✓ TAKANA-INSTALL-OK" echo "==> (3) boot del DISCO instalado (sin ISO, sin -kernel)" timeout "$BOOT_DEADLINE" qemu-system-x86_64 -m "$MEM" -no-reboot -nographic "${accel[@]}" \ -drive file="$TGT",format=raw,if=virtio > "$BLOG" 2>&1 || true fail=0 check() { if grep -qiE "$1" "$BLOG"; then echo " ✓ $2"; else echo " ✗ $2" >&2; fail=1; fi; } reject() { if grep -qiE "$1" "$BLOG"; then echo " ✗ $2 (apareció)" >&2; fail=1; else echo " ✓ $2"; fi; } echo "==> asserts sobre el arranque del disco:" check "GNU GRUB" "GRUB del disco (MBR→core.img del hueco post-MBR)" check "Linux version 6\.16" "kernel cargado del disco" check "Server listening on .* port 22" "sshd escuchando (producto instalado en servicio)" check "hammer-recover:" "hook de auto-recover de upgrades corrió al arranque (#4b)" reject "ARRANQUE FALLIDO|seed.card no encontrada" "arje-zero arrancó sin fallo de seed" reject "no pude montar" "particiones dedicadas /store y /var/lib/hammer montadas" if [ "$fail" = 0 ]; then echo; echo "✓✓ INSTALL-FROM-LIVE VERDE: ISO live → takana-install → disco que bootea solo y sirve SSH" else echo; echo "✗ install-from-live FALLÓ — ver $ILOG / $BLOG" >&2; exit 1 fi