#!/bin/sh
#
#ident "@(#)smwebapp	1.26 05/08/08 SMI"
# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.

# Get console installation home directory
# This command is in ${CONSOLE_HOME}/bin
PROGDIR=`dirname "$0"`
SAVEDIR=`pwd`
cd $PROGDIR/..
CONSOLE_HOME=`pwd`
cd ${SAVEDIR}

# Get the path to the native directory
# This is kludgy because it is not a subdirectory from home
# for Solaris platforms.
NTV_PATH=""
OS=`uname -s`
if [ "${OS}" = "SunOS" ]; then
    NTV_PATH="/usr/lib/webconsole"
else
    NTV_PATH=${CONSOLE_HOME}/native
fi

# Get the path to the java command
if [ "${JAVA_HOME}" = "" ]; then
    JAVA_PATH=/usr/java/bin/java
else
    JAVA_PATH=${JAVA_HOME}/bin/java
fi

# Get the subcommand name and arguments.
# Build up one big argument with a special value between options.
# This allows option values with white space to be handled.
SUBCMD=$1
shift
ARGS=""
if [ $# -gt 0 ]; then
    ARGS=$1
    shift
    while [ $# -gt 0 ]; do
        ARGS="${ARGS}_WxS_$1"
        shift
    done
fi

# Set umask for creating new files
umask 022

# Set classpath
LIB_PATH=${CONSOLE_HOME}/lib
CLASSPATH=${LIB_PATH}/consoleutil.jar:${LIB_PATH}/serviceapi.jar:${LIB_PATH}/serviceimpl.jar

# Execute the java based command
${JAVA_PATH} -classpath ${CLASSPATH} \
    -Dcom.sun.web.console.home=${CONSOLE_HOME} \
    -Djava.library.path=${NTV_PATH} \
    -Djava.awt.headless=true \
    com.sun.web.util.WebappCliDriver ${SUBCMD} "${ARGS}"

exit $?
