diff --git a/install.sh b/install.sh index 1822a3b..a566baa 100755 --- a/install.sh +++ b/install.sh @@ -101,6 +101,12 @@ info "Richte PostgreSQL ein..." systemctl enable postgresql --quiet systemctl start postgresql +# Falls config.yml schon existiert, DB-Passwort daraus lesen (verhindert Passwort-Mismatch bei Re-Install) +if [ -f "$CONFIG_DIR/config.yml" ]; then + EXISTING_PW=$(grep -A5 '^database:' "$CONFIG_DIR/config.yml" | awk '/password:/{print $2}' | head -1) + [[ -n "$EXISTING_PW" ]] && DB_PASSWORD="$EXISTING_PW" && info "DB-Passwort aus vorhandener config.yml übernommen" +fi + su -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='archivmail'\" | grep -q 1 \ && psql -c \"ALTER USER archivmail WITH PASSWORD '$DB_PASSWORD'\" \ || psql -c \"CREATE USER archivmail WITH PASSWORD '$DB_PASSWORD'\"" postgres