#!/bin/bash # Setup testing environment for archsetup # Author: Craig Jennings # License: GNU GPLv3 # # This script performs one-time setup of the testing infrastructure: # - Installs QEMU/KVM, sshpass, OVMF firmware, and socat # - Verifies KVM support # - Creates directories for test artifacts 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" # Initialize logging mkdir -p "$PROJECT_ROOT/test-results" LOGFILE="$PROJECT_ROOT/test-results/setup-$(date +'%Y%m%d-%H%M%S').log" init_logging "$LOGFILE" section "ArchSetup Testing Environment Setup" # Check if running on Arch Linux if [ ! -f /etc/arch-release ]; then fatal "This script is designed for Arch Linux" fi # Check if user has sudo if ! sudo -n true 2>/dev/null; then warn "This script requires sudo access" info "You may be prompted for your password" fi # Install required packages section "Installing Required Packages" PACKAGES=( qemu-full sshpass edk2-ovmf socat ) to_install=() for pkg in "${PACKAGES[@]}"; do if pacman -Qi "$pkg" &>/dev/null; then info "$pkg is already installed" else to_install+=("$pkg") fi done if [ "${#to_install[@]}" -gt 0 ]; then step "Installing in one transaction: ${to_install[*]}" if sudo pacman -S --needed --noconfirm "${to_install[@]}" >> "$LOGFILE" 2>&1; then success "All required packages installed" else fatal "Package installation failed" fi fi # Verify KVM support section "Verifying KVM Support" if [ -e /dev/kvm ]; then if [ -r /dev/kvm ] && [ -w /dev/kvm ]; then success "KVM is available and accessible" else warn "KVM exists but is not readable/writable by user $(id -un)" info "Add the user to the kvm group: sudo gpasswd -a $(id -un) kvm" info "Then log out and back in so the new group takes effect" fi else error "KVM is not available" info "Check if virtualization is enabled in BIOS" info "Load kvm module: sudo modprobe kvm-intel (or kvm-amd)" fatal "KVM not available" fi # Check which KVM module is loaded if lsmod | grep -q kvm_intel; then info "Using Intel KVM" elif lsmod | grep -q kvm_amd; then info "Using AMD KVM" else warn "No KVM module detected" info "Load with: sudo modprobe kvm-intel (or kvm-amd)" fi # Verify OVMF firmware section "Verifying OVMF Firmware" OVMF_CODE="/usr/share/edk2/x64/OVMF_CODE.4m.fd" OVMF_VARS="/usr/share/edk2/x64/OVMF_VARS.4m.fd" if [ -f "$OVMF_CODE" ] && [ -f "$OVMF_VARS" ]; then success "OVMF firmware files present" else fatal "OVMF firmware files not found (expected at $OVMF_CODE)" fi # Create directory structure section "Creating Directory Structure" DIRS=( "$PROJECT_ROOT/vm-images" "$PROJECT_ROOT/test-results" ) for dir in "${DIRS[@]}"; do if [ -d "$dir" ]; then info "Directory exists: $dir" else step "Creating directory: $dir" if mkdir -p "$dir" 2>> "$LOGFILE"; then success "Directory created: $dir" else error "Failed to create directory: $dir" fi fi done # Summary section "Setup Complete" success "Testing environment is ready" info "" info "Next steps:" info " 1. Copy an archangel ISO to: $PROJECT_ROOT/vm-images/" info " 2. Create base VM: ./scripts/testing/create-base-vm.sh" info " 3. Run a test: ./scripts/testing/run-test.sh" info "" info "Log file: $LOGFILE"