Files
boc/iom/scripts/deploy_postgres.sh
T

50 lines
1.1 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
echo "=== Deploying PostgreSQL + PostGIS ==="
# Check if PostgreSQL is installed
if ! command -v psql &> /dev/null; then
echo "Installing PostgreSQL..."
sudo -n dnf install -y postgresql15 postgresql15-server postgresql15-contrib
sudo -n postgresql-setup --initdb
fi
# Install PostGIS
if ! rpm -q postgis33_15 &> /dev/null; then
echo "Installing PostGIS..."
sudo -n dnf install -y postgis33_15
fi
# Start PostgreSQL
sudo -n systemctl enable postgresql
sudo -n systemctl start postgresql
# Create database and user
sudo -n -u postgres psql << 'EOF'
-- Create user
CREATE USER iom WITH PASSWORD 'iom_password' SUPERUSER;
-- Create database
CREATE DATABASE iom OWNER iom;
-- Enable PostGIS
\c iom
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
-- Grant permissions
GRANT ALL PRIVILEGES ON DATABASE iom TO iom;
GRANT ALL ON SCHEMA public TO iom;
-- Create tables
\i /home/bernt/.openclaw/workspace/iom/database/schema.sql
EOF
echo "=== PostgreSQL Deployed ==="
echo "Database: iom"
echo "User: iom"
echo "PostGIS: Enabled"
echo ""
echo "Connection: psql -h localhost -U iom -d iom"