#!/bin/bsh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# tcpip720 src/tcpip/usr/sbin/mkqos/mkqos.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1999 
# 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 
#
# @(#)73	1.2  src/tcpip/usr/sbin/mkqos/mkqos.sh, tcpqos, tcpip720 4/23/99 22:16:49
#
#
#   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.
#

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

COMMAND_NAME=`/bin/basename $0`
MKITAB="/usr/sbin/mkitab"

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

set -- `/usr/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 take place (IPL)
	    if [ -n "${WHEN}" ] ; then echo "$USAGE"; exit 1 ; fi
	    WHEN="I"
	    shift
	    ;;
	"-N")			#WHEN should this 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")	# Start QoS now
	/etc/rc.qos
	;;
    "I"|"B")	# add the entry to inittab (if it doesn't exist)
	/usr/sbin/lsitab rcqos > /dev/null 2>&1 # check to see if it is there
	if [ $? -ne 0 ] ; then
		$MKITAB -i rctcpip "rcqos:2:wait:/etc/rc.qos > /dev/console 2>&1 # Start QoS"
		if [ $? -ne 0 ] ; then
			echo "${COMMAND_NAME}: error in adding entry to inittab\n"
			exit 1
		fi
	fi

	# Check to see if we need to start nfs
	if [ "${WHEN}" = "B" ] ; then
		/etc/rc.qos
	fi
	;;
esac
exit $?
