#!/bin/sh
#
# De-installation setup of ravpostfix

PATH=/bin:/usr/bin:/sbin:/usr/sbin
PREFIX="/usr/local"
RAVPOSTFIX_CONTROL_FILE="${PREFIX}/etc/rc.d/rpostfix.sh"

# Function: disable autostarting script
#
do_disable()
{
	echo ""
	echo "| Starting script $RAVPOSTFIX_CONTROL_FILE"
	echo "| has not been deleted. To do this:"
	echo "| execute 'rm -f $RAVPOSTFIX_CONTROL_FILE' as root."

main_cf=/etc/postfix/main.cf
master_cf=/etc/postfix/master.cf

	if [ -f $main_cf -a -f $master_cf ]; then
	
		echo "-> Restoring the postfix configuration ..."
		sed '/^#rav-begin/,/^#rav-end/d' < $main_cf > $main_cf.sed && \
		mv -f $main_cf.sed $main_cf
		sed '/^#rav-begin/,/^#rav-end/d' < $master_cf > $master_cf.sed && \
		mv -f $master_cf.sed $master_cf
		
		echo "-> Reloading postfix ..."
		postfix reload 2>/dev/null
		
		echo "-> Stopping ravpostfix ..."
		killall -TERM ravpostfix
	else 
		echo "| You have to restore manually the postfix configuration"
		echo "| files. Please read the UNINSTALL file for more information."
	fi
}

# verify proper execution
#
if [ $# -ne 2 ]; then
	echo "usage: $0 distname { DEINSTALL | POST-DEINSTALL }" >&2
	exit 1
fi

# Verify/process the command
#
case $2 in
	DEINSTALL)
	do_disable
	echo ""
	;;
	POST-DEINSTALL)
	;;
	*)
	echo "Usage: `basename $0` distname DEINSTALL | POST-DEINSTALL" >&2
	exit 1
	;;
esac

exit 0