OpenSolaris_b135/pkgdefs/common_files/i.drvalias

#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

PATH=/usr/bin:/usr/sbin:$PATH; export PATH

#
# obsolete_sparc - Filter function to remove obsolete SPARC driver aliases.
# Use sed to delete lines matching driver aliases we want to remove.
#
obsolete_sparc()
{
	sed \
	    -e '/^[ 	]*cpu[ 	][ 	]*modi4v0m$/d' \
	    -e '/^[ 	]*cpu[ 	][ 	]*modi4v0m[ 	#].*$/d' \
	    -e '/^[ 	]*PFUaga[ 	][ 	]*PFU,aga$/d' \
	    -e '/^[ 	]*PFUaga[ 	][ 	]*PFU,aga[ 	#].*$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRIs3$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRIs3[ 	#].*$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRId$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRId[ 	#].*$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRIe$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRIe[ 	#].*$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRIf$/d' \
	    -e '/^[ 	]*dbri[ 	][ 	]*SUNW,DBRIf[ 	#].*$/d' \
	    -e '/^[ 	]*leo[ 	][ 	]*SUNW,leo104$/d' \
	    -e '/^[ 	]*leo[ 	][ 	]*SUNW,leo104[ 	#].*$/d' \
	    -e '/^[ 	]*atapicd[ 	][ 	]*"ide-cdrom"$/d' \
	    -e '/^[ 	]*atapicd[ 	][ 	]*"ide-cdrom"[ 	#].*$/d' \
	    -e '/^[ 	]*cpu[ 	][ 	]*TI,TMS390Z50$/d' \
	    -e '/^[ 	]*cpu[ 	][ 	]*TI,TMS390Z50[ 	#].*$/d' \
	    -e '/^[ 	]*obio[ 	][ 	]*bootbus$/d' \
	    -e '/^[ 	]*obio[ 	][ 	]*bootbus[ 	#].*$/d' \
	    -e '/^[ 	]*sw[ 	][ 	]*drum$/d' \
	    -e '/^[ 	]*sw[ 	][ 	]*drum[ 	#].*$/d' \
	    -e '/^[ 	]*ie[ 	][ 	]*sie$/d' \
	    -e '/^[ 	]*ie[ 	][ 	]*sie[ 	#].*$/d' \
	    -e '/^[ 	]*sbus[ 	][ 	]*sbi$/d' \
	    -e '/^[ 	]*sbus[ 	][ 	]*sbi[ 	#].*$/d' \
	    -e '/^[ 	]*pn[ 	][ 	]*SUNW,pn$/d' \
	    -e '/^[ 	]*pn[ 	][ 	]*SUNW,pn[ 	#].*$/d' \
	    -e '/^[ 	]*glm[ 	][ 	]*SUNW,glm$/d' \
	    -e '/^[ 	]*glm[ 	][ 	]*SUNW,glm[ 	#].*$/d' \
	    -e '/^[ 	]*gpio_87317[ 	][ 	]*"gpio"$/d' \
	    -e '/^[ 	]*gpio_87317[ 	][ 	]*"gpio"[ 	#].*$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*SUNW,pci$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*SUNW,pci[ 	#].*$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*"pci108e,8000"$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*"pci108e,8000"[ 	#].*$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*"pci108e,a000"$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*"pci108e,a000"[ 	#].*$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*"pciclass,060000"$/d' \
	    -e '/^[ 	]*pci[ 	][ 	]*"pciclass,060000"[ 	#].*$/d' \
	    -e '/^[ 	]*px[ 	][ 	]*"pci108e,80f0"$/d' \
	    -e '/^[ 	]*px[ 	][ 	]*"pci108e,80f0"[ 	#].*$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci1033,124"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci1033,124"[ 	#].*$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci1033,125"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci1033,125"[ 	#].*/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci8086,340"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci8086,340"[ 	#].*$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci8086,341"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci8086,341"[ 	#].*$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci10b5,8532"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci10b5,8532"[ 	#].*$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci10b5,8516"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pci10b5,8516"[ 	#].*$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pciexclass,060400"$/d' \
	    -e '/^[ 	]*px_pci[ 	][ 	]*"pciexclass,060400"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_bcm[ 	][ 	]*"pciex1166,103"$/d' \
	    -e '/^[ 	]*pxb_bcm[ 	][ 	]*"pciex1166,103"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8114"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8114"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8532"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8532"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8516"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8516"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8548"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8548"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8533"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8533"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8517"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8517"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8518"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex10b5,8518"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex108e,9010"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex108e,9010"[ 	#].*$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex108e,9020"$/d' \
	    -e '/^[ 	]*pxb_plx[ 	][ 	]*"pciex108e,9020"[ 	#].*$/d' \
	    -e '/^[ 	]*sx[ 	][ 	]*SUNW,sx$/d' \
	    -e '/^[ 	]*sx[ 	][ 	]*SUNW,sx[ 	#].*$/d' \
	    -e '/^[ 	]*sx[ 	][ 	]*"SUNW,sx"$/d' \
	    -e '/^[ 	]*sx[ 	][ 	]*"SUNW,sx"[ 	#].*$/d' \
	    -e '/^[ 	]*xbox[ 	][ 	]*SUNW,xbox$/d' \
	    -e '/^[ 	]*xbox[ 	][ 	]*SUNW,xbox[ 	#].*$/d' \
	    -e '/^[ 	]*xbox[ 	][ 	]*"SUNW,xbox"$/d' \
	    -e '/^[ 	]*xbox[ 	][ 	]*"SUNW,xbox"[ 	#].*$/d' \
	    -e '/^[ 	]*stc[ 	][ 	]*SUNW,spif$/d' \
	    -e '/^[ 	]*stc[ 	][ 	]*SUNW,spif[ 	#].*$/d' \
	    -e '/^[ 	]*fjulsa[ 	][ 	]*"pci13e9,30"$/d' \
	    -e '/^[ 	]*fjulsa[ 	][ 	]*"pci13e9,30"[ 	#].*$/d' \
	    -e '/^[ 	]*fjulsa[ 	][ 	]*"pci1000,30"$/d' \
	    -e '/^[ 	]*fjulsa[ 	][ 	]*"pci1000,30"[ 	#].*$/d' \
	    -e '/^[ 	]*cpu[ 	][ 	]*TI,TMS390Z55$/d' \
	    -e '/^[ 	]*cpu[ 	][ 	]*TI,TMS390Z55[ 	#].*$/d' \
	    -e '/^[ 	]*mic[ 	][ 	]*SUNW,mic$/d' \
	    -e '/^[ 	]*mic[ 	][ 	]*SUNW,mic[ 	#].*$/d' \
	    -e '/^[ 	]*pln[ 	][ 	]*SUNW,pln$/d' \
	    -e '/^[ 	]*pln[ 	][ 	]*SUNW,pln[ 	#].*$/d' \
	    -e '/^[ 	]*soc[ 	][ 	]*SUNW,soc$/d' \
	    -e '/^[ 	]*soc[ 	][ 	]*SUNW,soc[ 	#].*$/d' \
	    -e '/^[ 	]*sc_nct[ 	][ 	]*"nct-ds80ch11-smc"$/d' \
	    -e '/^[ 	]*sc_nct[ 	][ 	]*"nct-ds80ch11-smc"[ 	#].*$/d' \
	    -e '/^[ 	]*tomtppm[ 	][ 	]*jbus-ppm$/d' \
	    -e '/^[ 	]*tomtppm[ 	][ 	]*jbus-ppm[ 	#].*$/d' \
	    -e '/^[ 	]*bpp[ 	][ 	]*SUNW,bpp$/d' \
	    -e '/^[ 	]*bpp[ 	][ 	]*SUNW,bpp[	#].*$/d'
}

