summaryrefslogtreecommitdiff
path: root/scripts/testing/create-base-vm.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-13 23:26:21 -0600
committerCraig Jennings <c@cjennings.net>2025-11-13 23:26:21 -0600
commit2e10a8856d0bdd4c8f77c53320221ad1b8deaa13 (patch)
tree95832c3b74fc523fe9d8319e25c5ea5bf1d40433 /scripts/testing/create-base-vm.sh
parentfd9cce59993556400b635256d712a65d87f5d72d (diff)
fix(archsetup): implement critical bug fixes and test improvements
This commit addresses several high-priority bugs and enhances the testing infrastructure: **Bug Fixes:** 1. Add root permission check at script start to fail fast with clear error message 2. Disable debug package installation by adding --nodebug flag to all yay calls 3. Replace unsafe `git pull --force` with safe rm + fresh clone to prevent data loss 4. Add geoclue package with correct systemd service configuration for geolocation 5. Add completion marker for reliable automated test detection **Testing Infrastructure:** - Add comprehensive VM-based testing framework in scripts/testing/ - Fix test script pgrep infinite loop using grep bracket self-exclusion pattern - Add network diagnostics and pre-flight checks - Support snapshot-based testing for reproducible test runs **Package Management:** - Remove anki (build hangs 98+ minutes) - Remove adwaita-color-schemes (CMake build issues) Test Results: 0 errors, 1,363 packages installed in 40 minutes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'scripts/testing/create-base-vm.sh')
-rwxr-xr-xscripts/testing/create-base-vm.sh173
1 files changed, 173 insertions, 0 deletions
diff --git a/scripts/testing/create-base-vm.sh b/scripts/testing/create-base-vm.sh
new file mode 100755
index 0000000..03409fe
--- /dev/null
+++ b/scripts/testing/create-base-vm.sh
@@ -0,0 +1,173 @@
+#!/bin/bash
+# Create base VM for archsetup testing - Manual Installation
+# Author: Craig Jennings <craigmartinjennings@gmail.com>
+# License: GNU GPLv3
+#
+# This script creates a VM booted from Arch ISO, then waits for you to
+# manually install Arch using archinstall.
+
+set -e
+
+# Get script directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
+
+# Source utilities
+source "$SCRIPT_DIR/lib/logging.sh"
+source "$SCRIPT_DIR/lib/vm-utils.sh"
+
+# Configuration
+VM_NAME="archsetup-base"
+VM_CPUS="${VM_CPUS:-4}"
+VM_RAM="${VM_RAM:-8192}" # MB
+VM_DISK="${VM_DISK:-50}" # GB
+VM_IMAGES_DIR="$PROJECT_ROOT/vm-images"
+ISO_URL="https://mirrors.kernel.org/archlinux/iso/latest/archlinux-x86_64.iso"
+ISO_PATH="$VM_IMAGES_DIR/arch-latest.iso"
+DISK_PATH="$VM_IMAGES_DIR/archsetup-base.qcow2"
+
+# Initialize logging
+LOGFILE="$PROJECT_ROOT/test-results/create-base-vm-$(date +'%Y%m%d-%H%M%S').log"
+init_logging "$LOGFILE"
+
+section "Creating Base VM for ArchSetup Testing"
+
+# Verify prerequisites
+step "Checking prerequisites"
+check_libvirt || fatal "libvirt not running"
+check_libvirt_group || fatal "User not in libvirt group"
+check_kvm || fatal "KVM not available"
+success "Prerequisites satisfied"
+
+# Create vm-images directory
+mkdir -p "$VM_IMAGES_DIR"
+
+# Download Arch ISO if needed
+section "Preparing Arch Linux ISO"
+
+if [ -f "$ISO_PATH" ]; then
+ info "Arch ISO exists: $ISO_PATH"
+
+ # Check if ISO is older than 30 days
+ if [ $(find "$ISO_PATH" -mtime +30 | wc -l) -gt 0 ]; then
+ warn "ISO is older than 30 days"
+ info "Downloading latest version..."
+ rm -f "$ISO_PATH"
+ else
+ success "Using existing ISO"
+ fi
+fi
+
+if [ ! -f "$ISO_PATH" ]; then
+ step "Downloading latest Arch ISO"
+ info "URL: $ISO_URL"
+ info "This may take several minutes..."
+
+ if wget --progress=dot:giga -O "$ISO_PATH" "$ISO_URL" 2>&1 | tee -a "$LOGFILE"; then
+ success "ISO downloaded"
+ else
+ fatal "ISO download failed"
+ fi
+fi
+
+# Remove existing VM and disk
+if vm_exists "$VM_NAME"; then
+ warn "VM $VM_NAME already exists - destroying it"
+ if vm_is_running "$VM_NAME"; then
+ virsh destroy "$VM_NAME" >> "$LOGFILE" 2>&1
+ fi
+ virsh undefine "$VM_NAME" --nvram >> "$LOGFILE" 2>&1 || true
+fi
+
+[ -f "$DISK_PATH" ] && rm -f "$DISK_PATH"
+
+# Create and start VM
+section "Creating and Starting VM"
+
+info "Creating VM: $VM_NAME"
+info " CPUs: $VM_CPUS | RAM: ${VM_RAM}MB | Disk: ${VM_DISK}GB"
+
+virt-install \
+ --connect qemu:///system \
+ --name "$VM_NAME" \
+ --memory "$VM_RAM" \
+ --vcpus "$VM_CPUS" \
+ --disk path="$DISK_PATH",size="$VM_DISK",format=qcow2,bus=virtio \
+ --cdrom "$ISO_PATH" \
+ --os-variant archlinux \
+ --network network=default,model=virtio \
+ --graphics vnc,listen=127.0.0.1 \
+ --console pty,target.type=serial \
+ --boot uefi \
+ --noreboot \
+ --check path_in_use=off \
+ --filesystem type=mount,mode=mapped,source="$PROJECT_ROOT/scripts",target=host-scripts \
+ >> "$LOGFILE" 2>&1 &
+
+VIRT_INSTALL_PID=$!
+
+progress "Waiting for VM to boot from ISO"
+sleep 30
+
+# Check if VM started
+if ! vm_is_running "$VM_NAME"; then
+ wait $VIRT_INSTALL_PID
+ EXIT_CODE=$?
+ fatal "VM failed to start (exit code: $EXIT_CODE)"
+fi
+
+success "VM started successfully"
+
+# Display manual installation instructions
+section "Manual Installation Required"
+
+cat << 'EOF'
+
+[i]
+[i] Base VM is running from Arch ISO
+[i]
+[i] NEXT STEPS - Complete installation manually:
+[i]
+[i] 1. Open virt-viewer (should already be open):
+[i] virt-viewer --connect qemu:///system archsetup-base
+[i]
+[i] 2. Login as 'root' (no password)
+[i]
+[i] 3. Run: archinstall
+[i]
+[i] 4. Configure with these settings:
+[i] - Hostname: archsetup-test
+[i] - Root password: archsetup
+[i] - Profile: minimal
+[i] - Network: dhcpcd (or NetworkManager)
+[i] - Additional packages: openssh git vim sudo iperf3 mtr traceroute bind net-tools sshfs
+[i] - Enable: sshd, dhcpcd (or NetworkManager)
+[i]
+[i] 5. After archinstall completes:
+[i] - Chroot into /mnt: arch-chroot /mnt
+[i] - Edit /etc/ssh/sshd_config:
+[i] sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
+[i] sed -i 's/#PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
+[i] - Set up shared folder mount (9p filesystem):
+[i] mkdir -p /mnt/host-scripts
+[i] echo 'host-scripts /mnt/host-scripts 9p trans=virtio,version=9p2000.L,rw 0 0' >> /etc/fstab
+[i] - Exit chroot: exit
+[i] - Poweroff: poweroff
+[i]
+[i] 6. After VM powers off, run:
+[i] ./scripts/testing/finalize-base-vm.sh
+[i]
+[i] Log file: $LOGFILE
+[i]
+
+EOF
+
+info "Waiting for VM to power off..."
+info "(This script will exit when you manually power off the VM)"
+
+# Wait for virt-install to finish (VM powers off)
+wait $VIRT_INSTALL_PID || true
+
+success "VM has powered off"
+info ""
+info "Next step: Run ./scripts/testing/finalize-base-vm.sh"