#!/bin/sh
#
#  install.sh
#
#  Install OpenLink products
#
#  Version: 7.0.2
#
#  Copyright (C) 1993-2016 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 022

#
#  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

#
#  Setup LD_LIBRARY_PATH
#
LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"
SHLIB_PATH="$PREFIX/lib:$SHLIB_PATH"
LIBPATH="$PREFIX/lib:$LIBPATH"
export LD_LIBRARY_PATH SHLIB_PATH LIBPATH

#
#  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) ..."

  if test "$file" = "*.taz"
  then
    echo "**"
    echo "** ERROR: The installer could not find any packages (.taz) to install."
    echo "**"
    exit 1
  fi

  #
  #  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 created a new oplrqb.ini.sample"
  echo "*"
  mv bin/oplrqb.ini.save bin/oplrqb.ini
elif [ -f bin/oplrqb.ini.sample ]
then
  echo "*"
  echo "* Creating new Session Rules Book"
  echo "* (the file oplrqb.ini) from oplrqb.ini.sample"
  echo "*"
  cp bin/oplrqb.ini.sample 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 created a new odbc.ini.sample"
  echo "*"
  mv bin/odbc.ini.save bin/odbc.ini
elif [ -f bin/odbc.ini.sample ]
then
  echo "*"
  echo "* Creating new ODBC DSN settings"
  echo "* (the file odbc.ini) from odbc.ini.sample"
  echo "*"
  cp bin/odbc.ini.sample 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 created a new odbcinst.ini.sample"
  echo "*"
  mv bin/odbcinst.ini.save bin/odbcinst.ini
elif [ -f bin/odbcinst.ini.sample ]
then
  echo "*"
  echo "* Creating new ODBC Installation settings"
  echo "* (the file odbcinst.ini) from odbcinst.ini.sample"
  echo "*"
  cp bin/odbcinst.ini.sample 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 created a new udbc.ini.sample"
  echo "*"
  mv bin/udbc.ini.save bin/udbc.ini
elif [ -f bin/udbc.ini.sample ]
then
  echo "*"
  echo "* Creating new UDBC DSN settings"
  echo "* (the file udbc.ini) from udbc.ini.sample"
  echo "*"
  cp bin/udbc.ini.sample 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 created a new freetds.conf.sample"
  echo "*"
  mv bin/freetds.conf.save bin/freetds.conf
elif [ -f bin/freetds.conf.sample ]
then
  echo "*"
  echo "* Creating new SQL Server settings"
  echo "* (the file freetds.conf) from freetds.conf.sample"
  echo "*"
  cp bin/freetds.conf.sample 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 created a new openlink.ini.sample"
  echo "*"
  mv bin/openlink.ini.save bin/openlink.ini
elif [ -f bin/openlink.ini.sample ]
then
  echo "*"
  echo "* Creating new UNIX Lite settings"
  echo "* (the file openlink.ini) from openlink.ini.sample"
  echo "*"
  cp bin/openlink.ini.sample bin/openlink.ini
fi

#
#  Check if the inifile program has been installed and
#  determine the memory model if possible (default=32bit)
#
MODEL=
if [ -x "$PREFIX/bin/inifile" ]
then
    MODEL=32
    INIFILE="inifile"
    file "$PREFIX/bin/inifile" | grep 64 > /dev/null && MODEL=64
else
    INIFILE=":"
fi

