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 # 24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25 # Use is subject to license terms. 26 # 27 #ident "%Z%%M% %I% %E% SMI" 28 29 PATH=/usr/bin:/usr/sbin:$PATH; export PATH 30 31 # 32 # obsolete_sparc - Filter function to remove obsolete SPARC driver entries. 33 # We define an associative array of bad driver names, and then nawk out 34 # lines where the first token is defined in our array. 35 # 36 obsolete_sparc() 37 { 38 nawk 'BEGIN { 39 obs["rip"] = 1; 40 obs["svloop"] = 1; 41 obs["tcl"] = 1; 42 obs["tco"] = 1; 43 obs["tcoo"] = 1; 44 obs["sp"] = 1; 45 obs["consfb"] = 1; 46 obs["dbri"] = 1; 47 obs["XXunusedXX"] = 1; 48 obs["sw"] = 1; 49 obs["cgtwo"] = 1; 50 obs["xy"] = 1; 51 obs["xd"] = 1; 52 obs["pc"] = 1; 53 obs["app"] = 1; 54 obs["evq"] = 1; 55 obs["win"] = 1; 56 obs["svarp"] = 1; 57 obs["svip"] = 1; 58 obs["svrip"] = 1; 59 obs["svicmp"] = 1; 60 obs["svudp"] = 1; 61 obs["svtcp"] = 1; 62 obs["vme"] = 1; 63 obs["ie"] = 1; 64 obs["qe"] = 1; 65 obs["qec"] = 1; 66 obs["ncr"] = 1; 67 obs["xt"] = 1; 68 obs["id"] = 1; 69 obs["vmemem"] = 1; 70 obs["pn"] = 1; 71 obs["kmac"] = 1; 72 obs["ipi3sc"] = 1; 73 obs["cgfour"] = 1; 74 obs["cgeight-p4"] = 1; 75 obs["xdc"] = 1; 76 obs["xyc"] = 1; 77 obs["mcp"] = 1; 78 obs["mcpzsa"] = 1; 79 obs["mcpp"] = 1; 80 obs["be"] = 1; 81 obs["p9000"] = 1; 82 obs["p9100"] = 1; 83 obs["pci"] = 1; 84 obs["profile"] = 1; 85 obs["eeprom"] = 1; 86 obs["PFUaga"] = 1; 87 obs["atapicd"] = 1; 88 obs["cgeight"] = 1; 89 obs["cgfourteen"] = 1; 90 obs["xbox"] = 1; 91 obs["sx"] = 1; 92 obs["sx_cmem"] = 1; 93 obs["stc"] = 1; 94 obs["bbc"] = 1; 95 obs["gptwo"] = 1; 96 obs["bwtwo"] = 1; 97 obs["cgthree"] = 1; 98 obs["obio"] = 1; 99 obs["cpu"] = 1; 100 obs["bootbus"] = 1; 101 obs["sbi"] = 1; 102 obs["mic"] = 1; 103 obs["pln"] = 1; 104 obs["soc"] = 1; 105 obs["sc_nct"] = 1; 106 obs["tomtppm"] = 1; 107 } !($1 in obs) { print $0 }' 108 } 109 110 # 111 # obsolete_i386 - Filter function to remove obsolete i386 driver entries. 112 # We define an associative array of bad driver names, and then nawk out 113 # lines where the first token is defined in our array. 114 # 115 obsolete_i386() 116 { 117 nawk 'BEGIN { 118 obs["aha"] = 1; 119 obs["aic"] = 1; 120 obs["app"] = 1; 121 obs["audiocs"] = 1; 122 obs["blogic"] = 1; 123 obs["chanmux"] = 1; 124 obs["chs"] = 1; 125 obs["cmtp"] = 1; 126 obs["corvette"] = 1; 127 obs["cpqncr"] = 1; 128 obs["csa"] = 1; 129 obs["dpt"] = 1; 130 obs["dsa"] = 1; 131 obs["eepro"] = 1; 132 obs["eha"] = 1; 133 obs["el"] = 1; 134 obs["elink"] = 1; 135 obs["elx"] = 1; 136 obs["envm"] = 1; 137 obs["esa"] = 1; 138 obs["esa"] = 1; 139 obs["iee"] = 1; 140 obs["ieef"] = 1; 141 obs["iss"] = 1; 142 obs["kd"] = 1; 143 obs["kdmouse"] = 1; 144 obs["lp"] = 1; 145 obs["mc"] = 1; 146 obs["mcis"] = 1; 147 obs["mega"] = 1; 148 obs["mlx"] = 1; 149 obs["nee"] = 1; 150 obs["nei"] = 1; 151 obs["nfe"] = 1; 152 obs["objmgr"] = 1; 153 obs["p9000"] = 1; 154 obs["p9100"] = 1; 155 obs["pcaic"] = 1; 156 obs["profile"] = 1; 157 obs["riles"] = 1; 158 obs["rip"] = 1; 159 obs["sbpro"] = 1; 160 obs["smartii"] = 1; 161 obs["smc"] = 1; 162 obs["smce"] = 1; 163 obs["smceu"] = 1; 164 obs["smcf"] = 1; 165 obs["sp"] = 1; 166 obs["svarp"] = 1; 167 obs["svicmp"] = 1; 168 obs["svip"] = 1; 169 obs["svloop"] = 1; 170 obs["svrip"] = 1; 171 obs["svtcp"] = 1; 172 obs["svudp"] = 1; 173 obs["tcl"] = 1; 174 obs["tco"] = 1; 175 obs["tcoo"] = 1; 176 obs["tiqmouse"] = 1; 177 obs["tr"] = 1; 178 obs["trantor"] = 1; 179 obs["pci_to_i2o"] = 1; 180 obs["i2o_scsi"] = 1; 181 obs["i2o_bs"] = 1; 182 } !($1 in obs) { print $0 }' 183 } 184 185 # 186 # Useful debugging which is reasonable to include in a production system: 187 # we copy the salient driver files to the package undo directory before 188 # doing any work. This will help diagnose add_drv errors before the system 189 # becomes an unbootable smoldering ruin. 190 # 191 for file in driver_aliases driver_classes minor_perm name_to_major; do 192 cp $BASEDIR/etc/$file $PKGSAV/$file.orig >/dev/null 2>&1 193 done 194 195 # 196 # check if the driver specified is already installed. 197 # the second token must be the decimal digit. 198 # ignore a comment if exists. 199 # 200 is_installed () 201 { 202 file=$2 203 nawk -v driver=$1 -v delimiter='#' ' \ 204 $1 == driver && $2 ~ /^[0-9][0-9]*$/ \ 205 { found = 1; exit 0 } \ 206 $1 == driver \ 207 { num = split($2, n_array, delimiter); \ 208 if (num > 1 && n_array[1] ~ /^[0-9][0-9]*$/) \ 209 { found = 1; exit 0 } \ 210 } \ 211 END { if (!found) exit 1 } ' $file 212 return $? 213 } 214 215 # 216 # Add_drv needs /etc/driver_aliases in order to work properly; if for 217 # some reason it has been removed, create an empty one at this time. 218 # Recall that in SUNWcsr's pkginfo.tmpl, the driver_aliases class-action 219 # script is invoked *after* this class-action script. This is critical 220 # because if we are going to add_drv a new driver 'foo', and 'foo' has 221 # an alias 'bar', the add_drv of 'foo' will fail if the alias is already 222 # present. Thus new aliases must be added *after* new driver major entries. 223 # The driver_aliases class-action script will add the complete set of aliases 224 # if we create an empty file here, so this code allows us to continue and 225 # get a correct upgrade in the face of a missing driver_aliases file. 226 # 227 if [ ! -f $BASEDIR/etc/driver_aliases ]; then 228 touch $BASEDIR/etc/driver_aliases 229 chmod 0644 $BASEDIR/etc/driver_aliases 230 chown root $BASEDIR/etc/driver_aliases 231 chgrp sys $BASEDIR/etc/driver_aliases 232 fi 233 234 while read src dest; do 235 if [ -f $dest ]; then 236 # 237 # Strip obsolete entries from the existing name_to_major 238 # 239 if [ $ARCH = sparc ]; then 240 obsolete_sparc < $dest > /tmp/onm.$$.tmp 241 else 242 obsolete_i386 < $dest > /tmp/onm.$$.tmp 243 fi 244 245 cp /tmp/onm.$$.tmp $dest 246 rm -f /tmp/onm.$$.tmp 247 248 # 249 # Remove comment and/or blank lines before reading 250 # 251 nawk '$1 !~ /^#|^$/ {print $0}' $src | sed -e 's/#.*$//' | \ 252 while read name major; do 253 # 254 # If the driver is already present in name_to_major, 255 # leave the existing number and continue 256 # 257 is_installed $name $dest >/dev/null 2>&1 && continue 258 # 259 # Otherwise add the driver to name_to_major using 260 # add_drv. add_drv produces spurious output even on 261 # success, so save its output in a temporary 262 # file in case an error occurs. 263 # 264 if add_drv -b $BASEDIR $name \ 265 >/tmp/ad.$$.tmp 2>&1; then 266 echo "added $name to $dest" 267 else 268 echo "$PKG: failed to add $name to " \ 269 "$dest:" >& 2 270 cat /tmp/ad.$$.tmp >& 2 271 fi 272 done 273 rm -f /tmp/ad.$$.tmp 274 else 275 # 276 # If no name_to_major is present on the target system, 277 # just copy over the one from the package. 278 # 279 cp -p $src $dest 280 fi 281 done 282 exit 0 283