#!/bin/bash
#
# This script handles the ADI ADSL Modem USB driver after firmware
# uploading. It loads the DSP code as needed by the modem.

. ./setvars

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

# 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 "${INSTALL_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

# if the "internet" service is started, pppd is automatically
# lauched when the modem is plugged or when the system starts
#if [ -f /var/run/eagle-usb ] ; then
#	fctStartAdsl
#	if [ $? == 0 ] ; then
#		logger "${PPPDOKMSG}"
#	else
#		logger "${PPPDERRORMSG} (${?})"
#	fi
#fi
