#!/bin/sh
# postrm script for eprints
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <overwriter>
#          <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

reload_apache()
{
	if apache2ctl configtest 2>/dev/null; then
		invoke-rc.d apache2 $1 || true
	else
		echo "Your apache2 configuration is broken, so we're not restarting it for you."
	fi
}

case "$1" in
    purge|remove|abort-install|disappear)
	if [ -f /etc/apache2/sites-available/eprints.conf ]; then
	        rm -f /etc/apache2/sites-available/eprints.conf
	else
		rm -f /etc/apache2/sites-available/eprints
	fi
	update-rc.d -f epindexer remove
	rm -f /etc/init.d/epindexer
	if getent passwd eprints >/dev/null; then
		deluser eprints
	fi
	if getent group eprints >/dev/null; then
		delgroup eprints
	fi
	reload_apache restart
    ;;

	abort-upgrade|failed-upgrade)
	;;

    upgrade)
	reload_apache restart
	echo "###################################################################";
	echo "##                                                               ##";
	echo "##                 EPrints 3 Upgrade Complete                    ##";
	echo "##                                                               ##";
	echo "###################################################################";
	echo "##                                                               ##";
	echo "##        You may need to upgrade the database structure to      ##";
	echo "##        obtain a fully working install, to do this:            ##";
	echo "##                                                               ##";
	echo "##  # ./bin/epadmin upgrade archiveID                            ##";
	echo "##                                                               ##";
	echo "##  # apache2ctl restart                                         ##";
	echo "##                                                               ##";
	echo "##                         ##### DONE #####                      ##";
	echo "##                                                               ##";
	echo "##  For more documentation please see the eprints wiki:          ##";
	echo "##           http://wiki.eprints.org/w/Documentation             ##";
	echo "##                                                               ##";
	echo "###################################################################";
    ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.



exit 0


