Fediversity/deployment/run/tf-proxmox/await-ssh.sh
Kiara Grouwstra 98bc0754cc
factor out await.ssh
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-23 22:42:38 +02:00

31 lines
604 B
Bash

#! /usr/bin/env bash
set -xeuo pipefail
declare username host key_file ssh_opts
readarray -t ssh_opts < <(echo "$ssh_opts" | jq -r '.[]')
sshOpts=(
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o ConnectTimeout=5 \
-o ServerAliveInterval=5 \
)
if [[ -n "${key_file}" ]]; then
sshOpts+=(
-i "${key_file}"
)
fi
for ssh_opt in "${ssh_opts[@]}"; do
sshOpts+=(
-o "${ssh_opt}"
)
done
for i in $(seq 1 30); do
if ssh "${sshOpts[@]}" "${username}@${host}" "true"; then
exit 0
fi
echo "Waiting for SSH (attempt #$i)..."
sleep 5
done
echo "SSH never came up!" >&2
exit 1