#!/bin/sh
# "$Date$ $Revision$"
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

GROUPNAME=""
RETCODE=""

#
# If the groupname begins with a numeric character, getent treats it 
# as a group id (!) and the getent test fails. So, requiring that groupname
# starts with a letter.
#
chkgroupname() {
        case $GROUPNAME in 
		[0-9]*) return 1;; 
	esac
	return 0
}

while true; do

  echo "Enter the name of a pre-existing group for use by the Sun Ray Connector: "
  read GROUPNAME
  case "$GROUPNAME" in 
    "")		  
	 ;;
    *)
       # validate the groupname
       chkgroupname
       if [ $? != 0 ]; then
           echo "Invalid group: $GROUPNAME. Please enter a valid group name."
           continue
       fi

       getent group $GROUPNAME > /dev/null
       RETCODE=$?
       if [ $RETCODE != 0 ]
        then
           echo "Invalid group (Error $RETCODE): $GROUPNAME. Please enter a valid group name."
        else
           echo "Using group name $GROUPNAME.."
           # export GROUPNAME to global PKG environment
           echo "GROUPNAME=${GROUPNAME}" >> $1
	   break
       fi       
       ;;
  esac
done
