#!/usr/bin/env bash set -e echo "=== Installazione ed Inizializzazione Server DB PostgreSQL per NetGescon ===" # 1. Installazione pacchetti sistema apt-get update apt-get install -y postgresql postgresql-contrib php-pgsql # 2. Avvio e abilitazione servizio PostgreSQL systemctl enable postgresql systemctl start postgresql # 3. Creazione Database e Utente NetGescon sudo -u postgres psql -c "CREATE DATABASE netgescon;" || true sudo -u postgres psql -c "CREATE USER netgescon WITH PASSWORD 'netgescon_pass';" || true sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE netgescon TO netgescon;" || true sudo -u postgres psql -d netgescon -c "GRANT ALL ON SCHEMA public TO netgescon;" || true # 3.1 Configurazione pg_hba.conf per consentire password auth sia su socket locale che TCP 127.0.0.1 PG_HBA=$(find /etc/postgresql/ -name "pg_hba.conf" | head -n 1) if [ -n "$PG_HBA" ] && [ -f "$PG_HBA" ]; then sed -i -E 's/local\s+all\s+all\s+peer/local all all scram-sha-256/' "$PG_HBA" || true systemctl reload postgresql || true fi # 4. Riavvio eventuale servizio PHP-FPM / Web server systemctl restart php*-fpm 2>/dev/null || true echo "=== INSTALLAZIONE ED INIZIALIZZAZIONE POSTGRESQL COMPLETATA CON SUCCESSO ==="