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