#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/cli_unmirrorvg.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2003 
# 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 
# @(#)21        1.1  src/43haes/usr/sbin/cluster/cspoc/utilities/cli_unmirrorvg.sh, hacmp.cspoc, 61haes_r714 12/8/03 10:02:38

###############################################################################
#
#   COMPONENT_NAME: CSPOC Command Line Interface
#
# Name:
#   cli_unmirrorvg
#
# Description:
#   Use C-SPOC to run the unmirrorvg command with the given parameters and make the
#   volume group definition known on all cluster nodes
#
# Arguments:
#   Same as for the unmirrorvg command; assumed validated by caller
#
#   Physical volume names are assumed valid on the node this command is run
#   on; C-SPOC will handle the case where the disk names are different on
#   different nodes
#
#   Setting the environment variable _DEBUG to 1 -> 9 turns on levels of
#   C-SPOC debugging
#
# Return Values:
#   As set by cl_unmirrorvg
#
# Notes:
#   The '-f' flag is passed on cl_unmirrorvg to surpress unnecessary checking.
#   As a consequenc, the operation will proceed even if not all nodes are
#   accessable
#
################################################################################


typeset DEBUG
typeset cl_unmirrorvg_args

#
#   Variables needed by cl_unmirrorvg
#   _REFNODE - the node on which the hdisk names are chosen, since they
#           may differ across the cluster
#   _CSPOC_MODE - working with shared (as opposed to concurrent) volume
#           groups
#   _CSPOC_CALLED_FROM_SMIT - can skip checks on input
#
export _REFNODE=$(/usr/es/sbin/cluster/utilities/get_local_nodename)
export _CSPOC_MODE="shared"
export _CSPOC_CALLED_FROM_SMIT="true"

#
#   If a _DEBUG value has been set, pass it through
#
if [[ -n $_DEBUG ]] ; then

    #
    #   The debug level is a number, 1 through 9.  Those values are passed
    #   through.  Anything else is turned into '1'
    #
    integer dbg_level=$_DEBUG
    if (( $dbg_level < 10 && $dbg_level >= 1 )) ; then
    DEBUG="-d $_DEBUG"
    else
    DEBUG="-d 1"
    fi
fi

#
#   Construct the node list so that the local node shows up as first in the
#   list, since the physical volume names are relative to the local node.
#   This is a comma separated, quote delimited list of the nodes on which this
#   change is made.  It is set to all cluster nodes.
#
all_nodes=$(odmget -q "object = VERBOSE_LOGGING" HACMPnode | grep 'name =' | cut -f2 -d'"')
for node in $all_nodes ; do
    if [[ $node != $_REFNODE ]] ; then
        other_nodes=${other_nodes:+"${other_nodes},"}$node
    fi
done
export _NODE_LIST="$_REFNODE,$other_nodes"

#
#   The arguments to cl_unmirrorvg are the same as passed in, with addition of
#   the local node as reference node
#
cl_unmirrorvg_args="-R $_REFNODE $*"

#
#   Invoke the cspoc code to unmirror the volume group and make it known on all
#   cluster nodes.  
#
/usr/es/sbin/cluster/sbin/cl_unmirrorvg -cspoc "-f $DEBUG -n $_NODE_LIST" $cl_unmirrorvg_args
return $?