#!/bin/bash

CLIENT_PATH=/opt/novell/messenger/client

# If you want to use a differenct JRE, change the line below.
JAVA_BIN=${CLIENT_PATH}/jre/bin/java

CLIENT_JAR=${CLIENT_PATH}/nmclient.jar
JARFILES=${CLIENT_JAR}:${CLIENT_PATH}/jh.jar:${CLIENT_PATH}/nmclhlp.jar:${CLIENT_PATH}/json.jar
JVM_ARGS="-Xms5M -Dawt.toolkit=sun.awt.motif.MToolkit -cp $JARFILES"

# Make sure JRE is > 1.4
if [ ! -z $JAVA_BIN ] && [ -f $JAVA_BIN ] ; then
	version=$($JAVA_BIN -version 2>&1|grep -m 1 -o -E '[0-9]+.[0-9]+.[0-9]+')
	major=$(echo $version|cut -f1 -d '.' -)
	minor=$(echo $version|cut -f2 -d '.' -)
	if [ ! -z $major ] && [ ! -z $minor ] ; then
		if [ $((major == 1)) = 1 ] && [ $((minor < 4)) = 1 ] ; then
			JAVA_BIN=""
		fi
	fi
fi

if [ ! -z $JAVA_BIN ] && [ -f $JAVA_BIN ] ; then
	umask 0066
	LD_LIBRARY_PATH=$CLIENT_PATH \
	    $JAVA_BIN $JVM_ARGS GWMessenger $@ >/dev/null
else

	# We could not find a JRE (1.4 or later) so show an error
	error1=$"Could not find JRE with version 1.4.2 (or later)."
	error2=$"Please install the JRE or set the JAVA_HOME environment variable."
	dialog=""

	# Try kdialog first
	if [ -e /opt/kde3/bin/kdialog ] ; then
		/opt/kde3/bin/kdialog --error "$error1\n$error2" >/dev/null 2>&1
	else
		# Try gdialog
		if gdialog --version >/dev/null 2>&1 ; then
			dialog=$(type -p gdialog)
		fi

		if [ -z $dialog ] ; then
			if [ -e /opt/gnome2/bin/gdialog ] ; then
				dialog=/opt/gnome2/bin/gdialog
			fi
		fi

		if [ ! -z $dialog ] ; then
			$dialog --title $"Error" --msgbox "\n        $error1        \n        $error2        \n" 100 200 >/dev/null 2>&1
		else
			# Just dump it to the terminal window (if there is one)
			echo "$error1"
			echo "$error2"
		fi
	fi
fi