#
# obsolete_i386 - Filter function to remove obsolete i386 driver aliases.
#
obsolete_i386() {
	sed \
	    -e '/^[ 	]*elx[^l].*10b7,9000.*/d' \
	    -e '/^[ 	]*elx[^l].*10b7,9050.*/d' \
	    -e '/^[ 	]*dpt[ 	][ 	]*"pci1044,a400"$/d' \
	    -e '/^[ 	]*dpt[ 	][ 	]*"pci1044,a400"[ 	#].*$/d' \
	    -e '/^[ 	]*audiocs[ 	][ 	]*"SUNW,CS4231"$/d' \
	    -e '/^[ 	]*audiocs[ 	][ 	]*"SUNW,CS4231"[ 	#].*$/d' \
	    -e '/^[ 	]*blogic[ 	][ 	]*"pci104b,1040"$/d' \
	    -e '/^[ 	]*blogic[ 	][ 	]*"pci104b,1040"[ 	#].*$/d' \
	    -e '/^[ 	]*mega[ 	][ 	]*"pci101e,9010"$/d' \
	    -e '/^[ 	]*mega[ 	][ 	]*"pci101e,9010"[ 	#].*$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,1"$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,1"[ 	#].*$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,2"$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,2"[ 	#].*$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,10"$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,10"[ 	#].*$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,11"$/d' \
	    -e '/^[ 	]*mlx[ 	][ 	]*"pci1069,11"[ 	#].*$/d' \
	    -e '/^[ 	]*p9000[ 	][ 	]*"pci100e,9001"$/d' \
	    -e '/^[ 	]*p9000[ 	][ 	]*"pci100e,9001"[ 	#].*$/d' \
	    -e '/^[ 	]*p9100[ 	][ 	]*"pci100e,9100"$/d' \
	    -e '/^[ 	]*p9100[ 	][ 	]*"pci100e,9100"[ 	#].*$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciex1011,1"$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciex1011,1"[ 	#].*$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciex1011,21"$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciex1011,21"[ 	#].*$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciex1014,22"$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciex1014,22"[ 	#].*$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciexclass,060400"$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciexclass,060400"[ 	#].*$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciexclass,060401"$/d' \
	    -e '/^[ 	]*pcie_pci[ 	][ 	]*"pciexclass,060401"[ 	#].*$/d' \
	    -e '/^[ 	]*spwr[ 	][ 	]*"pci10b8,0005"$/d' \
	    -e '/^[ 	]*spwr[ 	][ 	]*"pci10b8,0005"[ 	#].*$/d' \
	    -e '/^[ 	]*chs[ 	][ 	]*"pci1014,2e"$/d' \
	    -e '/^[ 	]*chs[ 	][ 	]*"pci1014,2e"[ 	#].*$/d' \
	    -e '/^[ 	]*cpqncr[ 	][ 	]*"pcie11,7004"$/d' \
	    -e '/^[ 	]*cpqncr[ 	][ 	]*"pcie11,7004"[ 	#].*$/d' \
	    -e '/^[ 	]*smartii[ 	][ 	]*"pcie11,4030"$/d' \
	    -e '/^[ 	]*smartii[ 	][ 	]*"pcie11,4030"[ 	#].*$/d' \
	    -e '/^[ 	]*smartii[ 	][ 	]*"pcie11,4031"$/d' \
	    -e '/^[ 	]*smartii[ 	][ 	]*"pcie11,4031"[ 	#].*$/d' \
	    -e '/^[ 	]*pci_to_i2o[ 	][ 	]*"pciclass,0e0001"$/d' \
	    -e '/^[ 	]*pci_to_i2o[ 	][ 	]*"pciclass,0e0001"[ 	#].*$/d'
}

