#!/bin/sh

if [ ! -d "$1" ] ; then
	echo "Usage: $0 root-dir pkg-name [ pkg-name [ ... ] ]"
	exit 1
fi

cd $1 || exit 1 ; shift

errcnt=/tmp/errcnt.$$
rm -f $errcnt ; touch $errcnt

for x
do
	if ! [ -f "var/adm/flists/$x" ] ; then
		echo "No such package: $x!"
		continue
	fi

	cat var/adm/md5sums/$x | \
	while read sum fn ; do
		if   test ! -f "$fn" ; then
			echo "$x: missing:   $fn" | tee -a $errcnt
		elif md5sum "$fn" | egrep -vqx "$sum +$fn" ; then
			echo "$x: modified:  $fn" | tee -a $errcnt
		fi
	done
done

errors=`wc -l < $errcnt` ; rm $errcnt
if   [ $errors = 0 ] ; then echo "No errors found."
elif [ $errors = 1 ] ; then echo "1 error found."
else echo $errors "errors found." ; fi
