
#sccs	"@(#)fndetc/convert:crontabconv	1.3"

#
#	crontabconv:                            July 2, 1986
#
#	This program searches the crontab file for entries
#	which may be missing from the new crontab.  Only
#	differences in program name and significant argument will
#	be detected.  If those fields are identical, then the
#	line will be ignored.
#

if [ $# -lt 2 ]
then
	echo "usage:  crontabconv {old file} {new file}"
	exit 2
fi

if [ $# -eq 3 ]
then	VERBOSE=$3
else	VERBOSE=""
fi


OLDFILE=$1
NEWFILE=$2

cp $OLDFILE /tmp/missing

while read LINE
do
	RET=`getprogram "$LINE"`
	if [ ! "$RET" ]
	then	continue
	fi
	eval set $RET
	PROG="$1"
	ARG="$2"

	# Remove email and memo from old crontab if package not installed

	if [ "$ARG" = "/usr/bin/email" ] 
	then
		if [ ! -s /usr/bin/email ]
		then
		grep -v "${PROG}.*${ARG}" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
		continue
		fi
	fi

	if [ "$ARG" = "/usr/bin/memo" ] 
	then
		if [ ! -s /usr/bin/memo ]
		then
		grep -v "${PROG}.*${ARG}" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
		continue
		fi
	fi

	# Remove uudemon.hr from old crontab
	if [ "$ARG" = "/usr/lib/uucp/uudemon.hr" ]
	then
		grep -v "${PROG}.*${ARG}" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
		continue
	fi

	# If entry in oldfile, remove from newfile
	if grep "${PROG}.*${ARG}" $NEWFILE > /dev/null
	then
		grep -v "${PROG}.*${ARG}" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
	fi
done < $OLDFILE


# Add random uudemon.hr
echo "`date '+%S'` * * * * /bin/su uucpadm -c \"/usr/lib/uucp/uudemon.hr > /dev/null\" ">> /tmp/missing

# Remove sccs comment line from old crontab
grep -v "#sccs" /tmp/missing > /tmp/lessline
mv /tmp/lessline /tmp/missing

cat /tmp/missing >> $NEWFILE

#	Do listing update as necessary.

if [ "$VERBOSE" ]
then 
	echo "new Release file updated with:"
	cat /tmp/missing
	echo
fi

rm -f /tmp/missing
