#!/bin/csh -f
# generate a new group file from /etc/passwd
cp /dev/null /tmp/grplist
foreach i (`awk -F: '{print $1}' </etc/passwd`)
	set groups=`hesinfo $i grplist`
	if (! $status) then
# The grouplist is of the form \(grpname:gid\)*
# this splits it up to put one grpname per line, with the current username
# as the sole member.
		echo $groups | sed -e "s/\([a-z0-9_]\):\([0-9]*\):*/\1:*:\2:$i\ /g" |awk '{for (i = 1; i <= NF; i++) print $i}' >>/tmp/grplist
	endif
end
sort </tmp/grplist >/tmp/grplist.new
awk -F: 'BEGIN {  oldgrp = ""; line = "" } { if ($1 == oldgrp) {line = line "," $4} else {print line; line = $0; oldgrp = $1}} END { print $line }' </tmp/grplist.new |sed -e '/^$/d' >/tmp/group.new
exit 0
