fatal () {
    echo "$*" >&2
    exit 1
}

# Check for root
#
user=`/bin/id | /usr/bin/grep root | /usr/bin/wc -l`
if [ $user -eq 0 ]; then
    fatal "You must be root to run this script."
fi

# Stop ESM if not running as part of esmpatch
#
if [ "$ESM_CONTEXT" != "patch" ]; then

    ESM_BASE=`/usr/bin/pkgparam SUNWstm ESM_BASE`
    if [ $? -ne 0 ]; then
        fatal "Could not determine ESM location!"
    fi

    $ESM_BASE/bin/esmcontrol stop 

    SWCSERVER=/usr/sbin/smcwebserver
    if [ -f "$SWCSERVER" ]; then
        $SWCSERVER stop
    else
        fatal "Unable to stop $SWCSERVER"
    fi
fi

exit 0
