#!/bin/sh
# /etc/hotplug.d/default/speedtouch.hotplug:
# This is a hack to make SpeedTouch 330 modem work with hotplug
#
# Copyright (C) 2005 Aurox Team <aurox@aurox.org>

# bail out if we're not configured
if [ ! -f /etc/sysconfig/speedtouch ]; then
	exit 0
fi

# only SpeedTouch 330 supported for now
if [ "$PHYSDEVBUS" = "usb" ] && [ "$PRODUCT" = "6b9/4061/400" ]; then
	if [ "$ACTION" = "add" ]; then
		sleep 1
		# load firmware and wait for synchro
		running="$(ps -aux |grep -v grep | grep modem_run)"
		if [ -z "$running" ] ; then
		    #bad d3ad semaphores workaround
		    ipcrm -S 0xdeadbeef
		    modem_run -f /lib/firmware/ZZZL_3.012
		    sleep 1
		    pppd call adsl
		fi
	elif [ "$ACTION" = "remove" ]; then
		kill `head -n1 /var/run/ppp-adsl.pid`
		# this won't die so easily
		killall modem_run
		killall -9 pppd
	fi
fi
