#!/bin/bash
#
# sea
#
# This Korn shell script starts DESTA-based System Event Analyzer processes.
# It uses the "desta" script in the DESTA Common Components kit, see the
# comments in that file for details.
#
# Usage: see $SVCTOOLS_HOME/common/ca/docs/userguide/cli_summary.txt
#
# Further options not included in cli_summary.txt:
# sea msg [args]
#     Drive the SendCAMsg class (see Java code).
# sea exec [com.compaq.myproject.mypackage.MyClass [args]]
#     Invokes the main() method of the given fully qualified class
#     (MyClass in this example), passing the given args to main().
#     The class must be accessible through either the CLASSPATH or the
#     SVCTOOLS_PATH environment variable (see below).
#
# Refer to the $SVCTOOLS_HOME/common/bin/desta script for information about
# overriding environment variables such as SVCTOOLS_HOME.
#
#----------------------------------------------------------------------------

# Uncomment this line to show what's going on, or (better) use the
# sea_g debug variant of this script instead (located in the same
# directory as the sea script).
#set -x

# Make all new files have no permissions for group and world.
#umask 077

# Remove all exported aliases so that ksh built-in commands do what we
# expect them to do.
#unalias -a

#  Derive the SVCTOOLS_HOME environment variable if not overridden, and
#  validate the directory.
STARTING_DIR=`/bin/pwd`
if [ "$SVCTOOLS_HOME" = "" ]
then
    #  Find my real directory, even if $0 is really a symbolic link
    MYREALDIR=`/bin/ls -l $0 | /bin/cut -f 2 -d '>' | /bin/cut -f 2 -d ' '`
    if [ "$MYREALDIR" = "" ]; then
        # Not a symbolic link
        SVCTOOLS_HOME=`/usr/bin/dirname $0`/../..
    else
        # Symbolic link, use the directory to which it points
        SVCTOOLS_HOME=`/usr/bin/dirname $MYREALDIR`/../..
    fi
fi

if [ ! -d "$SVCTOOLS_HOME" ]
then
    echo "$0 Error: $SVCTOOLS_HOME directory does not exist."
    exit 642
fi

#  Define the directory for WCCProxy shared libraries, if not defined already.
if [ "$SVCTOOLS_WCCPROXY_SHARE" = "" ]
then
    SVCTOOLS_WCCPROXY_SHARE=$SVCTOOLS_HOME/common/wccproxy/share
fi
export LD_LIBRARY_PATH=$SVCTOOLS_WCCPROXY_SHARE


#  The following is to fix an anomaly whereby if this script is executed
#  in a dir below where SVCTOOLS_HOME is to be, it ends up getting
#  assigned a relative path instead of an absolute which can cause
#  problems if a class file is expecting and requires an absolute path.
cd $SVCTOOLS_HOME
SVCTOOLS_HOME=`/bin/pwd`
cd $STARTING_DIR

export SVCTOOLS_HOME

case "$1" in

    'msg')
        if [ "$2" = "-auto" ]
        then
           echo "The syntax has been changed to conform to the New Common Syntax."
           echo "Refer to the 'sea [n] test [input] <inputFile>' command."
           exit 0
        fi
        if [ "$2" = "-autoall" ]
        then
           echo "The syntax has been changed to conform to the New Common Syntax."
           echo "Refer to the 'sea [n] test [input] <inputFile>' command."
           exit 0
        fi
        #  Start the command-line interface to send message(s).
        shift
        $SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.ca.cli.SendCAMsg $*
        ;;

    'report')
        #  Start the command-line interface to report active problems from auto-analysis.
        shift
        $SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.ca.cli.ReportKnownProblems $*
        ;;

    'sicl')
        shift
    	echo "Note: The enabling and disabling of SICL using DSNlink has changed from"
	echo "'wsea sicl [on|off]' to 'desta sicl [on|off]'. Please use the desta syntax"
	echo "and update any scripts that refer to the 'wsea sicl' command before this"
	echo "is completely phased out in a future release."
        $SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.desta.cli.ToggleSICL $*
        ;;


    'log')
        #  Start the command-line interface to turn on auto-logging of either decomposed bins or problem reports.
        shift
        $SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.desta.cli.ToggleLOG $*
        ;;

    'exec')
        #  Execute the given Java class, with optional parameters.
        shift
        $SVCTOOLS_HOME/common/bin/desta exec $*
        ;;

    'NTFileHdr')
	# correct an NT file header for a hand built log
	shift
	$SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.ca.services.eventreaderes.EventDirectory $* 1 true
	;;
    *)
        #  Run all other commands through the CLI Interpreter
        export ANALYSIS_WARNING_FN=/dev/null
        export ANALYSIS_ERROR_FN=/dev/null
        $SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.ca.cli.CACLIInterpreter $*
        export ANALYSIS_WARNING_FN=
        export ANALYSIS_ERROR_FN=

esac

# End of file
