#! /bin/sh
#**********************************************************************#
#*                                                                    *#
#* Copyright (c) 2001 by Sun Microsystems, Inc.                       *#
#* All rights reserved.                                               *#
#*                                                                    *#
#**********************************************************************#


# setup default variables  for ORACLE, INFORMIX, SYBASE etc.
CURHOME=`pwd`
SKILLED="`echo $SKILLED`+";export SKILLED
OHOME=`echo $ORACLE_HOME`+
IHOME=`echo $INFORMIXDIR`+
SHOME=`echo $SYBASE`+
DHOME=`echo $INSTHOME`+
DCHOME=`echo $DATACOM`+
INGHOME=`echo $II_SYSTEM`+
ADABIN=`echo $ADABIN`+
#-------------------------------------------------------------------#
#  The following code defines clear screen function
#-------------------------------------------------------------------#
trap 'echo "RTSFS Configuration aborted!";exit' 1 2 3 15
BSD=NO;export BSD
KIXCLS=clear
case `uname -m` in
      i386)
          KIXCLS='tput clear';;
      DPX/2300)
          KIXCLS='tput clear';;
esac
export KIXCLS

#-----------------------------------------------------------------------#
#  The following code is required for systems where echo always adds a  #
#  new line.  The code checks for new line suppressing and makes it as  #
#  varible to be used
#-----------------------------------------------------------------------#
if  echo "\c" | grep c >$DEVNULL 2>&1; then    
    N='-n'
else
    C='\c'
fi
export N C
#-----------------------------------------------------------------------#
#-----------------------------------------------------------------------#

flag=1
while [ $flag -le 10 ]
do
# this line clears the screen 
DATEVAR=`date '+%m/%d/%y   %H:%M:%S'`
export DATEVAR

if [ "$SKILLED" = "+" ]
then
  $KIXCLS
  echo "                       Database Configuration Menu           $DATEVAR"
  echo " "
  echo " "
  echo "             1.  Clean Up & Set RTS Install Directory"
  echo " "
  echo "             2.  Oracle RDBMS      "
  echo "             3.  Informix On-Line  "
  echo "             4.  Ingres RDBMS      "
  echo "             5.  DB2/6000 RDBMS    "
  echo "             6.  CA-DATACOM        "
  echo "             7.  Sybase RDBMS      "
  echo "             8.  Adabas DBMS       "
  echo " "
  echo "             B.  Build COBOL Runtime System"
  echo " "
  echo "             X.  Exit configuration "
  echo " "
  echo " "
  echo " "
  echo " "
  echo " "
  echo " "
  echo " "
  echo "--------------------------------------------------------------------------------"
  echo $N "Enter the option number corresponding to the selection you want: $C"
fi
read opt
case $opt in
     1) rm -f /tmp/config.current
        rm -f /tmp/oraobj.sh /tmp/oralnk.sh
        rm -f /tmp/infobj.sh /tmp/inflnk.sh
        rm -f /tmp/sybobj.sh /tmp/syblnk.sh
        rm -f /tmp/db2obj.sh /tmp/db2lnk.sh
        rm -f /tmp/ingobj.sh /tmp/inglnk.sh
        rm -f /tmp/adaobj.sh /tmp/adalnk.sh
        rm -f /tmp/workdir
        ./rtssetup
        ;;
     2) if [ $OHOME = + ]
        then
         echo "#
         echo "# ERROR: No ORACLE_HOME variable set. Set ORACLE_HOME variable to Oracle directory"
         echo "#
         echo "Type return to continue"
         read risp
        else
          if  test ! -d $ORACLE_HOME ;
          then
           echo "#"
           echo "# ERROR: $ORACLE_HOME directory not found"
           echo "#"
           echo "Type return to continue"
           read risp
          else
            if [ ! -f /tmp/config.current ]
            then
              echo $N "# ERROR: Set the RTS install directory (option 1) before selecting this option"
              echo "Type return to continue"
              read risp
            else
#start of BT=4653492 -- C only Oracle Support
               if [ "$appl_lang_cob_mf" = "$SELECTED" ]
               then
                 ./kixoracle "COB_MF"
               else
                 if [ "$appl_lang_cob_acu" = "$SELECTED" ]
                 then
                   ./kixoracle "COB_ACU"
                 else
                   if [ "$appl_lang_pli_liant" = "$SELECTED" ]
                   then
                     ./kixoracle "PLI_ONLY"
                   else
                     ./kixoracle "C_ONLY"
                   fi
                 fi
               fi
