#!/bin/bsh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# tcpip72F src/tcpip/usr/sbin/rmqos/rmqos.sh 1.4.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999,2016 
# 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 
#
# @(#)09	1.4.1.1  src/tcpip/usr/sbin/rmqos/rmqos.sh, tcpqos, tcpip72F, f2016_28A2 7/11/16 14:54:47
#
#
#   COMPONENT_NAME: TCPQOS
#
#   FUNCTIONS:
#
#   ORIGINS: 27
#
#   (C) COPYRIGHT International Business Machines Corp. 1999
#   All Rights Reserved
#   Licensed Materials - Property of IBM
#   US Government Users Restricted Rights - Use, duplication or
#   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#

PATH=/usr/bin:/usr/sbin:$PATH
export PATH

set -f			# this is so that the case statement will work

COMMAND_NAME=`/bin/basename $0`
RMITAB=/usr/sbin/rmitab

USAGE="
usage:  ${COMMAND_NAME}	[{-I|-B|-N}]\n"

stop_daemons()
{
        if [ -f /usr/sbin/rsvpd ]; then
                stopsrc -f -s rsvpd
        fi
        if [ -f /usr/sbin/policyd ]; then
                stopsrc -f -s policyd
        fi
	sleep 2
}

unload_ke ()
{
	if [ -x /usr/lib/methods/ucfgqos ]
	then
		/usr/lib/methods/ucfgqos > /dev/null 2>&1
		if [ $? -eq 17 ]   # QoS kernel extension not loaded
		then
			return 0
		fi
	else
		return 1
	fi
}

set -- `/bin/getopt IBN $*  2>/dev/null` 
if [ $? != 0 ] ; then         # Test for syntax error
    echo "${USAGE}"
    exit 1
fi

while [ $1 != -- ]
do
    case "$1" in
	"-I")			#WHEN should this change take place (IPL)
	    if [ -n "${WHEN}" ] ; then echo "$USAGE"; exit 1 ; fi
	    WHEN="I"
	    shift
	    ;;
	"-N")			#WHEN should this change take place (NOW)
	    if [ -n "${WHEN}" ] ; then echo "$USAGE"; exit 1 ; fi
	    WHEN="N"
	    shift
	    ;;
	"-B")			#WHEN should this take place (BOTH)
	    if [ -n "${WHEN}" ] ; then echo "$USAGE"; exit 1 ; fi
	    WHEN="B"
	    shift
	    ;;
	*)
	    echo "$USAGE"
	    exit 1
	    ;;
    esac
done

# check to make sure that there are not any extra parameters
shift		# get rid of the -- parameter
if [ -n "$1" ] ; then	# something extra here.
    echo "${USAGE}"
    exit 1
fi

# Set the default for WHEN the 'operation' is to take place
# Set WHEN only if it has not been specified.
WHEN=${WHEN:-"B"}

case "${WHEN}" in
    "N")	# stop qos without changing INITTAB
	# Call function to stop daemon process etc...
	stop_daemons

	# Unload the QoS kernel extension
	unload_ke

	if [ $? -ne 0 ] ; then
		MESG=`/usr/bin/dspmsg -s 1 rmqos.cat 1 \
		"${COMMAND_NAME}: error unloading QoS kernel extension\n" ${COMMAND_NAME} `
		echo "$MESG"
	fi
	;;
    "I"|"B")	# remove the rcqos entry in inittab
	$RMITAB rcqos > /dev/null 2>& 1
	if [ $? -ne 0 ] ; then
                MESG=`/usr/bin/dspmsg -s 1 rmqos.cat 2 \
	        "${COMMAND_NAME}: error in removing \"rcqos\" entry from inittab\n" ${COMMAND_NAME} `
		echo "$MESG"
	fi
	
	# Check to see if we need to stop qos now
	if [ "${WHEN}" = "B" ] ; then
	    # Call function to stop daemon process etc...
	    stop_daemons
	    unload_ke
		if [ $? -ne 0 ] ; then
			MESG=`/usr/bin/dspmsg -s 1 rmqos.cat 1 \
			"${COMMAND_NAME}: error unloading QoS kernel extension\n" ${COMMAND_NAME} `
			echo "$MESG"
		fi
	fi
	;;
esac
exit $?