#!/bin/ksh
#
# Copyright 2003 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 xxx_config.
#     This file will be sourced instead of xxx_config if -f filename is specified



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

typeset opt

while getopts 'f:z:' opt
do
        case "${opt}" in
                f)      MYCONFIG=${OPTARG};;
                *)      logger -p daemon.err \
                        "ERROR: ${MYNAME} Option ${OPTARG} unknown - early End. Only -z and -f are valid"
                        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`/ha_mysql_config
	echo "sourcing ${PKGCONF}"
	. ${PKGCONF}
fi

# Rewmoving 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
