:
#ident "@(#)scsi.sh	1.16 91/07/12"
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989.
#	Portions Copyright (C) Altos Computer Systems 1989, 1990.
#	This Module contains Proprietary Information of
#	Altos Computer Systems, The Santa Cruz Operation, 
#	and should be treated as Confidential.
#
#	edits SCSI configuration file and optionally rebuilds the kernel
#

# set the standard exit values
: ${OK=0} ${FAIL=1} ${STOP=10}

# set the environment variables
LANG=english_us.ascii
export LANG
PATH=/etc:/bin:/usr/bin:/altos/bin
export PATH
umask 0

SADAPTER=${ROOT}/etc/conf/cf.d/Sadapter
TMPFILE=/tmp/_Sadapter
TMPFILE2=/tmp/_Sadapter2
major=0

if [ -x /bin/clear ]
then
	CLEAR=`clear`
else
	CLEAR=`echo "\n\n"`
fi

#
# Standard functions
#


# Prompt with mesg, return non-zero on q
prompt() {
	while	echo "${mesg}\c" >&2
	do	read cmd
		case $cmd in
		+x|-x)	set $cmd					;;
		Q|q)	return $FAIL					;;
		!*)	eval `expr "$cmd" : "!\(.*\)"`			;;
		"")	# If there is an argument use it as the default
			# else loop until 'cmd' is set
			[ "$1" ] && { 
				cmd=$1
				return $OK
			}
			: continue
			;;
		*)	return $OK					;;
		esac
	done
}

# Prompt for yes or no answer - returns non-zero for no
getyn() {
	while	echo "$* (y/n):  \c">&2
	do	read yn rest
		case $yn in
		[yY])	return $OK 			;;
		[nN])	return $FAIL			;;
		*)	echo "
	Please answer 'y' or 'n'." >&2	;;
		esac
	done
}

#
# begin mkdev scsi functions
#

settrap () {
	trap 'cleanup $FAIL' 1 2 3 15
}

unsettrap () {
	trap '' 1 2 3 15
}

cleanup ()  {
	rm -f /tmp/scsi_*
	rm -f $TMPFILE $TMPFILE2
	exit $1
}

check_link () {
	dir=`pwd`
	cd /
	if [ -f /etc/perms/extmd ]
	then
		PERM=/etc/perms/extmd
	else
		echo "Cannot find /etc/perms/extmd. \nCannot verify that the \
Link Kit is installed."
		# or return 1
		cleanup $FAIL

	fi
	# test to see if link kit is installed
	until	fixperm -i -d LINK $PERM
	do	case $? in
		0) echo "
	fixperm returned 0 in link kit check
"
 		   return 0					          ;;	
		4) echo "
	The Link Kit is not installed.
" >&2	          ;;
		5) echo "
	The Link Kit is only partially installed.
" >&2 ;;
		*) echo "
	Error testing for Link Kit.  Exiting.
">&2
		   cleanup $FAIL					  ;;
		esac

		# Not fully installed. Do so here
		getyn "Do you wish to install it now?" || {
			# answered no
			echo "
	SCSI devices cannot be installed without the 
	Link Kit.  Re-invoke this mkdev script after 
	installing the Link Kit.">&2
			cleanup $FAIL
		}

		# answered yes, so install link kit
		/etc/custom -o -i LINK || {
			# custom exited unsuccessfully
			echo "
	'custom' failed to install Link Kit successfully.
	Please try again.
"
			cleanup $FAIL
		}
	done
	cd $dir
	return 0
}