#
#  Ask user which version of JDBC they are using
#
C1="# "
C2="# "
C3="# "
C4="# "
C5="# "
C6="# "
C7="# "
C8="# "
if [ -f jdk1.1/opljdbc.jar -o -f jdk1.2/opljdbc2.jar -o -f jdk1.3/opljdbc2.jar -o -f jdk1.4/opljdbc3.jar -o -f jdk1.5/opljdbc3.jar -o -f jdk1.6/opljdbc4.jar -o -f jdk1.7/opl2dbc4_1.jar -o -f jdk1.8/opljdbc4_2.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 " 5)	JDK 1.5.x"
    echo " 6)	JDK 1.6.x"
    echo " 7)	JDK 1.7.x"
    echo " 8)	JDK 1.8.x"
    echo ""
    echo $echo_n "Please enter your choice [ENTER=6] : $echo_c"
    read jdbcver
    case $jdbcver in
	1)
	    C1=""
	    ;;
	2)
	    C2=""
	    ;;
	3)
	    C3=""
	    ;;
	4)
	    C4=""
	    ;;
	5)
	    C5=""
	    ;;
	6)
	    C6=""
	    ;;
	7)
	    C7=""
	    ;;
	8)
	    C8=""
	    ;;
	*)	# default is 6
	    C6=""
	    ;;
    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 inf10_mv ]
  then
    echo "Using Informix 10 Multi Threaded Agent (inf10_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_inf10 -k Program -v inf10_mv
    $INIFILE -f oplrqb.ini -s generic_inf10 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_inf10_jet -k Program -v inf10_mv
    $INIFILE -f oplrqb.ini -s generic_inf10_jet -k ReUse -v always
  fi
  if [ -x inf11_mv ]
  then
    echo "Using Informix 11 Multi Threaded Agent (inf11_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_inf11 -k Program -v inf11_mv
    $INIFILE -f oplrqb.ini -s generic_inf11 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_inf11_jet -k Program -v inf11_mv
    $INIFILE -f oplrqb.ini -s generic_inf11_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 mys4_mv ]
  then
    echo "Using MySQL 4.x Multi Threaded Agent (mys4_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_mys4 -k Program -v mys4_mv
    $INIFILE -f oplrqb.ini -s generic_mys4 -k ReUse -v always
  fi
  if [ -x mys5_mv ]
  then
    echo "Using MySQL 5.x Multi Threaded Agent (mys5_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_mys5 -k Program -v mys5_mv
    $INIFILE -f oplrqb.ini -s generic_mys5 -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 ora100_mv ]
  then
    echo "Using Oracle 10.x Multi Threaded Agent (ora100_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ora100 -k Program -v ora100_mv
    $INIFILE -f oplrqb.ini -s generic_ora100 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ora100_jet -k Program -v ora100_mv
    $INIFILE -f oplrqb.ini -s generic_ora100_jet -k ReUse -v always
  fi
  if [ -x ora110_mv ]
  then
    echo "Using Oracle 11.x Multi Threaded Agent (ora110_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ora110 -k Program -v ora110_mv
    $INIFILE -f oplrqb.ini -s generic_ora110 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ora110_jet -k Program -v ora110_mv
    $INIFILE -f oplrqb.ini -s generic_ora110_jet -k ReUse -v always
  fi
  if [ -x ora120_mv ]
  then
    echo "Using Oracle 12.x Multi Threaded Agent (ora120_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_ora120 -k Program -v ora120_mv
    $INIFILE -f oplrqb.ini -s generic_ora120 -k ReUse -v always
    $INIFILE -f oplrqb.ini -s generic_ora120_jet -k Program -v ora120_mv
    $INIFILE -f oplrqb.ini -s generic_ora120_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 prs100_mv ]
  then
    echo "Using Progress 10 (SQL-92) Multi Threaded Agent (prs100_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_pro100sql -k Program -v prs100_mv
    $INIFILE -f oplrqb.ini -s generic_pro100sql -k ReUse -v always
  fi
  if [ -x prs110_mv ]
  then
    echo "Using Progress 11 (SQL-92) Multi Threaded Agent (prs110_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_pro110sql -k Program -v prs110_mv
    $INIFILE -f oplrqb.ini -s generic_pro110sql -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
  if [ -x jdbc15_mv ]
  then
    echo "Using JDBC 1.5 Multi Threaded Agent (jdbc15_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc15 -k Program -v jdbc15_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc15 -k ReUse -v always
  fi
  if [ -x jdbc16_mv ]
  then
    echo "Using JDBC 1.6 Multi Threaded Agent (jdbc16_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc16 -k Program -v jdbc16_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc16 -k ReUse -v always
  fi
  if [ -x jdbc17_mv ]
  then
    echo "Using JDBC 1.7 Multi Threaded Agent (jdbc17_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc17 -k Program -v jdbc17_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc17 -k ReUse -v always
  fi
  if [ -x jdbc18_mv ]
  then
    echo "Using JDBC 1.8 Multi Threaded Agent (jdbc18_mv) ..."
    $INIFILE -f oplrqb.ini -s generic_jdbc18 -k Program -v jdbc18_mv
    $INIFILE -f oplrqb.ini -s generic_jdbc18 -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}

    ENV="Environment INFORMIX73"

    [ -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"
    [ -x inf10_sv  -o -x inf10_mv  ]	&& ENV="Environment INFORMIX10"
    [ -x inf11_sv  -o -x inf11_mv  ]	&& ENV="Environment INFORMIX11"

    $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"
    [ -x inf10_sv  -o -x inf10_mv  ] && RegisterZeroConfig "Informix 10"
    [ -x inf11_sv  -o -x inf11_mv  ] && RegisterZeroConfig "Informix 11"

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

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

    ENV="Environment 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"

    $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}

    ENV="Environment ORACLE100"

    [ -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"
    [ -x ora100_sv -o -x ora100_mv ]	&& ENV="Environment ORACLE100"
    [ -x ora110_sv -o -x ora110_mv ]	&& ENV="Environment ORACLE110"
    [ -x ora120_sv -o -x ora120_mv ]	&& ENV="Environment ORACLE120"

    $INIFILE -f oplrqb.ini -s "$ENV" -k "ORACLE_HOME" -v "$ORACLE_HOME"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "ORACLE_SID" -v "$ORACLE_SID"

    if [ -d "$ORACLE_HOME/lib" ]
    then
        DIR="$ORACLE_HOME/lib"
    else
        DIR="$ORACLE_HOME"
    fi
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LD_LIBRARY_PATH" -v "$DIR"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "LIBPATH" -v "$DIR"
    $INIFILE -f oplrqb.ini -s "$ENV" -k "SHLIB_PATH" -v "$DIR"

    #
    #  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"
    [ -x ora100_sv -o -x ora100_mv ] && RegisterZeroConfig "Oracle 10.x"
    [ -x ora110_sv -o -x ora110_mv ] && RegisterZeroConfig "Oracle 11.x"
    [ -x ora120_sv -o -x ora120_mv ] && RegisterZeroConfig "Oracle 12.x"

    echo "$DIR" >> "$PREFIX/.openlink.libdirs"
  fi


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

      ENV="Environment SYBASE12"

      [ -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"

      #  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/.*Release \(.*\) 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"
      [ -x prs100_sv -o -x prs100_mv ] && PROVERSION="100SQL"
      [ -x prs110_sv -o -x prs110_mv ] && PROVERSION="110SQL"

      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

      if [ -x prs100_sv -o -x prs100_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
#
if test -d $PREFIX/bin
then
    cd $PREFIX/bin
    for i in *_[ms]v
    do
	case "$i" in
	    mys3_*)		RegisterZeroConfig "MySQL 3.x";;
	    mys4_*)		RegisterZeroConfig "MySQL 4.x";;
	    mys5_*)		RegisterZeroConfig "MySQL 5.x";;
	    pgr7_*)		RegisterZeroConfig "PostgreSQL";;
	    virt_*)		RegisterZeroConfig "Virtuoso";;
	esac
    done
    cd $PREFIX
