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

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    configure)
	# Why is this adding a user here (in config?)
	#adduser --system --home @PREFIX@ --shell /bin/bash --group @INSTALL_GROUP@ > /dev/null
	#adduser www-data @INSTALL_USER@ > /dev/null
	# Why disable the site in configure?!
	#rm -f /etc/apache2/sites-available/@PACKAGE@
	#rm -f /etc/apache2/sites-enabled/@PACKAGE@
	if [ ! -e /etc/apache2/sites-available/@PACKAGE@ ]; then 
		echo "Include @PREFIX@/cfg/apache.conf" > /etc/apache2/sites-available/@PACKAGE@
	elif [ "`cat /etc/apache2/sites-available/@PACKAGE@`" != "Include @PREFIX@/cfg/apache.conf" ]; then
		echo "WARNING: /etc/apache2/sites-available/@PACKAGE@ differs from maintainer's version.  Apache may have problems loading this configuration."
	fi
	ln -fs /etc/apache2/sites-available/@PACKAGE@ /etc/apache2/sites-available/@PACKAGE@.conf
	ln -fs @PREFIX@/bin/epindexer /etc/init.d/epindexer
	update-rc.d epindexer defaults 99 99 > /dev/null
	chown @INSTALL_USER@:www-data @PREFIX@ -R > /dev/null
	chmod g+w @PREFIX@/lib -R > /dev/null
	chmod g+w @PREFIX@/var > /dev/null
	echo "######################################################################";
	echo "##                                                                  ##";
	echo "##                       Welcome to EPrints 3                       ##";
	echo "##                                                                  ##";
	echo "######################################################################";
	echo "##                                                                  ##";
	echo "## For installation advice and known issues please check:           ##";
	echo "##   https://wiki.eprints.org/w/Installing_EPrints_on_Debian/Ubuntu ##";
	echo "##                                                                  ##";
	echo "## Getting Started:                                                 ##";
	echo "##   Before you can start using eprints you need to configure your  ##";
	echo "## install, follow these simple steps:                              ##";
	echo "##                                                                  ##";
	echo "##   # su eprints                                                   ##"; 
	echo "##       You have to logged in as the eprints user to operate       ##";
	echo "##       with eprints                                               ##";
	echo "##   # cd                                                           ##";
	echo "##       To the eprints home directory (/usr/share/eprints)         ##";
	echo "##                                                                  ##";
	echo "##   # ./bin/epadmin create                                         ##";
	echo "##       Follow the instruction to create your archive.             ##";
	echo "##                                                                  ##";
	echo "##   # exit                                                         ##";
	echo "##                                                                  ##";
	echo "##   # a2ensite eprints                                             ##";
	echo "##                                                                  ##";
	echo "##   # apache2ctl restart                                           ##";
	echo "##                                                                  ##";
	echo "##                         ##### DONE #####                         ##";
	echo "##                                                                  ##";
	echo "##  For more documentation please see the eprints wiki:             ##";
	echo "##    https://wiki.eprints.org/w/Documentation                      ##";
	echo "##                                                                  ##";
	echo "######################################################################";
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst 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


