#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/events/utils/cl_SNAapp.sh 1.4 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1998,2004 
# 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 
# @(#)39	1.4 src/43haes/usr/sbin/cluster/events/utils/cl_SNAapp.sh, hacmp.hawan, 61haes_r714 2/20/04 10:54:01
###############################################################################
#
#  Name: cl_SNAapp
#
#  Starts and stops an SNA application layer
#
#  Flags:
#        -start
#        -stop
#
#  Inputs:
#
#     -Configuration file
#     -Link Type
#
#  Returns:
#       0 -  Success
#      -1 -  Failure
#
###############################################################################

USAGE="Usage: $0 [-start/-stop] config_file"

if (($# == 3))
then
	FLAG=$1
	CONFIGFILE=$2
	LINKTYPE=$3
	# Check configuration file exists
	if [[ ! -f $CONFIGFILE ]]
	then
		echo "Configuration file does not exist"
		exit -1
	fi
	
	# Now crunch the config file to create the start and stop modules	
	START=`cat $CONFIGFILE | grep -n START | cut -f 1 -d":"`
	((STARTSTART = START + 1))
	STOP=`cat $CONFIGFILE | grep -n STOP | cut -f 1 -d":"`
	((ENDSTART = STOP - 1))
	((STARTSTOP = STOP + 1))
	/usr/bin/csplit -s $CONFIGFILE $STARTSTART $STOP $STARTSTOP
	if [[ $FLAG = "-start" ]]
	then
		echo "Starting..."
		ksh xx01 "$LINKTYPE" &
		exit 0
	elif [[ $FLAG = "-stop" ]]
	then
		echo "Stopping..."
		ksh xx03 "$LINKTYPE" &
		exit 0
	else
		echo "Invalid flag"
		rm xx*	
		exit -1
	fi
else
        print $USAGE
	exit -1
fi
exit 0

