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 (c) 1993-2001 by Sun Microsystems, Inc. 27 # All rights reserved. 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/login into the new replacement 36 # /etc/default/login ($src) file. 37 # 38 # If there is no existing ($dest) login file, the script simply copies 39 # the new ($src) default login file into place. However, if there is an 40 # existing ($dest) login 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 login 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/sftmp.$$ 79 cat /dev/null > $sedfile 80 81 for word in TIMEZONE ULIMIT CONSOLE PASSREQ ALTSHELL \ 82 PATH SUPATH TIMEOUT UMASK SYSLOG SLEEPTIME DISABLETIME \ 83 RETRIES SYSLOG_FAILED_LOGINS; do 84 85 oldline1=`grep "^$word=" $dest | tail -1 2> /dev/null` 86 oldline2=`grep "^#[ ]*$word=" $dest | tail -1 2> /dev/null` 87 88 if [ -n "$oldline1" ]; then 89 echo "s|^[# ]*$word=.*|$oldline1|" >> $sedfile 90 elif [ -n "$oldline2" ]; then 91 echo "s|^[# ]*$word=.*|$oldline2|" >> $sedfile 92 fi 93 94 done 95 96 sed -f $sedfile $src > $dest 97 rm -f $sedfile 98 99 fi 100 done 101 102 exit 0 103