#!/bin/bash

########################################################################
#                      (c) Copyright 2009 Lexmark                      #
#                        All rights reserved                           #
########################################################################
#                                                                      #
#  This script launches the Wireless Setup Utility.		       		   #
#                                                                      #
########################################################################
OEM_PATH=/usr/local/lexmark
DRIVER_PATH=$OEM_PATH/wsu_legacy
DRIVER_LIB_PATH=$DRIVER_PATH/lib
JAR_PATH=$DRIVER_PATH/jar
JAVA_CMD=java
REQUIRED_VERSION=1.6

if [ -f "/usr/local/lexmark/wsu_legacy/jre/bin/java" ]; then
	JAVA_CMD="/usr/local/lexmark/wsu_legacy/jre/bin/java"
elif [ -f "/usr/local/printer/fwu_legacy/jre/bin/java" ]; then
	JAVA_CMD="/usr/local/printer/fwu_legacy/jre/bin/java"
elif [ -f "/usr/local/lexmark/legacy/jre/bin/java" ]; then
	JAVA_CMD="/usr/local/lexmark/legacy/jre/bin/java"
elif [ -f "/usr/bin/java" ]; then
	JAVA_CMD="/usr/bin/java"
elif [ -f "/etc/alternatives/java" ]; then
	JAVA_CMD="/etc/alternatives/java"
else
	xmessage -buttons "OK" "There is no Java Runtime Environment (JRE) detected in your system.
Kindly download the *driver with included JRE or use *openJDK.

*driver  (e.g. lexmark-inkjet-legacy-wJRE-2.0-1.i386.rpm, lexmark-inkjet-legacy-wJRE-2.0-1.i386.deb)
*openJDK (e.g. [Ubuntu]# apt-get install openjdk-6-jre
	       [Fedora]# yum install java-1.6.0-openjdk
	       [OpenSuse]# zypper install java-1.6.0-openjdk)" -center
	exit 1
fi

CLASS_PATH="$JAR_PATH/localize.jar:\
$JAR_PATH/localize_wsu.jar:\
$JAR_PATH/config.jar:\
$JAR_PATH/tools.jar:\
$JAR_PATH/xpp3_min-1.1.4c.jar:\
$JAR_PATH/xstream-1.3.1.jar:\
$JAR_PATH/uiframework.jar:\
$JAR_PATH/wsu.jar"

TARGET="mdwapclss.apps.unix.wsu.Wsu"

OPTIONS="-Xms4m -Xmx8m -DconfigKey=wsu"

$JAVA_CMD -version 2> /tmp/java_version
VERSION=`cat /tmp/java_version | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
rm /tmp/java_version
VERSION=`echo $VERSION | awk '{ print substr($1, 1, 3); }' | sed -e 's;\.;0;g'`
REQUIRED_VERSION=`echo $REQUIRED_VERSION | sed -e 's;\.;0;g'`

if [ $VERSION ]
then
      if [ $VERSION -ge $REQUIRED_VERSION ]
      then
           ${JAVA_CMD} -cp ${CLASS_PATH} ${OPTIONS} ${TARGET}
      else
	xmessage -buttons "OK" "The version of Java Runtime Environment (JRE) detected in your system is below the required version.
The required version for Java Runtime Environment (JRE) should be 1.6 or higher." -center
	exit 1
      fi
else
	xmessage -buttons "OK" "The version of Java Runtime Environment (JRE) detected in your system is below the required version.
The required version for Java Runtime Environment (JRE) should be 1.6 or higher." -center
	exit 1
fi

