Push the API key to the conf path the partner actually uses, and say so when there is no conf there
This commit is contained in:
@@ -34,7 +34,8 @@
|
|||||||
# 1. Check whether a Varaverk key already exists in the unraid-api registry
|
# 1. Check whether a Varaverk key already exists in the unraid-api registry
|
||||||
# 2. Create or overwrite it — the registry is ephemeral, so re-registering is the norm
|
# 2. Create or overwrite it — the registry is ephemeral, so re-registering is the norm
|
||||||
# 3. Write the resulting key into this host's conf, replacing any previous value
|
# 3. Write the resulting key into this host's conf, replacing any previous value
|
||||||
# 4. Report whether the key was created, refreshed, or unchanged
|
# 4. Push the key into each partner's OWN conf, at the path their varaverk.cfg reports
|
||||||
|
# 5. Report whether the key was created, refreshed, or unchanged
|
||||||
#
|
#
|
||||||
# Runs at array start. The registry does not survive OS updates or an unraid-api restart,
|
# Runs at array start. The registry does not survive OS updates or an unraid-api restart,
|
||||||
# which is why this re-registers unconditionally rather than only when the key is missing —
|
# which is why this re-registers unconditionally rather than only when the key is missing —
|
||||||
@@ -49,6 +50,17 @@
|
|||||||
# Conf file check — aborts before any writes if the host conf is missing
|
# Conf file check — aborts before any writes if the host conf is missing
|
||||||
# dry-run mode — shows what would happen without touching anything
|
# dry-run mode — shows what would happen without touching anything
|
||||||
#
|
#
|
||||||
|
# Remote path discovery
|
||||||
|
# The partner's conf path comes from resolve_remote_scripts_dir(), which reads their
|
||||||
|
# varaverk.cfg, so a partner in appdata storage mode is found. The path was hardcoded
|
||||||
|
# to the flash plugin directory, which is wrong for any such partner.
|
||||||
|
#
|
||||||
|
# Remote target must exist
|
||||||
|
# The pushed script refuses to create the conf and reports the path it looked at.
|
||||||
|
# resolve_remote_scripts_dir() falls back to our own SCRIPTS_DIR when the probe fails,
|
||||||
|
# and appending an API key to a merely plausible path is how the hardcoded version
|
||||||
|
# failed without saying so.
|
||||||
|
#
|
||||||
# ==============================================================================================
|
# ==============================================================================================
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
# ==============================================================================================
|
# ==============================================================================================
|
||||||
@@ -194,6 +206,9 @@ if [[ -z "$SSH_KEY" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# resolve_remote_scripts_dir() reads this; every inline timeout below already uses 10.
|
||||||
|
SSH_TIMEOUT=10
|
||||||
|
|
||||||
for host_var in $(compgen -v | grep -E '^HOST[0-9]+$'); do
|
for host_var in $(compgen -v | grep -E '^HOST[0-9]+$'); do
|
||||||
partner_host="${!host_var}"
|
partner_host="${!host_var}"
|
||||||
[[ -z "$partner_host" ]] && continue
|
[[ -z "$partner_host" ]] && continue
|
||||||
@@ -203,16 +218,27 @@ for host_var in $(compgen -v | grep -E '^HOST[0-9]+$'); do
|
|||||||
partner_ip=$(resolve_tailscale_ip "$partner_host" 2>/dev/null || true)
|
partner_ip=$(resolve_tailscale_ip "$partner_host" 2>/dev/null || true)
|
||||||
[[ -z "$partner_ip" ]] && { log "Cannot resolve IP for $partner_host — skipping"; continue; }
|
[[ -z "$partner_ip" ]] && { log "Cannot resolve IP for $partner_host — skipping"; continue; }
|
||||||
|
|
||||||
# Target is the partner's OWN conf on their machine
|
# Target is the partner's OWN conf on their machine. Their SCRIPTS_DIR is read from their
|
||||||
partner_conf="/boot/config/plugins/varaverk/Configurations/${partner_slot}.conf"
|
# varaverk.cfg rather than assumed — this was hardcoded to the flash plugin path, so a
|
||||||
|
# partner in appdata storage mode had its key appended under a directory that does not
|
||||||
|
# exist there. HOST2 has run in appdata mode since it was installed.
|
||||||
|
partner_sd=$(resolve_remote_scripts_dir "$partner_ip" "$SSH_KEY" "no")
|
||||||
|
partner_conf="${partner_sd}/Configurations/${partner_slot}.conf"
|
||||||
tmp=$(mktemp /tmp/vv_kp_XXXXXX.sh)
|
tmp=$(mktemp /tmp/vv_kp_XXXXXX.sh)
|
||||||
remote="/tmp/vv_kp_${RANDOM}.sh"
|
remote="/tmp/vv_kp_${RANDOM}.sh"
|
||||||
chmod 700 "$tmp"
|
chmod 700 "$tmp"
|
||||||
|
|
||||||
# Key stays in the temp file — never appears in SSH command args
|
# Key stays in the temp file — never appears in SSH command args.
|
||||||
|
# The conf must already exist: resolve_remote_scripts_dir falls back to our own SCRIPTS_DIR
|
||||||
|
# when the probe fails, and appending a key to a path that is merely plausible is how the
|
||||||
|
# hardcoded version failed silently. Report the path instead of guessing.
|
||||||
cat > "$tmp" <<PUSHSCRIPT
|
cat > "$tmp" <<PUSHSCRIPT
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
target='${partner_conf}'
|
target='${partner_conf}'
|
||||||
|
if [ ! -f "\$target" ]; then
|
||||||
|
echo "missing:\$target"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
if grep -q "\b${VAR_NAME}\b" "\$target" 2>/dev/null; then
|
if grep -q "\b${VAR_NAME}\b" "\$target" 2>/dev/null; then
|
||||||
sed -i 's|^\(\\s*${VAR_NAME}\\s*=\\s*\)"[^"]*"|\1"${KEY}"|' "\$target"
|
sed -i 's|^\(\\s*${VAR_NAME}\\s*=\\s*\)"[^"]*"|\1"${KEY}"|' "\$target"
|
||||||
else
|
else
|
||||||
@@ -223,13 +249,14 @@ PUSHSCRIPT
|
|||||||
|
|
||||||
if timeout 10 scp -i "$SSH_KEY" -o ConnectTimeout=10 -o BatchMode=yes \
|
if timeout 10 scp -i "$SSH_KEY" -o ConnectTimeout=10 -o BatchMode=yes \
|
||||||
-o StrictHostKeyChecking=no "$tmp" "root@${partner_ip}:${remote}" 2>/dev/null; then
|
-o StrictHostKeyChecking=no "$tmp" "root@${partner_ip}:${remote}" 2>/dev/null; then
|
||||||
if timeout 10 ssh -i "$SSH_KEY" -o ConnectTimeout=10 -o BatchMode=yes \
|
push_out=$(timeout 10 ssh -i "$SSH_KEY" -o ConnectTimeout=10 -o BatchMode=yes \
|
||||||
-o StrictHostKeyChecking=no "root@${partner_ip}" \
|
-o StrictHostKeyChecking=no "root@${partner_ip}" \
|
||||||
"bash '${remote}'; rc=\$?; rm -f '${remote}'; exit \$rc" 2>/dev/null | grep -q ok; then
|
"bash '${remote}'; rc=\$?; rm -f '${remote}'; exit \$rc" 2>/dev/null)
|
||||||
echo "Key pushed to $partner_host ✅"
|
case "$push_out" in
|
||||||
else
|
*ok*) echo "Key pushed to $partner_host ✅" ;;
|
||||||
warn "Key push to $partner_host failed — they can create their own copy"
|
missing:*) warn "Key push to $partner_host failed — no conf at ${push_out#missing:}" ;;
|
||||||
fi
|
*) warn "Key push to $partner_host failed — they can create their own copy" ;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
warn "SCP to $partner_host failed — skipping"
|
warn "SCP to $partner_host failed — skipping"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user