#!/bin/bash

case "$1" in
	start)
		count=0
		while [[ $((count++)) -lt 40 ]]
		do
			if dmesg | grep 'ADSL line is up'
			then
				pppd call speedtch
				# start link monitor
				sleep 2
				/usr/bin/test-link &
				exit 0
			fi
			sleep 1
		done
		echo "The SpeedTouch firmware did not load"
	;;

	stop)
		killall pppd
		killall test-link
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac
