diff --git a/scripts/server-postgres/.list_files.txt b/scripts/server-postgres/.list_files.txt index 6b23531..7151abb 100644 --- a/scripts/server-postgres/.list_files.txt +++ b/scripts/server-postgres/.list_files.txt @@ -1,3 +1,3 @@ create_pg_db.sh create_pg_role.sh -setup-postgres17.sh +setup-postgres.sh diff --git a/scripts/server-postgres/setup-postgres17.sh b/scripts/server-postgres/setup-postgres.sh similarity index 61% rename from scripts/server-postgres/setup-postgres17.sh rename to scripts/server-postgres/setup-postgres.sh index 6040975..9bcad81 100755 --- a/scripts/server-postgres/setup-postgres17.sh +++ b/scripts/server-postgres/setup-postgres.sh @@ -9,18 +9,32 @@ check_root set -e -echo "Ajout du dépôt officiel PostgreSQL 17..." -mkdir -p /etc/apt/keyrings -wget -qO /etc/apt/keyrings/postgresql.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc -chmod 644 /etc/apt/keyrings/postgresql.asc - -echo "deb [signed-by=/etc/apt/keyrings/postgresql.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list - -echo "Installation de PostgreSQL 17..." +echo "📦 Mise à jour des paquets..." apt update -y -apt install -y postgresql-17 -echo "Activation et démarrage du service PostgreSQL..." +echo "📚 Installation de postgresql-common (pour script de dépôt officiel)..." +apt install -y postgresql-common + +echo "➕ Ajout automatique du dépôt officiel PostgreSQL (via pgdg script)..." +/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y + +echo "" +echo "🧩 Versions disponibles dans le dépôt :" +AVAILABLE_VERSIONS=$(apt-cache search "^postgresql-[0-9][0-9]$" | awk '{print $1}' | cut -d'-' -f2 | sort -nr) +echo "$AVAILABLE_VERSIONS" + +read -p "➡️ Entrez la version PostgreSQL à installer (ex: 17) : " PG_VERSION + +if ! echo "$AVAILABLE_VERSIONS" | grep -q "^${PG_VERSION}$"; then + echo "❌ Version PostgreSQL invalide ou non disponible : ${PG_VERSION}" + exit 1 +fi + +echo "📦 Installation de PostgreSQL $PG_VERSION..." +apt update -y +apt install -y "postgresql-${PG_VERSION}" + +echo "🚀 Activation et démarrage du service PostgreSQL..." systemctl enable postgresql systemctl start postgresql @@ -48,14 +62,14 @@ echo "🔧 Configuration du mot de passe de l'utilisateur postgres..." sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '${POSTGRES_PASSWORD}';" echo "🔧 Configuration de l'accès local en md5..." -PG_HBA="/etc/postgresql/17/main/pg_hba.conf" +PG_HBA="/etc/postgresql/${PG_VERSION}/main/pg_hba.conf" sed -i "s/^\(local\s\+all\s\+postgres\s\+\)peer/\1md5/" "$PG_HBA" echo "♻️ Redémarrage de PostgreSQL pour appliquer les changements..." systemctl restart postgresql echo "" -echo "✅ Installation terminée." +echo "✅ Installation de PostgreSQL ${PG_VERSION} terminée." echo "-------------------------------------------" echo " Mot de passe de l'utilisateur postgres :" echo " ${POSTGRES_PASSWORD}"