#!/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 /usr/share/eprints --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 /usr/share/eprints/cfg/apache.conf" > /etc/apache2/sites-available/eprints
	elif [ "`cat /etc/apache2/sites-available/eprints`" != "Include /usr/share/eprints/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 /usr/share/eprints/bin/epindexer /etc/init.d/epindexer
	update-rc.d epindexer defaults 99 99 > /dev/null
	chown eprints:www-data /usr/share/eprints -R > /dev/null
	chmod g+w /usr/share/eprints/lib -R > /dev/null
	chmod g+w /usr/share/eprints/var > /dev/null
	echo "###################################################################";
	echo "##                                                               ##";
	echo "##                    Welcome to EPrints 3                       ##";
	echo "##                                                               ##";
	echo "###################################################################";
	echo "##                                                               ##";
	echo "## For known issues please check:                                ##";
	echo "##     http://wiki.eprints.org/w/Debian_Known_Issues             ##";
	echo "##                                                               ##";
	echo "## Getting Started:                                              ##";
	echo "##        Before you can start using eprints you need to         ##";
	echo "## configure your 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/eprints3)    ##";
	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 "##           http://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


