#!/bin/bash
# Copyright (C) 2003-2005 Olivier Borowski
# Copyright (C) 2005-2006 Aurox Team <aurox@aurox.org>
#
# this script should only be called by hotplug (giving the $DEVICE param)

# this script is called multiple times by hotplug, so we try to
# send DSP only one time
SEND_DSP="false"
if [ -z "$DEVPATH" ] ; then
	# kernel 2.4
	SEND_DSP="true"
else
	# kernel 2.5+
	LAST_CHARS=`echo $DEVPATH | sed -e "s/.*\-.[^:]*//1"`
	if [ "x$LAST_CHARS" = "x:1.0" ] ; then
		SEND_DSP="true"
	fi
fi

if [ $SEND_DSP = "true" ] ; then
	# small delay to prevent a bug
	sleep 1s
	if [ "$REMOVER" ]; then
		mkdir -p `dirname $REMOVER`
		echo '#!/bin/sh' > $REMOVER
		echo 'kill `head -n1 /var/run/ppp-adsl.pid`' >> $REMOVER
		chmod +x $REMOVER
	fi
	# wait for synchro
	# FIXME: works for 1 modem only
	while ! grep -q operational /proc/driver/ueagle-atm/*; do
		sleep 2s
	done
	pppd call adsl
fi