# get host adapter driver, host adapter number, ID number, and LUN
get_numbers () {

    grep -v "^#" ${SADAPTER} | \
		pr -n | \
		grep "^ " > ${TMPFILE}
    awk -F \" '{print "\t\t"NR".  " $2}' ${TMPFILE} > ${TMPFILE2}

    while echo "${CLEAR}

	SCSI ${devdscr} Configuration
"
    do
   	echo " 
	The following host adapter types are currently 
	supported on this system:
"
	cat ${TMPFILE2}
	if [ "${action}" = "add" ]
	then
		echo "
	Enter the number corresponding to the host adapter
	type to which you wish to attach the ${devdscr}, or 
	type 'q' to quit:  \c"
	else
		echo "
	Enter the number corresponding to the host adapter
	type from which you wish to detach the ${devdscr}, or 
	type 'q' to quit:  \c"
	fi

	read x
		
	case ${x} in
		q|Q)	cleanup $FAIL 
			break
			;;
		*)	ha_entry=`grep "^[ ]*${x}" ${TMPFILE}` 
			if [ $? -ne 0 -o "${x}" = "" ]
			then
				echo "
	Invalid selection.  Please try again."
		 		sleep 2
		 		${CLEAR}
			else
				set ${ha_entry}
				HATYPE=$2
				CHANS_PER_BOARD=$3
				BRDS_PER_SYSTEM=$4
				shift 4
				DESCRIPTION=`echo $* | sed "s/\"//g"`
				HA_MAX=`expr ${CHANS_PER_BOARD} \* ${BRDS_PER_SYSTEM}`
				break
			fi
			;;
	esac
    done

    HA=0
    if [ ${HA_MAX} -gt 1 ]
    then
    	while echo "${CLEAR}

	SCSI ${devdscr} Configuration

	Host Adapter Type:	`eval echo ${DESCRIPTION}`

	The ${DESCRIPTION} SCSI interface supports ${HA_MAX} host adapters,
	numbered 0-`expr ${HA_MAX} \- 1`.
"
	if [ "${action}" = "add" ]
	then
		echo "
	Enter the SCSI host adapter number to which you 
	wish to attach the ${devdscr} or type 'q' to quit:  \c"
	else
		echo "
	Enter the SCSI host adapter number from which you 
	wish to detach the ${devdscr} or type 'q' to quit:  \c"
	fi
	do
		read HA
		case ${HA} in
			q|Q)	cleanup $FAIL
				;;
		      [0-9])	if [ "${HA}" != "" -a ${HA} -ge 0 -a \
					${HA} -lt ${HA_MAX} ]
				then
					break
				else
					echo "
	Invalid selection.  Please try again."
		 			sleep 2
				fi
				;;
			  *)	echo "
	Invalid selection.  Please try again."
		 		sleep 2
				;;
		esac
	done
    fi

    while echo "${CLEAR}

	SCSI ${devdscr} Configuration


	Host Adapter Type:	`eval echo ${DESCRIPTION}`
	Host Adapter Number:	${HA}

	Each host adapter supports 7 SCSI controllers,
	numbered 0-6.
"
	if [ "${action}" = "add" ]
	then
		echo "
	Enter the controller ID of the ${devdscr} you
	wish to attach or type 'q' to quit:  \c"
	else
		echo "
	Enter the controller ID of the ${devdscr} you
	wish to detach or type 'q' to quit:  \c"
	fi
    do
	read ID
	case ${ID} in
		q|Q)	cleanup $FAIL
			;;
	      [0-9]) 	if [ "${ID}" != "" -a "${ID}" -ge 0 \
				-a "${ID}" -le 6 ]
			then
				break
			else
				echo "
	Invalid selection.  Please try again."
			 	sleep 2
			fi
			;;
		*)	echo "
	Invalid selection.  Please try again."
			sleep 2
			;;
	esac
    done

    # Don't prompt for LUN number, it is always 0 for now.
    LUN=0

}


# display current kernel SCSI configuration
scsi_display () {
	egrep -v "^\*|^-" $mscsi > /tmp/scsi_d$$   # info from new mscsi
	echo "${CLEAR}
	The current SCSI configuration file has entries for
 	the following devices:

	Host
	Adapter		Adapter
	Type	Device	Number	ID	LUN
	-----------------------------------
"
	sed "s/Sdsk/disk/g" /tmp/scsi_d$$ | \
		sed "s/Stp/tape/g" | \
		sed "s/Srom/cd-rom/g" | \
		sed "s/^/	/" | pg -15 -p "	:" -ne
	echo "
	Press any key to continue:  \c"
	read x 
	return 0
}


# is this entry already in mscsi? 
check_dup ()  {
    if grep "^$thisentry" /tmp/scsi_a$$ > /dev/null 2>&1
    then
	[ "$action" = "add" ] && {
	    case $devtype in
		Sdsk) devname=disk 
			;;
	         Stp) devname=tape
			;;
		Srom) devname=cd-rom
			;;
	    esac
	    echo "
	Cannot add this $devname.  Another $devname is already 
	configured at this location."
	    sleep 2
	}
	return 1
    fi
    return 0
}

