Home | History | Annotate | Download | only in common_files
      1 #!/bin/sh
      2 #
      3 # CDDL HEADER START
      4 #
      5 # The contents of this file are subject to the terms of the
      6 # Common Development and Distribution License, Version 1.0 only
      7 # (the "License").  You may not use this file except in compliance
      8 # with the License.
      9 #
     10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     11 # or http://www.opensolaris.org/os/licensing.
     12 # See the License for the specific language governing permissions
     13 # and limitations under the License.
     14 #
     15 # When distributing Covered Code, include this CDDL HEADER in each
     16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     17 # If applicable, add the following below this CDDL HEADER, with the
     18 # fields enclosed by brackets "[]" replaced with your own identifying
     19 # information: Portions Copyright [yyyy] [name of copyright owner]
     20 #
     21 # CDDL HEADER END
     22 #
     23 #
     24 #ident	"%Z%%M%	%I%	%E% SMI"
     25 #
     26 # Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
     27 # Use is subject to license terms.
     28 #
     29 
     30 PATH="/usr/bin:/usr/sbin:${PATH}"
     31 export PATH
     32 
     33 #
     34 # During an upgrade this class action script merges user modifications
     35 # in the original ($dest) /etc/default/nfs into the new replacement
     36 # /etc/default/nfs ($src) file.
     37 #
     38 # If there is no existing ($dest) nfs file, the script simply copies 
     39 # the new ($src) default nfs file into place.  However, if there is an 
     40 # existing ($dest) nfs file, the script greps out each line which sets 
     41 # a parameter in the original file and overwrites the corresponding line 
     42 # in the new ($src) file.  Since the entire line is ripped from the ($dest)
     43 # original, the state of being commented or uncommented is implicitly passed 
     44 # along into the replacement ($src) file. 
     45 #
     46 # The script works by looping through each variable name, grepping out
     47 # the apropos line, and creating a sed line, which when applied to the
     48 # replacement ($src) file will preserve modifications in the original 
     49 # ($dest) file.  
     50 #
     51 # We grep for both the commented keyword and the uncommented keyword.  We 
     52 # pipe this grep through a 'tail -1' to insure that only one (1) line is
     53 # returned.  Multiple lines will spoil the sed pattern, and we use a
     54 # tail because the last uncommented ENV setting is the one which will take.  
     55 # Although multiple entries ( commented or uncommented ) are possible we 
     56 # preserve only the active ( uncommented ) entries.  The preservation is 
     57 # accomplished by building a file of sed actions, which when applied to 
     58 # the new nfs file ($src)  preserves the original ($dest) file settings.
     59 #
     60 # The logic for this merge is as follows: 
     61 # 
     62 # If both an active ( uncommented ) entry and an inactive ( commented ) 
     63 # exist, we preserve the active entry and discard the inactive entry.
     64 #
     65 # If only an active ( uncommented ) entry exists we preserve the active
     66 # entry.
     67 #
     68 # If only an inactive ( commented ) entry exists we preserve the inactive
     69 # entry.  NOTE - the fact that a variable is commented out must be preserved
     70 # because it too may be a user modification.
     71 #
     72 
     73 while read src dest
     74 do
     75 	if [ ! -f $dest ] ; then
     76 		cp -p $src $dest
     77 	else
     78 		sedfile=/tmp/nfstmp.$$
     79 		cat /dev/null > $sedfile
     80 
     81 		for word in NFSD_MAX_CONNECTIONS NFSD_LISTEN_BACKLOG NFSD_PROTOCOL \
     82 		    NFSD_DEVICE NFSD_SERVERS LOCKD_LISTEN_BACKLOG \
     83 		    LOCKD_SERVERS LOCKD_RETRANSMIT_TIMEOUT LOCKD_GRACE_PERIOD \
     84 		    NFS_SERVER_VERSMIN NFS_SERVER_VERSMAX \
     85 		    NFS_CLIENT_VERSMIN NFS_CLIENT_VERSMAX \
     86 		    NFS_SERVER_DELEGATION NFSMAPID_DOMAIN GRACE_PERIOD; do
     87 			oldline1=`grep "^$word=" $dest | tail -1 2> /dev/null`
     88 			oldline2=`grep "^#[ 	]*$word=" $dest | tail -1 2> /dev/null`
     89 
     90 			if [ -n "$oldline1" ]; then
     91 				if [ $word = "LOCKD_GRACE_PERIOD" ]; then
     92 					# extract value of LOCKD_GRACE_PERIOD
     93 					valuestr=`echo $oldline1 | \
     94 					    sed -e 's|^'$word'=||'`
     95 					# strip any trailing comment
     96 					value=`echo $valuestr | \
     97 					    sed -e 's|[^0-9].*||'`
     98 					if [ "$value" != "45" ]; then
     99 						echo "s|^$word=.*|#$word=90|" \
    100 						    >> $sedfile
    101 			echo "s|^GRACE_PERIOD=.*|GRACE_PERIOD=$valuestr|" \
    102 						    >> $sedfile
    103 					fi
    104 					continue
    105 				fi
    106 
    107 				echo "s|^[# 	]*$word=.*|$oldline1|" >> $sedfile
    108 			elif [ -n "$oldline2" ]; then
    109 				#
    110 				# If oldline is the old (commented-out) default,
    111 				# we want to upgrade it. Any detectable mods by
    112 				# the user will be preserved.
    113 				#
    114 				[ "$oldline2" = "#NFS_CLIENT_VERSMAX=3" ] &&
    115 					continue;
    116 				[ "$oldline2" = "#NFS_SERVER_VERSMAX=3" ] &&
    117 					continue;
    118 				[ "$oldline2" = "#NFS_SERVER_DELEGATION=off" ] &&
    119 					continue;
    120 
    121 				echo "s|^[# 	]*$word=.*|$oldline2|" >> $sedfile
    122 			fi
    123 		done
    124 
    125 		sed -f $sedfile $src > $dest
    126 		rm -f $sedfile       
    127 
    128 	fi
    129 done
    130 
    131 exit 0
    132