#!/bin/sh -e

# Debian Postfix preinst
# LaMont Jones <lamont@debian.org>
# Modified to use debconf by Colin Walters <levanti@verbum.org>

# do we have debconf?
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
    DEBCONF=true
else
    DEBCONF=
fi

dpkg_vers=$(dpkg --status dpkg | sed -n '/Version: /s/^Version: //p')
CONFIG=/etc/postfix/main.cf
POSTDROP=/usr/sbin/postdrop

case "$1" in
    install)
	if [ -d /var/spool/postfix -a -f /etc/postfix/main.cf \
		 -a -x /etc/init.d/postfix ]; then
	    touch /var/spool/postfix/restart
	    /etc/init.d/postfix stop || true
	fi
	;;

    upgrade)
	if [ -d /var/spool/postfix -a -f /etc/postfix/main.cf \
		 -a -x /etc/init.d/postfix ]; then
	    touch /var/spool/postfix/restart
	    /etc/init.d/postfix stop
	fi
        ;;

    abort-upgrade)
	;;

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

# deal with smtpd delivering a man page on top of us.
if [ install = "$1" -o upgrade = "$1" ]; then
    dpkg-divert --package postfix-tls --add --rename \
	 --divert /usr/lib/postfix/lmtp.postfix \
		  /usr/lib/postfix/lmtp
    dpkg-divert --package postfix-tls --add --rename \
	 --divert /usr/lib/postfix/smtp.postfix \
		  /usr/lib/postfix/smtp
    dpkg-divert --package postfix-tls --add --rename \
	 --divert /usr/lib/postfix/smtpd.postfix \
		  /usr/lib/postfix/smtpd
fi

#DEBHELPER#
