:
#	@(#) mkrmgroup 25.1 92/05/13 
#
#	Copyright (C) 1990-1992 The Santa Cruz Operation, Inc.
#	and SecureWare, Inc.	All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
# rmgroup	--  Helper script for rmuser to remove account names
#		    from /etc/group
#
# Usage: rmgroup 
#
# The account names to be removed are read from standard in
#
# NOTE this script is not intended to be called directly but via rmuser
# so that the necessary lock file is created beforehand.

# cleanup() - remove working copy of /etc/group
cleanup() { rm -f /tmp/group.ip; exit 1; }

trap '/bin/echo "$0: Stopped"; cleanup' 1 2 3 15

# check the lock file has been created by ale
[ -f /etc/group-t ] || { echo "$0:/etc/group-t not created"; exit 1; }

# make a working copy of /etc/group
cp /etc/group /etc/group-t

# check sed is executable
[ -x /bin/sed ] || { echo "$0:/bin/sed is not executable"; cleanup; }

# delete each account name read from stdin
while read account 
do	cp /dev/null /tmp/group.ip
	until	cmp -s /tmp/group.ip /etc/group-t
	do      /bin/cp /etc/group-t /tmp/group.ip
		/bin/sed "s/\(:[0-9].*[:,]\)$account,/\1/
			  s/\(:[0-9].*[:,]\)$account"'$/\1/
			  s/,$//' < /tmp/group.ip > /etc/group-t
	done
done
rm -f /tmp/group.ip

exit 0;
