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