#!/bin/sh
# Copyright 2003 by Kai 'Oswald' Seidler, oswald@apachefriends.org

exdir="/opt/lampp/lib/php/extensions/no-debug-non-zts-20020429"

if test "`id -u`" -ne 0
then
	$de && echo "Bitte als root starten."
	$de || echo "Please run me as root."
	exit
fi

. /opt/lampp/share/lampp/lampplib

d=`dirname $0`
cd $d

$de && echo "Bitte gib den Pfad zur Oracle-Installation ein:"
$de || echo "Please enter the path to your Oracle installation:"

ora_home="/opt/oracle/OraHome1"

while true
do
	echo -n "ORA_HOME [$ora_home] "
	read a

	if test "$a"
	then
		ora_home="$a"	
	fi
	if test ! -e "$ora_home"
	then
		$de && echo "Verzeichnis nicht gefunden."
		$de || echo "No such directory."
	else
		break
	fi
done

# which oracle version?

test -e "$ora_home/lib/libclntsh.so.9.0" && libclntsh="$ora_home/lib/libclntsh.so.9.0"
test -e "$ora_home/lib/libwtc9.so" && libwtc="$ora_home/lib/libwtc9.so"

if test -z "$libclntsh"
then
	$de && echo "Finde die libclntsh.so.9.0 nicht. Sorry."
	$de || echo "Can't find libclntsh.so.9.0 nicht. Sorry."
	exit
fi

# remove symlinks

echo "installing symlinks..."

rm /opt/lampp/lib/libclntsh.so.9.0 /opt/lampp/lib/libwtc9.so 2> /dev/null

# install symlinks

ln -s $libclntsh /opt/lampp/lib/libclntsh.so.9.0
ln -s $libwtc /opt/lampp/lib/libwtc9.so

# patching php.ini

echo "patching php.ini..."

f="/opt/lampp/etc/php.ini"
$awk -vpw="$word" '
f==0 && $0 == ";oci8mark" {
		print "; patched by oci8 add-on"
		print ";"$0                              
		print "extension=oci8.so"
		f=1                                                                    
		next
	}
	{
		print
	}
' $f > /tmp/lampp$$
cp /tmp/lampp$$ $f
rm /tmp/lampp$$

$de && echo "PHP-OCI8-Aktivierung wahrscheinlich erfolgreich."
$de || echo "OCI8 add-on activation likely successful."

if test -f /opt/lampp/logs/httpd.pid
then
	/opt/lampp/lampp stopapache
	/opt/lampp/lampp startapache
fi

