#! /bin/ksh

#  (c) 1998  Sun Microsystems, Inc.
#
#  @(#)install_conduit.ksh	1.2 99/11/04 1.2 SMI

# Save the arguments
ARGUMENTS=$*

# Save the current directory.
current_dir=`pwd`

# Check if java exists in the user's environment
if [ -a /usr/java1.2 ]; then
	JAVA_HOME=/usr/java1.2
else
	echo "You need to have JDK 1.2 installed in order to run sdtpdasync."
	exit(1)
fi

# Change directory to location of packages.
cd /usr/dt/appconfig/sdtpdasync

# Set the LD_LIBRARY_PATH
cd lib
LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
cd ..

# Set the class path to include each and every jar file of the application
cd classes
CLASSPATH=`pwd`:${CLASSPATH}
jarfiles=`/bin/ls *.jar`
for i in ${jarfiles}; do
	CLASSPATH=`pwd`/${i}:${CLASSPATH}
done
cd ..

# Set the class path to include each and every conduit jar file.
cd conduits
jarfiles=`/bin/ls *.jar`
for i in ${jarfiles}; do
	CLASSPATH=`pwd`/${i}:${CLASSPATH}
done
cd ..

# Check for classes in /etc/dt/appconfig/sdtpdasync/classes and
# /etc/dt/appconfig/sdtpdasync/conduits
if [ -d /etc/dt/appconfig/sdtpdasync ]; then

	cd /etc/dt/appconfig/sdtpdasync
	if [ -d classes ]; then
		cd classes
		CLASSPATH=`pwd`:${CLASSPATH}
		jarfiles=`/bin/ls *.jar`
		for i in ${jarfiles}; do
			CLASSPATH=`pwd`/${i}:${CLASSPATH}
		done
		cd ..
	fi

	if [ -d conduits ]; then
		cd conduits
		jarfiles=`/bin/ls *.jar`
		for i in ${jarfiles}; do
			CLASSPATH=`pwd`/${i}:${CLASSPATH}
		done
		cd ..
	fi
fi

export LD_LIBRARY_PATH
export CLASSPATH

# Get the java version.
${JAVA_HOME}/bin/java -version 2>/tmp/sdtpdasync.version_test

java_ver=`awk -F\" '{ print $2 }' /tmp/sdtpdasync.version_test`

# Get the major.minor.subminor java version numbers.
major=`awk -F\" '{ print $2 }' /tmp/sdtpdasync.version_test | awk -F\. '{ print $1 }' `
minor=`awk -F\" '{ print $2 }' /tmp/sdtpdasync.version_test | awk -F\. '{ print $2 }' `
subminor=`awk -F\" '{ print $2 }' /tmp/sdtpdasync.version_test | awk -F\. '{ print $3 }' `

rm /tmp/sdtpdasync.version_test

# Start the pdasync application, based on the java version.
cd $current_dir
if (( ${minor} >= 2 )); then
	# JDK 1.2 or higher
	${JAVA_HOME}/bin/java -classpath ${CLASSPATH} com.sun.pdasync.Registry.ConduitInstall ${ARGUMENTS}
        print "Command is: $*"

elif (( ${subminor} >= 6 )); then

	# JDK 1.1.6 or higher
	${JAVA_HOME}/bin/java -ss64m -oss64m -classpath ${CLASSPATH} com.sun.pdasync.Registry.ConduitInstall ${ARGUMENTS}

else

	# Less than JDK 1.1.6
	print "Unsupported jdk version - exiting."

fi
