#!/bin/sh -x
# This script does the request task for
# the Seabreeze configuration.
#
# Copyright (c) 1998 by Sun Microsystems, Inc.
# All rights reserved.
#
# @(#)request	1.6        04/16/99 
#

##############################################################################################
########## Get the primary admin if AdminSuite is being installed from the command line ######

askyesno_default ()
{
        while true
        do
         echo "\n##### Setting the Primary Administrator. #####"
         echo "If you choose to skip setting the Primary Administrator now,you"
         echo " must log on as root when you start AdminSuite and define a Primary Administrator" 
         echo " with the Users application."

           echo "\nDo you want to setup the primary administrator now ? [y/n] (default: n) : \c"
                read answer
                if [ "${answer}" = "" ]
                then
                        answer="n"   ## Default to no ##
                fi

                case ${answer} in

                        "Y"|"y") return 0;;

                        "N"|"n") return 1;;

                        *) echo "\tInvalid Input: $answer";;
                esac
        done
}



getAdmin() {
 case "${1}" in

    "")
          echo "\nYou must enter a valid unix user to continue."
          echo "Otherwise type CTRL-C to cancel and exit....\n" 
          return 1
             ;;   

    root)
          echo "\nThe root user cannot be the primary administrator."
          echo "\You must enter a valid unix user to continue." 
          echo "Otherwise type CTRL-C to cancel and exit.....\n"
          return 1
           ;;

############### Validate the user if it succeeds return 0 or 1 otherwise #################

   *)

      /usr/bin/getent passwd $1 >>/dev/null

      if [ "$?" != "0" ]; then
    echo "\nPrimary Administrator user name validation failed"
    return 1
    fi
      ;;
   
  esac
  
 echo "\nPrimary Administrator user name validation completed successfully"
 return 0
  }

############################ Now prompt the user for the name  ###########################  

askyesno_default

if [ "$?" = "0" ]; then

echo "Please enter the name of the primary administrator and press RETURN : \c"
 read PRIMARY_ADMIN
until getAdmin ${PRIMARY_ADMIN}

 do
 echo "Please enter the name of the primary administrator and press RETURN: \c"
 read PRIMARY_ADMIN
done

   else
       PRIMARY_ADMIN=""
 fi


# Now export PRIMARY_ADMIN

cat >$1 <<!
PRIMARYADMIN='$PRIMARY_ADMIN'
!

######################### Done #######################################################
exit 0

