fix(push-host-keys): detect non-interactive stdin, direct to SUDO_PASS

read exits non-zero when stdin is not a terminal (set -e killed the
script silently). Catch that and emit a clear error pointing to the
SUDO_PASS environment variable rather than crashing with no output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 15:55:06 +10:00
co-authored by Claude Sonnet 4.6
parent fa53d37360
commit b65d78a515
+8 -1
View File
@@ -66,7 +66,14 @@ prompt_sudo_password() {
sudo_password="$SUDO_PASS"
return
fi
read -r -s -p "sudo password for ${SSH_USER} on remote hosts: " sudo_password
# read exits non-zero when stdin is not a terminal (e.g. CI, background
# agents). Catch that and give a clear message rather than a silent exit.
if ! read -r -s -p "sudo password for ${SSH_USER} on remote hosts: " sudo_password; then
echo >&2
echo "ERROR: stdin is not a terminal -- cannot prompt for sudo password." >&2
echo " Set SUDO_PASS=<password> in the environment and re-run." >&2
exit 1
fi
echo >&2
}