#!/bin/sh
#
# $Header: odbc_update_ini.sh 29-nov-2005.22:47:31 akapila Exp $
#
# odbc_update_ini.sh
#
# Copyright (c) 2005, Oracle. All rights reserved.  
#
#    NAME
#      odbc_update_ini.sh - <one-line expansion of the name>
#
#    DESCRIPTION
#      <short description of component this file declares/defines>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    akapila     11/29/05 - created for bug 4741148. 
#    akapila     11/29/05 - Creation
#
# =========================================================================

# ODBCDM_HOME needs to be passed as arg-1
if [ ! "$1" ]
then
   echo " *** Please pass ODBCDM_HOME as arg-1, and optional arguments -"
   echo " *** Install location (arg-2), Driver name (arg-3) & DSN (arg-4)."
   echo " *** Usage:  odbc_update_ini.sh <ODBCDM_Home> [<Install_Location>] [<Driver_Name>] [<DSN>]"
   exit
else
   ODBCDM_HOME="$1"
fi

# Check whether Driver Manager is installed or not
if [ ! -f  $ODBCDM_HOME/etc/odbc.ini  -o  ! -f $ODBCDM_HOME/etc/odbcinst.ini ]
then
   echo " *** INI file not found. Driver Manager not installed!"
   exit
fi

# Add driver entry in $ODBCDM_HOME/etc/odbcinst.ini file
#
DRIVER_DESCRIPTION="Oracle ODBC driver for Oracle 10g"

# If a driver location is passed, use that or use the current directory
if [ ! "$2" ]
     then
        DRIVER_LOCATION=`pwd`
     else
        DRIVER_LOCATION="$2"
fi

# Check for Driver name
if [ ! "$3" ]
     then
        DRIVER_NAME="Oracle 10g ODBC driver"
     else
        DRIVER_NAME="$3"
fi

# We know driver .so name 
SO_NAME=libsqora.so.10.1

echo "
[$DRIVER_NAME]
Description     = $DRIVER_DESCRIPTION
Driver          = $DRIVER_LOCATION/$SO_NAME
Setup           =
FileUsage       =
CPTimeout       =
CPReuse         = " >> $ODBCDM_HOME/etc/odbcinst.ini
			      
# Add DSN entry 
# If a DSN name is passed, use that or use the default name
if [ ! "$4" ]
     then
        DSN="OracleODBC-10g"
     else
        DSN="$4"
fi
			      
echo "
[$DSN]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = $DRIVER_NAME
DSN = $DSN
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = 
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
UserID = 

"  >> $HOME/.odbc.ini

# Add DSN entry in "ODBC Data Sources" list
#
cat $HOME/.odbc.ini | sed "s/\[ODBC Data Sources\]/\[ODBC Data Sources\]\n$DSN = $DRIVER_DESCRIPTION/g" > odbc.ini
mv odbc.ini $HOME/.odbc.ini

