#!/bin/sh
#
#ident	"$Id: badnames,v 1.2 2005/01/04 22:03:15 mikew Exp $"
#
# Check for sanity in browsing for keys that have invalid names/illegal chars
#

NAME=`basename $0`
InitFile="../src/tests.init"

if [ "x${SERVER1}" = "x" ]; then
	if [ -f ${InitFile} ]; then
		. ${InitFile}
	fi
fi

verbose () {
	if [ "x${VERBOSE}" != "x" ]; then
		echo $*
	fi
}

process_entries () {
	while read name count ; do
		if [ "x$name" != "x" ] ; then
			verbose "Looking at $name $count"
			actual=`ls -a ${AUTO_CLIENT_MNTPNT}/badnames/ | grep "^$name\$" | wc -l`
			if [ $actual -ne $count ] ; then
				echo "Expected $name $count times but saw it $actual times"
				errors="yes"
			fi
		fi
	done
	if [ "x$errors" != "x" ] ; then
		exit 1
	fi
}

errors="";
awk '/^#/ || /^[:space:]*$/ {next;}; {print;}' ${AUTOMAP_DIR}/dat/${NAME} \
	| process_entries;
if [ $? -ne 0 ]; then
	echo "$NAME: FAILED"
	exit 1
else
	echo "$NAME: SUCCEEDED"
fi