fi

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

    #
    #  Calculate full name of driver
    #
    ext=""
    case "$dll" in
        *u)
	    ext="${ext}(Unicode)"
	    dsn="${dsn}_unicode"
	    ;;
    esac

    case "$dll" in
        *_mt_*)
	    ext="${ext}(Multi Threaded)"
	    ;;
    esac

    if [ "x$ext"  != "x" ]
    then
        name="$name $ext"
    fi


    #
    #  Check if driver has been installed
    #
    if [ -f "lib/$dll.la" ]
    then
        #
	#  Read driver name from .la file
	#
        . "lib/$dll.la"
	driver="$PREFIX/lib/$dlname"

	#
	#  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
    fi
}


RegisterSETUP()
{
    dll="$1"
    name="$2"

    if [ -f "lib/$dll.la" ]
    then
        #
	#  Read driver name from .la file
	#
        . "lib/$dll.la"
	driver="$PREFIX/lib/$dlname"

	#
	#  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"
    fi
}


#
#  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 "oplodbc"  "OpenLink" "OpenLink Generic ODBC Driver" "Oracle 12.x"
    RegisterODBC "oplodbcu" "OpenLink" "OpenLink Generic ODBC Driver" "Oracle 12.x"
fi   


#
#  Install Generic Client setup library if available
#
RegisterSETUP "oplsetup" "OpenLink Generic ODBC Driver"
RegisterSETUP "oplsetup" "OpenLink Generic ODBC Driver"


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
    #
    RegisterODBC "db2_st_lt" "db2_lite" "$DRIVER" "DB2"
    RegisterODBC "db2_mt_lt" "db2_lite" "$DRIVER" "DB2"
    RegisterODBC "db2_st_lu" "db2_lite" "$DRIVER" "DB2"
    RegisterODBC "db2_mt_lu" "db2_lite" "$DRIVER" "DB2"
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
    #
    RegisterODBC "inf73_st_lt" "inf73_lite" "$DRIVER" "Informix 7.3"
    RegisterODBC "inf73_mt_lt" "inf73_lite" "$DRIVER" "Informix 7.3"
    RegisterODBC "inf73_st_lu" "inf73_lite" "$DRIVER" "Informix 7.3"
    RegisterODBC "inf73_mt_lu" "inf73_lite" "$DRIVER" "Informix 7.3"
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
    #
    RegisterODBC "inf9_st_lt" "inf9_lite" "$DRIVER" "Informix 2000"
    RegisterODBC "inf9_mt_lt" "inf9_lite" "$DRIVER" "Informix 2000"
    RegisterODBC "inf9_st_lu" "inf9_lite" "$DRIVER" "Informix 2000"
    RegisterODBC "inf9_mt_lu" "inf9_lite" "$DRIVER" "Informix 2000"