# has the maximum for this device type already been reached?
check_max () {
	devcount=`grep -v "^-" /tmp/scsi_a$$ | grep -c "$devtype"`	
	case $devtype in
	      Sdsk) [ $devcount -ge 52 ] && {
			echo "\nError. Cannot add another hard disk."
			echo "\nThe maximum number of disks -- 52 -- are \
already configured."
			return 1
                    } ;;
	       Stp) [ $devcount -ge 8 ] && {
			echo "\nError. Cannot add another tape ."
			echo "\nThe maximum number of tapes -- 8 -- are \
already configured."
			return 1
                    } ;;
	       Srom) [ $devcount -eq 4 ] && {
			echo "\nError. Cannot add another cd-rom."
			echo "\nThe maximum number of cd-roms -- 4 -- are \
already configured."
			return 1
                    } ;;
	esac
	return 0
}

# issue warning if another device type is at that location
check_other () {

	# if disk, check for tape and cd-rom,
	# if tape check for disk and cd-rom,
	# if cd-rom check for disk and tape.

	if [ "$devtype" = "Sdsk" ] 
	then
		tmpdevtype="Stp"
		tmpdevtype2="Srom"
	elif [ "$devtype" = "Stp" ]
	then
		tmpdevtype="Sdsk"
		tmpdevtype2="Srom"
	elif [ "$devtype" = "Srom" ]
	then
		tmpdevtype="Sdsk"
		tmpdevtype2="Stp"
	fi

	nullentry="-	${tmpdevtype}	0	0	0"
	nullentry2="-	${tmpdevtype2}	0	0	0"

	entrytonull="$HATYPE	$tmpdevtype	$HA	$ID	$LUN"
	entrytonull2="$HATYPE	$tmpdevtype2	$HA	$ID	$LUN"

	if grep "^$entrytonull" /tmp/scsi_a$$ > /dev/null 2>&1
	then
		if getyn "
	Warning! Another device is configured at this 
	location.  Do you want to overwrite this location 
	with the new entry?"
		then 
			# Nullify the device entry by placing a "-" before it
			sed "s/^$entrytonull/$nullentry/" /tmp/scsi_a$$ \
				> /tmp/scsi_d$$
			mv /tmp/scsi_d$$ /tmp/scsi_a$$
			return 0
		else
			return 1
		fi
	elif grep "^$entrytonull2" /tmp/scsi_a$$ > /dev/null 2>&1
	then
		if getyn "
	Warning! Another device is configured at this 
	location.  Do you want to overwrite this location 
	with the new entry?"
		then 
			# Nullify the device entry by placing a "-" before it
			sed "s/^$entrytonull2/$nullentry2/" /tmp/scsi_a$$ \
				> /tmp/scsi_d$$
			mv /tmp/scsi_d$$ /tmp/scsi_a$$
			return 0
		else
			return 1
		fi
	fi
	return 0
}


configure_in () {
	mdev=/etc/conf/cf.d/mdevice
	for dev in ${HATYPE} ${devtype}
	do
		sdev=/etc/conf/sdevice.d/$dev
		if grep -s N $sdev >/dev/null
		then	# configure in: change N to Y in sdevice.d file
			sed "s/N/Y/" $sdev >$sdev.new
			devline=`grep "^$dev	" $mdev`
			echo "$devline" | while read dev calls flags others
			do	# add "r"equired flag to mdevice line
				newline="$dev	$calls	${flags}r	$others"
				sed "s/$devline/$newline/" $mdev >$mdev.new
			done
			mv $mdev.new $mdev
			mv $sdev.new $sdev
		fi
	done
}

configure_out () {
	mdev=/etc/conf/cf.d/mdevice

	dev=${HATYPE}
	sdev=/etc/conf/sdevice.d/$dev

	if grep -s Y $sdev >/dev/null
	then	# configure out: change Y to N in sdevice.d file
		sed "s/Y/N/" $sdev >$sdev.new
		devline=`grep "^$dev	" $mdev`
		echo "$devline" | while read dev calls flags others
		do	# remove "r"equired flag from mdevice line
			flags=`echo $flags | sed "s/r//"`
			newline="$dev	$calls	${flags}	$others"
			sed "s/$devline/$newline/" $mdev >$mdev.new
		done
		mv $mdev.new $mdev
		mv $sdev.new $sdev
	fi
}


