#!/bin/bash set -e # ========= CONFIGURACIÓN ========= APP_NAME="rss" APP_DIR="$(cd "$(dirname "$0")" && pwd)" # SIEMPRE el directorio del script PYTHON_ENV="$APP_DIR/venv" SERVICE_FILE="/etc/systemd/system/$APP_NAME.service" FLASK_FILE="app.py" DB_NAME="rss" DB_USER="rss" DB_PASS="x" # ========= INSTALAR POSTGRESQL (ÚLTIMA VERSIÓN RECOMENDADA) ========= echo "🟢 Instalando PostgreSQL (repositorio oficial)..." sudo apt update sudo apt install -y wget ca-certificates # Añade el repositorio oficial de PostgreSQL (ajusta para tu distro si hace falta) echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt update sudo apt install -y postgresql postgresql-contrib # ========= CAMBIAR AUTENTICACIÓN DE peer A md5 ========= PG_HBA=$(find /etc/postgresql -name pg_hba.conf | head -1) if grep -q "local\s\+all\s\+all\s\+peer" "$PG_HBA"; then echo "📝 Ajustando pg_hba.conf para autenticación md5 (contraseña)..." sudo sed -i 's/local\s\+all\s\+all\s\+peer/local all all md5/' "$PG_HBA" sudo systemctl restart postgresql else echo "✅ pg_hba.conf ya configurado para md5." fi # ========= CONFIGURAR BASE DE DATOS Y USUARIO ========= echo "🛠️ Configurando PostgreSQL: usuario y base de datos..." sudo -u postgres psql < /dev/null <