#!/bin/bash
#
# ccat
#
# This Korn shell script starts DESTA-based Compaq Crash Analysis Tool processes. 
# It uses the "desta" script in the DESTA Common Components kit, see the
# comments in that file for details.
#
# Usage:
# (not all of these are shown in the Usage echo's below, to hide the
# options intended for expert users)
# 
# ccat [help]
#     Show this help.
# ccat gui [profile]
#     Start the CCAT GUI.
# ccat direct [crash file name]
#     Force a crash file through the entire CCAT process (notification included)
#
# You can set the following environment variables to change the behavior.
# This script will assign them to proper installed defaults if not set
# by the user.
#
# SVCTOOLS_HOME
#     The top-level directory of Compaq Service Tools. By default,
#     assigned to the SVCTOOLS_BASE.
# SVCTOOLS_PATH
#     The list of directories and/or .jar files (colon-separated) containing
#     Java-based Service Tools' class files to use. Assigned to be the
#     .jar files in the default installed jars directory where all Service
#     Tools store them, by default. If SVCTOOLS_HOME is set by the user,
#     but not SVCTOOLS_PATH, then SVCTOOLS_PATH is defined to be the
#     .jar files in the directory $SVCTOOLS_HOME/jars.
# DESTA_CMD
#     The DESTA executable to run, if you wish to override desta_exec
#     (see comments where this is addressed below).
#
#  Build the DESTA environment variables based on the SVCTOOLS_BASE
#  or the user's settings.
#
#
#====================================================================
#  Change History
#
#  8/8/02   jwarihay   Change gui log file location to use "specific".
#
#  10/17/02        L. Thomas     PTR 91-22-782, added umask so new files 
#                                have no group or world permissions.
#
#  10/16/03  jwarihay     PTR 91-22-1517   Add /usr to environment settings.
#
#====================================================================

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

function usage {
	CA_CMD_NAME=`basename $0`
	echo "Usage:"
        echo "   $CA_CMD_NAME gui                 - Start the CCAT GUI."
        echo "   $CA_CMD_NAME direct [crash file] - Force a crash file through"
        echo "          the entire CCAT process, notification included.  You must"
	echo "          supply the complete path of the crash file."
}

REGISTRY_HOME=/usr/opt/hp/svctools/webes_registry
DEFAULT_SVCTOOLS_HOME=/usr/opt/hp/svctools

if [ -a $REGISTRY_HOME/RegistryFile ]; then
    SVCTOOLS_HOME="`cat $REGISTRY_HOME/RegistryFile |grep common.Root |cut -f 2 -d=`"
   # echo " SVCTOOLS_Home read yields $SVCTOOLS_HOME "
else
  SVCTOOLS_HOME=$DEFAULT_SVCTOOLS_HOME
fi

if [ -z "$SVCTOOLS_HOME" ]; then
   SVCTOOLS_HOME=$DEFAULT_SVCTOOLS_HOME;export SVCTOOLS_HOME
else
   SVCTOOLS_HOME=$SVCTOOLS_HOME;export SVCTOOLS_HOME
fi

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

case "$1" in

    'gui')
        #  Start the Compaq Analyze GUI.
        #  The default profile name is the user's username.
        shift
        if [ "$1" = "" ]
        then
            GUI_PROFILE=`/usr/bin/whoami`
        else
            GUI_PROFILE=$1
            shift
    	fi
        echo Starting the CCAT GUI.
        LOGOUT=$SVCTOOLS_HOME/specific/ccat/logs/ccat_gui.$GUI_PROFILE.out
	echo Logging outputs to: $LOGOUT
	LOGERR=$SVCTOOLS_HOME/specific/ccat/logs/ccat_gui.$GUI_PROFILE.err
	echo Logging errors to: $LOGERR
	cd $SVCTOOLS_HOME/common/ccat/data
	$SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.ccat.gui.CCATGui  >$LOGOUT 2>$LOGERR
    ;;
    
    'direct')
        #  Start the command-line interface to register knowledge.
	#  Make sure we have the right number of parameters otherwise
	#  give the user the usage message
        
        if [ "$#" = "2" ]
	then
		shift
	    cd $SVCTOOLS_HOME/common/ccat/data
            $SVCTOOLS_HOME/common/bin/desta exec com.compaq.svctools.ccat.CCATDirect $* cli
        else
	    echo "$0 Error: Bad command syntax or missing filename parameter"
            usage
        fi
        ;;

    *)
	#  Unknown or "help" command
        if [ "$1" = "" ]
        then
            echo "$0 Error: No command given."
        else
            if [ ! "$1" = "help" ]
            then
                echo "$0 Error: Unknown command $1"
            fi
        fi
        usage
    ;;

esac

# End of file
