#ident	"@(#)pkg.rfs:crontab	1.3.1.1"
#
# script to install/remove cron entry for rmnttry polling
#

CRONDIR=/var/spool/cron/crontabs
CRONTAB=$CRONDIR/root
TEMPCRON=/usr/tmp/cron.$$

if [ "$1" = install ]
then
	POLL='10,25,40,55 * * * * /etc/rfs/rmnttry >/dev/null'

	if [ ! -f $CRONTAB ]; then
		> $CRONTAB 2>/dev/null
	fi

	if [ ! -f $CRONTAB ]
	then
		echo "** WARNING **  crontab entry cannot be installed"
		echo "Daemon will not be running when installation is finished"
		exit 2
	fi

	if grep "rmnttry" $CRONTAB >/dev/null 2>&1 ; then :
	else
		# must remove any entry which already exists
		# since this must be idempotent
		crontab -l |
			grep -v "/etc/rfs/rmnttry.*#$PKGINST$" \
			>$TEMPCRON 2>/dev/null
		echo "$POLL #$PKGINST" >> $TEMPCRON || exit 2
		cat $TEMPCRON 2>/dev/null || exit 2
		/usr/bin/rm -f $TEMPCRON
	fi
	exit 0
fi

if [ "$1" = remove ]
then
	if [ -f $CRONTAB ]; then
		crontab -l |
			grep -v "/etc/rfs/rmnttry.*#$PKGINST$" \
			>$TEMPCRON 2>/dev/null
		cat $TEMPCRON 2>/dev/null || exit 2
		/usr/bin/rm -f $TEMPCRON
	fi
	exit 0
fi

echo "ERROR: invalid argument supplied to build script" >&2
exit 1
