#! /bin/sh 


# Some older versions of dictd relied on a ps|grep|cut kludge to stop
# the daemon.  With procps version 2.0.2 the output format from ps
# causes the old ps|grep|cut kludges to fail.  At this stage, the old
# version of the maintainer scripts are still installed.  Therefore a
# positive means of stopping it is provided.  

# Ideally this would only be needed for the `upgrade' case, but
# paranoia says an old version may have been removed without stopping
# the daemon, so I include this for `install' as well.

set -e

PID=`pidof -x dictd` ||true

#adduser --quiet --system --home /var/lib/dictd --no-create-home \
#        --group dictd || true

# Fix home dir as versions <= 1.9.14-1 did not specify --home as above
#usermod -d /var/lib/dictd dictd

case "$1" in
    upgrade)

    if [ -e /var/run/dictd.pid ]; then rm -f /var/run/dictd.pid; fi
    if [ "$PID" ]; then  kill $PID >/dev/null 2>&1; fi
# /etc/dictd.conf moved to /etc/dictd/dictd.conf in 1.9.x
    if dpkg --compare-versions "$2" lt "1.9"; then
       if [ -e /etc/dictd.conf ]; then
         echo "Moving dictd.conf from /etc to /etc/dictd."
         mkdir -p /etc/dictd
         mv /etc/dictd.conf /etc/dictd/dictd.conf
         touch /etc/dictd.conf.moved_by_preinst
       fi
       if [ -e /etc/dictd.order ]; then
         mv /etc/dictd.order /etc/dictd/dictd.order
       fi 
     fi             
    exit 0
    ;;

    install)
     if [ -e /var/run/dictd.pid ]; then rm -f /var/run/dictd.pid; fi
     if [ "$PID" ]; then  kill $PID >/dev/null 2>&1; fi
     exit 0
    ;;

    failed-upgrade|abort-install|abort-upgrade|disappear)
     exit 0
    ;;

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


     exit 0
