#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r720 src/43haes/usr/sbin/cluster/cspoc/utilities/fix_args.sh 1.7 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1996,2015 
# 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 
# @(#)92  1.7  src/43haes/usr/sbin/cluster/cspoc/utilities/fix_args.sh, hacmp.cspoc, 61haes_r720, 1539B_hacmp720 9/10/15 13:35:43

###############################################################################
#   COMPONENT_NAME: CSPOC
#
# Name:
#       fix_args
#
# Description:
#	This is a wrapper script that is called by SMIT to call C-SPOC 
#	commands with the C-SPOC arguments properly formatted.
#
# Arguments:
#
# Return Values:
#
###############################################################################

#
# Main Starts Here
#

[[ $VERBOSE_LOGGING == "high" ]] && set -x
PROGNAME=${0##*/}
PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"
HA_DIR="es"


  typeset EXTRA_ARGS OPT=$1 CMD=$2 
  shift 2

  case $OPT in
    nop) # No filtering
	FILTER=""
      ;;
    lis) # List command filtering
	FILTER="| sed '/^.*#.*/d' | tr ':' '\011'"
      ;;
    dis) # Discover command filtering for a Group
	FILTER="| tail +3 | cut -d' ' -f2-500"
      ;;
    dis_u) # Discover command filtering for a User
	FILTER="| head -2 | cut -d' ' -f2-500"
      ;;
    sel) # Selector command filtering
	FILTER="| cut -d' ' -f2 | sort -u"
      ;;
  esac

  case $CMD in
    cl_rc.cluster)
      EXTRA_ARGS="-boot"
      ;;
  esac

  while (( $# > 0 ))
  do
    case $1 in
      -cspoc-n)
        FIRST_ARGS="$FIRST_ARGS -cspoc \"-n $2\""
	shift 2
        ;;

      -cspoc-g)
        FIRST_ARGS="$FIRST_ARGS -cspoc \"-g $2\""
	shift 2
        ;;

      -cspoc-f)
        FIRST_ARGS="$FIRST_ARGS -cspoc \"-f\""
	shift 1
        ;;

      *)
        CMD_ARGS="$CMD_ARGS \"$1\""
	shift
        ;;

    esac
  done

  eval $CMD $FIRST_ARGS $EXTRA_ARGS $CMD_ARGS $FILTER