#!/bin/sh
#
#ident  "@(#)_esm_em_moboot 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 managed
# object for Enclosure Manager in the CMC framework, and start the
# administration of the managed object.
#
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.mo.host.HostMOImpl"

set_lock_location()
{
	# Caution: changing the lock directory or the name will affect the 
	#		functioning of esm_em_moboot. Change the lock name 
	# 		and directory in that script accordingly.
        LOCK_DIR=/tmp/SUNWencm
        LOCK=_esm_em_moboot.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_moboot	      
	      touch $LOCK_LOCATION

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

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

exit 0
