OpenSolaris_b135/pkgdefs/CPQary3/postinstall

#!/sbin/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.
#

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

check_add_drv()
{
	if [ "$BASEDIR" = "" ]; then
		BASEDIR=/  
		DEVLINK_TAB="/etc/devlink.tab"
	else
		DEVLINK_TAB="$BASEDIR/etc/devlink.tab"
		
	fi
	alias=""
	class=""
	ADD_ALIAS=0
	ADD_CLASS=0
	ADD_MINOR=0
	OPTIND=1
	IS_NET_DRIVER=0

	cmd="add_drv"

	while getopts i:b:m:c:n  opt; do
		case $opt in
			i )	ADD_ALIAS=1	
				alias=$OPTARG
				cmd=$cmd" -i '$alias'"
				;;
			m )	ADD_MINOR=1
				minor=$OPTARG
				cmd=$cmd" -m '$minor'"
				;;
			c)	ADD_CLASS=1
				class=$OPTARG
				cmd=$cmd" -c $class"
				;;
			b)	BASEDIR_OPT="-b $BASEDIR"
				cmd=$cmd" $BASEDIR_OPT"
				;;
			n)	IS_NET_DRIVER=1
				;;
			\?) 	echo "check_add_drv can not handle this option"
				return
				;;
			esac
	done 
	shift `/usr/bin/expr $OPTIND - 1`
	
	drvname=$1

	cmd=$cmd" "$drvname

	drvname=`echo $drvname | /usr/bin/sed 's;.*/;;g'`

	/usr/bin/grep "^$drvname[ 	]" $BASEDIR/etc/name_to_major >  /dev/null 2>&1

	if [ $? -ne 0 ] ; then
		eval $cmd
	else	
		# entry already in name_to_major, add alias, class, minorperm
		# if necessary
		if [ $ADD_ALIAS = 1 ]; then
			for i in $alias; do
				/usr/bin/egrep "^$drvname[ 	]+$i" $BASEDIR/etc/driver_aliases>/dev/null 2>&1
				if [ $? -ne 0 ]; then
					echo "$drvname $i" >> $BASEDIR/etc/driver_aliases	
				fi
			done
		fi

		if [ $ADD_CLASS = 1 ]; then
			/usr/bin/egrep "^$drvname[ 	]+$class( |	|$)" $BASEDIR/etc/driver_classes > /dev/null 2>&1
			if [ $? -ne 0 ]; then
				echo "$drvname\t$class" >> $BASEDIR/etc/driver_classes
			fi
		fi

		if [ $ADD_MINOR = 1 ]; then
			/usr/bin/grep "^$drvname:" $BASEDIR/etc/minor_perm > /dev/null 2>&1
			if [ $? -ne 0 ]; then
				minorentry="$drvname:$minor"
				echo $minorentry >> $BASEDIR/etc/minor_perm
			fi
		fi

	fi

	# The following clone device/dev is needed for Custom Jumpstart

	if [ $IS_NET_DRIVER -eq 1 ]; then
		CLONE_DEVICE=devices/pseudo/clone@0:$drvname
		set `/usr/bin/grep "^clone[ 	]" $BASEDIR/etc/name_to_major`
		CLONE_MAJ=$2
		set `/usr/bin/grep "^$drvname[ 	]" $BASEDIR/etc/name_to_major`
		DRIVER_MAJ=$2
		mknod $BASEDIR/$CLONE_DEVICE c $CLONE_MAJ $DRIVER_MAJ
		chmod 600 $BASEDIR/$CLONE_DEVICE
		chgrp sys $BASEDIR/$CLONE_DEVICE
		chown root $BASEDIR/$CLONE_DEVICE
		ln -s ../$CLONE_DEVICE $BASEDIR/dev/$drvname
	fi
	
}

add_devlink()
{
        PATTERN="$1"
        LINK="$2"
        PLINK="`echo $LINK | sed 's/[$*^|\]/\\\&/g'`"
	TMP=/tmp/$$
        grep -v "^$PATTERN      $PLINK$" ${DEVLINK_TAB} >$TMP.devlink
        echo "$PATTERN\t$LINK" >>$TMP.devlink
        cp $TMP.devlink ${DEVLINK_TAB}
        rm -f $TMP.devlink
}

check_add_drv -i '"pcie11,4070" "pcie11,4082" "pcie11,4083" "pcie11,409a"
"pcie11,409b" "pcie11,409c" "pcie11,409d" "pcie11,4091" "pcie11,4080"
"pci103c,3225" "pci103c,3211" "pci103c,3212" "pci103c,3234" "pci103c,3235"
"pci103c,3223" "pci103c,3237" "pci103c,323d" "pci103c,3245" "pci103c,3241"
"pci103c,3243" "pci103c,3247" "pci103c,324b" "pci103c,324a" "pci103c,3249"' $BASEDIR_OPT -c scsi cpqary3

add_devlink 'type=ddi_pseudo;minor1=cpqary3'	'cpqary3\\M2'

exit 0