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 (the "License").
      7 # You may not use this file except in compliance with the License.
      8 #
      9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10 # or http://www.opensolaris.org/os/licensing.
     11 # See the License for the specific language governing permissions
     12 # and limitations under the License.
     13 #
     14 # When distributing Covered Code, include this CDDL HEADER in each
     15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16 # If applicable, add the following below this CDDL HEADER, with the
     17 # fields enclosed by brackets "[]" replaced with your own identifying
     18 # information: Portions Copyright [yyyy] [name of copyright owner]
     19 #
     20 # CDDL HEADER END
     21 #
     22 #
     23 #ident	"%Z%%M%	%I%	%E% SMI"
     24 #
     25 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     26 # Use is subject to license terms.
     27 #
     28 
     29 PATH="/usr/bin:/usr/sbin:${PATH}"
     30 export PATH
     31 
     32 #
     33 # This class action script is based on the fact that unique identifiers
     34 # used by Sun are reserved for Sun usage ONLY and can be removed or 
     35 # updated as needed. 
     36 #
     37 # User defined entries and comments in an existing inittab file will be
     38 # preserved and appended to the new ($src) inittab file.  
     39 #
     40 # If there is no existing ($dest) inittab file, the script simply copies 
     41 # the new ($src) inittab file into place.  However, if there is an existing 
     42 # ($dest) inittab file, the script attempts to strip out all Sun Reserved 
     43 # lines, what remains should be the user defined entries and comments 
     44 # which are subsequently appended to the new ($src) inittab file.
     45 #
     46 # The script works by generating two sets of sed parameters which 
     47 # will strip out the Sun Reserved unique identifiers from the existing 
     48 # inittab file. 
     49 #
     50 # PRMVALCUR - a list of sed regular expressions generated from the 
     51 # 	unique identifier field of the new ($src) inittab file.
     52 #
     53 #	- this parameter list is generated from the $src inittab file by 
     54 #	stripping out all comment lines, taking the remaining lines which 
     55 #	match the regular expression /:(.*):(.*):/ and stripping out the 
     56 #	two character uniq id field, which is then used to construct a 
     57 #	a sed parameter list of the type '-e /^<uniq id>:/d' which will
     58 #	delete out lines matching the uniq id.
     59 #
     60 # PRMVALOLD - sed regular expression removal parameters for old unique 
     61 #	identifier entries.  These are here in case an existing unique 
     62 #	identifier is retired in some future version of the inittab file.
     63 #	
     64 #	- this parameter list is a static list which contains all 
     65 #	unique identifiers used by Solaris since 2.51 on both sparc and 
     66 #	x86.  If a uniq id is retired from the inittab file it will no 
     67 #	longer be properly stripped via PRMVALCUR in an upgrade. This 
     68 #	parameter list insures that uniq id removals in the inittab will
     69 #	not require modification of this class action script.  This 
     70 #	script will only require modification if a new entry is made 
     71 #	to the inittab, which is subsequently removed.  In which case 
     72 #	the uniq id of that entry should be added to this parameter list.
     73 #
     74 # The new ($src) inittab file is copied to a temporary location.  The
     75 # existing ($dest) inittab file is then run through sed with the 
     76 # parameters defined above.  The results are then appended to the
     77 # temporary copy of the ($src) inittab, skipping anything before
     78 # '^#ident', which is where the Sun comment block ends.  The results
     79 # are then copied back onto the original temp file to ensure file
     80 # ownership and permissions are preserved.  This resulting file
     81 # representing the merge between the old and new inittab is then
     82 # copied into place.
     83 #
     84 # We also pick up any customizations of the ttymon invocation.
     85 
     86 ttymonopts() {
     87 	ttymon_nohangup=false
     88 	while getopts d:ghl:m:p:T:t: opt
     89 	do
     90 		case $opt in
     91 		d) ttymon_device=$OPTARG ;;
     92 		h) ttymon_nohangup=true ;;
     93 		l) ttymon_label=$OPTARG ;;
     94 		m) ttymon_modules=$OPTARG ;;
     95 		p) ttymon_prompt=$OPTARG ;;
     96 		T) ttymon_termtype=$OPTARG ;;
     97 		t) ttymon_timeout=$OPTARG ;;
     98 		*) ;;
     99 		esac
    100 	done
    101 }
    102 
    103 updatettymon() {
    104 	SEDCMD='s+\`+\\\`+g;s+\$+\\\$+g;'
    105 	TTYMONLINE="^co:234:respawn:/usr/lib/saf/ttymon"
    106 	tmp=`grep $TTYMONLINE $dest | sed "s+$TTYMONLINE+ttymonopts+;$SEDCMD"`
    107 	eval $tmp
    108 
    109 	ttymon_prompt=`echo $ttymon_prompt | sed $SEDCMD`
    110 
    111 	cat >> $PKG_INSTALL_ROOT/var/svc/profile/upgrade <<-EOFA
    112 
    113 ttymon_opt() {
    114 	/usr/sbin/svccfg -f - <<-EOFB
    115 select system/console-login
    116 setprop ttymon/\$1 = "\$2"
    117 EOFB
    118 }
    119 
    120 [ -n "$ttymon_device" ] && ttymon_opt device "$ttymon_device"
    121 [ -n "$ttymon_nohangup" ] && ttymon_opt nohangup "$ttymon_nohangup"
    122 [ -n "$ttymon_label" ] && ttymon_opt label "$ttymon_label"
    123 [ -n "$ttymon_modules" ] && ttymon_opt modules "$ttymon_modules"
    124 [ -n "$ttymon_prompt" ] && ttymon_opt prompt "$ttymon_prompt"
    125 [ -n "$ttymon_termtype" ] && ttymon_opt terminal_type "$ttymon_termtype"
    126 [ -n "$ttymon_timeout" -a "$ttymon_timeout" -ne 0 ] && \
    127     ttymon_opt timeout "$ttymon_timeout"
    128 
    129 /usr/sbin/svcadm refresh svc:/system/console-login
    130 
    131 EOFA
    132 }
    133 
    134 while read src dest; do
    135 	if [ ! -f $dest ]; then
    136 		cp -p $src $dest
    137 	else
    138 		updatettymon
    139 
    140 		PRMVALCUR=`sed -e '/^#/d' $src | awk '
    141 			    /^[^:]*:[^:]*:[^:]*:/{ split ($0,tmp,":");
    142 			      if ( length ( tmp[1] ) > 0 && tmp[1] != $0 )
    143 			          param=" -e /^" tmp[1] ":/d" param;
    144 			    }
    145 			END { print param ; }'`
    146 
    147 		PRMVALOLD='	-e /^co:/d -e /^sc:/d -e /^rb:/d -e /^of:/d 
    148 				-e /^fw:/d -e /^s6:/d -e /^s5:/d -e /^s3:/d 
    149 				-e /^s2:/d -e /^s1:/d -e /^s0:/d -e /^sS:/d 
    150 				-e /^p3:/d -e /^is:/d -e /^fs:/d -e /^ap:/d 
    151 				-e /^sp:/d '
    152 
    153 		cp -p $src /tmp/d1.$$
    154 		sed $PRMVALCUR $dest | sed $PRMVALOLD | awk '
    155 			/^#/ { if (end_sun_comments) print $0 }
    156 			!/^#/ { end_sun_comments = 1; print $0 }
    157 		' >>/tmp/d1.$$
    158 		cp -p /tmp/d1.$$ $dest
    159 		rm -f /tmp/d1.$$
    160 	fi
    161 done
    162 
    163 exit 0
    164