#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/lib/nim/methods/c_destroy.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2008 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)16 1.4  src/bos/usr/lib/nim/methods/c_destroy.sh, cmdnim, bos720  7/15/08  13:34:33 
#
#   COMPONENT_NAME: CMDNIM
#
#   FUNCTIONS: ./usr/lib/nim/methods/c_destroy.sh
#

# include common NIM shell defines/functions
NIMPATH=${0%/*}
NIMPATH=${NIMPATH%/*}
[[ ${NIMPATH} = ${0} ]] && NIMPATH=/usr/lpp/bos.sysmgt/nim
NIM_METHODS="${NIMPATH}/methods"
. ${NIM_METHODS}/c_sh_lib

#---------------------------- module globals    --------------------------------
REQUIRED_ATTRS=""
OPTIONAL_ATTRS="cmd_flags type"

#---------------------------- c_destroy      --------------------------------
#
# NAME: c_destroy
#
# FUNCTION:
#       Removes a managed system
#
# EXECUTION ENVIRONMENT:
#
#
# RECOVERY OPERATION:
#
# DATA STRUCTURES:
#		parameters:
#		global:
#
# RETURNS: (int)
#
# OUTPUT:
#-------------------------------------------------------------------------------

# signal processing
trap cleanup 0
trap err_signal 1 2 11 15

type="wpar"

# NIM initialization
nim_init

# set parameters from command line
while getopts :a:qv c
do
	case ${c} in

		a) 	# validate the attr ass
			parse_attr_ass "${OPTARG}"

			# include the assignment for use in this environment
			eval ${variable}=\"${value}\"
		;;

		q)	# show attr info
			cmd_what
			exit 0
		;;

		v)	# verbose mode (for debugging)
			verbose=TRUE
			set -x
			for i in $(typeset +f)
			do
				typeset -ft $i
			done
		;;

		\?)	# unknown option
			error ${ERR_BAD_OPT} ${OPTARG}
		;;
	esac
done

# check for missing attrs
ck_attrs

shift $((OPTIND - 1))

# run proper activation command - type variable must be set 
if [[ "$type" = "wpar" ]]
then
	${RMWPAR} ${cmd_flags} $@  2>${ERR}
else
	error ${ERR_BAD_OPT} ${OPTARG}
fi

# Save the return code from the create command.
destroy_rc=$?

if [[ ${destroy_rc} -ne 0 ]]
then
   err_from_cmd ${RMWPAR}
fi

exit ${destroy_rc}
