#!/bin/sh
#
#  install.sh
#
#  Install OpenLink products
#
#  Version: 5.1.2
#
#  (C)Copyright 1993-2003 OpenLink Software.
#  All Rights Reserved.
#
#  The copyright above and this notice must be preserved in all
#  copies of this source code.  The copyright above does not
#  evidence any actual or intended publication of this source code.
#
#  This is unpublished proprietary trade secret of OpenLink Software.
#  This source code may not be copied, disclosed, distributed, 
#  demonstrated or licensed except as authorized by OpenLink Software.
#
#  This file is an OpenLink Software product installation script.
#  To learn more about this product, or any other product in our
#  portfolio, please check out our web site at:
#
#      http://www.openlinksw.com 
#
#  or contact us at:
#
#      general.information@openlinksw.com
#
#  If you have any technical questions, please contact our support
#  staff at:
#
#      technical.support@openlinksw.com
#

umask 002

#
#  Installation directory
#
PREFIX=`pwd`

#
#  Determine hostname
#
HOST=`hostname | sed -e 's/\..*//' 2>/dev/null`
HOST=${HOST:-localhost}
echo ""
echo "Started installation on : $HOST"
echo ""


#
#  Setup the PATH
#
PATH="$PREFIX/bin:.:$PATH"
export PATH

#
#  Test for -n or \c in echo command
#
if (echo "testing\c") | grep c >/dev/null; then
  echo_n=-n 
  echo_c= 
else
  echo_n= 
  echo_c='\c'
fi


#
#  Check whether to use uncompress or gunzip
#
UNZIP=uncompress
SUFFIX=Z
IFS="${IFS= 	}"; SAVE_IFS="$IFS"; IFS=":" 
for dir in $PATH
do
   if [ -x "$dir/gunzip" ] 
   then
       UNZIP="$dir/gunzip"
       SUFFIX=gz
       break
   fi
done
IFS="$SAVE_IFS"


#
#  Check if the broker is already running
#
set dummy `(ps -e; ps -a) | grep oplrqb | grep -v grep 2>/dev/null`
shift
BRKPID=$1
if [ $# -gt 0 ]
then
    echo ""
    echo "The installer detected a running broker on this system."
    echo "It is recommended the broker is shutdown before upgrading."
    echo "Do you wish to attempt to:"
    echo ""
    echo "  1. Shutdown the broker"
    echo "  2. Continue with the installation"
    echo "  3. Abort the installation"
    echo ""
    echo $echo_n "Please enter your choice [ENTER=1] : $echo_c"
    read answer
    case $answer in
	2)
	    echo "Continuing with installation ..."
	    ;;
	3)
	    echo "Aborting installation ..."
	    exit 1
	    ;;
	*)
	    if [ -x bin/oplshut ]
	    then
	        bin/oplshut -fy
		STATUS=$?
	    else
		echo "Initiating shutdown ..."
	        kill -15 $BRKPID
		STATUS=$?
	    fi
	    if [ $STATUS -ne 0 ]
	    then
		echo "**"
		echo "** ERROR: The broker could not be shutdown."
		echo "**        Please shutdown the broker manually"
		echo "**        before retrying the installation."
		echo "**"
		exit 1
	    fi
	    ;;
    esac 
    echo ""
fi


