#!/bin/bash

#set -x
if [ ! -f /opt/hsc/data/user_license/.prompt_for_agreement ]
then
   exit 0
fi

JAVAPATH="/opt/IBMJava/jre/bin/"
x=`type -p java 2>/dev/null`
if [ "$x" != "" ]
then
  JAVAPATH=`/usr/bin/dirname $x`
fi
##  This is a script to run the User License Manager java app.
##  This script is invoked every time the HMC is started.
##  If the user does not accept the terms of the license, the login
##  will end.
##   

#   echo "run License Manager"
export PATH=$JAVAPATH:$PATH
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/hsc.jar:/opt/hsc/data:/usr/websm/codebase/pluginjars/auifw.jar:/usr/websm/codebase/pluginjars/auibase.jar:/usr/websm/codebase/pluginjars/auiml_properties.jar:/usr/websm/codebase/pluginjars/auiswing.jar:/usr/websm/codebase/pluginjars/auii18n.jar:/usr/websm/codebase/pluginjars/uil.jar:/usr/websm/codebase/pluginjars/jhall.jar:/usr/websm/codebase/pluginjars/swing11spinner_Runtime.jar:$CLASSPATH

java com.ibm.hsc.common.util.UserLicenseManager

exit $?
