#!/bin/sh

#----------------------------------------------------
# Script for installation of the ORACLE driver
# after a porting set update
#----------------------------------------------------

RELEASE=6.1
ORA_ENV=$BSE/bin/ora_env${RELEASE}
ORA_CLIENT_DIST=${BSE}/bin/ora_client_files

ORA_RSF_DIR=${BSE}/lib/ora/oracle_home
BaanResFile=$BSE/lib/defaults/db_resource

# OS dependent options
uname=`uname`
if [ ${uname} = "Linux" ]
then
	ECHO="echo -e"
else
	ECHO="echo"
fi


. $ORA_ENV

#
# One some platforms we changed from static to shared libraries
#

if oradriver_shlib_based
then
	# Now we have a shared library based driver
	# Undo specific settings for static lib based drivers when they still hang around
	
	if [ -f $BaanResFile ]
	then
		# Remove resources set for static driver

		ed $BaanResFile << !EndEdit > /dev/null
g/oracle_client_home:/d
w
q
!EndEdit
	fi

	if [ -d $ORA_RSF_DIR ]
	then
		# Remove old client env used by the static libs
		rm -rf $ORA_RSF_DIR 
	fi

	# All obsolete stuff checked and maybe removed.
	# Nothing more to do.
	exit 0
else
	if [ ! -f $ORA_CLIENT_DIST ]
	then
		exit 0
	fi

	# continue with the normal processing below.
fi


#
# Create missing directories and files
#

Old_mask=`umask`
umask 02

if [ ! -d $ORA_RSF_DIR ]
then
	mkdir $ORA_RSF_DIR 
fi

if [ ! -f $BaanResFile ]
then
	# Create empty resource file
	> $BaanResFile
	baan_chown $BaanResFile
fi

#
# Install Oracle Required Support Files
#

if [ -d $ORA_RSF_DIR ]
then
	(
		cd $ORA_RSF_DIR
		read Version
		${ECHO} "$Version" > $ORA_RSF_DIR/Version
		zcat | cpio -icdu	# unpack distribution
	) < $ORA_CLIENT_DIST

	baan_chown $ORA_RSF_DIR
fi

umask $Old_mask

if [ -r "$ORA_RSF_DIR/Version" ]
then
	# Only set for Oracle8

	ed $BaanResFile << !EndEdit > /dev/null
g/oracle_client_home:/d
\$
a
oracle_client_home:${ORA_RSF_DIR}
.
w
q
!EndEdit

fi

#
# Ready
#

exit 0