#
# check if the driver aliase specified is already installed.
# ignore a comment if exists.
#
is_installed ()
{
	file=$3
	nawk -v driver=$1 -v alias=$2 -v delimiter='#' ' \
	$1 == driver && $2 == alias \
		{ found = 1; exit 0 } \
	$1 == driver \
		{ num = split($2, a_array, delimiter); \
			if (num > 1 && a_array[1] == alias) \
				{ found = 1; exit 0 } \
		} \
	END { if (!found) exit 1 } ' $file
	return $?
}

#
# Generate /etc/driver_aliases file.  Each entry present in $src (the copy
# of driver_aliases being delivered by the package) is automatically added
# to $dest (the driver_aliases file on the target system) if not already
# present; thus it is NOT necessary to add any code below to cause a new
# alias which has been added to the driver_aliases source to be added to
# the target system on upgrade.
#
while read src dest; do
	if [ -f $dest ]; then
		#
		# Strip obsolete entries from the existing driver_aliases
		#
		if [ $ARCH = sparc ]; then
			obsolete_sparc < $dest > /tmp/oda.$$.tmp
			cp /tmp/oda.$$.tmp $dest
			rm -f /tmp/oda.$$.tmp
		elif [ $ARCH = i386 ]; then
			obsolete_i386 < $dest > /tmp/oda.$$.tmp
			cp /tmp/oda.$$.tmp $dest
			rm -f /tmp/oda.$$.tmp
		fi
		#
		# Remove comment and/or blank lines before reading
		#
		egrep -v -e "^[ 	]*#.*$|^[ 	]*$" $src | \
		    sed -e 's/#.*$//' > /tmp/oda.$$.tmp
		#
		# If the alias is not present in the driver_aliases
		# file, then append it:
		#
		while read driver alias; do
			is_installed $driver $alias $dest \
			    >/dev/null 2>&1 || echo "$driver $alias" >>$dest
		done < /tmp/oda.$$.tmp
		rm -f /tmp/oda.$$.tmp
	else
		#
		# If no driver_aliases is present on the target system,
		# just copy over the one from the package.
		#
		cp -p $src $dest
	fi
done
exit 0