#!/bin/bash
#
# run as root with "sudo sh <script>"
#
# This file expects the JB248.sql file to be under the JB248 directory under the home directory
#
# If this is not the case, set the directory here.
export JB248_INST_DIR=/home/student

# Full burn uninstall, uncomment if needed...
# /usr/bin/yum remove -y postgresql-server
# /bin/rm -rf /var/lib/pgsql

# Set up postgres
/bin/echo "Setting up postgresql-server..."
/usr/bin/yum install -y postgresql-server
/bin/echo 'postgres' | /usr/bin/passwd --stdin postgres
/usr/bin/sudo -u postgres /usr/bin/initdb -D /var/lib/pgsql/data
/sbin/service postgresql start
/bin/cp ${JB248_INST_DIR}/JB248/db/JB248.sql /var/lib/pgsql/.
/usr/bin/sudo -u postgres /usr/bin/psql -f /var/lib/pgsql/JB248.sql
/bin/rm /var/lib/pgsql/JB248.sql
/sbin/chkconfig postgresql on
