OpenSolaris_b135/pkgdefs/common_files/i.defnfs

#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#ident	"%Z%%M%	%I%	%E% SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

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

#
# During an upgrade this class action script merges user modifications
# in the original ($dest) /etc/default/nfs into the new replacement
# /etc/default/nfs ($src) file.
#
# If there is no existing ($dest) nfs file, the script simply copies 
# the new ($src) default nfs file into place.  However, if there is an 
# existing ($dest) nfs file, the script greps out each line which sets 
# a parameter in the original file and overwrites the corresponding line 
# in the new ($src) file.  Since the entire line is ripped from the ($dest)
# original, the state of being commented or uncommented is implicitly passed 
# along into the replacement ($src) 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 ($src) file will preserve modifications in the original 
# ($dest) file.  
#
# We grep for both the commented keyword and the uncommented keyword.  We 
# pipe this grep through a 'tail -1' to insure that only one (1) line is
# returned.  Multiple lines will spoil the sed pattern, and we use a
# tail because the last uncommented ENV setting is the one which will take.  
# Although multiple entries ( commented or uncommented ) are possible we 
# preserve only the active ( uncommented ) entries.  The preservation is 
# accomplished by building a file of sed actions, which when applied to 
# the new nfs file ($src)  preserves the original ($dest) file settings.
#
# The logic for this merge is as follows: 
# 
# If both an active ( uncommented ) entry and an inactive ( commented ) 
# exist, we preserve the active entry and discard the inactive entry.
#
# If only an active ( uncommented ) entry exists we preserve the active
# entry.
#
# If only an inactive ( commented ) entry exists we preserve the inactive
# entry.  NOTE - the fact that a variable is commented out must be preserved
# because it too may be a user modification.
#

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

		for word in NFSD_MAX_CONNECTIONS NFSD_LISTEN_BACKLOG NFSD_PROTOCOL \
		    NFSD_DEVICE NFSD_SERVERS LOCKD_LISTEN_BACKLOG \
		    LOCKD_SERVERS LOCKD_RETRANSMIT_TIMEOUT LOCKD_GRACE_PERIOD \
		    NFS_SERVER_VERSMIN NFS_SERVER_VERSMAX \
		    NFS_CLIENT_VERSMIN NFS_CLIENT_VERSMAX \
		    NFS_SERVER_DELEGATION NFSMAPID_DOMAIN GRACE_PERIOD; do
			oldline1=`grep "^$word=" $dest | tail -1 2> /dev/null`
			oldline2=`grep "^#[ 	]*$word=" $dest | tail -1 2> /dev/null`

			if [ -n "$oldline1" ]; then
				if [ $word = "LOCKD_GRACE_PERIOD" ]; then
					# extract value of LOCKD_GRACE_PERIOD
					valuestr=`echo $oldline1 | \
					    sed -e 's|^'$word'=||'`
					# strip any trailing comment
					value=`echo $valuestr | \
					    sed -e 's|[^0-9].*||'`
					if [ "$value" != "45" ]; then
						echo "s|^$word=.*|#$word=90|" \
						    >> $sedfile
			echo "s|^GRACE_PERIOD=.*|GRACE_PERIOD=$valuestr|" \
						    >> $sedfile
					fi
					continue
				fi

				echo "s|^[# 	]*$word=.*|$oldline1|" >> $sedfile
			elif [ -n "$oldline2" ]; then
				#
				# If oldline is the old (commented-out) default,
				# we want to upgrade it. Any detectable mods by
				# the user will be preserved.
				#
				[ "$oldline2" = "#NFS_CLIENT_VERSMAX=3" ] &&
					continue;
				[ "$oldline2" = "#NFS_SERVER_VERSMAX=3" ] &&
					continue;
				[ "$oldline2" = "#NFS_SERVER_DELEGATION=off" ] &&
					continue;

				echo "s|^[# 	]*$word=.*|$oldline2|" >> $sedfile
			fi
		done

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

	fi
done

exit 0