#!/bin/sh
# $Header: autorcs.sh,v 1.4 86/05/05 20:06:40 mb Exp $
# Script to checkin any changes to an RCSed file since last checkin.
# Designed to be run by users and from crontab
#

PATH=/usr/ucb:/bin:/usr/bin
rc=0

if [ $# -lt 1 ]
then
	echo "usage: $0 file ..." >&2
	exit 1
fi

for target
do
	if [ ! -f "$target" ]
	then
		echo "$0: $target: no such file or directory" >&2
		rc=1
	else
		file=`basename "$target"`
		dir=`echo "$target" | sed "s/$file$/./"`
		(
			cd "$dir"
			rlog -R "$file" > /dev/null || exit 1
			if [ -n "`rlog -R -L "$file"`" ]
			then
				echo "$0: $target: locked by RCS" >&2
				exit 1
			elif co -p -q "$file" | cmp -s - "$file"
			then
				: nothing to do
			else
				echo "Autorcs'ing $target"
				rcs -l "$file" &&
					ci -m"Automatic update by $0" -u "$file"
			fi
		) || rc=1
	fi
done
exit $rc
