#!/bin/bash
# $Id: eu_dsp,v 1.4 2004/02/21 01:25:02 Tux Exp $
# Name: eu_dsp
# Goal: This script handles the ADI ADSL Modem USB driver after firmware
#       uploading. It loads the DSP code as needed by the modem.
#		It create a script /var/run/usb/%proc%bus%usb%002%005 in order
#		for the ADSL connexion to be stopped and module to be unloaded.
#       It should only be run by hotplug.
# Author: Tux
# Params (given by hotplug):
#	$DEVICE (ex: /proc/bus/usb/002/005)

. /etc/eagle-usb/scripts/setvars

# this script can only be called by hotplug (giving the $DEVICE param)
if [ -z $DEVICE ] ; then
	echo -e "$NO_PARAM_MSG"
	exit
fi

LAST_CHARS="${DEVPATH:`expr ${#DEVPATH} - 3`}"
if [ -z "$LAST_CHARS" ] || [ "x$LAST_CHARS" = "x1.0" ] ; then
	# script called when the modem will be unplugged
	mkdir -p /var/run/usb
	UNPLUGSCRIPT="/var/run/usb/`echo $DEVICE | sed 's/\//%/g'`"
	echo "#!/bin/bash" > $UNPLUGSCRIPT
	echo "${SBIN_DIR}/fctStopAdsl" >> $UNPLUGSCRIPT
	echo "rmmod eagle-usb" >> $UNPLUGSCRIPT
	echo "rm -f ${UNPLUGSCRIPT}" >> $UNPLUGSCRIPT
	chmod u+x $UNPLUGSCRIPT
	
	# load DSP & options
	eaglectrl -d 0>&1 1>&1 2>&1 | logger
fi
