Fix DB/admin password regeneration on rerun in 5 services

Same bug class just fixed in mattermost.sh: immich, joplin, koha,
mail-archiver, and nextcloud all generated a fresh random
DB/admin password on every single run with no check for an
existing one. Each backs its database with a persistent volume, so
Postgres/MariaDB keeps the password from its first init while the
freshly overwritten .env (or config-main.env for koha) no longer
matches it — any rerun would have locked the app out of its own
database. koha, mail-archiver, and nextcloud also regenerated an
app-level admin login password the same way.

Found by cross-referencing every service with a DB password against
which ones actually guard reuse on rerun (only traccar.sh did,
already correctly) rather than waiting to be told about each one
individually.

Fix mirrors traccar.sh's existing pattern: read the password back out
of the existing .env/config file if present, only generate fresh when
there's genuinely nothing there yet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NQkdAn3iG5A4WoqU9FHMaN
This commit is contained in:
Claude
2026-08-04 17:08:55 +00:00
parent cf3d4bf6de
commit f731efa2fa
5 changed files with 55 additions and 12 deletions
+11 -2
View File
@@ -207,9 +207,18 @@ install_mail-archiver() {
ensure_docker_dir_ownership "$MA_DIR"
cd "$MA_DIR" || return 1
# Reused across reruns if already set — the Postgres volume keeps
# DB_PASS from its first init, and an already-created admin account
# keeps ADMIN_PASS; regenerating either on a rerun would lock the
# reinstall out of the database and the app's own admin login.
local DB_PASS ADMIN_PASS TZ_VAL
DB_PASS=$(generate_password 32)
ADMIN_PASS=$(generate_password 24)
DB_PASS="" ADMIN_PASS=""
if [ -f ".env" ]; then
DB_PASS="$(grep '^POSTGRES_PASSWORD=' .env | cut -d= -f2-)"
ADMIN_PASS="$(grep '^Authentication__Password=' .env | cut -d= -f2-)"
fi
[ -n "$DB_PASS" ] || DB_PASS="$(generate_password 32)"
[ -n "$ADMIN_PASS" ] || ADMIN_PASS="$(generate_password 24)"
TZ_VAL="${SITE_TZ:-$(cat /etc/timezone 2>/dev/null || echo UTC)}"
# Mirrors configure_caddy_for_service's own mode resolution (lib/common.sh):