#!/bin/sh
#set -x

PATH=$PATH:/dcs/bin
export PATH

# if the user gave an argument to the script, assume that is the stamp
# file to check, and not the default stampfile: /var/adm/stamp.gz
if [ "$#" = 0 ]
then
	compare_against=/var/adm/stamp.gz
else
	compare_against="$1"
fi

if [ -f "$compare_against" ]
then
	# if the stamp file to compare against contains '^l ' somewhere, then
	# it's an old stampfile, before stamp started outputting the target
	# of symlinks.  If that's the case, use the old stamp program to
	# do the new stamp when comparing.  Otherwise, use the newer program
	# for more complete results
	if gunzip -c $compare_against | grep '^l ' > /dev/null
	then
		stamp_prog=/dcslib/allsys/etc/stamp
	else
		stamp_prog=/dcslib/allsys/etc/stamp-old
	fi
	export stamp_prog

	TMPFILE=/tmp/stamp.$$
	$stamp_prog > $TMPFILE
	gunzip -c $compare_against | \
		diff - $TMPFILE | \
		grep '^>' | \
		sed \
			-e 's/> l [^ ]* [^ ]* [^ ]* [^ ]* //' \
			-e 's/> s [^ ]* [^ ]* [^ ]* [^ ]* //' \
			-e 's/> u [^ ]* [^ ]* [^ ]* //' | \
		egrep -v '^/var/adm/stamp\.gz$|^/var/adm/stamp-completed$'
else
	echo Could not find "$compare_against" 1>&2
	exit 1
fi