refactor: consolidate test-iso.sh and monitor-build.sh into run.sh
- Merged VM testing functions into run.sh (test:iso commands) - Merged build monitoring into run.sh (monitor command) - Updated tests to reference ./run.sh test:iso instead of ./test-iso.sh - Updated documentation (README.md, AGENTS.md, STATUS.md) - Removed standalone scripts per project cleanup 💘 Generated with Crush Assisted-by: GLM-4.7 via Crush <crush@charm.land>
This commit is contained in:
433
run.sh
433
run.sh
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# KNEL-Football ISO Builder - Host Wrapper
|
||||
# This script orchestrates Docker-based build process
|
||||
# KNEL-Football ISO Builder - Main Entry Point
|
||||
# Orchestrates Docker-based build process and VM testing
|
||||
# Copyright © 2026 Known Element Enterprises LLC
|
||||
# License: GNU Affero General Public License v3.0 only
|
||||
|
||||
@@ -12,30 +12,383 @@ readonly SCRIPT_DIR
|
||||
readonly DOCKER_IMAGE="knel-football-dev:latest"
|
||||
readonly OUTPUT_DIR="${SCRIPT_DIR}/output"
|
||||
readonly BUILD_DIR="${SCRIPT_DIR}/tmp"
|
||||
readonly BUILD_LOG="/tmp/knel-iso-build.log"
|
||||
|
||||
# VM Testing Configuration
|
||||
readonly ISO_PATH="${SCRIPT_DIR}/output/knel-football-secure-v1.0.0.iso"
|
||||
readonly VM_NAME="knel-football-test"
|
||||
readonly VM_RAM="2048"
|
||||
readonly VM_CPUS="2"
|
||||
readonly VM_DISK_SIZE="10G"
|
||||
readonly VM_DISK_PATH="/tmp/${VM_NAME}.qcow2"
|
||||
|
||||
# Colors for output
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[1;33m'
|
||||
readonly NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
|
||||
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
|
||||
|
||||
# Create output and build directories if they don't exist
|
||||
mkdir -p "${OUTPUT_DIR}" "${BUILD_DIR}"
|
||||
|
||||
# Function to show usage
|
||||
# ============================================================================
|
||||
# VM TESTING FUNCTIONS (merged from test-iso.sh)
|
||||
# ============================================================================
|
||||
|
||||
# Check VM testing prerequisites
|
||||
vm_check_prerequisites() {
|
||||
log_info "Checking VM testing prerequisites..."
|
||||
|
||||
# Check for virsh command
|
||||
if ! command -v virsh &> /dev/null; then
|
||||
log_error "virsh command not found"
|
||||
log_error "Install libvirt: sudo apt install libvirt-clients libvirt-daemon-system qemu-system-x86"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check actual libvirt access (not just group membership)
|
||||
if ! virsh list &> /dev/null; then
|
||||
log_error "Cannot connect to libvirt"
|
||||
log_error "Ensure libvirtd is running and you have access"
|
||||
log_error "Try: sudo usermod -aG libvirt \$USER && logout/login"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check for qemu-img command
|
||||
if ! command -v qemu-img &> /dev/null; then
|
||||
log_error "qemu-img command not found"
|
||||
log_error "Install qemu: sudo apt install qemu-utils"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check ISO exists
|
||||
if [[ ! -f "$ISO_PATH" ]]; then
|
||||
log_error "ISO not found at: $ISO_PATH"
|
||||
log_error "Build the ISO first: ./run.sh iso"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "All prerequisites satisfied"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Create VM disk image
|
||||
vm_create_disk() {
|
||||
log_info "Creating disk image: $VM_DISK_PATH"
|
||||
rm -f "$VM_DISK_PATH"
|
||||
qemu-img create -f qcow2 "$VM_DISK_PATH" "$VM_DISK_SIZE"
|
||||
}
|
||||
|
||||
# Create and start VM
|
||||
vm_create() {
|
||||
log_info "Creating VM: $VM_NAME"
|
||||
|
||||
# Destroy existing VM if present
|
||||
virsh destroy "$VM_NAME" 2>/dev/null || true
|
||||
virsh undefine "$VM_NAME" 2>/dev/null || true
|
||||
|
||||
# Create disk
|
||||
vm_create_disk
|
||||
|
||||
# Find UEFI firmware with Secure Boot support (REQUIRED)
|
||||
local uefi_code=""
|
||||
local uefi_vars=""
|
||||
|
||||
# Prefer Secure Boot enabled firmware
|
||||
for fw_dir in /usr/share/OVMF /usr/share/qemu; do
|
||||
if [[ -f "$fw_dir/OVMF_CODE_4M.secboot.fd" ]]; then
|
||||
uefi_code="$fw_dir/OVMF_CODE_4M.secboot.fd"
|
||||
uefi_vars="$fw_dir/OVMF_VARS_4M.ms.fd"
|
||||
break
|
||||
elif [[ -f "$fw_dir/OVMF_CODE_4M.fd" ]]; then
|
||||
uefi_code="$fw_dir/OVMF_CODE_4M.fd"
|
||||
uefi_vars="$fw_dir/OVMF_VARS_4M.fd"
|
||||
break
|
||||
elif [[ -f "$fw_dir/OVMF_CODE.fd" ]]; then
|
||||
uefi_code="$fw_dir/OVMF_CODE.fd"
|
||||
uefi_vars="$fw_dir/OVMF_VARS.fd"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "$uefi_code" || ! -f "$uefi_code" ]]; then
|
||||
log_error "UEFI firmware with Secure Boot (OVMF) not found"
|
||||
log_error "Install required: sudo apt install ovmf"
|
||||
log_error "UEFI with Secure Boot is REQUIRED for KNEL-Football testing"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Create copy of OVMF_VARS for this VM (Secure Boot state stored here)
|
||||
local vm_vars="/tmp/${VM_NAME}_OVMF_VARS.fd"
|
||||
cp "$uefi_vars" "$vm_vars"
|
||||
|
||||
if [[ "$uefi_code" == *".secboot.fd" ]]; then
|
||||
log_info "Using UEFI firmware with Secure Boot: $uefi_code"
|
||||
else
|
||||
log_warn "Using UEFI firmware WITHOUT Secure Boot: $uefi_code"
|
||||
log_warn "For full Secure Boot testing, install: sudo apt install ovmf"
|
||||
fi
|
||||
|
||||
# Try virt-install first, fall back to direct QEMU
|
||||
if virt-install \
|
||||
--connect qemu:///session \
|
||||
--name "$VM_NAME" \
|
||||
--ram "$VM_RAM" \
|
||||
--vcpus "$VM_CPUS" \
|
||||
--disk path="$VM_DISK_PATH",format=qcow2 \
|
||||
--cdrom "$ISO_PATH" \
|
||||
--os-variant debian12 \
|
||||
--network user \
|
||||
--graphics vnc,listen=0.0.0.0 \
|
||||
--boot uefi \
|
||||
--noautoconsole \
|
||||
--virt-type kvm 2>&1; then
|
||||
log_info "VM created via virt-install (UEFI mode)"
|
||||
else
|
||||
log_warn "virt-install failed, using direct QEMU with UEFI..."
|
||||
|
||||
# Use QEMU directly with UEFI firmware
|
||||
qemu-system-x86_64 \
|
||||
-name "$VM_NAME" \
|
||||
-m "$VM_RAM" \
|
||||
-smp "$VM_CPUS" \
|
||||
-drive file="$VM_DISK_PATH",format=qcow2,if=virtio \
|
||||
-cdrom "$ISO_PATH" \
|
||||
-netdev user,id=net0 \
|
||||
-device virtio-net-pci,netdev=net0 \
|
||||
-vnc :0 \
|
||||
-drive if=pflash,format=raw,readonly=on,file="$uefi_code" \
|
||||
-drive if=pflash,format=raw,file="$vm_vars" \
|
||||
-enable-kvm \
|
||||
-daemonize \
|
||||
-pidfile "/tmp/${VM_NAME}.pid"
|
||||
log_info "VM started via QEMU with UEFI (PID: $(cat /tmp/${VM_NAME}.pid 2>/dev/null || echo 'unknown'))"
|
||||
fi
|
||||
}
|
||||
|
||||
# Connect to VM console
|
||||
vm_console() {
|
||||
log_info "Connecting to VM console..."
|
||||
virsh console "$VM_NAME"
|
||||
}
|
||||
|
||||
# Get VM status
|
||||
vm_status() {
|
||||
log_info "VM Status for: $VM_NAME"
|
||||
virsh dominfo "$VM_NAME" 2>/dev/null || log_error "VM not running"
|
||||
}
|
||||
|
||||
# Check if VM is running
|
||||
vm_is_running() {
|
||||
# Check virsh first
|
||||
if virsh domstate "$VM_NAME" 2>/dev/null | grep -q "running"; then
|
||||
return 0
|
||||
fi
|
||||
# Check QEMU pidfile
|
||||
if [[ -f "/tmp/${VM_NAME}.pid" ]]; then
|
||||
local pid
|
||||
pid=$(cat "/tmp/${VM_NAME}.pid")
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Capture boot screenshot
|
||||
vm_capture_screen() {
|
||||
local output_dir="${SCRIPT_DIR}/tmp/vm-screenshots"
|
||||
mkdir -p "$output_dir"
|
||||
|
||||
log_info "Capturing boot screen..."
|
||||
virsh screenshot "$VM_NAME" "${output_dir}/boot-screen.ppm" 2>/dev/null || {
|
||||
log_warn "Could not capture screenshot"
|
||||
}
|
||||
}
|
||||
|
||||
# Destroy VM and cleanup
|
||||
vm_destroy() {
|
||||
log_info "Destroying VM: $VM_NAME"
|
||||
# Try virsh first
|
||||
virsh destroy "$VM_NAME" 2>/dev/null || true
|
||||
virsh undefine "$VM_NAME" 2>/dev/null || true
|
||||
# Kill QEMU process if running
|
||||
if [[ -f "/tmp/${VM_NAME}.pid" ]]; then
|
||||
local pid
|
||||
pid=$(cat "/tmp/${VM_NAME}.pid")
|
||||
kill "$pid" 2>/dev/null || true
|
||||
rm -f "/tmp/${VM_NAME}.pid"
|
||||
fi
|
||||
rm -f "$VM_DISK_PATH"
|
||||
log_info "Cleanup complete"
|
||||
}
|
||||
|
||||
# Run automated boot test
|
||||
vm_boot_test() {
|
||||
log_info "Running automated boot test..."
|
||||
|
||||
if ! vm_check_prerequisites; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
vm_create
|
||||
|
||||
log_info "Waiting for VM to boot (30 seconds)..."
|
||||
sleep 30
|
||||
|
||||
if vm_is_running; then
|
||||
log_info "VM is running - boot test PASSED"
|
||||
vm_status
|
||||
vm_capture_screen
|
||||
return 0
|
||||
else
|
||||
log_error "VM not running - boot test FAILED"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Test Secure Boot
|
||||
vm_test_secure_boot() {
|
||||
log_info "Testing Secure Boot..."
|
||||
|
||||
if ! vm_is_running; then
|
||||
log_error "VM not running, start it first"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "Secure Boot verification requires manual console inspection"
|
||||
log_info "Use: ./run.sh test:iso console"
|
||||
log_info "Then check: dmesg | grep -i secure"
|
||||
}
|
||||
|
||||
# Test FDE passphrase prompt
|
||||
vm_test_fde() {
|
||||
log_info "Testing FDE passphrase prompt..."
|
||||
|
||||
if ! vm_is_running; then
|
||||
log_error "VM not running, start it first"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "FDE prompt verification requires manual console inspection"
|
||||
log_info "Use: ./run.sh test:iso console"
|
||||
log_info "Watch for 'Please unlock disk' prompt during boot"
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# BUILD MONITOR FUNCTION (merged from monitor-build.sh)
|
||||
# ============================================================================
|
||||
|
||||
monitor_build() {
|
||||
local check_interval="${1:-180}"
|
||||
|
||||
echo "=== ISO Build Monitor ==="
|
||||
echo "Started: $(date)"
|
||||
echo "Checking every ${check_interval}s"
|
||||
echo "Log file: $BUILD_LOG"
|
||||
echo ""
|
||||
|
||||
while true; do
|
||||
if [ -f "$BUILD_LOG" ]; then
|
||||
local lines
|
||||
lines=$(wc -l < "$BUILD_LOG")
|
||||
local last_stage
|
||||
last_stage=$(grep -E "^\[.*\] lb (bootstrap|chroot|installer|binary|source)" "$BUILD_LOG" 2>/dev/null | tail -1)
|
||||
local errors
|
||||
errors=$(grep -ic "error\|failed\|fatal" "$BUILD_LOG" 2>/dev/null || echo "0")
|
||||
|
||||
echo "[$(date '+%H:%M:%S')] Lines: $lines | Errors: $errors"
|
||||
[ -n "$last_stage" ] && echo " Stage: $last_stage"
|
||||
|
||||
# Check if build completed
|
||||
if grep -q "ISO build completed" "$BUILD_LOG" 2>/dev/null; then
|
||||
echo ""
|
||||
echo "=== BUILD COMPLETED ==="
|
||||
echo "Finished: $(date)"
|
||||
ls -lh "${OUTPUT_DIR}"/*.iso 2>/dev/null || echo "No ISO found in output/"
|
||||
break
|
||||
fi
|
||||
|
||||
# Check if build failed
|
||||
if grep -q "ISO build failed" "$BUILD_LOG" 2>/dev/null; then
|
||||
echo ""
|
||||
echo "=== BUILD FAILED ==="
|
||||
echo "Check log: $BUILD_LOG"
|
||||
tail -20 "$BUILD_LOG"
|
||||
break
|
||||
fi
|
||||
else
|
||||
echo "[$(date '+%H:%M:%S')] Waiting for build log..."
|
||||
fi
|
||||
|
||||
sleep "$check_interval"
|
||||
done
|
||||
}
|
||||
|
||||
# ============================================================================
|
||||
# USAGE AND MAIN
|
||||
# ============================================================================
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [command]"
|
||||
echo "Commands:"
|
||||
echo " build Build Docker image"
|
||||
echo " test Run all tests"
|
||||
echo " test:unit Run unit tests only"
|
||||
echo " test:integration Run integration tests only"
|
||||
echo " test:security Run security tests only"
|
||||
echo " test:system Run system tests only (requires libvirt)"
|
||||
echo " test:iso Test ISO with libvirt VM (runs on host)"
|
||||
echo " lint Run linting checks"
|
||||
echo " clean Clean build artifacts"
|
||||
echo " shell Interactive shell in build container"
|
||||
echo " iso Build ISO (30-60 minutes)"
|
||||
echo " help Show this help message"
|
||||
cat <<EOF
|
||||
KNEL-Football ISO Builder - Main Entry Point
|
||||
|
||||
Usage: $0 <command> [args]
|
||||
|
||||
Build Commands:
|
||||
build Build Docker image
|
||||
iso Build ISO (60-90 minutes)
|
||||
monitor [secs] Monitor build progress (default: check every 180s)
|
||||
clean Clean build artifacts
|
||||
|
||||
Test Commands:
|
||||
test Run all tests
|
||||
test:unit Run unit tests only
|
||||
test:integration Run integration tests only
|
||||
test:security Run security tests only
|
||||
test:system Run system tests only (requires libvirt)
|
||||
lint Run linting checks (shellcheck)
|
||||
|
||||
VM Testing Commands (requires libvirt on host):
|
||||
test:iso check Check VM testing prerequisites
|
||||
test:iso create Create and start test VM (UEFI/Secure Boot)
|
||||
test:iso console Connect to VM console
|
||||
test:iso status Show VM status
|
||||
test:iso destroy Destroy VM and cleanup
|
||||
test:iso boot-test Run automated boot test
|
||||
test:iso secure-boot Test Secure Boot (manual verification)
|
||||
test:iso fde-test Test FDE passphrase prompt (manual verification)
|
||||
|
||||
Other Commands:
|
||||
shell Interactive shell in build container
|
||||
help Show this help message
|
||||
|
||||
Prerequisites for VM Testing:
|
||||
- User must be in libvirt group
|
||||
- libvirtd service must be running
|
||||
- OVMF must be installed (sudo apt install ovmf)
|
||||
- ISO must exist in output/
|
||||
|
||||
Examples:
|
||||
$0 build # Build Docker image
|
||||
$0 iso # Build ISO (60-90 min)
|
||||
$0 monitor # Monitor build progress
|
||||
$0 test # Run all tests
|
||||
$0 test:iso boot-test # Boot test in VM
|
||||
$0 test:iso console # Connect to VM console
|
||||
$0 test:iso destroy # Cleanup test VM
|
||||
|
||||
Note: After adding user to libvirt group, logout and login again.
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Main execution logic
|
||||
# Main entry point
|
||||
main() {
|
||||
local command="${1:-help}"
|
||||
|
||||
@@ -175,11 +528,51 @@ else
|
||||
echo "ISO build failed"
|
||||
exit 1
|
||||
fi
|
||||
' 2>&1 | tee /tmp/knel-iso-build.log
|
||||
' 2>&1 | tee "$BUILD_LOG"
|
||||
;;
|
||||
monitor)
|
||||
monitor_build "${2:-180}"
|
||||
;;
|
||||
test:iso)
|
||||
shift # Remove 'test:iso' from args
|
||||
bash "${SCRIPT_DIR}/test-iso.sh" "$@"
|
||||
local subcmd="${1:-help}"
|
||||
case "$subcmd" in
|
||||
check)
|
||||
vm_check_prerequisites
|
||||
;;
|
||||
create)
|
||||
vm_check_prerequisites && vm_create
|
||||
;;
|
||||
console)
|
||||
vm_console
|
||||
;;
|
||||
status)
|
||||
vm_status
|
||||
;;
|
||||
destroy)
|
||||
vm_destroy
|
||||
;;
|
||||
boot-test)
|
||||
vm_boot_test
|
||||
;;
|
||||
secure-boot)
|
||||
vm_test_secure_boot
|
||||
;;
|
||||
fde-test)
|
||||
vm_test_fde
|
||||
;;
|
||||
help|*)
|
||||
echo "VM Testing Commands:"
|
||||
echo " check Check prerequisites"
|
||||
echo " create Create and start test VM"
|
||||
echo " console Connect to VM console"
|
||||
echo " status Show VM status"
|
||||
echo " destroy Destroy VM and cleanup"
|
||||
echo " boot-test Run automated boot test"
|
||||
echo " secure-boot Test Secure Boot"
|
||||
echo " fde-test Test FDE passphrase prompt"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
help|*)
|
||||
usage
|
||||
|
||||
Reference in New Issue
Block a user