Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Speedtouch USB Hotplug script.
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 28 May 2003
Posts: 368
Location: Alexandria, Egypt

PostPosted: Wed Apr 14, 2004 4:25 pm    Post subject: Speedtouch USB Hotplug script. Reply with quote

I wrote this not-so-little python script to do that.
It simply forks in the background and waits until modem_run and pppd are done.
copy it to /etc/hotplug/usb/speedtch then chmod +x it.
the code is pretty simple to understand.
this is for speedtouch-1.2 package, if you gonna use the older version then set BOOTSECTOR="".

#!/usr/bin/python -O
# this goes to /etc/hotplug/usb/speedtch
# Speedtouch hotplug script by OneOfOne{at}
# this is released under the GPL.
Q: Why is this a daemon?
A: The whole point of this script (IMHO) is to be run in background and since you can't actually do that with hotplug (afaik, specially while booting) it must be run as a daemon or else it'd block the init script until modem_run and pppd are done executing.
import os, sys
import atexit
MODEM_RUN_PATH = "/usr/sbin/modem_run"
PPPD_PATH = "/usr/sbin/pppd"
FIRMWARE = "/root/adsl/KQD6_3.012"       # modem_run's -f option
BOOTSECTOR = "-a /usr/share/speedtouch/boot.v123.bin"    # modem_run's -a option, should be the same as FIRMWARE in most cases, if it doesn't work set it to /usr/share/speedtouch/boot.v123.bin
MODEM_RUN_VERBOSE_LEVEL = 2          # guess :p, level is [0-2]
PPPD_CONNECTION_NAME = "adsl"         # take another guess!   
"""Main program"""
def main():
   myexec('modprobe speedtch')
   _mrs = myexec(cmd)
   cmd = '%s call %s' % (PPPD_PATH, PPPD_CONNECTION_NAME)
   _ps = myexec(cmd)
   sys.exit(_mrs + _ps)
def isRunning(app):
   return len(os.popen('ps -C "%s" -ocmd' % app).readlines()) > 1
def fork_me():
   if not DAEMON: return 0
   # thanks to
      pid = os.fork()
      if pid > 0: os._exit(0)
      os.chdir("/"); os.setsid(); os.umask(8)
      pid = os.fork()
      if pid > 0: os._exit(0)
      return 2   
   return 0
def myexec(cmd):
   if type(cmd) == type(' '): cmd = cmd.split()
   return os.spawnv(os.P_WAIT, cmd[0], cmd)
if __name__ == "__main__":
   ACTION = os.environ.get('ACTION', None)
   if not ACTION:
   if fork_me() == 2:
      sys.stderr.write('%s[%d]: Couldn\'t be forked.\n' % (sys.argv[0], os.getpid()))
   if ACTION == 'add':
      if isRunning('modem_run') or isRunning('pppd'):
   elif ACTION == 'remove':
      myexec('killall pppd')
      myexec('killall modem_run')
      myexec('rmmod speedtch')

Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum