#!/bin/sh
#
#ident  "@(#)_esm_em_mcboot 1.3    99/10/07 SMI"
#
# Copyright (c) 1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# This script is Enclosure Manager specific. It loads the bootable management
# classes for Enclosure Manager in the CMC framework, and start the
# administration of the management classes.
#
TEXTDOMAIN=SUNW_SMS_CM
PATH=/usr/bin:/usr/sbin:/sbin:/usr/ucb/bin
PKGINFO=pkginfo
cwd=`pwd`

progname=$0
OPTION=$1

LOCATION=`${PKGINFO} -r SUNWesm`
if [ "$LOCATION" != "" ]
then
    LOCATION=${LOCATION}/SUNWesm/sbin
else
    LOCATION=/opt/SUNWesm/sbin
fi

CLASSES="com.sun.esm.apps.health.host.HostHealth \
        com.sun.esm.apps.control.host.HostControl \
        com.sun.esm.apps.config.host.HostConfig"

set_lock_location()
{
	# Caution: changing the lock directory or the name will affect the 
	#		functioning of esm_em_mcboot. Change the lock name 
	# 		and directory in that script accordingly.
        LOCK_DIR=/tmp/SUNWencc
        LOCK=_esm_em_mcboot.lck
 
        if [ ! -d $LOCK_DIR ]
        then
            mkdir -p $LOCK_DIR > /dev/null 2>&1
            if [ $? -ne 0 ]
                then
                echo "$progname: \c" >&2
                gettext $TEXTDOMAIN "Unable to locate Process lock directory" >&2
                echo " $LOCK_DIR" >&2
                echo >&2
                LOCK_LOCATION=/tmp/$LOCK
            else
                LOCK_LOCATION=$LOCK_DIR/$LOCK
            fi
        else
            LOCK_LOCATION=$LOCK_DIR/$LOCK
        fi
}

set_lock_location

case x$OPTION in 
    'xstart') 
	      # Create lock that will be monitored by esm_em_mcboot
	      touch $LOCK_LOCATION

              [ -f $LOCATION/esm_mcboot ] && $LOCATION/esm_mcboot -load "$CLASSES" -start "$CLASSES";

	      # Clear lock that will be monitored by esm_em_mcboot
	      rm -rf $LOCK_LOCATION
              ;;
    'xstatus') 
              [ -f $LOCATION/esm_moboot ] && $LOCATION/esm_mcboot status
              ;;
              
    *)        
	      echo "usage: $progname { start | status }"
	      ;;
esac

exit 0
