#!/bin/sh
echo "Shutting down aolserver"
/etc/init.d/aolserver4 stop
# make sure nsd is really gone
pkill nsd

echo "Removing the www-data user in Postgres and the dotlrn database."
su - postgres "dropuser www-data"
su - postgres "dropdb dotlrn"

echo "Removing the dotlrn crontab jobs from postgres' crontab"
su - postgres "crontab -l |grep -v dotlrn> /tmp/pgcrontab.$$; \
crontab /tmp/pgcrontab.$$; \
rm /tmp/pgcrontab.$$;"

echo "Restoring default aolserver and postgresql config."
cp -p /usr/share/doc/dotlrn/default-etc/init.d/aolserver4 /etc/init.d/
cp -p /usr/share/doc/dotlrn/default-etc/aolserver4/aolserver4.tcl /etc/aolserver4/
cp -p /usr/share/doc/dotlrn/default-etc/postgresql/postgresql.conf /etc/postgresql/
cp -p /usr/share/doc/dotlrn/default-etc/postgresql/pg_hba.conf /etc/postgresql/

echo "Restarting aolserver"
/etc/init.d/aolserver4 start