#! /bin/sh -
#
# Usage: pccard_scsi interface name
#
# example: pccard_scsi aic0
#
# T. Ichinoseki
#

# default value of delay (second)
pccard_scsi_delay=2

# Suck in the configuration variables
if [ -f /etc/defaults/rc.conf ]; then
	. /etc/defaults/rc.conf
elif [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

interface=$1
bus=`/sbin/camcontrol devlist -v | \
	/usr/bin/grep ${interface} | \
	/usr/bin/sed -e "s/ .*$//"`

if [ "$bus" ]; then
	if [ "$pccard_scsi_delay" ]; then
	    if [ ${pccard_scsi_delay} -gt 0 ]; then
		if [ ${pccard_scsi_delay} -gt 15 ]; then
		    # set muximum delay to 15 seconds
		    pccard_scsi_delay=15
		fi
		/bin/sleep ${pccard_scsi_delay}
	    fi
	fi
	/sbin/camcontrol reset $bus
	/sbin/camcontrol rescan $bus
fi
