#!/bin/sh
# We need a file to look at.
if [ -z "$*" ] ; then
	echo Usage: `basename $0` uidgid
	exit 1
fi
error=0
# The format of the file is (currently)
for infile in "$@" ; do
	uidlist=`tail -n +2 "$infile" | awk '{print $2}' | grep -v '?' | grep -v -e - | sort -nu`
	gidlist=`tail -n +2 "$infile" | awk '{print $3}' | grep -v '?' | grep -v -e - | sort -nu`
	for uid in $uidlist ; do
		if test `tail -n +2 "$infile" | awk '{print $2}' | grep '^'"$uid"'$' | wc -l` -ne 1 ; then
			echo Duplicate UID: $uid
			error=1
		fi
	done
	for gid in $gidlist ; do
		if test `tail -n +2 "$infile" | awk '{print $3}' | grep '^'"$gid"'$' | wc -l` -ne 1 ; then
			echo Duplicate GID: $gid
			error=1
		fi
	done
done
exit $error
