55 lines
No EOL
1.6 KiB
Bash
Executable file
55 lines
No EOL
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# Setup APRS database on PostgreSQL VM
|
|
|
|
set -e
|
|
|
|
POSTGRES_HOST="10.0.19.5"
|
|
POSTGRES_USER="postgres"
|
|
APRS_USER="aprs"
|
|
APRS_PASSWORD="xK9mP2vQ7sR3nL5w"
|
|
APRS_DATABASE="aprs"
|
|
|
|
echo "Setting up APRS database on PostgreSQL server at $POSTGRES_HOST"
|
|
echo "This requires the postgres user password or SSH access to the PostgreSQL VM"
|
|
echo ""
|
|
|
|
# Create the SQL commands
|
|
SQL_COMMANDS="
|
|
-- Create APRS user
|
|
CREATE USER $APRS_USER WITH PASSWORD '$APRS_PASSWORD';
|
|
|
|
-- Create APRS database
|
|
CREATE DATABASE $APRS_DATABASE OWNER $APRS_USER;
|
|
|
|
-- Grant privileges
|
|
GRANT ALL PRIVILEGES ON DATABASE $APRS_DATABASE TO $APRS_USER;
|
|
"
|
|
|
|
# Option 1: Try with psql directly (requires postgres password)
|
|
echo "Attempting to connect to PostgreSQL directly..."
|
|
echo "$SQL_COMMANDS" | psql -h $POSTGRES_HOST -U $POSTGRES_USER -d postgres 2>/dev/null && {
|
|
echo "✓ Database setup completed successfully!"
|
|
echo ""
|
|
echo "Connection details:"
|
|
echo " Host: $POSTGRES_HOST"
|
|
echo " Database: $APRS_DATABASE"
|
|
echo " User: $APRS_USER"
|
|
echo " Password: $APRS_PASSWORD"
|
|
echo ""
|
|
echo "Connection string:"
|
|
echo " ecto://$APRS_USER:$APRS_PASSWORD@$POSTGRES_HOST:5432/$APRS_DATABASE"
|
|
exit 0
|
|
}
|
|
|
|
# If direct connection fails, provide manual instructions
|
|
echo "Could not connect directly. Please run these commands on the PostgreSQL server:"
|
|
echo ""
|
|
echo "sudo -u postgres psql << EOF"
|
|
echo "$SQL_COMMANDS"
|
|
echo "EOF"
|
|
echo ""
|
|
echo "Or SSH to the PostgreSQL VM and run:"
|
|
echo " ssh <user>@$POSTGRES_HOST"
|
|
echo " sudo -u postgres psql"
|
|
echo " Then paste the following:"
|
|
echo "$SQL_COMMANDS" |