#! /bin/sh
# postrm script for lurker
#
# see: dh_installdeb(1)

set -e

# debhelper stuff
#DEBHELPER#

case "$1" in
  remove)
    if [ -f /etc/apache2/conf.d/lurker ] || [ -h /etc/apache2/conf.d/lurker ]; then
      echo "Removing the lurker apache2 configuration."
      rm -f /etc/apache2/conf.d/lurker

      if [ -x /usr/sbin/invoke-rc.d ]; then
        invoke-rc.d apache2 restart
      else
        /etc/init.d/apache2 restart
      fi
    fi
  ;;

  purge)
    # remove the systemgroup lurker
    LURKER_GROUP=lurker
    if [ -x $(command -v delgroup) ]; then
      echo -n "Removing $LURKER_GROUP group .."
      delgroup --quiet --system $LURKER_GROUP > /dev/null || true
      echo "..done"
    else
      echo >&2 "not removing $LURKER_GROUP system group because delgroup command was not found."
    fi

    echo "Removing lurker configuration and database."

    # remove the configuration file itself
    rm -f /etc/lurker/lurker.conf

    # and finally clear it out from the ucf database
    if [ -x /usr/bin/ucf ]; then
      ucf --purge /etc/lurker/lurker.conf
    fi
    
    rm -rf /var/lib/lurker
  ;;
  
  upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
  ;;
  
  *)
    echo "postrm called with unknown argument \`$1'" >&2
    exit 0
  ;;
esac

exit 0
