
#	ATT: ident	"sadmin:admin/menu/usermgmt/delgroup	2.3"

#ident	"@(#)sadmin/admin/menu/usermgmt:delgroup	25.1"

#menu# delete a group from the system
#help# 
#help#	Delgroup allows you to remove groups from the computer.  The
#help#	deleted group is no longer identified by name.  However files may
#help#	still be identified with the group ID number.


#test if yellow page is up
ps -e > /tmp/t1
if grep ypbind /tmp/t1 > /dev/null
then
# if so, is this the yp master server?
	host=`uname -n`					
	master=`ypwhich`
	if test $host = $master; then
		flag=`cat /tmp/t1`
	else
		echo "Must be YP master server to execute delgroup\n"
		rm /tmp/t1
		exit 1
	fi
fi
rm /tmp/t1

minuid=100	# minimum group ID number that is deletable

flags="-qq -k$$"
trap 'exit 0' 1 2  15

echo 0 > /tmp/t0
while true
do
	groupname=`checkre ${flags} -fe 'Which group name do you wish to delete? [q]' \
		'.' 'You must enter at least one character.'`
	idline=`grep "^${groupname}:" /etc/group`
	if [ -n "${idline}" ]
	then
		gid=`echo "${idline}"  |  cut -d: -f3`
		if [ "${gid}" -lt ${minuid} ]
		then
			echo "\\tThat group has group ID ${gid} which is less than ${minuid}.
	This procedure will not delete that group ID."
		elif  checkyn ${flags} -H"
	If you answer  y  files with group ID ${gid} will no longer be
	identified as being in group ${groupname}." \
			-f "Do you want to delete group name '${groupname}', group ID ${gid}?"
		then
			ed - /etc/group <<-!
				H
				/^${groupname}:/d
				w
				q
			!
			echo ${groupname} has been deleted.
			echo 1 > /tmp/t0
		fi

	else
		echo "\\t'${groupname}' is not an existing group.
\\tThis is the current list:"
		cut -d: -f1 /etc/group  |  sort  |  pr -t -w80 -6
	fi
	checkyn -f ${flags} 'Do you want to delete any other groups?'  ||  break
done

#test if yellow page is up
ps -e > /tmp/t1
if grep ypbind /tmp/t1 > /dev/null
then
	flag=`cat /tmp/t0`
	rm /tmp/t0
	if test $flag -gt 0; then
		make -eif /etc/yp/Makefile
	fi
fi
