
Listing 1: listgroup

#! /bin/sh
# @(#)mksccs 1.1 listgroup.sh
#
# listgroup - list contents of the netgroup database by key in a human
#             readable form. copyright Brett Wynkoop 14 April 1992
#
# modification history -
#
#  92/09/01 - Added listing of groups if no arguments are passed. [BEW]
#
############################################################################
#
# First like all good shell programs set our PATH and some needed variables.
#
############################################################################
PATH=/usr/local/etc:/usr/local/bin:/usr/ucb:/usr/bin:/bin:
MYNAME=`basename $0`
NETGROUP=$@
##############################################################################
#
# Now since /bin/sh on Suns has functions built in let's setup our 
# usage message function.
#
##############################################################################
usage()
    {
     echo
     echo "Usage: $MYNAME netgroup "
     echo
     echo "       lists the contents of the named netgroup to standard out."
     echo "       copyright Brett Wynkoop 14 April 1992"
     echo
     exit 1
     }
 
#########################################################################
# 
# Is the user asking for help? If so give it to him.
#
#########################################################################

if [ x$1 = x-h ]
then
    usage
fi
if [ x$1 = x-? ]
then
    usage
fi
 
#######################################################################
#
# No command line arguments so we will give the user a list of all 
# netgroups we know about.
#
########################################################################

if [ $# -lt 1 ]
then
     ypcat -k netgroup | awk ' {print $1} ' | sort
     exit 0
fi

############################################################################
#
# This is the real heart of listgroup.  We get the contents of the desired
# netgroup and massage the data with tr to put it into an easy to use
# format on standard out.
#
#############################################################################

GROUP=`ypmatch ${NETGROUP} netgroup`
echo ${GROUP} | grep -s "("
if [ $? -eq 0 ]
then 
     echo ${GROUP}| tr -d "(,-)"
     exit 0
fi

############################################################################
# 
# if we are looking at a group made up of groups take what we have 
# learned and exec ourselves again with the new argument.
#
############################################################################
exec $MYNAME ${GROUP}


