#sccs	"@(#)fndetc/convert:inittabconv	1.4"

#
#	FILE:  inittabconv
#
#	This program takes any new entries in /etc/inittab and
#	adds them to the old one.
#

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

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

OLDFILE=$1
NEWFILE=$2

#	The old file and new file must be diff'ed.  Anything missing
#	from the new file is appended to the end of the old file.

grep -v "rc:" $OLDFILE > /tmp/inittab
mv /tmp/inittab $OLDFILE

diff $NEWFILE $OLDFILE | getmissing - > /tmp/missing

cp /tmp/missing /tmp/compare
while read LINE
do
	DEV=`getdevid "$LINE"`
	if [ ! "$DEV" ]
	then
		grep -v "$LINE" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
		continue
	fi

	if grep "$DEV" $OLDFILE > /dev/null
	then
		grep -v "$DEV" /tmp/missing > /tmp/lessline
		mv /tmp/lessline /tmp/missing
	fi
done < /tmp/compare

cat /tmp/missing >> $OLDFILE
ln $OLDFILE $NEWFILE

#	Do listing update as necessary.

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

#	Clean up scratch files created.

rm -f /tmp/missing /tmp/compare