fi


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

    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
    #
    RegisterODBC "inf10_st_lt" "inf10_lite" "$DRIVER" "Informix 10"
    RegisterODBC "inf10_mt_lt" "inf10_lite" "$DRIVER" "Informix 10"
    RegisterODBC "inf10_st_lu" "inf10_lite" "$DRIVER" "Informix 10"
    RegisterODBC "inf10_mt_lu" "inf10_lite" "$DRIVER" "Informix 10"
fi


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

    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
    #
    RegisterODBC "inf11_st_lt" "inf11_lite" "$DRIVER" "Informix 11"
    RegisterODBC "inf11_mt_lt" "inf11_lite" "$DRIVER" "Informix 11"
    RegisterODBC "inf11_st_lu" "inf11_lite" "$DRIVER" "Informix 11"
    RegisterODBC "inf11_mt_lu" "inf11_lite" "$DRIVER" "Informix 11"
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
    #
    RegisterODBC "ingii_st_lt" "ingii_lite" "$DRIVER" "Ingres II"
    RegisterODBC "ingii_mt_lt" "ingii_lite" "$DRIVER" "Ingres II"
    RegisterODBC "ingii_st_lu" "ingii_lite" "$DRIVER" "Ingres II"
    RegisterODBC "ingii_mt_lu" "ingii_lite" "$DRIVER" "Ingres II"
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
    #
    RegisterODBC "jdbc11_st_lt" "jdbc11_lite" "$DRIVER" "Jdbc 1.1"
    RegisterODBC "jdbc11_mt_lt" "jdbc11_lite" "$DRIVER" "Jdbc 1.1"
    RegisterODBC "jdbc11_st_lu" "jdbc11_lite" "$DRIVER" "Jdbc 1.1"
    RegisterODBC "jdbc11_mt_lu" "jdbc11_lite" "$DRIVER" "Jdbc 1.1"
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
    #
    RegisterODBC "jdbc12_st_lt" "jdbc12_lite" "$DRIVER" "Jdbc 1.2"
    RegisterODBC "jdbc12_mt_lt" "jdbc12_lite" "$DRIVER" "Jdbc 1.2"
    RegisterODBC "jdbc12_st_lu" "jdbc12_lite" "$DRIVER" "Jdbc 1.2"
    RegisterODBC "jdbc12_mt_lu" "jdbc12_lite" "$DRIVER" "Jdbc 1.2"
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
    #
    RegisterODBC "jdbc13_st_lt" "jdbc13_lite" "$DRIVER" "Jdbc 1.3"
    RegisterODBC "jdbc13_mt_lt" "jdbc13_lite" "$DRIVER" "Jdbc 1.3"
    RegisterODBC "jdbc13_st_lu" "jdbc13_lite" "$DRIVER" "Jdbc 1.3"
    RegisterODBC "jdbc13_mt_lu" "jdbc13_lite" "$DRIVER" "Jdbc 1.3"
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
    #
    RegisterODBC "jdbc14_st_lt" "jdbc14_lite" "$DRIVER" "Jdbc 1.4"
    RegisterODBC "jdbc14_mt_lt" "jdbc14_lite" "$DRIVER" "Jdbc 1.4"
    RegisterODBC "jdbc14_st_lu" "jdbc14_lite" "$DRIVER" "Jdbc 1.4"
    RegisterODBC "jdbc14_mt_lu" "jdbc14_lite" "$DRIVER" "Jdbc 1.4"
