#!/bin/sh
#
# $Log: vdeldomain_handle.in,v $
# Revision 2.8  2023-07-31 21:51:28+05:30  Cprogrammer
# cd to root before doing svc -h.
#
# Revision 2.7  2023-03-20 10:35:01+05:30  Cprogrammer
# use SERVICEDIR, CONTROLDIR env variable if set for service and control directory
#
# 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.8 2023-07-31 21:51:28+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
if [ -n "$CONTROLDIR" ] ; then
	controldir=$CONTROLDIR
else
	controldir=/etc/indimail/control
fi
for i in spamignore nodnscheck
do
	if [ -f $controldir/$i ] ; then
		$grep -w @"$1" $controldir/$i > /dev/null
		if [ $? -eq 0 ] ; then
			$grep -v -w  @"$1" $controldir/$i > /tmp/$i.$$
			if [ -s /tmp/$i.$$ ] ; then
				echo "removing $1 from $controldir/$i control file"
				$mv /tmp/$i.$$ $controldir/$i
				$chown root:qmail $controldir/$i
				$chmod 644 $controldir/$i
			else
				/bin/rm -f /tmp/$i.$$
			fi
		fi
	fi
done
if [ -n "$SERVICEDIR" ] ; then
	servicedir=$SERVICEDIR
else
	servicedir=/service*
fi
cd /
exec /usr/bin/svc -h $servicedir/inlookup.* $servicedir/*-send.* 2>/dev/null
