From 092e888c3f1d49deaac4f7735e82a57573d92f46 Mon Sep 17 00:00:00 2001 From: Rick Peters Date: Wed, 30 Sep 2026 09:43:05 +0200 Subject: [PATCH] fix: the VM's ssh key is looked up at every call (a clean host failed the first-boot check: common.sh was sourced before the key existed) --- scripts/common.sh | 11 +++++++++-- scripts/vmbootloadertest.sh | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index f715e64..defc97a 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -17,8 +17,15 @@ VM_USER="${VM_USER:-theupriser}" VM_SSH_OPTS=(-o BatchMode=yes -o "UserKnownHostsFile=$VM_DIR/known_hosts" -o StrictHostKeyChecking=accept-new) if [[ -z "${VM_SSH_KEY:-}" && -f "$VM_DIR/ssh-key" ]]; then VM_SSH_KEY="$(cat "$VM_DIR/ssh-key")"; fi [[ -n "${VM_SSH_KEY:-}" ]] && VM_SSH_OPTS+=(-i "$VM_SSH_KEY" -o IdentitiesOnly=yes) -vm_ssh() { ssh -p "$VM_PORT" "${VM_SSH_OPTS[@]}" "$VM_USER@$VM_HOST" "$@"; } -vm_scp() { scp -q -P "$VM_PORT" "${VM_SSH_OPTS[@]}" "$@"; } +# The VM's key, looked up at every call: vminstall.sh and vmbootloadertest.sh source this file before the key +# exists or is chosen (a clean host has no other key the VM would accept). +vm_key() { + if [[ -n "${VM_SSH_KEY:-}" ]]; then printf '%s\n' "$VM_SSH_KEY" + elif [[ -f "$VM_DIR/ssh-key" ]]; then cat "$VM_DIR/ssh-key"; fi +} +_vm_key_opts() { local k; k="$(vm_key)"; [[ -n "$k" ]] && printf '%s\n' -i "$k" -o IdentitiesOnly=yes; } +vm_ssh() { local -a k; mapfile -t k < <(_vm_key_opts); ssh -p "$VM_PORT" "${VM_SSH_OPTS[@]}" "${k[@]}" "$VM_USER@$VM_HOST" "$@"; } +vm_scp() { local -a k; mapfile -t k < <(_vm_key_opts); scp -q -P "$VM_PORT" "${VM_SSH_OPTS[@]}" "${k[@]}" "$@"; } # One Konsole for every test run: it follows $TEST_LOG, which the test scripts append to. # Started only when there is a desktop, the run is headless and no such window exists. diff --git a/scripts/vmbootloadertest.sh b/scripts/vmbootloadertest.sh index 8d9472c..858d7f6 100755 --- a/scripts/vmbootloadertest.sh +++ b/scripts/vmbootloadertest.sh @@ -39,7 +39,7 @@ running() { pgrep -f "[h]ostfwd=tcp::$VM_PORT-" >/dev/null; } stop_vm() { running || return 0 # Whichever VM runs: its key and host key are not this VM's. - ssh -p "$VM_PORT" -i "$VM_SSH_KEY" -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR \ + ssh -p "$VM_PORT" -i "$(vm_key)" -o BatchMode=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR \ "$VM_USER@$VM_HOST" 'sudo systemctl poweroff' >/dev/null 2>&1 local _; for _ in $(seq 30); do running || return 0; sleep 2; done pkill -f "[h]ostfwd=tcp::$VM_PORT-"; sleep 2