#!/bin/ksh
# 
# Copyright (c) 2002 by Sun Microsystems, Inc.
# All rights reserved.                           
#
# Start the MTP CCI Gateway
#
# This script assumes that it is located in the bin directory of the
# installed MTP Client. If it is moved, then the KIXCLI_INSTALL_DIR
# environment variable can be set to override the calculations here.
#

#
# Store the arguments
#
ARGS=$*

#
# Determine where the installation of the agent is.
#
if [ -z "$KIXCLI_INSTALL_DIR" ]; then
    D=$(dirname $0)
    B=$(basename $0)
    abspath="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
    KIXCLI_INSTALL_DIR=`dirname $(dirname $abspath)`
else
    if [ -f "${KIXCLI_INSTALL_DIR}/lib/sunmaa.jar" ]; then
        echo "Using MTP Client installation directory '"$KIXCLI_INSTALL_DIR"'"
    else
        echo "Could not find '"${KIXCLI_INSTALL_DIR}"/lib/ccigateway.jar'"
        exit 1
    fi
fi

cd ${KIXCLI_INSTALL_DIR}

#
# Ensure LD_LIBRARY_PATH includes the lib directory so that the native
# library and its dependencies can be found
#
export LD_LIBRARY_PATH=${KIXCLI_INSTALL_DIR}/lib:$LD_LIBRARY_PATH

#
# The following line starts up the CCI Gateway, passing in the command
# line arguments. If there are no arguments, the gateway starts up and 
# advertises its offers in a new, in-process COS Naming service listening
# on the default port (7865).
#
java -server -jar lib/ccigateway.jar ${ARGS}

