#!/bin/sh

# SmartLink USB modem hotplug integration
# Eduard Bloch <blade@debian.org>, 2004
# 
# If you have good ideas how to extend it to detect multiple modems,
# please tell me!

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/slmodemd
NAME=slmodemd
PIDFILE=/var/run/$NAME.usb.pid

if ! test -x $DAEMON ; then
   echo "Please install sl-modem-daemon!"
fi

# You need to define options there there
test -r /etc/default/slmodemd && . /etc/default/slmodemd

# or here
test -r /etc/default/sl-modem-daemon && . /etc/default/sl-modem-daemon

PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

test -r /etc/default/sl-modem-daemon && . /etc/default/sl-modem-daemon

mkdev ()
{
   if test ! -e /dev/$1$2; then
      mknod -m 660 /dev/$1$2 c $3 $2
      chown root:dialout /dev/$1$2
   fi
}

mkdev slusb 0 213

case "$ACTION" in
   add)
   start-stop-daemon --start --pidfile $PIDFILE --exec $DAEMON --make-pidfile --background --quiet -- $OPTS /dev/slusb0 -c "$SLMODEMD_COUNTRY"
   RETVAL=$?
   if [ "$RETVAL" = 0 -a "$NOSYMLINK" != 1 ] ; then
      echo "Creating /dev/modem symlink, pointing to: /dev/ttySL0."
      ln -sf ttySL0 /dev/modem
   fi

   ;;
   remove)
   start-stop-daemon --stop --pidfile $PIDFILE --exec $DAEMON --quiet && rm -f $PIDFILE
   # the not-so-nice termination method
   if test -r $PIDFILE ; then
      pid=`cat $PIDFILE`
      if test "$pid" -a -e /proc/$pid ; then
         kill -9 $pid && rm $PIDFILE
      fi
   fi
   ;;
esac

exit 0

