#!/bin/sh
#
#ident	"@(#)postpatch	1.1	05/03/29 SMI"
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

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

CheckZones()
{
	if [ "$ROOTDIR" = "/" -a -x /usr/bin/zonename ]; then
		ZONENAME=`/usr/bin/zonename`
		if [ ${ZONENAME} = "global" ]; then
			GLOBAL_ZONE=true
		else
			GLOBAL_ZONE=false
		fi
	else
		# Unable to determine zone
		GLOBAL_ZONE=true
	fi
}

GlobalZones()
{
	if [ -z "${ROOTDIR}" ]; then
		echo "\n$0 Failed: ROOTDIR is not set.\n" >&2
		exit 1
	fi
	
	# Driver definitions
	DRVR_NAME=qus
	DRVR_PERM="-m '* 0600 root sys'"
	DRVR_CLASS="-c scsi"
	DRVR_ALIASES="-i '\"pci1077,1016\"'"

	HARDWARE_STRING="pci1077,1016"

	if [ ${ARCH} != "sparc" ]; then
		echo "\n$0 Failed: Hardware is not supported.\n" >&2
	fi

	# Remove existing definition, if it exists. 
	/usr/sbin/rem_drv -b "${ROOTDIR}" ${DRVR_NAME} > /dev/null 2>&1

	if [ "$ROOTDIR" = "/" ] ; then
		# Check for hardware
		prtconf -pv | egrep "${HARDWARE_STRING}" > /dev/null 2>&1
		hardware_result=$?
	else
		hardware_result=1
	fi

	if [ $hardware_result -eq 0 ]; then
		# Hardware is present, attach the drivers
		ADD_DRV="add_drv -b ${ROOTDIR}"
	else
		# No hardware found on the system
		# or alternate root install
		ADD_DRV="add_drv -n -b ${ROOTDIR}"
	fi

	eval ${ADD_DRV} "${DRVR_PERM}" ${DRVR_CLASS} "${DRVR_ALIASES}" ${DRVR_NAME}
	if [ $? -ne 0 ]; then
		echo "\nCommand Failed:" >&2
		echo "${ADD_DRV} "${DRVR_PERM}" ${DRVR_CLASS} "${DRVR_ALIASES}" ${DRVR_NAME}\n" >&2
		exit 1
	fi
}

NonGlobalZones()
{
	return 0
}


CheckZones

if [ "${GLOBAL_ZONE}" = "true" ]; then
	GlobalZones
else
	NonGlobalZones
fi

exit 0

