#!/bin/sh
# $Revision: 1.8 $
# Sun Packaging Request script for NetBackup Encryption, 56-bit DES.
INSTALL_DES_DIR="/opt"
# Prepend /usr/5bin to PATH on Suns to get System V behaviour from echo.
PATH=/usr/5bin:$PATH
test_yn ()
{
case $1 in
  Y*|y*) return 0 ;;
  *)	return 1 ;;
esac
}
# Get_Client_List sets up a list of the clients to install
Get_Client_List ()
{
HEADER="\n\n\tChoose the Platform Client types you wish to install\n"
HEADER1="\tby selecting the platform type one at a time\n\tor select ALL client platforms.\n"
HEADER2="\n\tPlatform Client Options\n\t-----------------------\n"
OPTION1="\t 1. DEC Alpha\n"
OPTION2="\t 2. Auspex\n"
OPTION3="\t 3. C910_920 / SGI\n"
OPTION4="\t 4. HP9000-800 \n"
OPTION5="\t 5. NCR\n"
OPTION6="\t 6. Pyramid\n"
OPTION7="\t 7. IBM RS6000\n"
OPTION8="\t 8. Sequent\n"
OPTION9="\t 9. Sun4 / SPARC\n"
OPTION10="\t10. Windows 95/ NT PC\n"
OPTION11="\t11. MACINTOSH PC\n"
OPTION12="\t12. ALL client platforms\n"

ListOK=0
while [ $ListOK = 0 ]
do
   echo $HEADER $HEADER1 $HEADER2 $OPTION1 $OPTION2 $OPTION3 \
         $OPTION4 $OPTION5 $OPTION6 $OPTION7 $OPTION8 $OPTION9 \
         $OPTION10 $OPTION11 $OPTION12

    # this is the server's "client type"
    ClientCLASSES="$REQ_CLASS"

    notdone=1
    while [ $notdone = 1 ]
    do
       option=`ckrange -l 1 -u 12 -b 10 -d 12 \
-h "Please enter an integer between 1 and 12, or q to quit. Default is 12." \
        -e "Please enter an integer between 1 and 12, or q to quit." \
	   -p "\tEnter Choice (Default is 12) " ` || notdone=0

       case $option in
           1) ClientCLASSES="$ClientCLASSES ALPHA56class" ;;
           2) ClientCLASSES="$ClientCLASSES Auspx56class" ;;
           3) ClientCLASSES="$ClientCLASSES C91056class" ;;
           4) ClientCLASSES="$ClientCLASSES HP56class" ;;
           5) ClientCLASSES="$ClientCLASSES NCR56class" ;;
           6) ClientCLASSES="$ClientCLASSES Pyram56class" ;;
           7) ClientCLASSES="$ClientCLASSES RS6K56class" ;;
           8) ClientCLASSES="$ClientCLASSES Seq56class" ;;
           9) ClientCLASSES="$ClientCLASSES Sun456class" ;;
           10) ClientCLASSES="$ClientCLASSES WIN56class" ;;
           11) ClientCLASSES="$ClientCLASSES MAC56class" ;;
           12) ClientCLASSES="ALL" ;;
       esac
   done # for while notdone

   for Client in $ClientCLASSES
   do
        echo $Client >> /tmp/ClientFILES.$$
   done

   if [ -f /tmp/ClientFILES.$$ ] ; then
       ClientCLASSES=""
       sort -u /tmp/ClientFILES.$$ > /tmp/ClientFILES.$$.$$
       ClientLIST=`cat /tmp/ClientFILES.$$.$$`
       echo "\tYou have chosen to install: \n"
       for client in $ClientLIST
       do
           if [ "$client" = "ALL" ] ; then
	       ClientLIST="ALL"
           fi
       done
       if [ "$ClientLIST" = "ALL" ] ; then
           echo "\tAll Encryption client platforms"
           ClientCLASSES="$ClientLIST"
       else
           for client in $ClientLIST
           do
              ClientCLASSES="$ClientCLASSES $client"
              case $client in
                "ALPHA56class") echo "\tALPHA" ;;
                "Auspx56class") echo "\tAuspex" ;;
                "C91056class")  echo "\tC910_920 / SGI" ;;
                "HP56class") 	echo "\tHP9000-800" ;;
                "NCR56class") 	echo "\tNCR" ;;
                "Pyram56class") echo "\tPyramid" ;;
                "RS6K56class") 	echo "\tRS6000" ;;
                "Seq56class") 	echo "\tSequent" ;;
                "Sun456class") 	echo "\tSun4" ;;
                "WIN56class") 	echo "\tWindows 95 / NT PC" ;;
                "MAC56class") 	echo "\tMACINTOSH PC" ;;
              esac
           done
       fi

       ans=`ckyorn -Q -d y \
            -p "\tIs this the list you wish to use? (y)" ` || exit $?

       test_yn $ans
       if [ $? = 0 ] ; then
             if [ "$ClientCLASSES" = "ALL" ] ; then
               ClientCLASSES="ALPHA56class Auspx56class \
C91056class HP56class NCR56class Pyram56class RS6K56class \
Seq56class Sun456class WIN56class MAC56class"
             fi
             ListOK=1
       fi
       rm -f /tmp/ClientFILES.$$ /tmp/ClientFILES.$$.$$
   else # /tmp CLIENTFILES.$$ doesnt exist
       echo "\tYou have not chosen any client platforms to install."
       ans=`ckyorn -Q -d y \
            -p "\tDo you want to load any of the NetBackup Encryption clients? (y)" ` || exit $?
 
       test_yn $ans
       if [ $? = 0 ] ; then
           :
       else
           ClientCLASSES="$REQ_CLASS"
           ListOK=1
       fi
   fi