#
#  Check if there are .ini.save files
#
FILES=""
for file in bin/*.ini.save
do
    if [ -f "$file" ]
    then
	FILES="$FILES $file"
    fi
done
if [ ! -z "$FILES" ]
then
    echo "**"
    echo "** ERROR: The installer detected the following files: "
    echo "**"
    for file in $FILES
    do
	echo "**          - $file"
    done
    echo "**"
    echo "**        which may be overwritten during installation."
    echo "**        Please move these files to a save location "
    echo "**        before retrying the installation."
    echo "**"
    exit 1
fi


#
#  Save the original oplrqb.ini, odbc.ini and odbcinst.ini files if present
#
if [ -f bin/oplrqb.ini ]
then
  echo "*"
  echo "* Temporarily saving your original Session Rules Book"
  echo "* (the file oplrqb.ini) to oplrqb.ini.save"
  echo "*"
  mv bin/oplrqb.ini bin/oplrqb.ini.save
fi

if [ -f bin/odbc.ini ]
then
  echo "*"
  echo "* Temporarily saving your original ODBC DSN settings"
  echo "* (the file odbc.ini) to odbc.ini.save"
  echo "*"
  mv bin/odbc.ini bin/odbc.ini.save
fi

if [ -f bin/odbcinst.ini ]
then
  echo "*"
  echo "* Temporarily saving your original ODBC Installation settings"
  echo "* (the file odbcinst.ini) to odbcinst.ini.save"
  echo "*"
  mv bin/odbcinst.ini bin/odbcinst.ini.save
fi

if [ -f bin/udbc.ini ]
then
  echo "*"
  echo "* Temporarily saving your original UDBC DSN settings"
  echo "* (the file udbc.ini) to udbc.ini.save"
  echo "*"
  mv bin/udbc.ini bin/udbc.ini.save
fi

if [ -f bin/freetds.conf ]
then
  echo "*"
  echo "* Temporarily saving your original SQL Server settings"
  echo "* (the file freetds.conf) to freetds.conf.save"
  echo "*"
  mv bin/freetds.conf bin/freetds.conf.save
fi

if [ -f bin/openlink.ini ]
then
  echo "*"
  echo "* Temporarily saving your original UNIX Lite settings"
  echo "* (the file openlink.ini) to openlink.ini.save"
  echo "*"
  mv bin/openlink.ini bin/openlink.ini.save
fi

#
#  Move the Request broker out of the way
#  
#
if [ -f bin/oplrqb ]
then
  mv bin/oplrqb bin/oplrqb.save
fi


# 
#  Extract the .taz files present in this directory
#
for file in *.taz
do
  echo "Extracting ($file) ..."

  #
  #  Uncompress a copy of the archive
  #
  cp $file $file.tar.$SUFFIX
  rm -f $file.tar
  "$UNZIP" $file.tar.$SUFFIX

  #
  #  Allow overwriting of our own files
  #  Remove shared libraries as they may be in use
  #
  tar tf $file.tar | while read filename
  do
    case "$filename" in
    */*.so)
        rm -f "$filename"	2>/dev/null
	;;
    */*.sl)
        rm -f "$filename"	2>/dev/null
	;;
    */*.so.*)
        rm -f "$filename"	2>/dev/null
	;;
    */*.sl.*)
        rm -f "$filename"	2>/dev/null
	;;
    *)
	chmod u+w "$filename"	2>/dev/null
	;;
    esac
  done

  #
  #  Extract the files from the archive
  #
  tar xf $file.tar || {
    #
    #  In case of an error, restore the original ini files 
    #
    [ -f bin/oplrqb.save ] && mv bin/oplrqb.save bin/oplrqb 
    [ -f bin/oplrqb.ini.save ] && mv bin/oplrqb.ini.save bin/oplrqb.ini
    [ -f bin/odbc.ini.save ] && mv bin/odbc.ini.save bin/odbc.ini 
    [ -f bin/odbcinst.ini.save ] && mv bin/odbcinst.ini.save bin/odbcinst.ini 
    [ -f bin/udbc.ini.save ] && mv bin/udbc.ini.save bin/udbc.ini 
    [ -f bin/freetds.conf.save ] && mv bin/freetds.conf.save bin/freetds.conf 
    [ -f bin/openlink.ini.save ] && mv bin/openlink.ini.save bin/openlink.ini 

    echo "**"
    echo "** ERROR: During the extraction of the archive the above errors occurred"
    echo "**        which cannot be ignored. Please check permissions and diskspace "
    echo "**        before retrying the installation."
    echo "**"
    exit 1
  }

  #
  #  Remove the copy of the archive
  #
  rm -f $file.tar
done


#
#  Either restore the original broker or delete it when a new one has been 
#  installed
#
if [ -f bin/oplrqb.save ]
then
  if [ -f bin/oplrqb ]
  then
    rm -f bin/oplrqb.save
  else
    mv bin/oplrqb.save bin/oplrqb
  fi
fi

#
#  Restore the original oplrqb.ini, odbc.ini and odbcinst.ini files if present
#
if [ -f bin/oplrqb.ini.save ]
then
  echo "*"
  echo "* Restoring your original Session Rules Book"
  echo "* (the file oplrqb.ini) and creating a new oplrqb.ini.sample"
  echo "*"
  mv bin/oplrqb.ini bin/oplrqb.ini.sample
  mv bin/oplrqb.ini.save bin/oplrqb.ini
fi

if [ -f bin/odbc.ini.save ]
then
  echo "*"
  echo "* Restoring your original ODBC DSN settings"
  echo "* (the file odbc.ini) and creating a new odbc.ini.sample"
  echo "*"
  if [ -f bin/odbc.ini ] 
  then
      mv bin/odbc.ini bin/odbc.ini.sample
  fi
  mv bin/odbc.ini.save bin/odbc.ini
fi

if [ -f bin/odbcinst.ini.save ]
then
  echo "*"
  echo "* Restoring your original ODBC Installation settings"
  echo "* (the file odbcinst.ini) and creating a new odbcinst.ini.sample"
  echo "*"
  if [ -f bin/odbcinst.ini ] 
  then
      mv bin/odbcinst.ini bin/odbcinst.ini.sample
  fi
  mv bin/odbcinst.ini.save bin/odbcinst.ini
fi

if [ -f bin/udbc.ini.save ]
then
  echo "*"
  echo "* Restoring your original UDBC DSN settings"
  echo "* (the file udbc.ini) and creating a new udbc.ini.sample"
  echo "*"
  mv bin/udbc.ini bin/udbc.ini.sample
  mv bin/udbc.ini.save bin/udbc.ini
fi

if [ -f bin/freetds.conf.save ]
then
  echo "*"
  echo "* Restoring your original SQL Server settings"
  echo "* (the file freetds.conf) and creating a new freetds.conf.sample"
  echo "*"
  mv bin/freetds.conf bin/freetds.conf.sample
  mv bin/freetds.conf.save bin/freetds.conf
fi

if [ -f bin/openlink.ini.save ]
then
  echo "*"
  echo "* Restoring your original UNIX Lite settings"
  echo "* (the file openlink.ini) and creating a new openlink.ini.sample"
  echo "*"
  mv bin/openlink.ini bin/openlink.ini.sample
  mv bin/openlink.ini.save bin/openlink.ini
fi

#
#  Check if the inifile program has been installed
#
if [ -x "$PREFIX/bin/inifile" ]
then
    INIFILE="inifile"
else
    INIFILE=":"
fi

#
#  Ask user which version of JDBC they are using
#
C1="# "
C2="# "
C3="# "
C4="# "
if [ -f jdk1.1/opljdbc.jar -o -f jdk1.2/opljdbc2.jar -o -f jdk1.3/opljdbc2.jar -o -f jdk1.4/opljdbc3.jar ]
then
    echo ""
    echo "Setting up CLASSPATH for Java connectivity."
    echo "You can choose between the following Java JDK versions:"
    echo ""
    echo " 1)	JDK 1.1.x"
    echo " 2)	JDK 1.2.x"
    echo " 3)	JDK 1.3.x"
    echo " 4)	JDK 1.4.x"
    echo ""
    echo $echo_n "Please enter your choice [ENTER=2] : $echo_c"
    read jdbcver
    case $jdbcver in
	1)
	    C1=""
	    ;;
	3)
	    C3=""
	    ;;
	4)
	    C4=""
	    ;;
	*)	# default is 2
	    C2=""
	    ;;
    esac
fi


#
#  Write the Zero Config entry in oplrqb.ini
#
RegisterZeroConfig()
{
    SVT="$1"
    KEY=`echo "$SVT ($HOST)"`
    DSN="SVT=$SVT"

    #
    #  Never update a key as it might have been changed by the user
    #
    oldsvt=`$INIFILE -f $PREFIX/bin/oplrqb.ini -s "Zero Config" -k "$KEY"`
    if [ "x$oldsvt" = "x" ]
    then
      echo "Adding Zero Config entry for $SVT ..."
      $INIFILE -f $PREFIX/bin/oplrqb.ini -s "Zero Config" -k "$KEY" -v "$DSN"
    fi
}



#
#  Set default value for BinaryDirectory
#
if [ -f bin/oplrqb ]
then
  cd bin

  echo "Entering default values in oplrqb.ini ..."
  $INIFILE -f oplrqb.ini -s "Request Broker" -k "BinaryDirectory" -v "$PREFIX/bin"
  $INIFILE -f oplrqb.ini -s "Environment WWW_SV" -k "ODBCINI" -v "$PREFIX/bin/odbc.ini"
  $INIFILE -f oplrqb.ini -s "Environment WWW_SV" -k "ODBCINSTINI" -v "$PREFIX/bin/odbcinst.ini"

  #
  #  Check for Multi threaded agents
  #
  if [ -x db2_mv ]
  then
    echo "Using DB2 Multi Threaded Agent (db2_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_db2 -k Program -v db2_mv
    $INIFILE -f oplrqb.ini -s generic_db2 -k ReUse -v always
  fi
  if [ -x inf73_mv ]
  then
    echo "Using Informix 7.3 Multi Threaded Agent (inf73_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_inf73 -k Program -v inf73_mv
    $INIFILE -f oplrqb.ini -s generic_inf73 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_inf73_jet -k Program -v inf73_mv
    $INIFILE -f oplrqb.ini -s generic_inf73_jet -k ReUse -v always
  fi
  if [ -x ingii_mv ]
  then
    echo "Using Ingres II Multi Threaded Agent (ingii_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ingresii -k Program -v ingii_mv
    $INIFILE -f oplrqb.ini -s generic_ingresii -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ingresii_jet -k Program -v ingii_mv
    $INIFILE -f oplrqb.ini -s generic_ingresii_jet -k ReUse -v always
  fi
  if [ -x inf9_mv ]
  then
    echo "Using Informix 2000 Multi Threaded Agent (inf9_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_inf2000 -k Program -v inf9_mv
    $INIFILE -f oplrqb.ini -s generic_inf2000 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_inf2000_jet -k Program -v inf9_mv
    $INIFILE -f oplrqb.ini -s generic_inf2000_jet -k ReUse -v always
  fi
  if [ -x mys3_mv ]
  then
    echo "Using MySQL 3.x Multi Threaded Agent (mys3_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_mys3 -k Program -v mys3_mv
    $INIFILE -f oplrqb.ini -s generic_mys3 -k ReUse -v always
  fi
  if [ -x odbc_mv ]
  then
    echo "Using ODBC Multi Threaded Agent (odbc_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_odbc -k Program -v odbc_mv
    $INIFILE -f oplrqb.ini -s generic_odbc -k ReUse -v always
  fi
  if [ -x ora80_mv ]
  then
    echo "Using Oracle 8.0.x Multi Threaded Agent (ora80_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ora80 -k Program -v ora80_mv
    $INIFILE -f oplrqb.ini -s generic_ora80 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ora80_jet -k Program -v ora80_mv
    $INIFILE -f oplrqb.ini -s generic_ora80_jet -k ReUse -v always
  fi
  if [ -x ora81_mv ]
  then
    echo "Using Oracle 8.1.x Multi Threaded Agent (ora81_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ora81 -k Program -v ora81_mv
    $INIFILE -f oplrqb.ini -s generic_ora81 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ora81_jet -k Program -v ora81_mv
    $INIFILE -f oplrqb.ini -s generic_ora81_jet -k ReUse -v always
  fi
  if [ -x ora90_mv ]
  then
    echo "Using Oracle 9.x Multi Threaded Agent (ora90_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ora90 -k Program -v ora90_mv
    $INIFILE -f oplrqb.ini -s generic_ora90 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ora90_jet -k Program -v ora90_mv
    $INIFILE -f oplrqb.ini -s generic_ora90_jet -k ReUse -v always
  fi
  if [ -x pgr7_mv ]
  then
    echo "Using PostgreSQL Multi Threaded Agent (pgr7_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_pgr7 -k Program -v pgr7_mv
    $INIFILE -f oplrqb.ini -s generic_pgr7 -k ReUse -v always
  fi
  if [ -x prs91_mv ]
  then
    echo "Using Progress 9.1x (SQL-92) Multi Threaded Agent (prs91_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_pro91sql -k Program -v prs91_mv
    $INIFILE -f oplrqb.ini -s generic_pro91sql -k ReUse -v always
  fi
  if [ -x sybc11_mv ]
  then
    echo "Using Sybase 11 CT-LIB Multi Threaded Agent (sybc11_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_syb11 -k Program -v sybc11_mv
    $INIFILE -f oplrqb.ini -s generic_syb11 -k ReUse -v always
  fi
  if [ -x sybc12_mv ]
  then
    echo "Using Sybase 12 CT-LIB Multi Threaded Agent (sybc12_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_syb12 -k Program -v sybc12_mv
    $INIFILE -f oplrqb.ini -s generic_syb12 -k ReUse -v always
  fi
  if [ -x sql_mv ]
  then
    echo "Using SQL Server Multi Threaded Agent (sql_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_sql -k Program -v sql_mv
    $INIFILE -f oplrqb.ini -s generic_sql -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_syb -k Program -v sql_mv
    $INIFILE -f oplrqb.ini -s generic_syb -k ReUse -v always
  fi
  if [ -x virt_mv ]
  then
    echo "Using Virtuoso Multi Threaded Agent (virt_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_virt -k Program -v virt_mv
    $INIFILE -f oplrqb.ini -s generic_virt -k ReUse -v always
  fi
  if [ -x jdbc11_mv ]
  then
    echo "Using JDBC 1.1 Multi Threaded Agent (jdbc11_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc11 -k Program -v jdbc11_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc11 -k ReUse -v always
  fi
  if [ -x jdbc12_mv ]
  then
    echo "Using JDBC 1.2 Multi Threaded Agent (jdbc12_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc12 -k Program -v jdbc12_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc12 -k ReUse -v always
  fi
  if [ -x jdbc13_mv ]
  then
    echo "Using JDBC 1.3 Multi Threaded Agent (jdbc13_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc13 -k Program -v jdbc13_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc13 -k ReUse -v always
  fi
  if [ -x jdbc14_mv ]
  then
    echo "Using JDBC 1.4 Multi Threaded Agent (jdbc14_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc14 -k Program -v jdbc14_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc14 -k ReUse -v always
  fi

  #
  #  Setting default environment
  #

  # DB/2
  if [ "x$DB2DIR" != "x" ]
  then
    echo "Setting default environment for DB2 ..."
    DB2DIR=${DB2DIR:-/dbs/DB2}
    DB2INSTANCE=${DB2INSTANCE:-db2inst1}
    $INIFILE -f oplrqb.ini -s "Environment DB2" -k "DB2DIR" -v "$DB2DIR"
    $INIFILE -f oplrqb.ini -s "Environment DB2" -k "DB2INSTANCE" -v "$DB2INSTANCE"
    $INIFILE -f oplrqb.ini -s "Environment DB2" -k "LD_LIBRARY_PATH" -v "$DB2DIR/lib"
    $INIFILE -f oplrqb.ini -s "Environment DB2" -k "LIBPATH" -v "$DB2DIR/lib"
    $INIFILE -f oplrqb.ini -s "Environment DB2" -k "SHLIB_PATH" -v "$DB2DIR/lib"

    #
    #  Add Zero Config entry
    #
    RegisterZeroConfig "DB2"

    echo "$DB2DIR/lib" >> "$PREFIX/.openlink.libdirs"
  fi

  # Informix 
  if [ "x$INFORMIXDIR" != "x" ]
  then
    echo "Setting default environment for Informix ..."

    INFORMIXSERVER=${INFORMIXSERVER:-alpha}

    [ -x inf5_sv  ] 			&& ENV="Environment INFORMIX5"
    [ -x inf6_sv  ] 			&& ENV="Environment INFORMIX6"
    [ -x inf71_sv ]			&& ENV="Environment INFORMIX71"
    [ -x inf72_sv -o -x inf72_mv ]	&& ENV="Environment INFORMIX72"
    [ -x inf73_sv -o -x inf73_mv ]	&& ENV="Environment INFORMIX73"
    [ -x inf9_sv  -o -x inf9_mv  ]	&& ENV="Environment INFORMIX2000"

    [ -z "$ENV" ] && ENV="Environment INFORMIX73"

    $INIFILE -f oplrqb.ini -s "$ENV" -k "INFORMIXDIR" -v "$INFORMIXDIR"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "INFORMIXSERVER" -v "$INFORMIXSERVER"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LD_LIBRARY_PATH" -v "$INFORMIXDIR/lib"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LIBPATH" -v "$INFORMIXDIR/lib"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "SHLIB_PATH" -v "$INFORMIXDIR/lib"

    #
    #  Add Zero Config entries
    #
    [ -x inf73_sv -o -x inf73_mv ] && RegisterZeroConfig "Informix 7.3"
    [ -x inf9_sv  -o -x inf9_mv  ] && RegisterZeroConfig "Informix 2000"

    echo "$INFORMIXDIR/lib" >> "$PREFIX/.openlink.libdirs"
  fi

  # Ingres II
  if [ "x$II_SYSTEM" != "x" ]
  then
    echo "Setting default environment for Ingres II  ..."

    [ -x ing6_sv ] 			&& ENV="Environment INGRES6"
    [ -x oig1_sv ] 			&& ENV="Environment OPENINGRES1"
    [ -x oig2_sv ] 			&& ENV="Environment INGRES_II"
    [ -x ingii_sv -o -x ingii_mv ]	&& ENV="Environment INGRES_II"

    [ -z "$ENV" ] && ENV="Environment INGRES_II"

    $INIFILE -f oplrqb.ini -s "$ENV" -k "II_SYSTEM" -v "$II_SYSTEM"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LD_LIBRARY_PATH" -v "$II_SYSTEM/ingres/lib"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LIBPATH" -v "$II_SYSTEM/ingres/lib"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "SHLIB_PATH" -v "$II_SYSTEM/ingres/lib"
    #
    #  Add Zero Config entries
    #
    [ -x ingii_sv -o -x ingii_mv ] && RegisterZeroConfig "Ingres II"

    echo "$II_SYSTEM/ingres/lib" >> "$PREFIX/.openlink.libdirs"
  fi

  # Oracle
  if [ "x$ORACLE_HOME" != "x" ]
  then
    echo "Setting default environment for Oracle ..."

    ORACLE_SID=${ORACLE_SID:-ORCL}

    [ -x ora6_sv ]			&& ENV="Environment ORACLE6"
    [ -x ora7_sv ]			&& ENV="Environment ORACLE7"
    [ -x ora80_sv -o -x ora80_mv ]	&& ENV="Environment ORACLE80"
    [ -x ora81_sv -o -x ora81_mv ]	&& ENV="Environment ORACLE81"
    [ -x ora90_sv -o -x ora90_mv ]	&& ENV="Environment ORACLE90"

    [ -z "$ENV" ] && ENV="Environment ORACLE81"

    $INIFILE -f oplrqb.ini -s "$ENV" -k "ORACLE_HOME" -v "$ORACLE_HOME"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "ORACLE_SID" -v "$ORACLE_SID"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LD_LIBRARY_PATH" -v "$ORACLE_HOME/lib"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LIBPATH" -v "$ORACLE_HOME/lib"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "SHLIB_PATH" -v "$ORACLE_HOME/lib"

    #
    #  Add Zero Config entries
    #
    [ -x ora80_sv -o -x ora80_mv ] && RegisterZeroConfig "Oracle 8.0.x"
    [ -x ora81_sv -o -x ora81_mv ] && RegisterZeroConfig "Oracle 8.1.x"
    [ -x ora90_sv -o -x ora90_mv ] && RegisterZeroConfig "Oracle 9.x"

    echo "$ORACLE_HOME/lib" >> "$PREFIX/.openlink.libdirs"
  fi


  #  Sybase
  if [ "x$SYBASE" != "x" ]
  then
      echo "Setting default environment for Sybase ..."
      DSQUERY=${DSQUERY:-SYBASE}

      [ -x syb10_sv  -o -x syb10_mv  ]	&& ENV="Environment SYBASE10"
      [ -x sybc10_sv -o -x sybc10_mv ]	&& ENV="Environment SYBASE10"
      [ -x syb11_sv  -o -x syb11_mv  ]	&& ENV="Environment SYBASE11"
      [ -x sybc11_sv -o -x sybc11_mv ]	&& ENV="Environment SYBASE11"
      [ -x syb12_sv  -o -x syb12_mv  ]	&& ENV="Environment SYBASE12"
      [ -x sybc12_sv -o -x sybc12_mv ]	&& ENV="Environment SYBASE12"

      [ -z "$ENV" ] && ENV="Environment SYBASE12"

      #  Sybase 12
      if [ "x$SYBASE_OCS" != "x" ]
      then
	  $INIFILE -f oplrqb.ini -s "Environment SYBASE12" -k "SYBASE" -v "$SYBASE"
	  $INIFILE -f oplrqb.ini -s "Environment SYBASE12" -k "DSQUERY" -v "$DSQUERY"
	  $INIFILE -f oplrqb.ini -s "Environment SYBASE12" -k "LD_LIBRARY_PATH" -v "$SYBASE/$SYBASE_OCS/lib"
	  $INIFILE -f oplrqb.ini -s "Environment SYBASE12" -k "LIBPATH" -v "$SYBASE/$SYBASE_OCS/lib"
	  $INIFILE -f oplrqb.ini -s "Environment SYBASE12" -k "SHLIB_PATH" -v "$SYBASE/$SYBASE_OCS/lib"

	  echo "$SYBASE/$SYBASE_OCS/lib" >> "$PREFIX/.openlink.libdirs"
      else
	  $INIFILE -f oplrqb.ini -s "$ENV" -k "SYBASE" -v "$SYBASE"
	  $INIFILE -f oplrqb.ini -s "$ENV" -k "DSQUERY" -v "$DSQUERY"
	  $INIFILE -f oplrqb.ini -s "$ENV" -k "LD_LIBRARY_PATH" -v "$SYBASE/lib"
	  $INIFILE -f oplrqb.ini -s "$ENV" -k "LIBPATH" -v "$SYBASE/lib"
	  $INIFILE -f oplrqb.ini -s "$ENV" -k "SHLIB_PATH" -v "$SYBASE/lib"

	  echo "$SYBASE/lib" >> "$PREFIX/.openlink.libdirs"
      fi

      #
      #  Add Zero Config entries
      #
      [ -x syb11_sv -o -x syb11_mv ] && RegisterZeroConfig "Sybase 11"
      [ -x syb12_sv -o -x syb12_mv ] && RegisterZeroConfig "Sybase 12"
  fi

  #  Progress
  if [ "x$DLC" != "x" ]
  then
      [ -f $DLC/version ] && PROVERSION=`cat $DLC/version | sed -e 's/.*Version \(.*\) as of .*/\1/' -e 's/[^0-9A-Za-z]//' -e 's/^\(...\).*/\1/' | tr "[a-z]" "[A-Z]" `
      [ -z "$PROVERSION" ] && PROVERSION="91C"
      [ -x prs91_sv -o -x prs91_mv ] && PROVERSION="91SQL"

      ENV="Environment PROGRESS$PROVERSION"

      echo "Setting default environment for Progress $PROVERSION ..."

      $INIFILE -f oplrqb.ini -s "$ENV" -k "DLC" -v "$DLC"
      $INIFILE -f oplrqb.ini -s "$ENV" -k "PROCFG" -v "$DLC/progress.cfg"

      if [ -x prs91_sv -o -x prs91_mv ]
      then
          $INIFILE -f oplrqb.ini -s "$ENV" -k "LD_LIBRARY_PATH" -v "$DLC/lib"
          $INIFILE -f oplrqb.ini -s "$ENV" -k "LIBPATH" -v "$DLC/lib"
          $INIFILE -f oplrqb.ini -s "$ENV" -k "SHLIB_PATH" -v "$DLC/lib"

	  echo "$DLC/lib" >> "$PREFIX/.openlink.libdirs"
      fi

      #
      #  Add Zero Config entries
      #
      RegisterZeroConfig "Progress $PROVERSION"
  fi

  # SQL Server
  if [ -x sql_sv -o -x sql_mv ]
  then
      ENV="Environment SQLSERVER"
      echo "Setting default environment for Microsoft SQL Server ..."

      $INIFILE -f oplrqb.ini -s "$ENV" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"

      ENV="Environment SYBASE"
      echo "Setting default environment for Sybase SQL Server ..."

      $INIFILE -f oplrqb.ini -s "$ENV" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"

      #
      #  Add Zero Config entries
      #
      RegisterZeroConfig "SQLServer"
      RegisterZeroConfig "Sybase"
  fi

  cd ..
