#!/bin/sh
#
# $Log: vdeldomain_handle.in,v $
# Revision 2.6  2020-09-21 07:57:40+05:30  Cprogrammer
# added /usr/sbin for FreeBSD for chown command
#
# Revision 2.5  2020-05-25 00:04:57+05:30  Cprogrammer
# use root:qmail permission for spamignore, nodnscheck
#
# Revision 2.4  2019-03-05 17:06:19+05:30  Cprogrammer
# supress message when there is no entries to be removed from spamignore, nodnscheck
#
# Revision 2.3  2018-01-27 09:05:18+05:30  Cprogrammer
# remove domain from spamigore, nodnscheck file on domain deletion
#
# Revision 2.2  2016-05-22 23:22:56+05:30  Cprogrammer
# fhs compliance
#
# Revision 2.1  2013-08-26 15:23:25+05:30  Cprogrammer
# script to issue sighup to inlookup, qmail-send on domain deletion
#
#
#
# $Id: vdeldomain_handle.in,v 2.6 2020-09-21 07:57:40+05:30 Cprogrammer Exp mbhangui $

# get securely chown, chmod path
PATH=/usr/bin:/usr/sbin:/bin
chown=$(which chown)
chmod=$(which chmod)
grep=$(which grep)
mv=$(which mv)
# send sighup to qmail-send, inlookup
# remove domain from spamignore nodnscheck
for i in spamignore nodnscheck
do
	if [ -f /etc/indimail/control/$i ] ; then
		$grep -w @"$1" /etc/indimail/control/$i > /dev/null
		if [ $? -eq 0 ] ; then
			$grep -v -w  @"$1" /etc/indimail/control/$i > /tmp/$i.$$
			if [ -s /tmp/$i.$$ ] ; then
				echo "removing $1 from $i control file"
				$mv /tmp/$i.$$ /etc/indimail/control/$i
				$chown root:qmail /etc/indimail/control/$i
				$chmod 644 /etc/indimail/control/$i
			else
				/bin/rm -f /tmp/$i.$$
			fi
		fi
	fi
done
/usr/bin/svc -h /service/inlookup.* /service*/qmail-send.* 2>/dev/null
exit 0
