#!/bin/sh
#
# License: GNU General Public License (GPL)
#
# postinst script for heartbeat
#
# 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>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
#

case "$1" in
    configure)

       addgroup --system haclient
        adduser --system hacluster --ingroup haclient --home /var/lib/heartbeat

       for i in /var/run/heartbeat/crm /var/lib/heartbeat/crm \
                       /var/lib/heartbeat/pengine /var/lib/pengine; do		if [ ! -d $i ]; then
		  mkdir $i
		fi
		chown hacluster $i
		chgrp haclient $i
	done
    ;;
	
    purge)
        id haclient >/dev/null 2>&1;
        if [ "x$?" = "x0" ]; then userdel -rf haclient && groupdel hacluster; fi
        
        rm -rf /var/lib/openais
	rm -rf /var/log/openais
    ;;
	
    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

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

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

#DEBHELPER#

exit 0
