diff --git a/unraid-1/basement.template.xml b/unraid-1/basement.template.xml index e3950ec..59251e5 100644 --- a/unraid-1/basement.template.xml +++ b/unraid-1/basement.template.xml @@ -55,7 +55,7 @@ Publicly served at https://basement.pq.io via Caddy on classe (reverse proxy → __GARAGE_ADMIN_TOKEN__ garage - - + __BASEMENT_ADMIN_USER__ + __BASEMENT_ADMIN_PASSWORD_HASH__ __BASEMENT_JWT_SECRET__ diff --git a/unraid-1/install.sh b/unraid-1/install.sh index ce69522..6189170 100755 --- a/unraid-1/install.sh +++ b/unraid-1/install.sh @@ -102,11 +102,30 @@ fetch_template \ -e "s|__GARAGE_ADMIN_TOKEN__|$GARAGE_ADMIN_TOKEN|" \ -e "s|__GARAGE_METRICS_TOKEN__|$GARAGE_METRICS_TOKEN|" +# Preserve user-set fields (admin user + password hash) across re-runs: +# pull whatever's currently in the existing my-basement.xml so we can +# sub it back into the freshly-fetched template. First-time installs +# substitute to empty (placeholders disappear) and the user fills them +# in via the Unraid UI; subsequent re-runs keep what they set. +PREV_BASEMENT_USER="" +PREV_BASEMENT_HASH="" +if [ -f "$TEMPLATE_DIR/my-basement.xml" ]; then + PREV_BASEMENT_USER=$(sed -n 's|.*]*>\([^<]*\).*|\1|p' "$TEMPLATE_DIR/my-basement.xml" | head -1) + PREV_BASEMENT_HASH=$(sed -n 's|.*]*>\([^<]*\).*|\1|p' "$TEMPLATE_DIR/my-basement.xml" | head -1) + # Don't carry forward the literal placeholder from an early-run template + [ "$PREV_BASEMENT_USER" = "__BASEMENT_ADMIN_USER__" ] && PREV_BASEMENT_USER="" + [ "$PREV_BASEMENT_HASH" = "__BASEMENT_ADMIN_PASSWORD_HASH__" ] && PREV_BASEMENT_HASH="" + [ -n "$PREV_BASEMENT_USER" ] && say "preserving BASEMENT_ADMIN_USER from existing template" + [ -n "$PREV_BASEMENT_HASH" ] && say "preserving BASEMENT_ADMIN_PASSWORD_HASH from existing template" +fi + fetch_template \ "$BASE/basement.template.xml" \ "$TEMPLATE_DIR/my-basement.xml" \ -e "s|__GARAGE_ADMIN_TOKEN__|$GARAGE_ADMIN_TOKEN|" \ - -e "s|__BASEMENT_JWT_SECRET__|$BASEMENT_JWT_SECRET|" + -e "s|__BASEMENT_JWT_SECRET__|$BASEMENT_JWT_SECRET|" \ + -e "s|__BASEMENT_ADMIN_USER__|$PREV_BASEMENT_USER|" \ + -e "s|__BASEMENT_ADMIN_PASSWORD_HASH__|$PREV_BASEMENT_HASH|" fetch_template \ "$BASE/watchtower.template.xml" \