fi


#
#  Check all other installed agents
#
cd $PREFIX/bin
for i in *_[ms]v
do
    case "$i" in
	mys3_*)		RegisterZeroConfig "MySQL 3.x";;
	pgr7_*)		RegisterZeroConfig "PostgreSQL";;
	virt_*)		RegisterZeroConfig "Virtuoso";;
    esac
done
cd $PREFIX


#
#  Write the necessary entries in odbcinst.ini
#
RegisterODBC()
{
    dsn="$1"
    name="$2"
    driver="$PREFIX/lib/$3"
    type="$4"

    #
    #  Add driver to odbcinst.ini
    #
    echo "Adding $name to odbcinst.ini ..."
    $INIFILE -f bin/odbcinst.ini -s "ODBC Drivers" -k "$name" -v "Installed"
    $INIFILE -f bin/odbcinst.ini -s "$name" -k "Driver" -v "$driver"

    #
    #  Delete old setup routine if present
    #
    $INIFILE -f bin/odbcinst.ini -s "$name" -k "Setup" -v -

    #
    #  Create or update sample DSN
    #
    $INIFILE -f bin/odbc.ini -s "ODBC Data Sources" -k "$dsn" -v "$name"
    old_driver=`$INIFILE -f bin/odbc.ini -s "$dsn" -k "Driver"`
    if [ "x$old_driver" = "x" ]
    then
	echo "Adding $dsn to odbc.ini ..."
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "Driver" -v "$driver"
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "ServerType" -v "$type"
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "Username" -v " "
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "Password" -v " "
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "Database" -v " "
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "Options" -v " "
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "FetchBufferSize" -v "99"
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "ReadOnly" -v "no"
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "DeferLongFetch" -v "no"
	if [ x$dsn = xOpenLink ]
	then
	    $INIFILE -f bin/odbc.ini -s "$dsn" -k "Host" -v "localhost:5000"
	    $INIFILE -f bin/odbc.ini -s "$dsn" -k "Description" -v "Sample $type Connection"
	elif [ x$dsn = xOpenLink_unicode ]
	then
	    $INIFILE -f bin/odbc.ini -s "$dsn" -k "Host" -v "localhost:5000"
	    $INIFILE -f bin/odbc.ini -s "$dsn" -k "Description" -v "Sample $type Connection using Unicode"
	else
	    $INIFILE -f bin/odbc.ini -s "$dsn" -k "JetFix" -v "no"
	    $INIFILE -f bin/odbc.ini -s "$dsn" -k "Description" -v "Sample $type Lite Connection"
	fi
    else
	echo "Updating $dsn in odbc.ini ..."
	$INIFILE -f bin/odbc.ini -s "$dsn" -k "Driver" -v "$driver"
    fi
}


