#!/bin/sh
#
#ident	"@(#)i.defrpcnisd	1.1	01/11/28 SMI"
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

# During an upgrade this class action script merges user modifications in
# the original ($dest) /etc/default/rpc.nisd into the new replacement
# /etc/default/rpc.nisd ($src) file.
#
# If there is no existing default/rpc.nisd file, the script simply copies
# the new default/rpc.nisd file into place. However, if there is an
# existing default/rpc.nisd file, the script greps out each line which sets
# a parameter in the original file and overwrites the corresponding line in
# the new default/rpc.nisd file.
#
# The script works by looping through each variable name, grepping out the
# apropos line, and creating a sed line, which when applied to the
# replacement default/rpc.nisd file will preserve modifications in the
# original default/rpc.nisd file.
#

while read src dest
do
	if [ ! -f $dest ] ; then
		cp -p $src $dest
	else
		sedfile=/tmp/sftmp.$$
		cat /dev/null > $sedfile

		for word in nisplusNumberOfServiceThreads \
		    nisplusMaxRPCRecordSize ENABLE_NIS_YP_EMULATION \
		    nisplusThreadCreationErrorAction \
		    nisplusThreadCreationErrorAttempts \
		    nisplusThreadCreationErrorTimeout nisplusDumpErrorAction \
		    nisplusDumpErrorAttempts nisplusDumpErrorTimeout \
		    nisplusResyncService nisplusUpdateBatching \
		    nisplusUpdateBatchingTimeout nisplusLDAPconfigDN \
		    nisplusLDAPconfigPreferredServerList \
		    nisplusLDAPconfigAuthenticationMethod nisplusLDAPconfigTLS \
		    nisplusLDAPconfigTLSCertificateDBPath \
		    nisplusLDAPconfigProxyUser nisplusLDAPconfigProxyPassword \
		    preferredServerList authenticationMethod defaultSearchBase \
		    nisplusLDAPbaseDomain nisplusLDAPTLS \
		    nisplusLDAPTLSCertificateDBPath nisplusLDAPproxyUser \
		    nisplusLDAPproxyPassword nisplusLDAPbindTimeout \
		    nisplusLDAPsearchTimeout nisplusLDAPmodifyTimeout \
		    nisplusLDAPaddTimeout nisplusLDAPdeleteTimeout \
		    nisplusLDAPsearchTimeLimit nisplusLDAPsearchSizeLimit \
		    nisplusLDAPfollowReferral nisplusLDAPinitialUpdateAction \
		    nisplusLDAPinitialUpdateOnly \
		    nisplusLDAPretrieveErrorAction \
		    nisplusLDAPretrieveErrorAttempts \
		    nisplusLDAPretrieveErrorTimeout \
		    nisplusLDAPstoreErrorAction nisplusLDAPstoreErrorAttempts \
		    nisplusLDAPstoreErrorTimeout nisplusLDAPrefreshErrorAction \
		    nisplusLDAPrefreshErrorAttempts \
		    nisplusLDAPrefreshErrorTimeout nisplusLDAPmatchFetchAction;
		    do

			oldline1=`grep -i "^$word=" $dest | \
					tail -1 2> /dev/null`
			oldline2=`grep -i "^#[ 	]*$word=" $dest | \
					tail -1 2> /dev/null`

			if [ -n "$oldline1" ]; then
				echo "s|^[# 	]*$word=.*|$oldline1|" >> $sedfile
			elif [ -n "$oldline2" ]; then
				echo "s|^[# 	]*$word=.*|$oldline2|" >> $sedfile
			fi

		done
		sed -f $sedfile $src > $dest 
		rm -f $sedfile       

	fi
done

exit 0

