#!/usr/bin/ksh
#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
#  This script to remove an smf service and its manifast takes 
#  the optional -f option
#
#  -f filename states a config file different from spsra_config.
#     This file will be sourced instead of spsra_config if -f filename is specified


MYCONFIG=
MANIFEST_DIR=/var/svc/manifest/application/sczone-agents

typeset opt

while getopts 'f:' opt
do
        case "${opt}" in
                f)      MYCONFIG=${OPTARG};;
                *)      exit 1;;
        esac
done

# Sourcing the specified config file, either the default one,
# or the one supplied with -f

if [ -n "${MYCONFIG}" ] && [ -f "${MYCONFIG}" ]
then
	echo "sourcing ${MYCONFIG}"
	. ${MYCONFIG}
else
	PKGCONF=`dirname $0`/spsra_config
	echo "sourcing ${PKGCONF}"
	. ${PKGCONF}
fi

# Removing the smf service and its manifest

SERVICE_TAG=svc:/application/sczone-agents:${RS}

echo "disabeling the smf service ${SERVICE_TAG}"
/usr/sbin/zlogin ${ZONE} svcadm disable ${SERVICE_TAG}

echo "removing the smf service ${SERVICE_TAG}"
/usr/sbin/zlogin ${ZONE} svccfg delete ${SERVICE_TAG}

echo "removing the smf manifest ${MANIFEST_DIR}/${RS}.xml"
/usr/sbin/zlogin ${ZONE} rm ${MANIFEST_DIR}/${RS}.xml

exit 0