# Add entry to mscsi, after appropriate error checking.
# Fill any null entry with the same devtype before
# appending to end of mscsi.
#
add_mscsi ()  {
	check_dup || return 2
	check_max || return 1
	check_other || return 1

	nullentry="^[ 	]*-[ 	]*$devtype"
	grep "${nullentry}" /tmp/scsi_a$$ > /dev/null 2>&1
	if [ $? -ne 0 ]
	then
		echo "$thisentry" >> /tmp/scsi_a$$
	else
		echo "/${nullentry}
i
${thisentry}
.
/${nullentry}
d
w
q" | ed /tmp/scsi_a$$ > /dev/null 2>&1
	fi

	configure_in
	reboot=TRUE
	return 0
}

rem_mscsi () {
	check_dup || {
		nullentry="-	$devtype	0	0	0"

		# Nullify the device entry by placing a "-" for host adapter
		sed "s/^$thisentry/$nullentry/" /tmp/scsi_a$$ > /tmp/scsi_b$$
		grep "^$HATYPE	" /tmp/scsi_b$$ > /dev/null 2>&1
	#	if [ $? -ne 0 ]
	#	then
	#		configure_out
	#	fi
		mv /tmp/scsi_b$$ /tmp/scsi_a$$
		reboot=TRUE
		return 0
	}
	echo "
	Error.  Cannot remove this device.

	The specified ${devdscr} is not configured at 
	this location.

	Press return to continue:  \c"
	read a
	return 1
}


# Edit mscsi to add or remove this device; return 0 if mscsi modified, 
# 1 if not.  Also, set NDISK to the number of disks configured in the
# mscsi file.
edit_mscsi () {
	# save commented lines in mscsi
	grep "^\*" $mscsi > /tmp/scsi_c$$

	grep -v "^\*" $mscsi > /tmp/scsi_a$$

	case $action in
		   add) add_mscsi || return $? ;;
		remove) rem_mscsi || return $? ;;
	esac

	cat /tmp/scsi_a$$ >> /tmp/scsi_c$$
	unsettrap
	mv $mscsi $mscsi.old
	mv /tmp/scsi_c$$ $mscsi

	# set NDISK to the number of hard disks on the system.
	NDISK=`grep -v "^*" $mscsi | grep Sdsk | wc -l`
	/etc/conf/bin/idtune -m NDISK $NDISK

	settrap
}


