#!/bin/sh
#
# postbackout script for SunCluster 2.2 CDB patch.
#
# Gather the cluster name and CDB file location
# PatchNum variable is inherited from the backout patch script
#

DEF_CLS_NAME=/etc/opt/SUNWcluster/conf/default_clustername
CDB_LOC=/etc/opt/SUNWcluster/conf
 
if [ ! -f ${DEF_CLS_NAME} ]; then
        echo "${DEF_CLS_NAME} non-existent"
        exit 1
fi
 
read clust < $DEF_CLS_NAME
 
CDB_FL=$CDB_LOC/$clust.cdb
 
if [ ! -f ${CDB_FL} ]; then
        echo "${CDB_FL} non-existent"
        exit 1
fi

/usr/bin/cp ${CDB_FL} ${CDB_FL}.${PatchNum}

#
# handle the comment line first, check to see if this was 
# the first patch that put the comment in the file. If
# not put the comment back into the real file.
#

grep -v "^# RPC monitoring tunable parameters." ${CDB_FL}.${PatchNum} > ${CDB_FL}

oldcomment=`grep "^# RPC monitoring tunable parameters." /var/sadm/patch/${PatchNum}/cdb.${PatchNum}`

if [ "${oldcomment}" ]
	then
	echo ${oldcomment} >> ${CDB_FL}
fi

#
# now handle the actual values themselves.
#
# Build a file containing the key : value pairs which we can then parse
# individually.
#

/usr/bin/cp ${CDB_FL} ${CDB_FL}.${PatchNum}

grep -v "^rpcmon" ${CDB_FL}.${PatchNum} > ${CDB_FL}
grep "^rpcmon" ${CDB_FL}.${PatchNum} > ${CDB_FL}.rpcmon

params=`cat ${CDB_FL}.rpcmon | cut -f1`

#
# work through all the parameters in a loop.
#

for param in ${params}
do

	#
	# First, gather the value for this key.
	#

	value=`grep ${param} ${CDB_FL}.rpcmon | cut -d":" -f2 | cut -d" " -f2`

	#
	# Check the stored copy of the cdb file from the patch's application,
	# if the key : value pair existed in there then restore them into the
	# working cdb.
	#

	oldparam=`grep ${param} /var/sadm/patch/${PatchNum}/cdb.${PatchNum}`

	if [ "${oldparam}" ]
		then
		echo "${oldparam}" >> ${CDB_FL}
	fi

	#
	# Check the parameter's value against the default value - if it
	# changed the store a copy under /var/opt/SUNWcluster for reference
	#

	case ${param} in
		rpcmon.action)
			defvalue="abort"
			;;
		rpcmon.retries)
			defvalue="1"
			;;
		rpcmon.ival)
			defvalue="30"
			;;
		rpcmon.noresponse)
			defvalue="5"
			;;
		rpcmon.loops)
			defvalue="0"
			;;
		rpcmon.sleep)
			defvalue="2"
			;;
		esac

	if [ "${value}" != "${defvalue}" ]
		then
		echo "${param} : ${value}" >> /var/opt/SUNWcluster/cdb.paramlog
	fi

	#
	# and back round the loop for the next parameter
	#

done

#
# Remove our temporary working files and exit the script
#

if [ -r ${CDB_FL}.${PatchNum} ]
	then
	rm ${CDB_FL}.${PatchNum}
fi

if [ -r ${CDB_FL}.rpcmon ]
	then
	rm ${CDB_FL}.rpcmon
fi

exit 0
