#!/bin/sh
# -------------------------------------------------------------------
# @(#)planviewer		Sybase, Inc.
# -------------------------------------------------------------------
# Start ASE Plan Viewer Java Edition.
# -------------------------------------------------------------------
# Sybase, Incorporated CONFIDENTIAL and PROPRIETARY material.
#
# One Sybase Drive
# Dublin, CA, USA  94568
#
# The object version of this software is furnished to purchaser under a
# license for use on a single computer system.  Such executable code can
# be copied (with the inclusion of Sybase' copyright notice) only for
# licensed use in such a system, except as may be otherwise provided in
# writing by Sybase Incorporated.
#
# The information in this program source code is subject to change without
# notice and should not be construed as a commitment by Sybase,
# Incorporated.  Sybase, Incorporated assumes no responsibility for any
# errors that may appear in, or result from the use of this program.  
# Sybase cannot assume any responsibility for the use of any portion of
# this software on any equipment not supplied or approved by Sybase
# Incorporated.
#
# This source code contains commercially valuable and substantial trade
# secrets of Sybase, the design and development of which reflect the
# effort of skilled development experts employed by Sybase Incorporated.
# No permission is granted for viewing or copying this source code unless
# permission in writing is explicitly given to a purchaser by Sybase,
# Incorporated.
#---------------------------------------------------------------------

PATH="/bin:/usr/bin:/etc:/$SYBASE/bin:$PATH:/usr/sbin"; export PATH

# ... Set the display and start ...

if [ -z "$DISPLAY" ]
then
	hostname=`who am i | cut -f2 -d'(' | cut -f1 -d')'`
	ipaddress=`/usr/sbin/ping -a $hostname | cut -f2 -d'(' | cut -f1 -d')'`
	DISPLAY=$ipaddress:0.0;export DISPLAY
fi

echo "\nStarting ASE Plan Viewer Java Edition (displaying to $DISPLAY) ...\n"

# ... Find the SYBASE Home directory ...............................

if [ "$SYBROOT" = "" ]
then
   echo "Error: \$SYBROOT variable not set"
   exit 1
fi 

# ... Environment settings ..........................................

LIB_PV="$SYBROOT/DBISQL/lib"
export LIB_PV

if [ ! -f "$LIB_PV/planviewer.jar" ] 
then
    echo "
        Error:  Unable to find the ASE Plan Viewer Binary.
                Please check that \$SYBROOT has been set correctly and
                that the file '$LIB_PV/planviewer.jar' exists.\n
                \$SYBASE currently set to '$SYBROOT'\n"
                        exit 1
fi


# ... Find the JRE and set JAVA_HOME .............................

PLATFORM=`uname -s`

# Set JRE directory
if [ "$SYBASE_JRE6" = "" ]
then
     echo "
	Error: 	You need to set \$SYBASE_JRE6 to the directory where your Java JRE is installed."
	exit 1
fi

if [ -f "$SYBASE_JRE6/bin/java" ]
then
    PATH="${SYBASE_JRE6}/bin:$PATH"  # PATH to local JRE first
    export PATH
    export SYBASE_JRE6
else
    echo "
	Error: 	Unable to find the Java Binary.
		Please check that \$SYBROOT has been set correctly and 
		that the file '$SYBASE_JRE6/bin/java exists' exists.\n
		\$SYBROOT currently set to '$SYBROOT'\n"
			exit 1
fi

# ... StartPVEN ...............................................

if [ $PLATFORM = AIX ]
then 	
	LIBPATH="$SYBASE_JRE6/bin:$SYBASE_JRE6/bin/classic"
	export LIBPATH
fi

eval java -Xms15m -Xmx500m -classpath "$LIB_PV/planviewer.jar" com.sybase.ase.planviewer.ASEPlanViewer $* 

# ... eof ...

