#! /bin/sh -e

case "$1" in
    failed-upgrade|abort-upgrade)
	if [ -d /var/lib/games/crossfire/ ] ; then
	    #only if we really moved everything
	    if [ "`ls /var/lib/games/crossfire/ | wc -l`" -eq 0 ] ; then
		if [ -d /var/games/crossfire/ ] ; then
		    echo "moving files and directories back to /var/lib/games/crossfire/"
		    mv /var/games/crossfire/* /var/lib/games/crossfire/ ||true
		fi
	    fi
	fi
    ;;

  abort-install)
    # do nothing
    ;;

  purge)
    if [ -e /usr/share/debconf/confmodule ] ; then
	. /usr/share/debconf/confmodule
	db_purge
    fi
    ##purge game files
    if [ -d /var/games/crossfire/ ] ; then
	if [ "`ls /var/games/crossfire/ | wc -l`" -gt 0 ] ; then
	echo "purging /var/games/crossfire/ and it's contents"
	rm -rf /var/games/crossfire/ ||true
	fi
    fi
    ##purge logfiles
    if [ -d /var/log/crossfire/ ] ; then
        if [ "`ls /var/log/crossfire/ | wc -l`" -gt 0 ] ; then
	echo "purging /var/games/crossfire/ and it's contents"
        rm -rf /var/log/crossfire/ ||true
	fi
    fi
    ;;

  upgrade)
      # do nothing
      ;;
  remove|disappear)
      # remove the 'crossfire' user if it exists
#      grep ^crossfire: /etc/passwd >/dev/null && {
#          /usr/sbin/userdel crossfire > /dev/null 2>&1
#      }
#
      # remove the 'crossfire' group if it exists
#      grep ^crossfire: /etc/group >/dev/null || {
#          /usr/sbin/groupdel crossfire > /dev/null 2>&1
#      }
    ;;
  *)
    echo "$0: incorrect arguments: $*" >&2
    exit 1
    ;;

esac

##DEBHELPER##