fi


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

    #
    #  Register the drivers
    #
    RegisterODBC "jdbc15_st_lt" "jdbc15_lite" "$DRIVER" "Jdbc 1.5"
    RegisterODBC "jdbc15_mt_lt" "jdbc15_lite" "$DRIVER" "Jdbc 1.5"
    RegisterODBC "jdbc15_st_lu" "jdbc15_lite" "$DRIVER" "Jdbc 1.5"
    RegisterODBC "jdbc15_mt_lu" "jdbc15_lite" "$DRIVER" "Jdbc 1.5"
fi


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

    #
    #  Register the drivers
    #
    RegisterODBC "jdbc16_st_lt" "jdbc16_lite" "$DRIVER" "Jdbc 1.6"
    RegisterODBC "jdbc16_mt_lt" "jdbc16_lite" "$DRIVER" "Jdbc 1.6"
    RegisterODBC "jdbc16_st_lu" "jdbc16_lite" "$DRIVER" "Jdbc 1.6"
    RegisterODBC "jdbc16_mt_lu" "jdbc16_lite" "$DRIVER" "Jdbc 1.6"
fi


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

    #
    #  Register the drivers
    #
    RegisterODBC "jdbc17_st_lt" "jdbc17_lite" "$DRIVER" "Jdbc 1.7"
    RegisterODBC "jdbc17_mt_lt" "jdbc17_lite" "$DRIVER" "Jdbc 1.7"
    RegisterODBC "jdbc17_st_lu" "jdbc17_lite" "$DRIVER" "Jdbc 1.7"
    RegisterODBC "jdbc17_mt_lu" "jdbc17_lite" "$DRIVER" "Jdbc 1.7"
fi


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

    #
    #  Register the drivers
    #
    RegisterODBC "jdbc18_st_lt" "jdbc18_lite" "$DRIVER" "Jdbc 1.8"
    RegisterODBC "jdbc18_mt_lt" "jdbc18_lite" "$DRIVER" "Jdbc 1.8"
    RegisterODBC "jdbc18_st_lu" "jdbc18_lite" "$DRIVER" "Jdbc 1.8"
    RegisterODBC "jdbc18_mt_lu" "jdbc18_lite" "$DRIVER" "Jdbc 1.8"
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
    #
    RegisterODBC "mys3_st_lt" "mys3_lite" "$DRIVER" "MySQL 3.x"
    RegisterODBC "mys3_st_lu" "mys3_lite" "$DRIVER" "MySQL 3.x"
    RegisterODBC "mys3_mt_lt" "mys3_lite" "$DRIVER" "MySQL 3.x"
    RegisterODBC "mys3_mt_lu" "mys3_lite" "$DRIVER" "MySQL 3.x"
fi


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

    #
    #  Register the drivers
    #
    RegisterODBC "mys4_st_lt" "mys4_lite" "$DRIVER" "MySQL 4.x"
    RegisterODBC "mys4_st_lu" "mys4_lite" "$DRIVER" "MySQL 4.x"
    RegisterODBC "mys4_mt_lt" "mys4_lite" "$DRIVER" "MySQL 4.x"
    RegisterODBC "mys4_mt_lu" "mys4_lite" "$DRIVER" "MySQL 4.x"
