#ident	"@(#)pkg.perf:crontab	1.5"

CRONDIR=/var/spool/cron/crontabs
CRONTAB=/var/spool/cron/crontabs/sys

if [ "$1" = install ]
then
	ENTRY1='0 * * * 0-6 /usr/lib/sa/sa1'
	ENTRY2='20,40 8-17 * * 1-5 /usr/lib/sa/sa1'
	ENTRY3='5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A'

	if [ -d $CRONDIR ]; then
		if [ ! -f $CRONTAB ]; then
			> $CRONTAB
			chmod 644  $CRONTAB 2>/dev/null
			chown root $CRONTAB 2>/dev/null
			chgrp sys  $CRONTAB 2>/dev/null
		fi
	else
		echo "***WARNING*** cannot install cron entries for SAR"
	fi
	if [ -f $CRONTAB ]; then
		if grep "sa1" $CRONTAB >/dev/null 2>&1 ; then  :
		else
			echo "$ENTRY1" >> $CRONTAB
			echo "$ENTRY2" >> $CRONTAB
		fi
		if grep "sa2" $CRONTAB >/dev/null 2>&1 ; then  :
		else
			echo "$ENTRY3" >> $CRONTAB
		fi
	fi
	cat $CRONTAB
	exit 0
fi

if [ "$1" = remove ]
then
	/usr/bin/ed $CRONTAB <<-! >/dev/null 2>&1
		g/sa1/d
		g/sa2/d
		w
		q
	!
	cat $CRONTAB
	exit 0
fi

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