#!/bin/bash # Network diagnostics for VM testing # Author: Craig Jennings # License: GNU GPLv3 # Note: logging.sh and vm-utils.sh should already be sourced by the calling script # Uses globals: ROOT_PASSWORD, SSH_PORT, SSH_OPTS, VM_IP (from vm-utils.sh or calling script) # Run quick network diagnostics run_network_diagnostics() { local password="${ROOT_PASSWORD:-archsetup}" local port="${SSH_PORT:-22}" local host="${VM_IP:-localhost}" local ssh_base="sshpass -p $password ssh $SSH_OPTS -p $port root@$host" section "Pre-flight Network Diagnostics" # Test 1: Basic connectivity (use curl instead of ping - SLIRP may not handle ICMP) step "Testing internet connectivity" if $ssh_base "curl -s --connect-timeout 5 -o /dev/null http://archlinux.org" 2>/dev/null; then success "Internet connectivity OK" else error "No internet connectivity" return 1 fi # Test 2: DNS resolution (use getent which is always available, unlike nslookup/dig) step "Testing DNS resolution" if $ssh_base "getent hosts archlinux.org >/dev/null 2>&1" 2>/dev/null; then success "DNS resolution OK" else error "DNS resolution failed" return 1 fi # Test 3: Arch mirror accessibility step "Testing Arch mirror access" if $ssh_base "curl -s -I https://mirrors.kernel.org/archlinux/ | head -1 | grep -qE '(200|301)'" 2>/dev/null; then success "Arch mirrors accessible" else error "Cannot reach Arch mirrors" return 1 fi # Test 4: AUR accessibility step "Testing AUR access" if $ssh_base "curl -s -I https://aur.archlinux.org/ | head -1 | grep -qE '(200|405)'" 2>/dev/null; then success "AUR accessible" else error "Cannot reach AUR" return 1 fi # Show network info info "Network configuration:" $ssh_base "ip addr show | grep 'inet ' | grep -v '127.0.0.1'" 2>/dev/null | while read line; do info " $line" done success "Network diagnostics complete" return 0 }