#!/bin/sh
set -e

DEBIAN_FRONTEND=`echo "$DEBIAN_FRONTEND" | tr A-Z a-z`

case $1 in
    configure)
        if [ -d /usr/doc -a -h /usr/doc/smtp-refuser -a -d /usr/share/doc/smtp-refuser ]; then
                rm -f /usr/doc/smtp-refuser
        fi

	if [ ! -f /etc/smtp-refuser.conf ]; then
	    touch /etc/smtp-refuser.conf ;
	fi
	if [ `wc -l </etc/smtp-refuser.conf` != 2 ]; then
	    if [ "$DEBIAN_FRONTEND" = "noninteractive" ]; then
		echo "$0: Running in noninteractive mode.  Not doing anything."
		echo "smtp-refuser may be set up later by running /usr/sbin/smtp-refuserconfig.";
		    
	    else
			
		echo -n "Do you wish to configure now? [Y/n] "
		read REPLY
		case $REPLY in
		    [nN]*) ;;
		    *) echo ; /usr/sbin/smtp-refuserconfig ;;
		esac
		echo "smtp-refuser may be set up again by running /usr/sbin/smtp-refuserconfig.";
	    fi
	fi
	;;
esac

# verisim.com no longer exists, so if this is here it's probably
# an old and unmodified copy of smtp-refuser's rules ... warn the
# administrator.

if grep -q -i 'gatekeeper\.verisim\.com' /etc/hosts.allow; then
    echo "WARNING: Your /etc/hosts.allow file appears to contain" ;
    echo "some very old and possibly harmful smtp-refuser rules." ;
    echo ;
    echo "Please read /usr/share/doc/smtp-refuser/examples/hosts.allow.sample" ;
    echo "and then manually update your /etc/hosts.allow rules." ;
    echo ;
    if [ "$DEBIAN_FRONTEND" != "noninteractive" ]; then
	echo "Press a key to continue..." ;
	read REPLY ;
    fi
fi

#DEBHELPER#
