#!/usr/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/filenet/sbin/cl_filenet_pe_etc_rc_dt_collector.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010 
# 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.1  src/43haes/usr/sbin/cluster/sa/filenet/sbin/cl_filenet_pe_etc_rc_dt_collector.sh, hacmp, 61haes_r714 11/28/11 15:05:11
############################################################################
#
# Name:         cl_filenet_pe_etc_rc_dt_collector
#
# Description:  1. This script is used to have following entries
#		at the beginning of file /etc/rc.dt
#		
#		/usr/sbin/no -o tcp_sendspace=16384
#		/usr/sbin/no -o tcp_recvspace=16384
#		/usr/sbin/no -o tcp_keepidle=80
#		/usr/sbin/no -o tcp_keepintvl=20
#		/usr/sbin/no -o tcp_ephemeral_high=65535
#		/usr/sbin/no -o tcp_ephemeral_low=42767
#		/usr/sbin/no -o udp_ephemeral_high=65535
#		/usr/sbin/no -o udp_ephemeral_low=42767
#
#		Any missing entries will be automatically
#		updated. If /etc/rc.dt file doesn't exist
#		file will be created after updating above
#		entries.
#
#		2. Below mentioned commands would be excuted
#		
#		/usr/sbin/no -p -o tcp_sendspace=16384
#		/usr/sbin/no -p -o tcp_recvspace=16384
#		/usr/sbin/no -p -o tcp_keepidle=80
#		/usr/sbin/no -p -o tcp_keepintvl=20
#		/usr/sbin/no -p -o tcp_ephemeral_high=65535
#		/usr/sbin/no -p -o tcp_ephemeral_low=42767
#		/usr/sbin/no -p -o udp_ephemeral_high=65535
#		/usr/sbin/no -p -o udp_ephemeral_low=42767
#
#		With the execution of above commands, entries will
#		be made under "no" section in "/etc/tunables/nextboot"
#
#		At first availablity of entries would be verified using
#		"no" command, any missing entries will be updated
#		after executing above respective command.
#
# Arguments:    n/a
#
# Returns:      n/a
#
############################################################################


#
# Required entries in /etc/rc.dt file
#

#
# Checking /etc/rc.dt file exists or not
#
typeset TOTAL_COUNT=8
typeset INDEX_LIST="tcp_sendspace tcp_recvspace tcp_keepidle tcp_keepintvl \
tcp_ephemeral_high tcp_ephemeral_low udp_ephemeral_high udp_ephemeral_low"

typeset -A VALS
VALS=( \
[tcp_sendspace]="/usr/sbin/no -o tcp_sendspace=16384"
[tcp_recvspace]="/usr/sbin/no -o tcp_recvspace=16384"
[tcp_keepidle]="/usr/sbin/no -o tcp_keepidle=80"
[tcp_keepintvl]="/usr/sbin/no -o tcp_keepintvl=20"
[tcp_ephemeral_high]="/usr/sbin/no -o tcp_ephemeral_high=65535"
[tcp_ephemeral_low]="/usr/sbin/no -o tcp_ephemeral_low=42767"
[udp_ephemeral_high]="/usr/sbin/no -o udp_ephemeral_high=65535"
[udp_ephemeral_low]="/usr/sbin/no -o udp_ephemeral_low=42767"
)

if [[ -f /etc/rc.dt ]]
then
	for index in $INDEX_LIST
	do
		cat /etc/rc.dt | grep -v "#" | grep -v -e "^$" | \
		head -n $TOTAL_COUNT | grep -w $index > /dev/null 2>&1
		(( $? != 0 )) && {
			line_num=$(cat -n /etc/rc.dt | grep -v "#" | head -1 | awk '{print $1}')
			if (( $line_num != 1 ))
			then
				#
				# Insertion of required entry at line number "$line_num"
				# in /etc/rc.dt file
				#
				echo "${line_num}i\n${VALS[$index]}\n.\nwq" | ex -s /etc/rc.dt
			else
				#
				# If "$line_num" is 1 then insert at first line of /etc/rc.dt
				#
				echo "1i\n${VALS[$index]}\n.\nwq" | ex -s /etc/rc.dt
			fi
		}
	done
else
	#
	# As the configuration file /etc/rc.dt doesn't exist, we are
	# creating here and is required for process engine (one of the
	# sub-components of FileNet P8)
	#
	typeset DATE
	DATE=$(date +"%m/%d/%y %H:%M:%S")
	echo "#!/usr/bin/ksh93" > /etc/rc.dt
	echo "#" >> /etc/rc.dt
	echo "# This file was created \
by \"/usr/es/sbin/cluster/sa/filenet/sbin/cl_filenet_pe_etc_rc_dt_collector\"" >> /etc/rc.dt
	echo "# as part of FileNet P8 smart assist on \"$DATE\" during" >> /etc/rc.dt
	echo "# verification process, and is required for \
Process Engine (one of the sub-components of FileNet)" >> /etc/rc.dt
	echo "#" >> /etc/rc.dt
	echo "/usr/sbin/no -o tcp_sendspace=16384" >> /etc/rc.dt
	echo "/usr/sbin/no -o tcp_recvspace=16384" >> /etc/rc.dt
	echo "/usr/sbin/no -o tcp_keepidle=80" >> /etc/rc.dt
	echo "/usr/sbin/no -o tcp_keepintvl=20" >> /etc/rc.dt
	echo "/usr/sbin/no -o tcp_ephemeral_high=65535" >> /etc/rc.dt
	echo "/usr/sbin/no -o tcp_ephemeral_low=42767" >> /etc/rc.dt
	echo "/usr/sbin/no -o udp_ephemeral_high=65535" >> /etc/rc.dt
	echo "/usr/sbin/no -o udp_ephemeral_low=42767" >> /etc/rc.dt
fi

#
# Executing below commands to have entries
# under "no" section in /etc/tunables/nextboot
#
/usr/sbin/no -p -o tcp_sendspace=16384 > /dev/null 2>&1
/usr/sbin/no -p -o tcp_recvspace=16384 > /dev/null 2>&1
/usr/sbin/no -p -o tcp_keepidle=80 > /dev/null 2>&1
/usr/sbin/no -p -o tcp_keepintvl=20 > /dev/null 2>&1
/usr/sbin/no -p -o tcp_ephemeral_high=65535 > /dev/null 2>&1
/usr/sbin/no -p -o tcp_ephemeral_low=42767 > /dev/null 2>&1
/usr/sbin/no -p -o udp_ephemeral_high=65535 > /dev/null 2>&1
/usr/sbin/no -p -o udp_ephemeral_low=42767 > /dev/null 2>&1
