#!/bin/sh

USAGE="*** Usage *** $0 [empresspath]"

case $1 in
 -help)
	echo "$USAGE"
	exit 0
	;;
 "")	;;
 *)	EMPRESSPATH=$1
	;;
esac
	
if test "$EMPRESSPATH" = ""
then
	echo "$USAGE"
	exit 1

elif test ! -d $EMPRESSPATH
then
	echo "'$1' is not a valid EMPRESSPATH"
	exit 1
fi

if test ! -f $EMPRESSPATH/config/initfile && \
   test ! -f $EMPRESSPATH/config/initfile.txt
then
	echo "'$1' is not a valid EMPRESSPATH"
	exit 1
fi

where_is ()
{
	prog=$1
	PTH=`echo $PATH | sed -e "s/:/ /"g`
	PTH="$PTH /bin /usr/bin /usr/local/bin"

	for I in $PTH
	do
		if test -x $I/$prog && test -f $I/$prog
		then
			echo "$I/$prog"
			return
		fi
	done
	echo
}

MD5SUM=`where_is md5sum`
SUM=`where_is sum`

if test "$MD5SUM" != ""
then
	METHOD=md5sum
elif test "$SUM" != ""
then
	METHOD=sum
else
	echo "*** Error *** Cannot find a checksum program to use"
	exit 1
fi

cd $EMPRESSPATH

find . -type f -print | sort | xargs $METHOD