#end   of BT=4653492 -- C only Oracle Support
            fi
          fi
        fi
        ;;

     3) if [ $IHOME = + ]
        then
          echo "#"
          echo "# ERROR: No INFORMIXDIR variable set. Set INFORMIXDIR variable to Informix directory"
           echo "#"
          echo "Type return to continue"
          read risp
        else
        if [ ! -d $INFORMIXDIR ] ; 
          then
            echo "#"
            echo "# ERROR: $INFORMIXDIR directory not found"
            echo "#"
            echo "Type return to continue"
            read risp
          else
            if [ ! -f /tmp/config.current ]
            then
              echo $N "# ERROR: Set the RTS install directory (option 1) before selecting this option"
              echo "Type return to continue"
              read risp
            else
              ./kixinformix
            fi
          fi
        fi
        ;;
     4) if [ +$INGHOME = + ]; 
        then
          echo "#"
          echo "# ERROR: No II_SYSTEM variable set. Set II_SYSTEM variable to  Ingress directory"
          echo "#"
          echo "Type return to continue"
          read risp
        else
          if [ ! -d $II_SYSTEM/ingres ]; 
          then
            echo "#"
            echo "# ERROR: $II_SYSTEM/ingres directory not found"
            echo "#"
            echo "Type return to continue"
            read risp
          else
            if [ ! -f /tmp/config.current ]
            then
              echo $N "# ERROR: Set the RTS install directory (option 1) before selecting this option"
              echo "Type return to continue"
              read risp
            else
              ./kixingres
            fi
          fi
        fi
        ;;
     5) if [ $DHOME = + ];
        then
          echo "#"
          echo "# ERROR: No INSTHOME variable set. Set INSTHOME variable to DB2/60000 directory"
          echo "#"
          echo "Type return to continue"
          read risp
        else
          if [ ! -d $INSTHOME ];
          then
            echo "#"
            echo "# ERROR: $INSTHOME directory not found"
            echo "#"
            echo "Type return to continue"
            read risp
          else
            if [ "$appl_lang_cob_mf" = "$SELECTED" -o "$appl_lang_cob_acu" = "$SELECTED" ]
            then
               ./kixdb2 "CBL"
            else
               ./kixdb2 "XXX"
            fi
          fi
        fi
     ;;
     6) if [ $DCHOME = + ];
        then
          echo "#"
          echo "# ERROR: No DATACOM variable set. Set DATACOM variable to CA-DATACOM directory"
          echo "#"
          echo "Type return to continue"
          read risp
        else
          if [ ! -d $DATACOM ];
          then
            echo "#"
            echo "# ERROR: $DATACOM directory not found"
            echo "#"
            echo "Type return to continue"
            read risp
          else
            ./kixdatacom
          fi
        fi
     ;;
     7) if [ $SHOME = + ]; 
        then
          echo "#"
          echo "# ERROR: No SYBASE variable set. Set SYBASE variable to Sybase directory"
          echo "#"
          echo "Type return to continue"
          read risp
        else
        if [ ! -d $SYBASE ]; 
          then
            echo "#"
            echo "# ERROR: $SYBASE directory not found"
            echo "#"
            echo "Type return to continue"
            read risp
          else
            if [ ! -f /tmp/config.current ]
            then
              echo $N "# ERROR: Set the RTS install directory (option 1) before selecting this option"
              echo "Type return to continue"
              read risp
            else
#Start of kixsysbase 12.5 changes BT=4714862
              if [ "$appl_lang_cob_mf" = "$SELECTED" -o "$appl_lang_cob_acu" = "$SELECTED" ]
              then
                 ./kixsybase "CBL"
              else
                 ./kixsybase "XXX"
              fi
#End   of kixsysbase 12.5 changes BT=4714862
            fi
          fi
        fi
        ;;
     8) if [ $ADABIN = + ];
        then
          echo "#"
          echo "# ERROR: No ADABIN variable set. Set ADABIN variable to Adabas directory"
          echo "#"
          echo "Type return to continue"
          read risp
        else
          if [ ! -d $ADABIN ];
          then
            echo "#"
            echo "# ERROR: $ADABIN directory not found"
            echo "#"
            echo "Type return to continue"
            read risp
          fi
        fi
     ;;
     B|b) if test -f /tmp/workdir;
          then 
            WORKDIR=`cat /tmp/workdir`;export WORKDIR
            rm -f /tmp/workdir
          fi
        if [ a$WORKDIR = a ]
          then
            echo $N "# ERROR: Set the RTS install directory (option 1) before selecting this option"
            echo "Type return to continue"
            read risp
          else
            if [ ! -f /tmp/config.current ]
            then
              echo $N "# ERROR: Set the RTS install directory (option 1) before selecting this option"
              echo "Type return to continue"
              read risp
            else
              ./rtsbuild
            fi
          fi 
          ;; 
     X|x) rm -f /tmp/config.current 
        rm -f /tmp/oraobj.sh /tmp/oralnk.sh 
        rm -f /tmp/infobj.sh /tmp/inflnk.sh 
        rm -f /tmp/sybobj.sh /tmp/syblnk.sh 
        rm -f /tmp/db2obj.sh /tmp/db2lnk.sh
        rm -f /tmp/ingobj.sh /tmp/inglnk.sh
        rm -f /tmp/workdir
        if [ "$SKILLED" = "+" ]
        then
          $KIXCLS
        fi
        exit
        ;;
     *) echo "#"
        echo "# ERROR: Wrong option selected"
        echo "#"
        echo "Type return to continue"
        read risp
        ;;
esac
done
