#!/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 /opt/eprints3 --shell /bin/bash --group eprints > /dev/null
	#adduser www-data eprints > /dev/null
	# Why disable the site in configure?!
	#rm -f /etc/apache2/sites-available/eprints
	#rm -f /etc/apache2/sites-enabled/eprints
	if [ ! -e /etc/apache2/sites-available/eprints ]; then 
		echo "Include /opt/eprints3/cfg/apache.conf" > /etc/apache2/sites-available/eprints
	elif [ "`cat /etc/apache2/sites-available/eprints`" != "Include /opt/eprints3/cfg/apache.conf" ]; then
		echo "WARNING: /etc/apache2/sites-available/eprints differs from maintainer's version.  Apache may have problems loading this configuration."
	fi
	ln -fs /etc/apache2/sites-available/eprints /etc/apache2/sites-available/eprints.conf
	ln -fs /opt/eprints3/bin/epindexer /etc/init.d/epindexer
	update-rc.d epindexer defaults 99 99 > /dev/null
	chown eprints:www-data /opt/eprints3 -R > /dev/null
	chmod g+w /opt/eprints3/lib -R > /dev/null
	chmod g+w /opt/eprints3/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


