#!/bin/sh
#
#ident	"@(#)i.cronroot	1.15	04/04/14 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

rtc='#
# The rtc command is run to adjust the real time clock if and when 
# daylight savings time changes.
#
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1'

while read src dest
do
	if [ ! -f $dest ] ; then
		cp $src $dest
		if [ $ARCH = i386 ]; then
			#
			# add rtc into root crontab entry
			# 
			echo "$rtc" >> $dest
		fi 
	else
		grep '^#ident[ 	]*\"@(#)root' $src \
		    > /tmp/newident.$$ 2>/dev/null
		grep -v '^#ident[ 	]*\"@(#)root' $dest \
		    > /tmp/rest.$$ 2>/dev/null
		cat /tmp/newident.$$ /tmp/rest.$$ > $dest
		#
		# 2.1 version of this file had a trailing blank line.
		# Remove it.
		#
		sed -e '$s/^[ 	]*$/%%%/' -e '/^%%%$/d' $dest > /tmp/d.$$
		cp /tmp/d.$$ $dest
		#
		# use nfsfind and reduce frequency from everyday to once a week 
		# without overriding the local admins changes
		#
		sed -e 's,find / -name \.nfs\\\* -mtime +7.*,/usr/lib/fs/nfs/nfsfind,' \
		    -e 's,\* \* \* /usr/lib/fs/nfs/nfsfind,\* \* 0 /usr/lib/fs/nfs/nfsfind,' $dest > /tmp/d.$$
		cp /tmp/d.$$ $dest
		#
		# logchecker goes away
		#
		sed -e '/[^#]*[ 	]*\/etc\/cron.d\/logchecker/d' $dest > /tmp/d.$$
		cp /tmp/d.$$ $dest
		#
		# newsyslog goes away if the entry hasn't been modifed
		#
		sed -e '/10 3 \* \* 0[ 	]*\/usr\/lib\/newsyslog/d' $dest > /tmp/d.$$
		cp /tmp/d.$$ $dest
		#
		# add logadm command
		#
		grep /usr/sbin/logadm $dest >/dev/null 2>&1
		if [ $? != 0 ] ; then
			grep /usr/sbin/logadm $src >> $dest
		fi
		#
		# add rtc entry if its missing for i386
		# delete rtc entry for sparc and other ARCH
		#
		if [ $ARCH = i386 ]; then
			grep /usr/sbin/rtc  $dest >/dev/null 2>&1
			if [ $? != 0 ] ; then
				echo "$rtc" >> $dest
			fi
		else
			grep /usr/sbin/rtc  $dest >/dev/null 2>&1
			if [ $? = 0 ] ; then
				sed -e '/^.*\/usr\/sbin\/rtc.*$/d' \
				    -e '/^# The rtc command is run/,/^#$/d' \
				    $dest > /tmp/cron.$$
				mv /tmp/cron.$$  $dest
			fi	
				
		fi
#		rm -f /tmp/d.$$ /tmp/newident.$$ /tmp/rest.$$
		#
		# take nptdate out of crontab. It was added in Beta 2.6.
		# Make sure it is gone evermore.
		#
		grep "/usr/lib/inet/ntpdate" $dest >/dev/null 2>&1
		if [ $? -eq 0 ] ; then
			sed ' 
				/^.*\/usr\/lib\/inet\/ntpdate.*$/ {
				d
				} ' $dest > /tmp/cron.$$
			mv /tmp/cron.$$ $dest
		fi
		#
		# ftpclean was added in 2.7 (pre-beta) but will
		# not be shipping in 2.7. Remove cron entry
		#
		grep "/usr/lib/inet/ftpclean" $dest >/dev/null 2>&1
		if [ $? -eq 0 ]; then
		    sed -e '/^.*\/usr\/lib\/inet\/ftpclean.*$/d' $dest >/tmp/cron.$$
		    mv /tmp/cron.$$ $dest
		fi
		#
		# add gsscred duplicates clean-up script - SUNWgss
		#
		grep "/usr/lib/gss/gsscred_clean" $dest >/dev/null 2>&1
		if [ $? != 0 ] ; then
			grep "/usr/lib/gss/gsscred_clean" $src >> $dest
		fi
	fi
done

exit 0
