Stop resolve_remote_scripts_dir silently returning the local path as the partner's

SSH_TIMEOUT comes from the calling script, so a caller without it made timeout fail before ssh ran; with stderr discarded the fallback then named this host's SCRIPTS_DIR as the remote's.
This commit is contained in:
Gmer4Lfe
2026-08-17 12:13:51 -04:00
parent 74e3b8b067
commit 73bbae14c1
+19 -3
View File
@@ -848,12 +848,28 @@ read_remote_conf_array() {
resolve_remote_scripts_dir() {
local ip="$1" ssh_key="${2:-$SSH_KEY}" strict_host_key="${3:-yes}"
local probe_cmd result
local -a opts=(-o ConnectTimeout="$SSH_TIMEOUT" -o BatchMode=yes)
# SSH_TIMEOUT is set by the calling script, not by any conf, so a caller that forgets it
# hands `timeout` an empty interval — which fails instantly, before ssh is ever run. With
# stderr discarded the failure is invisible and the fallback below then returns THIS host's
# SCRIPTS_DIR as though it were the partner's. Every use of the result is a remote path, so
# the caller goes on to run commands against a directory that exists here and not there.
# That is how Step 1b ended up pointing at /boot on an appdata mirror.
local _to="${SSH_TIMEOUT:-15}"
local -a opts=(-o ConnectTimeout="$_to" -o BatchMode=yes)
[[ "$strict_host_key" == "no" ]] && opts+=(-o StrictHostKeyChecking=no)
probe_cmd=$(platform_scripts_dir_probe_cmd)
result=$(timeout "$SSH_TIMEOUT" ssh -i "$ssh_key" "${opts[@]}" root@"$ip" "$probe_cmd" \
result=$(timeout "$_to" ssh -i "$ssh_key" "${opts[@]}" root@"$ip" "$probe_cmd" \
2>/dev/null | tr -d '[:space:]')
echo "${result:-$SCRIPTS_DIR}"
# A probe that answered is the only thing trusted. The fallback stays — callers need a path
# to name in an error message — but it is announced, because "we could not ask the partner
# where it keeps its scripts" and "the partner keeps them where we do" are different facts
# and were being reported identically.
if [[ -z "$result" ]]; then
warn "Could not read SCRIPTS_DIR from $ip — assuming $SCRIPTS_DIR, which is wrong if it runs from appdata" >&2
result="$SCRIPTS_DIR"
fi
echo "$result"
}
# ==============================================================================================