banger/verify.sh

57 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
log() {
printf '[verify] %s\n' "$*"
}
cleanup() {
if [[ -n "${VM_INFO:-}" && -f "$VM_INFO" ]]; then
# shellcheck disable=SC1090
source "$VM_INFO"
if [[ -n "${pid:-}" ]]; then
sudo kill "$pid" 2>/dev/null || true
fi
if [[ -n "${tap:-}" ]]; then
sudo ip link del "$tap" 2>/dev/null || true
fi
if [[ -n "${vm_dir:-}" ]]; then
rm -rf "$vm_dir"
fi
fi
}
trap cleanup EXIT
log "starting VM"
./run.sh
VM_DIR="$(ls -dt state/vm-* | head -n 1)"
VM_INFO="$VM_DIR/info"
if [[ ! -f "$VM_INFO" ]]; then
log "info file not found: $VM_INFO"
exit 1
fi
# shellcheck disable=SC1090
source "$VM_INFO"
vm_dir="$VM_DIR"
log "asserting VM is reachable via SSH"
ssh -i "./id_ed25519" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
"root@${guest_ip}" "uname -a" >/dev/null
log "cleaning up VM"
cleanup
log "asserting cleanup success"
if ip link show "$tap" >/dev/null 2>&1; then
log "tap still exists: $tap"
exit 1
fi
if [[ -d "$vm_dir" ]]; then
log "vm dir still exists: $vm_dir"
exit 1
fi
log "ok"