From 1a8d40d631237ea466b2af64308675238e960a68 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Mon, 1 Jun 2026 21:28:09 -0400 Subject: [PATCH] unraid_api_key_renew: always sync registry key to conf Previously exited early when key was found in registry without checking if the conf matched. After a reboot or key rotation the registry holds the current key but the conf could have a stale value causing API auth failures on every boot. Now compares registry key to conf value and syncs if they differ. --- unRAID_Essentials/unraid_api_key_renew.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/unRAID_Essentials/unraid_api_key_renew.sh b/unRAID_Essentials/unraid_api_key_renew.sh index 4270a6a..251b8df 100755 --- a/unRAID_Essentials/unraid_api_key_renew.sh +++ b/unRAID_Essentials/unraid_api_key_renew.sh @@ -63,8 +63,21 @@ KEY=$(echo "$EXISTING" | jq -r '.key // empty' 2>/dev/null) if [[ -n "$KEY" ]]; then PREVIEW="${KEY:0:8}...${KEY: -4}" - echo "API key valid ✅ — $VAR_NAME = $PREVIEW" - log "Key found in registry — no renewal needed" + # Always sync registry key → conf — prevents stale key mismatch after reboot/update + CONF_KEY=$(grep "^\s*${VAR_NAME}\s*=" "$CONF_FILE" 2>/dev/null | \ + sed 's/.*="\(.*\)".*/\1/' | tr -d '[:space:]') + if [[ "$CONF_KEY" == "$KEY" ]]; then + echo "API key valid ✅ — $VAR_NAME = $PREVIEW" + log "Key in sync — no update needed" + exit 0 + fi + log "Registry key differs from conf — syncing..." + if grep -q "^\s*${VAR_NAME}\s*=" "$CONF_FILE"; then + sed -i "s|^\(\s*${VAR_NAME}\s*=\s*\)\"[^\"]*\"|\1\"${KEY}\"|" "$CONF_FILE" + else + echo " ${VAR_NAME}=\"${KEY}\"" >> "$CONF_FILE" + fi + warn "API key synced to conf ✅ — $VAR_NAME = $PREVIEW" exit 0 fi