fi


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

    #
    #  Register the drivers
    #
    RegisterODBC "mys5_st_lt" "mys5_lite" "$DRIVER" "MySQL 5.x"
    RegisterODBC "mys5_st_lu" "mys5_lite" "$DRIVER" "MySQL 5.x"
    RegisterODBC "mys5_mt_lt" "mys5_lite" "$DRIVER" "MySQL 5.x"
    RegisterODBC "mys5_mt_lu" "mys5_lite" "$DRIVER" "MySQL 5.x"
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
    #
    RegisterODBC "ora80_st_lt" "ora80_lite" "$DRIVER" "Oracle 8.0.x"
    RegisterODBC "ora80_mt_lt" "ora80_lite" "$DRIVER" "Oracle 8.0.x"
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
    #
    RegisterODBC "ora81_st_lt" "ora81_lite" "$DRIVER" "Oracle 8.1.x"
    RegisterODBC "ora81_st_lu" "ora81_lite" "$DRIVER" "Oracle 8.1.x"
    RegisterODBC "ora81_mt_lt" "ora81_lite" "$DRIVER" "Oracle 8.1.x"
    RegisterODBC "ora81_mt_lu" "ora81_lite" "$DRIVER" "Oracle 8.1.x"
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
    #
    RegisterODBC "ora90_st_lt" "ora90_lite" "$DRIVER" "Oracle 9.x"
    RegisterODBC "ora90_mt_lt" "ora90_lite" "$DRIVER" "Oracle 9.x"
    RegisterODBC "ora90_st_lu" "ora90_lite" "$DRIVER" "Oracle 9.x"
    RegisterODBC "ora90_mt_lu" "ora90_lite" "$DRIVER" "Oracle 9.x"
fi


