Skip to content

Commit 7cfd346

Browse files
committed
fix: preserve admin credentials across re-runs (idempotency)
When ./setup.sh is re-run, generate_env_file() overwrites .env, destroying auto-generated admin passwords. configure_arr_auth() then sees 'Forms' already configured and returns early without re-appending credentials, leaving manage.sh keys showing blank passwords. Fix: extract existing admin credentials in check_existing_installation() and inject them back into .env in generate_env_file() when present.
1 parent 70ad26e commit 7cfd346

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

setup.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,20 @@ DECYPHARR_USER="${DECYPHARR_USER:-torbox}"
911911
DECYPHARR_PASS="${DECYPHARR_PASS:-}"
912912
ENV_EOF
913913

914+
# Preserve existing admin credentials if this is a re-run
915+
if [[ -n "${EXISTING_RADARR_ADMIN_USER:-}" ]]; then
916+
cat >> "${ENV_FILE}" << ADMIN_EOF
917+
918+
# Admin Credentials (Preserved)
919+
RADARR_ADMIN_USER="${EXISTING_RADARR_ADMIN_USER}"
920+
RADARR_ADMIN_PASS="${EXISTING_RADARR_ADMIN_PASS}"
921+
SONARR_ADMIN_USER="${EXISTING_SONARR_ADMIN_USER}"
922+
SONARR_ADMIN_PASS="${EXISTING_SONARR_ADMIN_PASS}"
923+
PROWLARR_ADMIN_USER="${EXISTING_PROWLARR_ADMIN_USER}"
924+
PROWLARR_ADMIN_PASS="${EXISTING_PROWLARR_ADMIN_PASS}"
925+
ADMIN_EOF
926+
fi
927+
914928
chmod 600 "${ENV_FILE}"
915929
log_info "Environment file written (profile: ${compose_profile})."
916930
}
@@ -2342,6 +2356,12 @@ EXISTING_RADARR_API_KEY=""
23422356
EXISTING_SONARR_API_KEY=""
23432357
EXISTING_PROWLARR_API_KEY=""
23442358
EXISTING_TORBOX_API_KEY=""
2359+
EXISTING_RADARR_ADMIN_USER=""
2360+
EXISTING_RADARR_ADMIN_PASS=""
2361+
EXISTING_SONARR_ADMIN_USER=""
2362+
EXISTING_SONARR_ADMIN_PASS=""
2363+
EXISTING_PROWLARR_ADMIN_USER=""
2364+
EXISTING_PROWLARR_ADMIN_PASS=""
23452365

23462366
check_existing_installation() {
23472367
if [[ -f "${SETUP_COMPLETE_FILE}" ]]; then
@@ -2379,6 +2399,14 @@ check_existing_installation() {
23792399
EXISTING_TORBOX_API_KEY=$(grep '^TORBOX_API_KEY=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
23802400
EXISTING_COMPOSE_PROFILES=$(grep '^COMPOSE_PROFILES=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
23812401

2402+
# Extract existing admin credentials
2403+
EXISTING_RADARR_ADMIN_USER=$(grep '^RADARR_ADMIN_USER=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
2404+
EXISTING_RADARR_ADMIN_PASS=$(grep '^RADARR_ADMIN_PASS=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
2405+
EXISTING_SONARR_ADMIN_USER=$(grep '^SONARR_ADMIN_USER=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
2406+
EXISTING_SONARR_ADMIN_PASS=$(grep '^SONARR_ADMIN_PASS=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
2407+
EXISTING_PROWLARR_ADMIN_USER=$(grep '^PROWLARR_ADMIN_USER=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
2408+
EXISTING_PROWLARR_ADMIN_PASS=$(grep '^PROWLARR_ADMIN_PASS=' "${ENV_FILE}" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'") || true
2409+
23822410
# Validate extracted API keys are valid 32-char hex; regenerate if corrupted
23832411
if [[ -n "$EXISTING_RADARR_API_KEY" && ! "$EXISTING_RADARR_API_KEY" =~ ^[0-9a-f]{32}$ ]]; then
23842412
log_warn "Corrupted API key detected for Radarr. Will regenerate."

0 commit comments

Comments
 (0)