OpenSolaris_b135/pkgdefs/SUNWusb/postinstall

#!/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 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
 
PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

if [ "${BASEDIR:=/}" != "/" ] 
then
	BASEDIR_OPT="-b $BASEDIR" 
fi

# Location of usb links, and the names of the types of links to remove
LINKDIR=${BASEDIR}/dev/usb
LINKFILES="hub* mass-storage* device*"

# since ohci, uhci and ehci are self probing nexus drivers,
# add_drv -n hid, hubd, usb_ia and usb_mid before add_drv ohci/uhci/ehci.
# ohci/uhci/ehci will create the hub and usb,device nodes and attach
# hubd, usb_mid and usb_ia drivers

not_installed() {
	driver=$1
	grep "^${driver} " $BASEDIR/etc/name_to_major > /dev/null 2>&1

	return $?
}

EXIT=0

not_installed hid || add_drv ${BASEDIR_OPT} -m '* 0600 root sys' \
	-i '"usbif,class3"' -n hid || EXIT=1

not_installed hubd || add_drv ${BASEDIR_OPT} -m '* 0644 root sys' \
	-i '"usbif,class9"' -n hubd || EXIT=1

not_installed scsa2usb || add_drv ${BASEDIR_OPT} \
	-i '"usbif,class8" "usb584,222"' -n scsa2usb || EXIT=1

not_installed usb_ia || add_drv ${BASEDIR_OPT} -i '"usb,ia"' -n usb_ia || 
EXIT=1

not_installed usb_mid || add_drv ${BASEDIR_OPT} -i '"usb,device"' -n usb_mid || 
EXIT=1

not_installed usbprn || add_drv ${BASEDIR_OPT}  -m '* 0666 root sys' \
	-i '"usbif,class7.1"' -n usbprn || EXIT=1 

not_installed wusb_ca || add_drv ${BASEDIR_OPT}  -m '* 0666 root sys' \
	-i '"usbif,classef.3.1"' -n wusb_ca || EXIT=1 

not_installed wusb_df || add_drv ${BASEDIR_OPT}  -m '* 0666 root sys' \
	-i '"usb3495,3007" "usb15a9,5"' -n wusb_df || EXIT=1 

not_installed hwahc || add_drv ${BASEDIR_OPT}  -m '* 0644 root sys' \
	-i '"usbif,classe0.2.1"' -n hwahc || EXIT=1 

not_installed hwarc || add_drv ${BASEDIR_OPT}  -m '* 0644 root sys' \
	-i '"usbif,classe0.1.2"' -n hwarc || EXIT=1 

not_installed usb_ac || add_drv ${BASEDIR_OPT}  -m '* 0600 root sys' \
	-i '"usbif,class1.1"' -n usb_ac || EXIT=1 

not_installed usb_as || add_drv ${BASEDIR_OPT}  -m '* 0600 root sys' \
	-i '"usbif,class1.2"' -n usb_as || EXIT=1 

not_installed ohci || add_drv ${BASEDIR_OPT} -m '* 0644 root sys' \
	-i '"pciclass,0c0310"' ohci || EXIT=1

not_installed ehci || add_drv ${BASEDIR_OPT} -m '* 0644 root sys' \
	-i '"pciclass,0c0320"' ehci || EXIT=1

not_installed uhci || add_drv ${BASEDIR_OPT} -m '* 0644 root sys' \
	-i '"pciclass,0c0300"' uhci || EXIT=1

# Cleanup to wipe out any defunct links

if [ -d ${LINKDIR} ]
then
	# ls -l shows linknames to curr dir and phys nodes relative to $LINKDIR
	OLDDIR=`pwd`
	cd ${LINKDIR}

	# List all entries with devctl (will be entries pointing to phys nodes
	# ending with "devctl"). Delete these entries & their physical nodes.
	ls -l ${LINKFILES} 2>/dev/null | grep ":devctl$" | \
	    nawk '{print $9, $11}' | xargs rm -f

	cd ${OLDDIR}
fi

exit $EXIT