#!/bin/sh
#*************************************************************************
#
#	Copyright (c) Advanced Visual Systems, Inc., 1996
#                     All Rights Reserved.  Unpublished rights reserved 
#                     under the copyright laws of the United States
#
#  The software contained on this media is proprietary to and embodies
#  the confidential technology of Advanced Visual Systems, Inc..
#  Possession, use, duplication or dissemination of the software and
#  media is authorized only pursuant to a valid written license from
#  Advanced Visual Systems, Inc..
#
#  RESTRICTED RIGHTS LEGEND  Use, duplication, or disclosure by the
#  U.S. Government is subject to restrictions as set forth in 
#  Subparagraph (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19,
#  as applicable.
#
#
#	File:		express/db_kit/install.sh
#	Date:		18-MAR-1996
#	Abstract:	AVS/Express Database Kit for UNIX
#                       support Subset Control Program
#
#	Change Log:
#	04/10/1998 pli	Added change to link in Oracle 8 as well as 7.
#			Modified the version numbers.
#
#*************************************************************************
#
#
#
PRODUCT_SET="AVS/Express"
#
RELEASE="$PRODUCT_SET Database Kit V4.0"
PRODUCT="$PRODUCT_SET Database Kit"
OPTION="Database Kit"
SUBSETNAME=`basename $0 .scp`
#
YEAR="1998"
#
VERSION="V4.0"
#
#
#----------------------------------------------------
#	GENERAL UTILITY ROUTINES
#----------------------------------------------------

:	-ShowMsg
#		Displays formatted user notification
#	given:  $1 - notification message string
#                 does:   Display product name then message
#                 return: NIL

ShowMsg()
{
	echo ""
	echo "$RELEASE"
	echo "$OPTION $1"
}

#------------------------------------------------------
#                  BEGIN EXECUTION HERE
#------------------------------------------------------
 cat << !EOF!


  Installing $PRODUCT_SET ($SUBSETNAME)...

      $RELEASE
      Copyright (c) Advanced Visual Systems, Inc., $YEAR.
      All Rights Reserved.  Unpublished rights reserved
      under the copyright laws of the United States.

      Possession, use, or copying of the software and
      media is authorized only pursuant to a valid written
      license from Advanced Visual Systems, Inc..

      RESTRICTED RIGHTS LEGEND   Use, duplication, or
      disclosure by the U.S. Government is subject to
      restrictions as set forth in Subparagraph (c)(1)(ii)
      of DFARS 252.227-7013, or in FAR 52.227-19, as
      applicable.

!EOF!


#------------------------------------------------------
#  First determine the platform that is doing the installation. 
#------------------------------------------------------

UNAME=`uname -s`

if [ "$UNAME" = "SunOS" ] ; then
   VERSION=`uname -r | sed -e 's/\..*$//'` 
   if [ "$VERSION" = "5" ] ; then
      TYPE=s2
   else
      TYPE=sun
   fi
elif [ "$UNAME" = "HP-UX" ] ; then
   if [ $MACHINE ] ; then
      TYPE=$MACHINE
   else
      MAJOR_VERSION=`uname -r | sed -e 's/B\.//' -e 's/\..*$//'`
      if [ "$MAJOR_VERSION" = "10" ] ; then
         MINOR_VERSION=`uname -r | sed -e 's/B\.10\.//'`
         if [ "$MINOR_VERSION" = "10" ] ; then
            TYPE=hp10 
         else
	    TYPE=hp1020
         fi
      else
         TYPE=hp 
      fi
   fi
elif [ "$UNAME" = "IRIX" ] ; then
   TYPE=sgi
elif [ "$UNAME" = "IRIX64" ] ; then
   if [ $MACHINE ] ; then
      TYPE=$MACHINE
   else 
      TYPE=sg6
   fi
elif [ "$UNAME" = "AIX" ] ; then
   TYPE=ibm
elif [ "$UNAME" = "OSF1" ] ; then
   TYPE=alpha