RegisterSETUP()
{
    name="$1"
    driver="$PREFIX/lib/$2"

    #
    #  Add driver to odbcinst.ini
    #
    echo "Registering setup module for $name to odbcinst.ini ..."
    $INIFILE -f bin/odbcinst.ini -s "$name" -k "Setup" -v "$driver"
}


#
#  Install Generic ODBC driver manager link
#
cd "$PREFIX"
if [ -f lib/libiodbc.la ]
then
    echo "Creating link for Generic ODBC driver manager ..."

    . lib/libiodbc.la

    cd lib
    for lib in $library_names
    do
	case $lib in
	  libiodbc.so.*)
	   rm -f libodbc.so
	   ln -s $lib libodbc.so
	   ;;
	  libiodbc.sl.*)
	   rm -f libodbc.sl
	   ln -s $lib libodbc.sl
	   ;;
	esac
	break
    done
    cd ..
fi


#
#  Install OpenLink Generic ODBC driver
#
cd "$PREFIX"
if [ -f lib/oplodbc.la ]
then
    . lib/oplodbc.la

    echo "Setting default driver in bin/odbc.ini ..."
    $INIFILE -f bin/odbc.ini -s "Default" -k "Driver" -v "$PREFIX/lib/$dlname"
    RegisterODBC "OpenLink" "OpenLink Generic ODBC Driver" "$dlname" "Oracle 8.1.x"
