#!/bin/sh
# postinst script for xCAT
#
# 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)
         #make dir for the current pid
         mkdir -p /var/run/xcat
	 cp -f /opt/xcat/share/xcat/scripts/xHRM /install/postscripts/
	. /etc/profile.d/xcat.sh
	if [ -f /tmp/xCAT_upgrade.tmp ]
	then
            if [ -r "/tmp/xcat/installservice.pid" ]; then
                mv /tmp/xcat/installservice.pid /var/run/xcat/installservice.pid
            fi
            if [ -r "/tmp/xcat/udpservice.pid" ]; then
                mv /tmp/xcat/udpservice.pid /var/run/xcat/udpservice.pid
            fi
            if [ -r "/tmp/xcat/mainservice.pid" ]; then
                mv /tmp/xcat/mainservice.pid /var/run/xcat/mainservice.pid
            fi
	    xcatconfig -u
	    rm /tmp/xCAT_upgrade.tmp
	else
	    xcatconfig -i -d -s
	fi
        
#        [ -e /etc/apache2/conf-enabled/xcat.conf ] && rm /etc/apache2/conf-enabled/xcat.conf
#        mv /etc/apache2/conf-enabled/xcat.conf.apach24 /etc/apache2/conf-enabled/xcat.conf

	/etc/init.d/apache2 restart
    ;;

    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.

#DEBHELPER#

exit 0