#!/bin/bash
# postinst script for ocalcli
#
# 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

SOURCEDIR=

INSTDIR=
LINKDIR=

USRCONFDIRNAME=
SRCCONFDIR=
PROFILE=

USRSKEL=

SCDIR=
INSTROOT=

#echo "POSTRM-CASE: "$1

case "$1" in
    purge)    	
    	#
    	if [ -e $USRSKEL ]; then
		rm -rf $USRSKEL
	fi
	
	# remove ocalcli-dirs in $HOME
	declare -a allusers
	allusers=(`cat /etc/passwd | cut -d":" -f1,3,6,7`)
	
	echo "Entferne Benutzerkonfigurationen ..."
	for usr in ${allusers[@]}
	do
		usrname=${usr%%\:*}
		usrshell=${usr##*\:}

		tmp=${usr%\:*}
		usrhome=${tmp##*\:}

		tmp=${usr#*\:}
		usrid=${tmp%%\:*}
		
		if [[ -e $usrhome && ( "$usrid" -gt "999" || "$usrid" -eq "0" ) && "$usrshell" != "/bin/false" ]] ; then
			if [ -e $usrhome"/"$USRCONFDIRNAME ]; then
				rm -rf $usrhome"/"$USRCONFDIRNAME
			fi
		fi
	done
    ;;
    
    remove)
    	if [ -f $SCDIR"/ocal" ]; then
    		rm $SCDIR"/ocal"
    	fi
    	
    	if [ -e $INSTROOT ]; then
	    	rm -rf $INSTROOT
    	fi
    ;;
    
    upgrade)
    ;;
    
    failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;

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


