From 447b04ce2011ef89aab5b481969a694644b89d98 Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 17 Mar 2026 15:57:18 +0100 Subject: [PATCH] feat : preparation de postgresql (WIP) --- RebuildBdd/Checkup/check-postgresql.sh | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/RebuildBdd/Checkup/check-postgresql.sh b/RebuildBdd/Checkup/check-postgresql.sh index 3473922..33ae3e6 100755 --- a/RebuildBdd/Checkup/check-postgresql.sh +++ b/RebuildBdd/Checkup/check-postgresql.sh @@ -45,6 +45,31 @@ require_cmd() { command -v "$1" >/dev/null 2>&1 } +ensure_postgres_cluster() { + if ! require_cmd pg_lsclusters || ! require_cmd pg_createcluster; then + return 0 + fi + + if pg_lsclusters --no-header 2>/dev/null | grep -q .; then + return 0 + fi + + local version="" + if [[ -d /etc/postgresql ]]; then + version="$(find /etc/postgresql -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | LC_ALL=C sort -V | tail -n 1)" + fi + + if [[ -z "$version" ]] && require_cmd psql; then + version="$(psql --version 2>/dev/null | awk '{print $3}' | cut -d. -f1)" + fi + + [[ -n "$version" ]] || return 1 + + log "Aucun cluster PostgreSQL détecté, création de ${version}/main..." + "$SUDO_BIN" pg_createcluster "$version" main --start >/dev/null 2>&1 || return 1 + return 0 +} + collect_postgres_diagnostics() { local diagnostics="" @@ -134,6 +159,8 @@ else log "PostgreSQL déjà installé." fi +ensure_postgres_cluster || fail "aucun cluster PostgreSQL disponible et création automatique impossible" + if ! "$SUDO_BIN" systemctl is-active --quiet "$POSTGRES_SERVICE_NAME"; then log "Démarrage du service PostgreSQL..." if ! start_postgres_service; then