# determine root disk type. Return 0 if SCSI, 1 if not
check_root () {
	[ -s /usr/adm/hwconfig ]  &&  {
	if grep "disk" /usr/adm/hwconfig > /dev/null 2>&1
	then
		d=`sed -n "/disk/s/.*\(type=.\).*/\1/p" /usr/adm/hwconfig`

		case $d in
			type=S*) return 0  	 ;;
			type=E*) return 1 	 ;;
			type=W*) return 1	 ;;
			      *) ;;
		esac
	fi
	}

	# system has never gone multiuser, read kernel printfs from /dev/error
	dparam /dev/rdsk/0s0 > /dev/error 2>&1
	while :
	do	root_type=`line < /dev/error`
		case $root_type in
			*disk*)	case $root_type in
				     *type=S*) return 0  ;;
		       		            *) return 1  ;;
				esac     ;;
		esac
	done
}

 
scsi_help () {
	echo "${CLEAR}

	SCSI Help Message

	Installation of a SCSI device will require 
	reconfiguration of the kernel.

	To specify the location of the device to be 
	added or removed, you need to know three pieces 
	of information:

	1.  Host adapter name,

	2.  Host adapter number, and

	3.  SCSI ID number of the controller of 
	    the device.


	Press return to continue:  \c"
	read x

	grep -v "^#" ${SADAPTER} | \
		pr -n | \
		grep "^ " > ${TMPFILE}
	awk -F \" '{print "\t\t"NR".  " $2}' ${TMPFILE} > ${TMPFILE2}
	NUMLINES=`wc -l ${TMPFILE2} | awk '{print $1}'`

	echo "${CLEAR}

	Host Adapter Name

	A host adapter is a card that plugs into a slot 
	on the motherboard.  It supports one or more 
	SCSI buses depending on the card.

	Presently, this system supports ${NUMLINES} host adapters:
"
	cat ${TMPFILE2} 
echo "

	Press return to continue:  \c"
	read x

echo "${CLEAR}

	Host Adapter Number

	Each host adapter supports a specified range of 
	channels or host adapter numbers.  When you 
	choose to add or delete a SCSI device, you will 
	be prompted for a host adapter number consistent 
	with that host adapter type.


	Press return to continue:  \c"
	read x

# Host Adapter Number --\
# For each host adapter, there are a specified number of channels or\
# host adapter numbers.  For the \"ti\" host adapter, there is only one\
# channel, \"0\".  For the \"hpfp\", there are four channels, \"0\"-\"3\".\
# For the \"ad\", there are two channels."
# 
# echo "\nPress return to continue:  \c"
# read x

echo "${CLEAR}

	SCSI Controller ID

	Up to 7 controllers may be activated on a SCSI
	bus.  Each controller has a unique ID number in 
	the range of 0 to 6.  This number is determined 
	by the jumper setting on the controller.


	Press return to continue:  \c"
	read x

# echo "\
# \nSCSI Controller ID number -- \
# \n\nUp to 7 controllers may be put on a SCSI bus.  Each controller has \
# \na unique ID number.  This number is determined by jumper settings \
# \non the controller.  The valid range of ID numbers is 0-6."
#\n\nSCSI Logical Unit Number (LUN) --\n\
#\nMost SCSI devices are manufactured with a controller embedded in the \
#\nsame physical unit as the device.  These controllers support one device \
#\nonly.  In this case, the LUN of the device is 0.\
#\nNon-embedded controllers may support up to 8 SCSI devices.\
#\nIn this case, LUN numbers are determinded by jumper settings on\
#\neach device. The valid range of LUN numbers is 0-7."
#
#echo "\nPress return to continue:  \c"
#read x

}

get_device () {
while
	mesg="${CLEAR}

	SCSI Device Configuration


	The following is a list of SCSI devices that
	are currently supported on this system.

		1.  Hard Disk
		2.  Tape Drive
		3.  CD-ROM
		4.  Other

	Enter the type of device you wish to $action or
	type 'q' to quit:  "

do
	prompt || {
		checkreboot
		cleanup $OK 
	}
	devcmd=$cmd
	case $devcmd in
		1) devtype=Sdsk
		   devdscr="Hard Disk"
		   break  ;;	
		2) devtype=Stp
		   devdscr="Tape Drive"
		   break ;;
		3) devtype=Srom
		   devdscr="CD-ROM"
		   break ;;
		4) echo "
	No other devices are supported yet." 
		   sleep 2 ;;
		*) echo "
	Please enter 1, 2, 3, 4 or 'q' to quit."
		   sleep 2 ;;
	esac
done
}


just_relink () {
	( cd /etc/conf/cf.d; ./link_unix )
	echo "
	Press return to continue:  \c"
	read a
}

	
ask_relink () {
	getyn "
	A new kernel must be built to reflect the changes 
	to the SCSI configuration.  Do you want to do this 
	now?"
	case $? in
		0) dir=`pwd`
		   cd /etc/conf/cf.d
		   ./link_unix  
		   case $? in
			0) cd $dir     
			   echo "
	Press return to continue:  \c"
			   read a
			   return 0  ;;
			1) cd $dir
			   echo "
	Press return to continue:  \c"
			   read a
			   return 1  ;;
		   esac 		;;
		1) return 1		;;
	esac
}

get_action () {

while
	mesg="${CLEAR}

	SCSI Device Configuration


	1.  Add a SCSI Device
	2.  Remove a SCSI Device
	3.  Display Current SCSI Configuration 
	4.  Display SCSI Help Message

	Enter your selection or type 'q' to quit:  "

do
	prompt || { 
		checkreboot 
		cleanup $OK 
	}
	maincmd=$cmd
	case $maincmd in
		1) action=add    
		   break ;;
		2) action=remove
		   break  ;;
		3) scsi_display  ;;  	 
		4) scsi_help     ;;
		*) echo "
	Please enter 1, 2, 3, 4 or 'q' to quit."
		   sleep 2 ;;
	esac
done
}