else
    cat << !EOF!

   There is a problem attempting to verify the system archectiture.
   When installing AVS/Express $OPTION ($SUBSETNAME) this operating 
   system is not supported.
!EOF!
	   ShowMsg "installation failed !"
           exit 1;

fi


#------------------------------------------------------
#  Check if  XP_ROOT is defined
#------------------------------------------------------
        if [ $XP_ROOT ]
        then
           echo "     "
       else
           echo "     "
           echo "     Installation cannot find required XP_ROOT environmental variable."
           echo "     Please check if  the environmental variable  (XP_ROOT) is set correctly."
           ShowMsg "installation failed !"
           exit 1;        		 
        fi


#------------------------------------------------------
#  Show the user where XP_ROOT is currently defined to....
#  Ask user if this is correct.  If not correct, then script will exit with warning.
#------------------------------------------------------
   echo "      "
   echo "   The environmental variable for XP_ROOT is currently set to $XP_ROOT"
   echo "   Is this the correct setting for XP_ROOT [n]?"
   read RESPONSE
   if [ "$RESPONSE" != "y" ] && [ "$RESPONSE" != "Y" ] ; then
     echo "   Please set XP_ROOT to the correct setting and re-run this installation."
    ShowMsg "Incorrect setting for XP_ROOT"
     exit 0
  fi


#------------------------------------------------------
#  Next ask the user if they want to save current Express image
#------------------------------------------------------
  echo "   Do you want to save current version of AVS/Express [n]?"
  read RESPONSE
  if [ "$RESPONSE" = "y" ] || [ "$RESPONSE" = "Y" ] ; then
        if [ -f $XP_ROOT/bin/$TYPE/express ]
        then
          mv $XP_ROOT/bin/$TYPE/express $XP_ROOT/bin/$TYPE/express_old
          SAVE=1
        else
          SAVE=0
        fi
  fi

#------------------------------------------------------
#  Ask the user which database(s) they have installed...
#------------------------------------------------------
  echo "     "
  echo "     This version of $PRODUCT_SET supports the following database products."
  echo "     Please indicate which database Client product(s) you wish to link to "
  echo "     $PRODUCT"
  echo "      "
  echo "            1.)  Oracle"
  echo "            2.)  None"
  echo "     "
  echo "     Your choice [2]: "

  read RESPONSE
  if [ "$RESPONSE" = "1" ]; then
	if [ "$TYPE" = "hp10" ]
        then
           echo "     "
           echo "    Oracle is not supported on HP 10.10 systems!!!"
	   exit 1;
	fi
        if [ -f $ORACLE_HOME/lib/libcore4.a ] || 
		[ -f $ORACLE_HOME/lib/libsqlnet.a ]
        then
           echo "     " 
           echo "    Oracle to be linked into $PRODUCT_SET..." 
       else
           echo "     "
           echo "     Installation cannot find required Oracle libraries."
           echo "     Please check if Oracle is installed and the environmental"
           echo "     variable (ORACLE_HOME) is set correctly."
           ShowMsg "installation failed !"
           if [ "$SAVE" = "1" ] && [ -f $XP_ROOT/bin/$TYPE/express_old ]
           then
              mv -f $XP_ROOT/bin/$TYPE/express_old $XP_ROOT/bin/$TYPE/express
           fi
           exit 1;        		 
        fi
  fi

  if [ "$RESPONSE" = "2" ]  || [ "$RESPONSE" = "" ]; then
           echo "     "
           echo "     You have selected not to install $PRODUCT_SET with any of the supported"
           echo "     database products.  This installation will exit."
           echo "      "   	
           ShowMsg "installation failed !"
           if [ "$SAVE" = "1" ] && [ -f $XP_ROOT/bin/$TYPE/express_old ]
           then
              mv -f $XP_ROOT/bin/$TYPE/express_old $XP_ROOT/bin/$TYPE/express
           fi
           exit 1;        
        fi