fi   


#
#  Install OpenLink Generic ODBC Driver (Unicode)
#
cd "$PREFIX"
if [ -f lib/oplodbcu.la ]
then
    . lib/oplodbcu.la

    RegisterODBC "OpenLink_unicode" "OpenLink Generic ODBC Driver (Unicode)" "$dlname" "Oracle 8.1.x"
fi   

#
#  Install Generic Client setup library if available
#
if [ -f lib/oplsetup.la ]
then
    . lib/oplsetup.la

    RegisterSETUP "OpenLink Generic ODBC Driver" "$dlname"
    RegisterSETUP "OpenLink Generic ODBC Driver (Unicode)" "$dlname"
fi


cd "$PREFIX"
INSTALL_LT_DOCS=0

#
#  Install DB2 Lite
#
if [ -f lib/db2_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink DB2 Lite Driver"
    ENV="Environment DB2"

    if [ -d "$DB2DIR" ]
    then
        DB2INSTANCE=${DB2INSTANCE:-db2inst1}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "DB2DIR" -v "$DB2DIR"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "DB2INSTANCE" -v "$DB2INSTANCE"
	echo "$DB2DIR/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/db2_st_lt.la

    RegisterODBC "db2_lite" "$DRIVER" "$dlname" "DB2"

    if [ -f lib/db2_mt_lt.la ]
    then
	. lib/db2_mt_lt.la

	RegisterODBC "db2_lite" "$DRIVER (multi threaded)" "$dlname" "DB2"
    fi
fi


#
#  Install Informix 7.3 Lite
#
if [ -f lib/inf73_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Informix 7.3 Lite Driver"
    ENV="Environment Informix 7.3"

    if [ -d "$INFORMIXDIR" ]
    then
	INFORMIXSERVER=${INFORMIXSERVER:-alpha}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "INFORMIXDIR" -v "$INFORMIXDIR"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "INFORMIXSERVER" -v "$INFORMIXSERVER"

	echo "$INFORMIXDIR/lib"      >> "$PREFIX/.openlink.libdirs"
	echo "$INFORMIXDIR/lib/esql" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/inf73_st_lt.la

    RegisterODBC "inf73_lite" "$DRIVER" "$dlname" "Informix 7.3"
    if [ -f lib/inf73_mt_lt.la ]
    then
	. lib/inf73_mt_lt.la

	RegisterODBC "inf73_lite" "$DRIVER (multi threaded)" "$dlname" "Informix 7.3"
    fi
fi


#
#  Install Informix 2000 Lite
#
if [ -f lib/inf9_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Informix 2000 Lite Driver"
    ENV="Environment Informix 2000" 

    if [ -d "$INFORMIXDIR" ]
    then
	INFORMIXSERVER=${INFORMIXSERVER:-alpha}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "INFORMIXDIR" -v "$INFORMIXDIR"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "INFORMIXSERVER" -v "$INFORMIXSERVER"

	echo "$INFORMIXDIR/lib"      >> "$PREFIX/.openlink.libdirs"
	echo "$INFORMIXDIR/lib/esql" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/inf9_st_lt.la

    RegisterODBC "inf9_lite" "$DRIVER" "$dlname" "Informix 2000"

    if [ -f lib/inf9_mt_lt.la ]
    then
	. lib/inf9_mt_lt.la

	RegisterODBC "inf9_lite" "$DRIVER (multi threaded)" "$dlname" "Informix 2000"
    fi

    if [ -f lib/inf9_st_lu.la ]
    then
	. lib/inf9_st_lu.la

	RegisterODBC "inf9_lite_unicode" "$DRIVER (Unicode)" "$dlname" "Informix 2000"
    fi

    if [ -f lib/inf9_mt_lu.la ]
    then
	. lib/inf9_mt_lu.la

	RegisterODBC "inf9_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "Informix 2000"
    fi
fi


#
#  Install Ingres II Lite
#
if [ -f lib/ingii_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Ingres II Lite Driver"
    ENV="Environment Ingres II"

    if [ -d "$II_SYSTEM" ]
    then
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "II_SYSTEM" -v "$II_SYSTEM"

	echo "$II_SYSTEM/ingres/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/ingii_st_lt.la

    RegisterODBC "ingii_lite" "$DRIVER" "$dlname" "Ingres II"

    if [ -f lib/ingii_mt_lt.la ]
    then
	. lib/ingii_mt_lt.la

	RegisterODBC "ingii_lite" "$DRIVER (multi threaded)" "$dlname" "Ingres II"
    fi
fi

#
#  Install JDBC/JDK 1.1 Lite
#
if [ -f lib/jdbc11_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink JDBC Lite Driver (JDK 1.1)"
    ENV="Environment Jdbc 1.1"

    #
    #  Register the drivers
    #
    . lib/jdbc11_st_lt.la

    RegisterODBC "jdbc11_lite" "$DRIVER" "$dlname" "Jdbc 1.1"

    if [ -f lib/jdbc11_mt_lt.la ]
    then
	. lib/jdbc11_mt_lt.la

	RegisterODBC "jdbc11_lite" "$DRIVER(multi threaded)" "$dlname" "Jdbc 1.1"
    fi

    if [ -f lib/jdbc11_st_lu.la ]
    then
	. lib/jdbc11_st_lu.la

	RegisterODBC "jdbc11_lite_unicode" "$DRIVER(Unicode)" "$dlname" "Jdbc 1.1"
    fi

    if [ -f lib/jdbc11_mt_lu.la ]
    then
	. lib/jdbc11_mt_lu.la

	RegisterODBC "jdbc11_lite_unicode" "$DRIVER(Unicode)(multi threaded)" "$dlname" "Jdbc 1.1"
    fi
fi


#
#  Install JDBC/JDK 1.2 Lite
#
if [ -f lib/jdbc12_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink JDBC Lite Driver (JDK 1.2)"
    ENV="Environment Jdbc 1.2"

    #
    #  Register the drivers
    #
    . lib/jdbc12_st_lt.la

    RegisterODBC "jdbc12_lite" "$DRIVER" "$dlname" "Jdbc 1.2"

    if [ -f lib/jdbc12_mt_lt.la ]
    then
	. lib/jdbc12_mt_lt.la

	RegisterODBC "jdbc12_lite" "$DRIVER(multi threaded)" "$dlname" "Jdbc 1.2"
    fi

    if [ -f lib/jdbc12_st_lu.la ]
    then
	. lib/jdbc12_st_lu.la

	RegisterODBC "jdbc12_lite_unicode" "$DRIVER(Unicode)" "$dlname" "Jdbc 1.2"
    fi

    if [ -f lib/jdbc12_mt_lu.la ]
    then
	. lib/jdbc12_mt_lu.la

	RegisterODBC "jdbc12_lite_unicode" "$DRIVER(Unicode)(multi threaded)" "$dlname" "Jdbc 1.2"
    fi
fi


#
#  Install JDBC/JDK 1.3 Lite
#
if [ -f lib/jdbc13_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink JDBC Lite Driver (JDK 1.3)"
    ENV="Environment Jdbc 1.3"

    #
    #  Register the drivers
    #
    . lib/jdbc13_st_lt.la

    RegisterODBC "jdbc13_lite" "$DRIVER" "$dlname" "Jdbc 1.3"

    if [ -f lib/jdbc13_mt_lt.la ]
    then
	. lib/jdbc13_mt_lt.la

	RegisterODBC "jdbc13_lite" "$DRIVER(multi threaded)" "$dlname" "Jdbc 1.3"
    fi

    if [ -f lib/jdbc13_st_lu.la ]
    then
	. lib/jdbc13_st_lu.la

	RegisterODBC "jdbc13_lite_unicode" "$DRIVER(Unicode)" "$dlname" "Jdbc 1.3"
    fi

    if [ -f lib/jdbc13_mt_lu.la ]
    then
	. lib/jdbc13_mt_lu.la

	RegisterODBC "jdbc13_lite_unicode" "$DRIVER(Unicode)(multi threaded)" "$dlname" "Jdbc 1.3"
    fi
fi


#
#  Install JDBC/JDK 1.4 Lite
#
if [ -f lib/jdbc14_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink JDBC Lite Driver (JDK 1.4)"
    ENV="Environment Jdbc 1.4"

    #
    #  Register the drivers
    #
    . lib/jdbc14_st_lt.la

    RegisterODBC "jdbc14_lite" "$DRIVER" "$dlname" "Jdbc 1.4"

    if [ -f lib/jdbc14_mt_lt.la ]
    then
	. lib/jdbc14_mt_lt.la

	RegisterODBC "jdbc14_lite" "$DRIVER(multi threaded)" "$dlname" "Jdbc 1.4"
    fi

    if [ -f lib/jdbc14_st_lu.la ]
    then
	. lib/jdbc14_st_lu.la

	RegisterODBC "jdbc14_lite_unicode" "$DRIVER(Unicode)" "$dlname" "Jdbc 1.4"
    fi

    if [ -f lib/jdbc14_mt_lu.la ]
    then
	. lib/jdbc14_mt_lu.la

	RegisterODBC "jdbc14_lite_unicode" "$DRIVER(Unicode)(multi threaded)" "$dlname" "Jdbc 1.4"
    fi
fi


#
#  Install MySQL 3.x Lite
#
if [ -f lib/mys3_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink MySQL 3.x Lite Driver"
    ENV="Environment MYSQL 3.x"

    #
    #  Register the drivers
    #
    . lib/mys3_st_lt.la

    RegisterODBC "mys3_lite" "$DRIVER" "$dlname" "MySQL 3.x"

    if [ -f lib/mys3_mt_lt.la ]
    then
	. lib/mys3_mt_lt.la

	RegisterODBC "mys3_lite" "$DRIVER (multi threaded)" "$dlname" "MySQL 3.x"
    fi
fi


#
#  Install Oracle 8.0 Lite
#
if [ -f lib/ora80_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Oracle 8.0 Lite Driver"
    ENV="Environment Oracle 8.0.x"

    if [ -d "$ORACLE_HOME" ]
    then
	ORACLE_SID=${ORACLE_SID:-ORCL}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "ORACLE_HOME" -v "$ORACLE_HOME"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "ORACLE_SID" -v "$ORACLE_SID"
	echo "$ORACLE_HOME/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/ora80_st_lt.la

    RegisterODBC "ora80_lite" "$DRIVER" "$dlname" "Oracle 8.0.x"

    if [ -f lib/ora80_mt_lt.la ]
    then
	. lib/ora80_mt_lt.la

	RegisterODBC "ora80_lite" "$DRIVER (multi threaded)" "$dlname" "Oracle 8.0.x"
    fi
fi


#
#  Install Oracle 8.1 Lite
#
if [ -f lib/ora81_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Oracle 8.1 Lite Driver"
    ENV="Environment Oracle 8.1.x"

    if [ -d "$ORACLE_HOME" ]
    then
	ORACLE_SID=${ORACLE_SID:-ORCL}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "ORACLE_HOME" -v "$ORACLE_HOME"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "ORACLE_SID" -v "$ORACLE_SID"
	echo "$ORACLE_HOME/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/ora81_st_lt.la

    RegisterODBC "ora81_lite" "$DRIVER" "$dlname" "Oracle 8.1.x"

    if [ -f lib/ora81_mt_lt.la ]
    then
	. lib/ora81_mt_lt.la

	RegisterODBC "ora81_lite" "$DRIVER (multi threaded)" "$dlname" "Oracle 8.1.x"
    fi

    if [ -f lib/ora81_st_lu.la ]
    then
	. lib/ora81_st_lu.la

	RegisterODBC "ora81_lite_unicode" "$DRIVER (Unicode)" "$dlname" "Oracle 8.1.x"
    fi

    if [ -f lib/ora81_mt_lu.la ]
    then
	. lib/ora81_mt_lu.la

	RegisterODBC "ora81_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "Oracle 8.1.x"
    fi
fi


#
#  Install Oracle 9.X Lite
#
if [ -f lib/ora90_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Oracle 9.x Lite Driver"
    ENV="Environment Oracle 9.x"

    if [ -d "$ORACLE_HOME" ]
    then
	ORACLE_SID=${ORACLE_SID:-ORCL}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "ORACLE_HOME" -v "$ORACLE_HOME"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "ORACLE_SID" -v "$ORACLE_SID"
	echo "$ORACLE_HOME/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/ora90_st_lt.la

    RegisterODBC "ora90_lite" "$DRIVER" "$dlname" "Oracle 9.x"

    if [ -f lib/ora90_mt_lt.la ]
    then
	. lib/ora90_mt_lt.la

	RegisterODBC "ora90_lite" "$DRIVER (multi threaded)" "$dlname" "Oracle 9.x"
    fi

    if [ -f lib/ora90_st_lu.la ]
    then
	. lib/ora90_st_lu.la

	RegisterODBC "ora90_lite_unicode" "$DRIVER (Unicode)" "$dlname" "Oracle 9.x"
    fi

    if [ -f lib/ora90_mt_lu.la ]
    then
	. lib/ora90_mt_lu.la

	RegisterODBC "ora90_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "Oracle 9.x"
    fi
fi


#
#  Install PostgreSQL Lite
#
if [ -f lib/pgr7_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink PostgreSQL Lite Driver"
    ENV="Environment PostgreSQL"

    #
    #  Register the drivers
    #
    . lib/pgr7_st_lt.la

    RegisterODBC "pgr7_lite" "$DRIVER" "$dlname" "PostgreSQL"

    if [ -f lib/pgr7_mt_lt.la ]
    then
	. lib/pgr7_mt_lt.la

	RegisterODBC "pgr7_lite" "$DRIVER (multi threaded)" "$dlname" "PostgreSQL"
    fi
fi


#
#  Install Progress 9.1 SQL Lite
#
if [ -f lib/prs91_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Progress 9.1 Lite Driver"
    ENV="Environment Progress 91SQL"

    if [ -d "$DLC" ]
    then
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "DLC" -v "$DLC"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "PROCFG" -v "$DLC/progress.cfg"
	echo "$DLC/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/prs91_st_lt.la

    RegisterODBC "prs91_lite" "$DRIVER" "$dlname" "Progress 91SQL"

    if [ -f lib/prs91_mt_lt.la ]
    then
	. lib/prs91_mt_lt.la

	RegisterODBC "prs91_lite" "$DRIVER (multi threaded)" "$dlname" "Progress 91SQL"
    fi

    if [ -f lib/prs91_st_lu.la ]
    then
	. lib/prs91_st_lu.la

	RegisterODBC "prs91_lite_unicode" "$DRIVER (Unicode)" "$dlname" "Progress 91SQL"
    fi
    if [ -f lib/prs91_mt_lu.la ]
    then
	. lib/prs91_mt_lu.la

	RegisterODBC "prs91_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "Progress 91SQL"
    fi
fi


#
#  Install Sybase 11 Lite
#
if [ -f lib/syb11_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Sybase 11 Lite Driver"
    ENV="Environment Sybase 11"

    if [ -d "$SYBASE" ]
    then
	DSQUERY=${DSQUERY:-SYBASE}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "SYBASE" -v "$SYBASE"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "DSQUERY" -v "$DSQUERY"

	echo "$SYBASE/lib" >> "$PREFIX/.openlink.libdirs"
    fi

    #
    #  Register the drivers
    #
    . lib/syb11_st_lt.la

    RegisterODBC "syb11_lite" "$DRIVER" "$dlname" "Sybase 11"

    if [ -f lib/syb11_mt_lt.la ]
    then
	. lib/syb11_mt_lt.la

	RegisterODBC "syb11_lite" "$DRIVER (multi threaded)" "$dlname" "Sybase 11"
    fi
fi


#
#  Install Sybase 12 Lite
#
if [ -f lib/syb12_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Sybase 12 Lite Driver"
    ENV="Environment Sybase 12"

    if [ -d "$SYBASE" ]
    then
	DSQUERY=${DSQUERY:-SYBASE}

	$INIFILE -f bin/openlink.ini -s "$ENV" -k "SYBASE" -v "$SYBASE"
	$INIFILE -f bin/openlink.ini -s "$ENV" -k "DSQUERY" -v "$DSQUERY"

	if [ "x$SYBASE_OCS" != "x" ]
	then
	    echo "$SYBASE/$SYBASE_OCS/lib" >> "$PREFIX/.openlink.libdirs"
	else
	    echo "$SYBASE/lib" >> "$PREFIX/.openlink.libdirs"
	fi
    fi

    #
    #  Register the drivers
    #
    . lib/syb12_st_lt.la

    RegisterODBC "syb12_lite" "$DRIVER" "$dlname" "Sybase 12"

    if [ -f lib/syb12_mt_lt.la ]
    then
	. lib/syb12_mt_lt.la

	RegisterODBC "syb12_lite" "$DRIVER (multi threaded)" "$dlname" "Sybase 12"
    fi

    if [ -f lib/syb12_st_lu.la ]
    then
	. lib/syb12_st_lu.la

	RegisterODBC "syb12_lite_unicode" "$DRIVER (Unicode)" "$dlname" "Sybase 12"
    fi

    if [ -f lib/syb12_mt_lu.la ]
    then
	. lib/syb12_mt_lu.la

	RegisterODBC "syb12_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "Sybase 12"
    fi
fi


#
#  Install SQL Server Lite
#
if [ -f lib/sql_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink SQL Server Lite Driver"

    #
    #  Fix the environment strings for both Sybase and SQL Server
    $INIFILE -f bin/openlink.ini -s "Environment SQLServer 2000" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"
    $INIFILE -f bin/openlink.ini -s "Environment SQLServer 7" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"
    $INIFILE -f bin/openlink.ini -s "Environment SQLServer 6" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"
    $INIFILE -f bin/openlink.ini -s "Environment SQLServer 4" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"
    $INIFILE -f bin/openlink.ini -s "Environment Sybase 10/11/12" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"
    $INIFILE -f bin/openlink.ini -s "Environment Sybase 4.2" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"


    #
    #  Register the drivers
    #
    . lib/sql_st_lt.la

    RegisterODBC "sql_lite" "$DRIVER" "$dlname" "SQLServer 2000"
    RegisterODBC "sybase_lite" "$DRIVER" "$dlname" "Sybase 10/11/12"


    if [ -f lib/sql_mt_lt.la ]
    then
	. lib/sql_mt_lt.la

	RegisterODBC "sql_lite" "$DRIVER (multi threaded)" "$dlname" "SQLServer 2000"
	RegisterODBC "sybase_lite" "$DRIVER (multi threaded)" "$dlname" "Sybase 10/11/12"
    fi

    if [ -f lib/sql_st_lu.la ]
    then
	. lib/sql_st_lu.la

	RegisterODBC "sql_lite_unicode" "$DRIVER (Unicode)" "$dlname" "SQLServer 2000"
	RegisterODBC "sybase_lite_unicode" "$DRIVER (Unicode)" "$dlname" "Sybase 10/11/12"
    fi

    if [ -f lib/sql_mt_lu.la ]
    then
	. lib/sql_mt_lu.la

	RegisterODBC "sql_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "SQLServer 2000"
	RegisterODBC "sybase_lite_unicode" "$DRIVER (Unicode)(multi threaded)" "$dlname" "Sybase 10/11/12"
    fi
fi


#
#  Configure port the broker listens on
#
if [ -f bin/oplrqb.ini ]
then
    echo ""
    echo          "Enter the port number the broker will listen on for"
    echo $echo_n "client connections [ENTER=Default]  : $echo_c"
    read port
    if [ "x$port" != "x" ]
    then
      $INIFILE -f bin/oplrqb.ini -s "Protocol TCP" -k "Listen" -v "$port" 
    fi
fi


#
#  Check for OpenLink Admin Assistant
#
if [ -x bin/w3config/setup ]
then
  #
  #  Check for Lite Admin Assistant
  #
  if [ -x bin/w3config/www_sv.mt ]
  then
      #
      # If we have a mixed installation, then remove the lite admin stuff
      # as the full multitier admin assistant is there
      #
      rm -f bin/w3config/www_sv.lite
      rm -f bin/w3config/setup.tcl.lite
      rm -f bin/w3config/include/globals.tcl.lite
      rm -f bin/w3config/include/menu.ini.lite
      rm -f bin/lite_admin.sh
      rm -f bin/iodbc-admin-httpd.sh

      #
      # Put the MT admin assistant in place
      #
      rm -f bin/w3config/www_sv
      mv    bin/w3config/www_sv.mt bin/w3config/www_sv

      #
      # Indicate mixed installation
      #
      echo  > bin/w3config/www_sv.mt
  elif [ -x bin/w3config/www_sv.lite ]
  then
      #
      # Standalone lite administrator
      #
      rm -f bin/w3config/www_sv
      mv bin/w3config/www_sv.lite bin/w3config/www_sv

      INSTALL_LT_DOCS=1

      #
      # Replacement pages
      #
      mv bin/w3config/setup.tcl.lite bin/w3config/setup.tcl
      mv bin/w3config/include/globals.tcl.lite bin/w3config/include/globals.tcl
      mv bin/w3config/include/menu.ini.lite bin/w3config/include/menu.ini

      #
      # Start/Stop script
      #
      cat > bin/iodbc-admin-httpd.sh <<-END_LITE_ADMIN
	#!/bin/sh
	#
	#  Start and Stop the HTTP based iODBC Administrator
	#
	#  This file is an OpenLink Software product shell script.
	#  To learn more about this product, or any other product in our
	#  portfolio, please check out our web site at:
	#
	#      http://www.openlinksw.com 
	#
	#  or contact us at:
	#
	#      general.information@openlinksw.com
	#
	#  If you have any technical questions, please contact our support
	#  staff at:
	#
	#      technical.support@openlinksw.com
	#
	
	ARG=\${1-usage}

        if [ "x\$OPENLINKINI" = "x" ]
	then
	    if [ -f "$PREFIX/openlink.sh" ]
	    then
	       . "$PREFIX/openlink.sh"
	    fi
	fi
	
	case \$ARG in
	start)
	    cd "$PREFIX/bin/w3config"
	    set dummy \`(ps -e ; ps -a) | grep www_sv | grep -v grep 2>/dev/null\`
	    shift
	    if test \$# -ne 0 
	    then
	        echo "iodbc-admin-httpd.sh: www_sv is already running"
		exit 1
	    fi

	    ./www_sv &

	    if test \$? -eq 0
	    then
	        echo "iodbc-admin-httpd.sh: www_sv started"
	    else
	        echo "iodbc-admin-httpd.sh: www_sv not started"
	        echo "iodbc-admin-httpd.sh: please check bin/w3config/www_sv.log for additional information"
	        exit 1
	    fi

	    sleep 1
	    set dummy \`(ps -e ; ps -a) | grep www_sv | grep -v grep 2>/dev/null\`
	    shift
	    if test \$# -eq 0 
	    then
	        echo "iodbc-admin-httpd.sh: www_sv has stopped running"
	        echo "iodbc-admin-httpd.sh: please check bin/w3config/www_sv.log for additional information"
	        exit 1
	    fi
	    ;;
	
	stop)
	    set dummy \`(ps -e ; ps -a) | grep www_sv | grep -v grep 2>/dev/null\`
	    shift
	    if test \$# -eq 0 
	    then
	        echo "iodbc-admin-httpd.sh: www_sv is not running"
	        exit 1
	    fi
	    kill -9 \$1 2>/dev/null || {
	        echo "iodbc-admin-httpd.sh: unable to shutdown www_sv"
	        exit 1
	    }
	    echo "iodbc-admin-httpd.sh: www_sv shutdown complete"
	    ;;
	
	status)
	    set dummy \`(ps -e ; ps -a) | grep www_sv | grep -v grep 2>/dev/null\`
	    shift
	    if test \$# -eq 0 
	    then
	        echo "iodbc-admin-httpd.sh: www_sv is not running"
	    else
	        echo "iodbc-admin-httpd.sh: www_sv is running"
	    fi
	    ;;

	*)
	    echo "Usage: iodbc-admin-httpd.sh [start|stop|status]"
	    ;;
	esac
	exit 0
END_LITE_ADMIN
      chmod 755 bin/iodbc-admin-httpd.sh
  fi

  #
  #  Remove old documentation entries
  #
  $INIFILE -f bin/w3config/include/menu.ini -s "docs" -k - -v -

  #
  #  Enable offline MT documentation when available
  #
  if [ -f bin/w3config/html/docs/mt/index.html ]
  then
    echo "Adding Offline Documentation to menu ..."

    # $INIFILE -f bin/w3config/include/menu.ini -s "docs" -k "1" -v "h,/docs/mt/features.html,Release Notes"

    $INIFILE -f bin/w3config/include/menu.ini -s "docs" -k "2" -v "hn,/docs/mt/index.html,Offline Multi-Tier Documentation"
  fi

  #
  #  Enable offline Lite documentation when available
  #
  if [ -f bin/w3config/html/docs/lite/index.html ]
  then
    $INIFILE -f bin/w3config/include/menu.ini -s "docs" -k "3" -v "hn,/docs/lite/index.html,Offline Single-Tier Documentation"
  fi

  #
  #  Always add the online documentation
  #
  if [ $INSTALL_LT_DOCS -eq 1 ]
  then
    $INIFILE -f bin/w3config/include/menu.ini -s "docs" -k "4" -v "un,http://www.openlinksw.com/info/docs/uda50/lite/index.html,Online Documentation"
  else
    $INIFILE -f bin/w3config/include/menu.ini -s "docs" -k "4" -v "un,http://www.openlinksw.com/info/docs/uda50/mt/index.html,Online Documentation"
  fi
    
  #
  #  Run the Admin Assistant setup program
  #
  bin/w3config/setup
fi


#
#  Collect the library paths we discovered so far
#
OPL_PATH="$PREFIX/lib"
if [ -f .openlink.libdirs ]
then
    #
    #  Split out current LD_LIBRARY_PATH SHLIB_PATH and LIB_PATH
    #
    IFS="${IFS= 	}"; SAVE_IFS="$IFS"; IFS=":" 
    for dir in $LD_LIBRARY_PATH:$SHLIB_PATH:$LIBPATH
    do
       IFS="$SAVE_IFS"
       if [ -d "$dir" ]
       then
           echo "$dir" >> "$PREFIX/.openlink.libdirs"
       fi
    done
    IFS="$SAVE_IFS"

    #
    #  Sort all directories and remove duplicates
    #
    cat .openlink.libdirs | sort | uniq > .openlink.newdirs
    mv .openlink.newdirs .openlink.libdirs

    #
    #  Generate new OPL_PATH string
    #
    for dir in `cat .openlink.libdirs | sed "s/ /\%20/g"`
    do
    	ndir=`echo $dir | sed "s/\%20/ /g"`
        if [ "x$ndir" != "x$PREFIX/lib" ]
	then
	    OPL_PATH="$OPL_PATH:$ndir"
	fi
    done
fi


#
#  Generate environment setting files
#
echo "Creating scripts ..."
cat > openlink.sh <<-END_OF_OPENLINK_SH
	#
	#  Shell Environment Settings
	#
	#  Include the contents of this file in your .profile or run
	#  it prior to starting any other commands using:
	#
	#      \$ . ./openlink.sh
	#
	#  This file is an OpenLink Software product shell script.
	#  To learn more about this product, or any other product in our
	#  portfolio, please check out our web site at:
	#
	#      http://www.openlinksw.com 
	#
	#  or contact us at:
	#
	#      general.information@openlinksw.com
	#
	#  If you have any technical questions, please contact our support
	#  staff at:
	#
	#      technical.support@openlinksw.com
	#
	#
	ODBCINI="$PREFIX/bin/odbc.ini"
	ODBCINSTINI="$PREFIX/bin/odbcinst.ini"
	OPENLINKINI="$PREFIX/bin/openlink.ini"

	PATH="$PREFIX/bin:$PREFIX/samples/ODBC:\$PATH"

	${C1}CLASSPATH="$PREFIX/jdk1.1/opljdbc.jar:\$CLASSPATH"
	${C2}CLASSPATH="$PREFIX/jdk1.2/opljdbc2.jar:\$CLASSPATH"
	${C3}CLASSPATH="$PREFIX/jdk1.3/opljdbc2.jar:\$CLASSPATH"
	${C4}CLASSPATH="$PREFIX/jdk1.4/opljdbc3.jar:\$CLASSPATH"

	LD_LIBRARY_PATH="$OPL_PATH:\$LD_LIBRARY_PATH"
	LIBPATH="$OPL_PATH:\$LIBPATH"
	SHLIB_PATH="$OPL_PATH:\$SHLIB_PATH"

	OPL_LOCALEDIR="$PREFIX/locale"

	export ODBCINI ODBCINSTINI OPENLINKINI PATH LD_LIBRARY_PATH LIBPATH SHLIB_PATH CLASSPATH OPL_LOCALEDIR
END_OF_OPENLINK_SH
chmod 755 openlink.sh
cat > openlink.csh <<-END_OF_OPENLINK_CSH
	#
	#  C-Shell Environment Settings
	#
	#  Include the contents of this file in your .login or run
	#  it prior to starting any other commands using:
	#
	#      \$ source ./openlink.csh
	#
	#  This file is an OpenLink Software product c-shell script.
	#  To learn more about this product, or any other product in our
	#  portfolio, please check out our web site at:
	#
	#      http://www.openlinksw.com 
	#
	#  or contact us at:
	#
	#      general.information@openlinksw.com
	#
	#  If you have any technical questions, please contact our support
	#  staff at:
	#
	#      technical.support@openlinksw.com
	#
	setenv ODBCINI "$PREFIX/bin/odbc.ini"
	setenv ODBCINSTINI "$PREFIX/bin/odbcinst.ini"
	setenv OPENLINKINI "$PREFIX/bin/openlink.ini"

	# set path=("$PREFIX/bin" "$PREFIX/samples/ODBC" "\$path")
	setenv PATH "$PREFIX/bin:$PREFIX/samples/ODBC:\$PATH"

	${C1}setenv OPLJDBC "$PREFIX/jdk1.1/opljdbc.jar"
	${C2}setenv OPLJDBC "$PREFIX/jdk1.2/opljdbc2.jar"
	${C3}setenv OPLJDBC "$PREFIX/jdk1.3/opljdbc2.jar"
	${C4}setenv OPLJDBC "$PREFIX/jdk1.4/opljdbc3.jar"

	if ( \${?OPLJDBC} == "1" ) then
	if ( \${?CLASSPATH} == "0" ) then
	setenv CLASSPATH "\${OPLJDBC}"
	else
	setenv CLASSPATH "\${OPLJDBC}:\${CLASSPATH}"
	endif
	unsetenv OPLJDBC
	endif

	if ( \${?LD_LIBRARY_PATH} == "0" ) then
	setenv LD_LIBRARY_PATH "$PREFIX/lib"
	else
	setenv LD_LIBRARY_PATH "$PREFIX/lib:\${LD_LIBRARY_PATH}"
	endif

	if ( \${?LIBPATH} == "0" ) then
	setenv LIBPATH "$PREFIX/lib"
	else
	setenv LIBPATH "$PREFIX/lib:\${LIBPATH}"
	endif

	if ( \${?SHLIB_PATH} == "0" ) then
	setenv SHLIB_PATH "$PREFIX/lib"
	else
	setenv SHLIB_PATH "$PREFIX/lib:\${SHLIB_PATH}"
	endif

	setenv OPL_LOCALEDIR "$PREFIX/locale"
END_OF_OPENLINK_CSH
chmod 755 openlink.csh


#
#  Change ownership
#
echo ""
echo          "Enter the name of the user that will own the"
echo $echo_n "programs [ENTER=Use Current User Settings]  : $echo_c"
read owner
echo          "Enter the name of the group that will own the"
echo $echo_n "programs [ENTER=Use Current Group Settings] : $echo_c"
read group

echo "Changing ownership ..."
if [ "x$owner" != "x" ]
then
    find . -print | xargs chown $owner
fi
if [ "x$group" != "x" ]
then
    find . -print | xargs chgrp $group
fi


#
#  The register program and register.ini file are now obsolete
#  
#
if [ -f bin/register ]
then
  echo "*"
  echo "* The register program is now deprecated and has been renamed"
  echo "* to register.obsolete"
  echo "*"
  mv bin/register bin/register.obsolete
fi

if [ -f bin/register.ini ]
then
  echo "*"
  echo "* The register.ini license file is now deprecated and has been"
  echo "* renamed as register.ini.obsolete"
  echo "*"
  echo "* You need to contact the OpenLink Sales department for a new"
  echo "* license file"
  echo "*"
  mv bin/register.ini bin/register.ini.obsolete
fi


#
#  End
#
echo "End of installation"
	
