#!/bin/sh
#usb modem
#Barry Kauler, LGPL 2008
#called from rc.local0. note, rc.local0 calls rc.modem beforehand which
#sets /dev/modem if a serial modem found.
#This script sets device links as cdcacm would, then ensures module cdc-acm gets loaded (even though its script will not be executed in current boot-up).  The dgcmodem-package modem initialzation script, dgc, will also execute, to complete dgc modem initialization.

[ -h /etc/init.d/dgc ] && rm /etc/init.d/dgc #delete dgcmodem package original init script link - use this instead.
[ ! -e /dev/ttyACM0 ] && ln -snf input/ttyACM0 /dev/ttyACM0  #device name for pupdial

#if a modem found, quit...
[ -h /dev/modem -a "`readlink /dev/modem`" != "ttyACM0" ] && exit

[ ! $1 ] && exit
[ "$1" != "start" ] && exit

[ "`lsmod | grep '^dgcusbdcp'`" = "" ] && exit
ln -snf ttyACM0 /dev/modem
if [ "`lsmod | grep '^cdc_acm'`" != "" ];then #also needs acm driver loaded
 echo "Loading cdc-acm (for dgcusbdcp)"
 modprobe cdc-acm
 sync
 [ "`lsmod | grep '^cdc_acm'`" = "" ] && sleep 5 #allow module time to load
fi

/usr/sbin/dgcconfig --rcstart

###END###
