#!/bin/bash

# This is the script used to start the Console Trace 

x=`type -p java 2>/dev/null`
if [ "$x" != "" ]
then
  JAVAPATH=`/usr/bin/dirname $x`
fi
export LD_LIBRARY_PATH=/usr/lib/:$LD_LIBRARY_PATH
export PATH=$JAVAPATH:$PATH

# Below is a temporary workaround for JRE 1.3.1 bug in the BigInteger class.
export JITC_COMPILEOPT=NINLINING{java/math/BigInteger}{oddModPow}

JARDIR="/usr/websm/codebase"
x=$JARDIR/wsmextra.jar:$JARDIR/wsm.jar:
for i in /usr/websm/codebase/pluginjars/*.jar
do
x=${x}$JARDIR/pluginjars/`basename $i`:
done

if [ "${DEBUG_JARS_DIRECTORY}" != "" ] ; then
  if [ -d ${DEBUG_JARS_DIRECTORY} ] ; then
    for i in ${DEBUG_JARS_DIRECTORY}/*.jar
    do
       debug_jars=${debug_jars}:$i
    done
  fi
fi

HOSTNAME=/bin/hostname

#
# check if the person is remotely logged in, set DISPLAY if yes  
#
LOG_PTS=`tty | sed 's@/dev/@@'`

LOG_HOST=`who | grep "$LOG_PTS " | grep "(" | cut -f2 -d '(' | cut -f1 -d')' | cut -f1 -d':'`
if [[ -n $LOG_HOST && -z $DISPLAY ]]; then
 export DISPLAY=$LOG_HOST:0
fi

                                      
if [[ -z $DISPLAY ]]; then
 # if no value is set, use DISPLAY for regular mode, and do
 # not use hostname b/c its faster    
 export DISPLAY=":0.0"
fi
export CLASSPATH=${DEBUG_JARS_DIRECTORY}:${debug_jars}:/usr/websm/codebase/pluginjars/hsc_${LANG}.jar:/usr/websm/codebase/pluginjars/aca.jar:/usr/websm/codebase/pluginjars/hsc.jar:/usr/websm/codebase/pluginjars/hsc_bundles.jar:/opt/hsc/auiml/properties:/usr/websm/codebase:/opt/hsc/com/ibm/hsc/auiml/databeans/images:$x:$CLASSPATH
#/usr/X11R6/bin/xset s off 1>/dev/null 2>&1
#/usr/X11R6/bin/xset -dpms 1>/dev/null 2>&1

java com.ibm.hsc.websm.launch.hscmgt.hscTrace