checkreboot() {
	[ -n "$reboot" ] && {
		echo "${CLEAR}

	SCSI ${devdscr} Configuration


	The SCSI configuration file has been previously 
	updated."
   		[ "$relink" = "no" ] && cleanup $OK
       		if ask_relink 
   		then
			cleanup $OK 
   		else
			echo "
	The kernel will not be rebuilt now."
			[ "$action" = "add" ] &&  { 
			echo "
	Note: Any device that has been added to the SCSI 
	configuration will not be usable until the kernel 
	is rebuilt & rebooted.  Also, if other changes 
	are made to the SCSI devices prior to the 
	rebuilding and rebooting of the kernel, previous 
	SCSI device changes may be lost.
"
			}
			cleanup $FAIL 
   		fi 
	}
}

usage () {
echo "\n\
Usage: /usr/lib/mkdev/scsi [ -artdconhu ]\n\n\
	-a	    add SCSI device\n\
	-r	    remove SCSI device\n\
	-t	    device is a tape\n\
	-d	    device is a disk\n\
	-c	    device is a cd-rom\n\
	-o	    initially use mscsi file and not information from kernel\n\
	-n	    do not reconfigure & relink the kernel\n\
	-h	    display SCSI help message\n\
	-u	    display this usage message\n\
	 
\n	All arguments are optional"

exit $OK
}

# begin main
mscsi=/etc/conf/cf.d/mscsi
devtype=
action=
relink= 
reboot=
moreentries=
noloop=
oldmscsi=


# arg processing
[ $# != 0 ] &&  {
	noloop=TRUE
	set -- `getopt uadrotcnh $*` || usage

	for i in $* 
	do
		case $i in
			-a) action=add	  ;;
			-r) action=remove ;;
			-t) devtype=Stp
			    devdscr="Tape Drive" ;;
			-d) devtype=Sdsk
			    devdscr="Hard Disk" ;;
			-c) devtype=Srom 
			    devdscr="CD-ROM" ;;
			-o) oldmscsi=TRUE ;;
			-n) relink=no	  ;;
			-h) scsi_help
		    	    exit $OK      ;;
			-u) usage         ;;
			--) shift; break  ;;
		esac
	shift
	done
}


# verify that link kit is installed
check_link

while :
do
[ ! "$action" ]   &&  get_action
[ ! "$devtype" ]  &&  get_device
[ ! "$HA" -o ! "$ID" -o ! "$LUN" -o ! "$HATYPE" ] && get_numbers
thisentry="$HATYPE	$devtype	$HA	$ID	$LUN"
edit_mscsi
case $? in
	0) echo "
	The SCSI configuration file has been updated.

	Press return to continue:  \c"
	   read a
	   if [ ! -n "$noloop" ]
	   then
		moreentries=TRUE
	   	getyn "
	Would you like to make any more changes?"
	   	case $? in
			0)
		   	   HA=
		   	   ID=
		   	   LUN=
		   	   HATYPE=
		   	   continue     ;;
			*) ;;
		esac 
	   fi

	   # if -n flag given on command line, don't prompt for relink
	   [ "$relink" = "no" ] && cleanup $OK

	   if [ "$_RELINK" -o "$_NOPROMPT" ]
	   then
		just_relink
		cleanup ${major}
	   fi

	   echo "${CLEAR}

	SCSI ${devdscr} Configuration
"
           if ask_relink 
	   then
		cleanup $OK
	   else
		echo "
	The kernel will not be rebuilt now.
"
		[ "$action" = "add" ] &&  { 
		echo "
	Note: Any device that has been added to the SCSI 
	configuration will not be usable until the kernel 
	is rebuilt & rebooted.

	Also, if other changes are made to the SCSI devices 
	prior to the rebuilding and rebooting of the kernel, 
	previous SCSI device changes may be lost.

	Press return to continue:  \c"
	read x
		}
		cleanup $FAIL 
	   fi ;;
	1) echo "
	The SCSI configuration file has not been updated.
"
	   getyn "
	Would you like to try again?"
	   case $? in
		0)
		   HA=
		   ID=
		   LUN=
		   HATYPE=
		   continue     ;;
		1) checkreboot  
		   echo "
	SCSI Configuration script exiting.
"
		   cleanup $FAIL  ;;
	   esac	;;
	2) echo "
	The SCSI configuration file has not been updated.
"
	   sleep 2
	   cleanup $FAIL  ;;
esac
done
