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:
+12
-4
@@ -190,10 +190,18 @@ install_nextcloud() {
|
||||
ensure_docker_dir_ownership "$DIR"
|
||||
cd "$DIR" || return 1
|
||||
|
||||
local DB_PASS
|
||||
DB_PASS=$(generate_password 32)
|
||||
local NC_ADMIN_PASS
|
||||
NC_ADMIN_PASS=$(generate_password 16)
|
||||
# Reused across reruns if already set — the MariaDB volume keeps DB_PASS
|
||||
# from its first init (regenerating it would lock Nextcloud out of its
|
||||
# own database), and NEXTCLOUD_ADMIN_USER/PASSWORD are only consulted by
|
||||
# the container on its very first boot to create the admin account —
|
||||
# printing a fresh NC_ADMIN_PASS on every rerun would silently show a
|
||||
# password that was never actually applied to the existing account.
|
||||
local DB_PASS=""
|
||||
[ -f ".env" ] && DB_PASS="$(grep '^MYSQL_PASSWORD=' .env | cut -d= -f2-)"
|
||||
[ -n "$DB_PASS" ] || DB_PASS="$(generate_password 32)"
|
||||
local NC_ADMIN_PASS=""
|
||||
[ -f ".env" ] && NC_ADMIN_PASS="$(grep '^NEXTCLOUD_ADMIN_PASSWORD=' .env | cut -d= -f2-)"
|
||||
[ -n "$NC_ADMIN_PASS" ] || NC_ADMIN_PASS="$(generate_password 16)"
|
||||
local TZ_VAL="${SITE_TZ:-UTC}"
|
||||
|
||||
# ── Dockerfile ──────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user