#------------------------------------------------------
#  Check if the Config.h file exists prior to editing
#------------------------------------------------------
        if [ -f $XP_ROOT/include/$TYPE/config.h ]
        then
           cp   $XP_ROOT/include/$TYPE/config.h     $XP_ROOT/include/$TYPE/config_old.h
       else
           echo "     "
           echo "     Installation cannot find required $PRODUCT  $XP_ROOT/include/$TYPE/config.h"
           echo "     Please check if  $PRODUCT is installed and the environmental variable"
           echo "     (XP_ROOT) is set correctly."
           ShowMsg "installation failed !"
           if [ "$SAVE" = "1" ] && [ -f $XP_ROOT/bin/$TYPE/express_old ]
           then
              mv -f $XP_ROOT/bin/$TYPE/express_old $XP_ROOT/bin/$TYPE/express
           fi
           exit 1;        		 
        fi


#------------------------------------------------------
#  Cleanup the Config.h file from previous database entries
#------------------------------------------------------
    sed  -e "/#define ORACLE_KIT/ D" $XP_ROOT/include/$TYPE/config.h    > $XP_ROOT/include/$TYPE/config.t
    mv   $XP_ROOT/include/$TYPE/config.t 	$XP_ROOT/include/$TYPE/config.h 

    sed  -e "/DB_KIT/ D" $XP_ROOT/include/$TYPE/config.h    		 > $XP_ROOT/include/$TYPE/config.t
    mv   $XP_ROOT/include/$TYPE/config.t 	$XP_ROOT/include/$TYPE/config.h 

    sed  -e "/ORACLE_KIT/ D" $XP_ROOT/include/$TYPE/config.h   	 > $XP_ROOT/include/$TYPE/config.t
    mv   $XP_ROOT/include/$TYPE/config.t 	$XP_ROOT/include/$TYPE/config.h  

 
#------------------------------------------------------
#  Update/EDIT the Config.h file with generic DB flag
#------------------------------------------------------

echo "#define DB_KIT" | cat >>  $XP_ROOT/include/$TYPE/config.h

#------------------------------------------------------
#  Update/EDIT the Config.h file with respect to Oracle
#------------------------------------------------------
  if [ "$RESPONSE" = "1" ]; then
   echo "#define ORACLE_KIT" | cat >>  $XP_ROOT/include/$TYPE/config.h
  fi

#------------------------------------------------------
#   Move the .proj_lock file aside while we relink system......
#    Don't forget to put it back.
#------------------------------------------------------
        if [ -f $XP_ROOT/.proj_lock ]
        then
           chmod 660 $XP_ROOT/.proj_lock
           mv   $XP_ROOT/.proj_lock   $XP_ROOT/.proj_lock_temp 
        fi


#------------------------------------------------------
#   Trap interrupt signal.
#    We want to guarentee that the .proj_lock gets put back if user signals
#------------------------------------------------------
  trap 'mv $XP_ROOT/.proj_lock_temp $XP_ROOT/.proj_lock; echo ""; echo "    $PRODUCT install terminated."; exit 1' 1 2 3 9 15


#------------------------------------------------------
#  Go relink the image...
#------------------------------------------------------
  echo " "
  echo "    Relinking $PRODUCT_SET..........................."
  echo " "
  cd $XP_ROOT
  $XP_ROOT/bin/$TYPE/base -gen_proc express -exit
  make -f express.mk relink


#------------------------------------------------------
#   PUT the .proj_lock file BACK!!!!
#------------------------------------------------------
        if [ -f $XP_ROOT/.proj_lock_temp ]
        then
           mv   $XP_ROOT/.proj_lock_temp   $XP_ROOT/.proj_lock
           chmod 444 $XP_ROOT/.proj_lock
        fi

        if [ "$SAVE" = "1" ] && [ -f $XP_ROOT/bin/$TYPE/express_old ] \
           && [ ! -f $XP_ROOT/bin/$TYPE/express ]; then
           mv -f $XP_ROOT/bin/$TYPE/express_old $XP_ROOT/bin/$TYPE/express
        fi

exit 0
#
#
# End of Subset Control Program script ...express/db_kit/install.sh
#