#
#  Install Oracle 10.X Lite
#
if [ -f lib/ora100_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Oracle 10.x Lite Driver"
    ENV="Environment Oracle 10.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
    #
    #
    RegisterODBC "ora100_st_lt" "ora100_lite" "$DRIVER" "Oracle 10.x"
    RegisterODBC "ora100_mt_lt" "ora100_lite" "$DRIVER" "Oracle 10.x"
    RegisterODBC "ora100_st_lu" "ora100_lite" "$DRIVER" "Oracle 10.x"
    RegisterODBC "ora100_mt_lu" "ora100_lite" "$DRIVER" "Oracle 10.x"
fi


#
#  Install Oracle 11.X Lite
#
if [ -f lib/ora110_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Oracle 11.x Lite Driver"
    ENV="Environment Oracle 11.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
    #
    RegisterODBC "ora110_st_lt" "ora110_lite" "$DRIVER" "Oracle 11.x"
    RegisterODBC "ora110_mt_lt" "ora110_lite" "$DRIVER" "Oracle 11.x"
    RegisterODBC "ora110_st_lu" "ora110_lite" "$DRIVER" "Oracle 11.x"
    RegisterODBC "ora110_mt_lu" "ora110_lite" "$DRIVER" "Oracle 11.x"
fi


#
#  Install Oracle 12.X Lite
#
if [ -f lib/ora120_st_lt.la ]
then
    #
    #  Set the lite environment
    #
    DRIVER="OpenLink Oracle 12.x Lite Driver"
    ENV="Environment Oracle 12.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
    #
    RegisterODBC "ora120_st_lt" "ora120_lite" "$DRIVER" "Oracle 12.x"
    RegisterODBC "ora120_mt_lt" "ora120_lite" "$DRIVER" "Oracle 12.x"
    RegisterODBC "ora120_st_lu" "ora120_lite" "$DRIVER" "Oracle 12.x"
    RegisterODBC "ora120_mt_lu" "ora120_lite" "$DRIVER" "Oracle 12.x"
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
    #
    RegisterODBC "pgr_st_lt" "pgr7_lite" "$DRIVER" "PostgreSQL"
    RegisterODBC "pgr_mt_lt" "pgr7_lite" "$DRIVER" "PostgreSQL"
    RegisterODBC "pgr_st_lu" "pgr7_lite" "$DRIVER" "PostgreSQL"
    RegisterODBC "pgr_mt_lu" "pgr7_lite" "$DRIVER" "PostgreSQL"
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
    #
    RegisterODBC "prs91_st_lt" "prs91_lite" "$DRIVER" "Progress 91SQL"
    RegisterODBC "prs91_mt_lt" "prs91_lite" "$DRIVER" "Progress 91SQL"
    RegisterODBC "prs91_st_lu" "prs91_lite" "$DRIVER" "Progress 91SQL"
    RegisterODBC "prs91_mt_lu" "prs91_lite" "$DRIVER" "Progress 91SQL"
fi


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

    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
    #
    RegisterODBC "prs100_st_lt" "prs100_lite" "$DRIVER" "Progress 100SQL"
    RegisterODBC "prs100_mt_lt" "prs100_lite" "$DRIVER" "Progress 100SQL"
    RegisterODBC "prs100_st_lu" "prs100_lite" "$DRIVER" "Progress 100SQL"
    RegisterODBC "prs100_mt_lu" "prs100_lite" "$DRIVER" "Progress 100SQL"
fi


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

    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
    #
    RegisterODBC "prs110_st_lt" "prs110_lite" "$DRIVER" "Progress 110SQL"
    RegisterODBC "prs110_mt_lt" "prs110_lite" "$DRIVER" "Progress 110SQL"
    RegisterODBC "prs110_st_lu" "prs110_lite" "$DRIVER" "Progress 110SQL"
    RegisterODBC "prs110_mt_lu" "prs110_lite" "$DRIVER" "Progress 110SQL"
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
    #
    RegisterODBC "syb11_st_lt" "syb11_lite" "$DRIVER" "Sybase 11"
    RegisterODBC "syb11_mt_lt" "syb11_lite" "$DRIVER" "Sybase 11"
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
    #
    RegisterODBC "syb12_st_lt" "syb12_lite" "$DRIVER" "Sybase 12"
    RegisterODBC "syb12_mt_lt" "syb12_lite" "$DRIVER" "Sybase 12"
    RegisterODBC "syb12_st_lu" "syb12_lite" "$DRIVER" "Sybase 12"
    RegisterODBC "syb12_mt_lu" "syb12_lite" "$DRIVER" "Sybase 12"
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 2005" -k "FREETDSCONF" -v "$PREFIX/bin/freetds.conf"
    $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
    #
    RegisterODBC "sql_st_lt" "sql_lite" "$DRIVER" "SQLServer 2000"
    RegisterODBC "sql_mt_lt" "sql_lite" "$DRIVER" "SQLServer 2000"
    RegisterODBC "sql_st_lu" "sql_lite" "$DRIVER" "SQLServer 2000"
    RegisterODBC "sql_mt_lu" "sql_lite" "$DRIVER" "SQLServer 2000"

    RegisterODBC "sql_st_lt" "sybase_lite" "$DRIVER" "Sybase 10/11/12"
    RegisterODBC "sql_mt_lt" "sybase_lite" "$DRIVER" "Sybase 10/11/12"
    RegisterODBC "sql_st_lu" "sybase_lite" "$DRIVER" "Sybase 10/11/12"
    RegisterODBC "sql_mt_lu" "sybase_lite" "$DRIVER" "Sybase 10/11/12"
fi


#
#  Clean .la files
#
rm -f lib/*_lt.la lib/*_lu.la  lib/libopljodbc*.la lib/*odbc.la lib/*odbcu.la lib/*odbcinst.la odbcsdk/lib*/*.la


#
#  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 [ -f 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
      #
      chmod 755 bin/w3config/www_sv.mt
      (cd bin/w3config; rm -f www_sv; ln -s www_sv.mt www_sv)

  elif [ -f bin/w3config/www_sv.lite ]
  then
      #
      # Standalone lite administrator
      #
      chmod 755 bin/w3config/www_sv.lite
      (cd bin/w3config; rm -f www_sv; ln -s www_sv.lite 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
	    if [ -d "$ndir$MODEL" ]
	    then
		OPL_PATH="$OPL_PATH:$ndir$MODEL"
	    elif [ -d "$ndir" ]
	    then
		OPL_PATH="$OPL_PATH:$ndir"
	    fi
	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"
	${C5}CLASSPATH="$PREFIX/jdk1.5/opljdbc3.jar:\$CLASSPATH"
	${C6}CLASSPATH="$PREFIX/jdk1.6/opljdbc4.jar:\$CLASSPATH"
	${C7}CLASSPATH="$PREFIX/jdk1.7/opljdbc4_1.jar:\$CLASSPATH"
	${C8}CLASSPATH="$PREFIX/jdk1.8/opljdbc4_2.jar:\$CLASSPATH"

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

	OPL_LOCALEDIR="$PREFIX/locale"

	OPL_LICENSE_DIR="/etc/oplmgr:$PREFIX/bin:\$OPL_LICENSE_DIR"

	export ODBCINI ODBCINSTINI OPENLINKINI PATH LD_LIBRARY_PATH LIBPATH SHLIB_PATH CLASSPATH OPL_LOCALEDIR OPL_LICENSE_DIR

	if test -x "$PREFIX/bin/oplmgr"
	then
	    "$PREFIX/bin/oplmgr" +start
	fi
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"
	${C5}setenv OPLJDBC "$PREFIX/jdk1.5/opljdbc3.jar"
	${C6}setenv OPLJDBC "$PREFIX/jdk1.6/opljdbc4.jar"
	${C7}setenv OPLJDBC "$PREFIX/jdk1.7/opljdbc4_1.jar"
	${C8}setenv OPLJDBC "$PREFIX/jdk1.8/opljdbc4_2.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 "$OPL_PATH"
	else
	    setenv LD_LIBRARY_PATH "$OPL_PATH:\${LD_LIBRARY_PATH}"
	endif

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

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

	setenv OPL_LOCALEDIR "$PREFIX/locale"

	if ( \${?OPL_LICENSE_DIR} == "0" ) then
	    setenv OPL_LICENSE_DIR "/etc/oplmgr:$PREFIX/bin"
	else
	    setenv OPL_LICENSE_DIR "/etc/oplmgr:$PREFIX/bin:\${OPL_LICENSE_DIR}"
	endif

	if ( -x "$PREFIX/bin/oplmgr" ) then
	    "$PREFIX/bin/oplmgr" +start
	endif
END_OF_OPENLINK_CSH
chmod 755 openlink.csh


#
#  Change ownership (DISABLED)
#
if false
then
  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 | sed -e 's/ /\ /' | xargs chown $owner
  fi
  if [ "x$group" != "x" ]
  then
      find . -print | sed -e 's/ /\ /' | xargs chgrp $group
  fi
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


#
#  Check for iODBC directory
#
if test -d $PREFIX/odbcsdk
then
    echo "*  If you want to develop your own iODBC enabled applications"
    echo "*  using the iODBC shared libraries, you may need to create a"
    echo "*  symlink between the odbcsdk and /usr/local/iODBC directories."
    echo "*"
    echo "*  On most Unix systems this will remove the need to set"
    echo "*  LD_LIBRARY_PATH, LIBPATH or SHLIB_PATH environment settings"
    echo "*  before your application can find the shared libraries."
    echo "*"
    echo "*  Note that this symlink is not needed when using the static"
    echo "*  iODBC libraries nor when using the OpenLink application itself."
    echo "*"
    echo "*  As this task can only be performed as root, the installer"
    echo "*  has generated a RUNASROOT.sh script which needs to be run"
    echo "*  only once, after the instal.sh has finished."
    echo "*"
    

cat > RUNASROOT.sh <<-END_OF_RUNASROOT_SH
	#!/bin/sh
	#
	#  To avoid problems locating the shared libiodbc libraries 
	#  OpenLink recommends adding a symlink between the odbcsdk directory
	#  and /usr/local/iODBC
	#
	#  On most Unix systems this will remove the need to set
	#  LD_LIBRARY_PATH, LIBPATH or SHLIB_PATH environment settings
	#  before your application can find the shared libraries.
	#  Note that this symlink is not needed when using the static
	#  iODBC libraries nor when using OpenLink application itself.
	#
	#  As this task can only be performed as root, the installer
	#  has generated this RUNASROOT.sh script which needs to be run
	#  only once by root, after the install.sh has finished.
	#

	if test -d "/usr/local/iODBC"
	then
	    echo "* ERROR: /usr/local/iODBC already exists"
	    exit 1
	elif test \! -d "$PREFIX/odbcsdk"
	then
	    echo "* ERROR: odbcsdk has not been installed"
	    exit 2
	else
	    ln -s "$PREFIX/odbcsdk" "/usr/local/iODBC"
	fi
	exit 0
END_OF_RUNASROOT_SH
   chmod 755 RUNASROOT.sh
fi


#
#  Install oplmgr with setuid bit enabled to avoid permission issues
#  with the Unix-socket in /tmp (DISABLED)
#
#  When installing as root, the script will try several user/group names
#  until successful. 
#
#  When installing as a non-root user, the chown/chgrp commands will fail
#  and the oplmgr will run under the permission of that user.
#
#  Note: the user needs to have read permissions on the licenses
#
if false #test -x bin/oplmgr
then
    echo "Installing license manager..."
    for username in nobody guest $owner bin 65534
    do
        chown $username bin/oplmgr 2>/dev/null && break
    done

    for groupname in nobody guest $group bin 65534
    do
        chgrp $groupname bin/oplmgr 2>/dev/null && break
    done

    chmod 4755 bin/oplmgr 2>/dev/null
fi


#
#  End
#
echo "End of installation"
exit 0
