#!/bin/sh

CAT=/bin/cat
SYNC=/bin/sync
HOME=/home/mail/#tmp

Usage()
{
	echo "Usage: mltran_add hh mm domain mlname"
	exit 1
}
if [ $# -ne 4 ]
then
	Usage
	exit 1
fi

fid=`date +%H%M%S`

user=`awk ' {
        if (/^userid=/) {
                split($1, array, "=");
                print array[2];
        }
                }'  /opt/nec/mail/ums.conf`

# $7 $8 in rulefile match??
if [ "$user" = "" ]
then
	echo ng 
	exit 1
fi
crontab -u $user -l > $HOME/rulefile.$fid

awk ' {  if (($7 != "'$3'" || $8 != "'$4'") && $1 != "#")
		print $0 }'  $HOME/rulefile.$fid > $HOME/tmpfile.$fid

$CAT >> $HOME/tmpfile.$fid << _EOF_
$2 $1 * * * /opt/nec/mail/mlist/push $3 $4
_EOF_

crontab -u $user $HOME/tmpfile.$fid
rm $HOME/tmpfile.$fid
rm $HOME/rulefile.$fid

if [ ! -d /home/mail/#failover/cron ]
then
    mkdir -p /home/mail/#failover/cron
fi
cp /var/spool/cron/$user /home/mail/#failover/cron

$SYNC
