[package] comgt: move 3g hotplug handling to tty subsystem, fixes race on coldplug...
[openwrt/svn-archive/archive.git] / package / comgt / files / 3g.usb
1 #!/bin/sh
2
3 . /etc/functions.sh
4
5 log() {
6 logger -t 3g-hotplug "$@"
7 }
8
9 find_3g_iface() {
10 local cfg="$1"
11 local tty="$2"
12
13 local proto
14 config_get proto "$cfg" proto
15
16 [ "$proto" = 3g ] && {
17 local auto
18 config_get_bool auto "$cfg" auto 1
19 [ "$auto" = 1 ] || return 0
20
21 local dev
22 config_get dev "$cfg" device
23
24 if [ "${dev##*/}" = "${tty##*/}" ]; then
25 [ -z "$(ls /var/lock | grep ${dev##*/})" ] && {
26 log "Starting interface $cfg for device ${dev##*/}"
27 sleep 1
28 /sbin/ifup "$cfg"
29 }
30 fi
31 }
32 }
33
34
35 if [ "$ACTION" = add ]; then
36 case "$DEVICENAME" in
37 tty*) config_load network;;
38 *) exit 0;;
39 esac
40
41 local tty
42 for tty in /dev/ttyUSB* /dev/ttyACM* /dev/ttyHS*; do
43 [ -e "$tty" ] || continue
44 config_foreach find_3g_iface interface "$tty"
45 done
46 fi