#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/cl_delete_efs.sh 1.6 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2011,2012 
# 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 

. /usr/es/lib/ksh93/func_include
. /usr/es/sbin/cluster/cspoc/cl_federatedsec_source
fsec_init

typeset ks_rg="EFS_KeyStore"
STANZAS="efsusrkeystore efsgrpkeystore efsadmkeystore"

odm_check

KS_mode=$(clodmget -n -q "group=EFSKeyStore AND name=mode" -f value HACMPLDAP 2>/dev/null)

[[ ! -z $KS_mode ]] || {
     dspmsg -s 129 cspoc.cat 75 "EFS Keystore is not configured for PowerHA SystemMirror.\n"
	exit 1
	}

NODES=`/usr/es/sbin/cluster/utilities/cllsnode -c | awk -F: '(NR != 1) {print $1}'`

[[ -z $NODES ]] && { 
	 dspmsg -s 129 cspoc.cat 64 "Nodes are not configured in cluster.\n"
	exit 1
	}
	
odmdelete -o HACMPLDAP -q group=EFSKeyStore >/dev/null || ret_fail "odmdelete failed" $?

if [[ $KS_mode == 2 ]]
then
	clvt delete resource_group $ks_rg || {  dspmsg -s 129 cspoc.cat 157 "Cannot remove EFS keystore from cluster.\n"; exit 1; }
fi

if [[ $KS_mode == 1 ]]
then
	for i in $NODES
	do
		for X in $STANZAS
		do
			cl_rsh -n $i "chsec -f /etc/nscontrol.conf -s $X -a secorder=files" >/dev/null \
					|| ret_fail "chsec command failed." $?
		done
	done
fi

fsec_vsync "EFS Keystore delete" || ret_fail "clverify restriction failed" $?

run_on_allnode "rm -rf $FSEC_LOG_DIR" || ret_fail "Removing log directory failed." $?

exit 0