done # for while list ok
}
exit_err=0
DIR=""

if [ -h /usr/openv ] || [ -d /usr/openv ] ; then
    HEREIAM=`pwd`
    cd /usr/openv
    DIR=`pwd`
    cd ${HEREIAM}
    INSTALL_DES_DIR=`dirname ${DIR}`
    echo "\n\n\tAn openv directory was found in $INSTALL_DES_DIR."
    echo "\tEncryption will be installed in $INSTALL_DES_DIR/openv/lib,"
    ans=`ckyorn -d y \
        -p "\tis this okay? (y)"` || exit $?
    test_yn $ans
    if [ $? = 1 ] ; then
      exit_err=1
      echo "\n\n\tThere can only be one soft-link from /usr/openv"
      echo "\tInstallation can not continue.\n\n"
    fi
fi

if [ $exit_err -eq 0 ] && [ "X${DIR}" = "X" ] ; then
  ans=`ckyorn -d y \
      -p "\tDefault location is /opt/openv/lib, is this okay? (y)"` || exit $?
  test_yn $ans
  if [ $? = 1 ] ; then
    INSTALL_DES_DIR=`ckpath -aoy \
    -p "\tWhere do you want the ./openv/lib directory?"` || exit $?

    HEREIAM=`pwd`
    cd ${INSTALL_VM_DIR}
    USER_DIR=`pwd`
    cd ${HEREIAM}
 
    if [ "${USER_DIR}" = "/usr" ] || [ "${USER_DIR}" = "/" ] ; then
      echo "\n\n\n\t Installation in /usr or /, is not allowed.\n\n"
      INSTALL_DES_DIR="/opt"
      exit_err=3
    fi
  fi 
fi 
#
# Select list of Clients to install
#
if [ $exit_err -eq 0 ] ; then
  REQ_CLASS="Sun456class"
  echo "\n\tEncryption for the Sun4 client will be loaded."
  ans=`ckyorn -Q -d y \
   -p "\tDo you want to load any other NetBackup \n\tEncryption clients onto the server? (y)" `\
    || exit $?
 
  test_yn $ans
  if [ $? = 0 ] ; then
     Get_Client_List
  else
     ClientCLASSES="$REQ_CLASS"
  fi
  CLASSES="NBU56class $ClientCLASSES"
fi
#
# make parameters available to preinstall/postinstall scripts
cat > $1 <<!
INSTALL_DES_DIR='$INSTALL_DES_DIR'
BASEDIR='$INSTALL_DES_DIR'
CLASSES='$CLASSES'
!
exit $exit_err
