#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/lpp/cluster/samples/appsvclabel/clchipdev.sh 1.6 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2006,2011 
# 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 
# @(#)10	1.6 src/43haes/usr/lpp/cluster/samples/appsvclabel/clchipdev.sh, hacmp.utils, 61haes_r714 11/28/11 15:12:02
###############################################################################
#
#  Name:  clchipdev
#
#  A sample script to help users configure their service IP label correctly
#
#  Syntax:
#  clchdevip -n <nodeame> -w <network_name> -a 'APP_SVC_LABEL=BOOT_LABEL ...' [-d alternate_HW_addr]
#
#
#
#  Arguments:   
#
#  Returns:     0 on SUCCESS
#               1 on FAILURE
#
###############################################################################


##############################################################################
#
# Prints usage message and exits the program.
#
# Arguments:  none
#
# Returns:    does not return
#
################################################################################
usage() {
    set +u
    [[ "$VERBOSE_LOGGING" == "high" ]] && set -x
    set -u
     cl_echo 10011  "Usage: $PROGNAME -n <node_name> -w <network_name> -a 'App_IP_Addr1=Boot_Addr1...' [-d <alternate_hardware_addr]\n" $PROGNAME
    exit 1
}


###############################################################################
# Main program procedure.
###############################################################################

PROGNAME=$(basename ${0})

# Set the path so that we can find cl_get_path
# regardless of whether we are running HAES or 'classic' HACMP.
#
PATH=${PATH}:/usr/sbin/cluster/utilities:/usr/es/sbin/cluster/utilities


PATH="$(cl_get_path all)"
HA_DIR="$(cl_get_path)"
export PATH

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
[[ "$VERBOSE_LOGGING" == "high" ]] && version='1.5'

# Determine what node we are on

LOCALNODENAME=$(odmget HACMPcluster | grep -w nodename | cut -d'"' -f2)
NODE_NAME=""
NETWORK_NAME=""
ALT_HW_ADDR=""

# Parse the command line.
while getopts ":n:a:w:d:" opt
  do
  case $opt in
      n)

      NODE_NAME=$OPTARG
      ;;
      w)
       NETWORK_NAME=$OPTARG
      ;;

      :)  usage
      ;;
      a)  LIST_ADDR=$OPTARG
      ;;
      d) ALT_FLAG="true"
      ALT_HW_ADDR=$OPTARG
      ;;
  esac
done

#  ## print error specific message 
# Parse the arg and print usage if error
if [[ $NODE_NAME == "" ]]; then
       usage
fi
if [[ $NETWORK_NAME == "" ]]; then
    usage
fi
if [[ $LIST_ADDR == "" ]]; then
      usage
fi
if [[ $ALT_FLAG == "true" ]]; then
    if [[ $ALT_HW_ADDR == "" ]]; then
   	usage
    fi
fi


# Check for the arguments ; If node name is not valid cl_rsh will fail.

#print $LOCALNODENAME 

if [[ $NODE_NAME == $LOCALNODENAME ]];
    then
    /usr/${HA_DIR}/sbin/cluster/samples/appsvclabel/cl_execute_chipdev $NETWORK_NAME "$LIST_ADDR"  $ALT_HW_ADDR
else
    cl_rsh "$NODE_NAME" /usr/${HA_DIR}/sbin/cluster/samples/appsvclabel/cl_execute_chipdev "$NETWORK_NAME" $LIST_ADDR $ALT_HW_ADDR
fi

if [[ $? != 0 ]]; then

cl_echo 10012 "$PROGNAME: Failed\n" $PROGNAME
 exit 1
fi 

exit 0









