#! /bin/sh
#
# SUNW1394x prebackout script
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

DRVALIAS='pciclass,0c0010'
#
# Is the hardware there?
#
hw_exists=0
prtconf -pv | egrep -s "${DRVALIAS}"
if [ $? -eq 0 ]; then
	hw_exists=1
fi

if [ "${ROOTDIR}" = "/" ]; then
	#
	# No need to add_drv if the running system is of a different arch
	# than the package
	#
	case ${hw_exists} in
		#
		# On a running system with *no* hardware,
		# modify the system files only
		#
		0 )
			ADD_DRV="add_drv -n"
			;;
		#
		# On a running system with hardware,
		# modify the system files and attach the driver
		#
		1 )
			ADD_DRV="add_drv"
			;;
	esac
else
	#
	# On a client,
	# modify the system files and touch /reconfigure
	# for reconfigure reboot
	#
	ADD_DRV="add_drv -b ${ROOTDIR}"
fi

# 
# av1394 driver
# 
AVDRV=av1394
AVDRVALIAS='"firewire00a02d,010000" "firewire00a02d,010001"'
AVDRVPERM='* 0600 root sys'

#
# Make sure the driver is not already installed.
#
grep "^${AVDRV} " $ROOTDIR/etc/name_to_major > /dev/null 2>&1
if [ $? -eq 0 ]; then
	exit 0
fi

if [ -f $ROOTDIR/kernel/drv/sparcv9/av1394 ]
then
	${ADD_DRV} -m "${AVDRVPERM}" -i "${AVDRVALIAS}" -n ${AVDRV}
	if [ $? -ne 0 ]; then
		echo "\nFailed add_drv of ${AVDRV}!\n" >&2
	        exit 1
        fi
fi

exit 0
