Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / usbmodeswitch / usb_modeswitch.sh
blob5c20059002f7a9b617af7e5efacc9e186d4e9195
1 #!/bin/sh
2 # part of usb_modeswitch 2.0.1
3 device_in()
5 if [ ! -e /var/lib/usb_modeswitch/$1 ]; then
6 return 0
7 fi
8 while read line
9 do
10 if [ $(expr "$line" : "$2:$3") != 0 ]; then
11 return 1
13 done </var/lib/usb_modeswitch/$1
14 if [ $(expr "$line" : "$2:$3") != 0 ]; then
15 return 1
17 return 0
20 if [ $(expr "$1" : "--.*") ]; then
21 p_id=$4
22 if [ -z $p_id ]; then
23 prod=$5
24 if [ -z $prod ]; then
25 prod=$3
27 prod=${prod%/*}
28 v_id=0x${prod%/*}
29 p_id=0x${prod#*/}
30 if [ "$v_id" = "0x" ]; then
31 v_id="0"
32 p_id="0"
34 v_id="$(printf %04x $(($v_id)))"
35 p_id="$(printf %04x $(($p_id)))"
36 else
37 v_id=$3
40 PATH=/sbin:/usr/sbin:$PATH
41 case "$1" in
42 --driver-bind)
44 dir=$(ls -d /sys$2/ttyUSB* 2>/dev/null)
45 sleep 1
46 if [ ! -z "$dir" ]; then
47 exit 0
49 set +e
50 device_in "bind_list" $v_id $p_id
51 if [ "$?" = "1" ]; then
52 id_attr="/sys/bus/usb-serial/drivers/option1/new_id"
53 if [ ! -e "$id_attr" ]; then
54 modprobe option 2>/dev/null || true
56 if [ -e "$id_attr" ]; then
57 echo "$v_id $p_id ff" > $id_attr
58 else
59 modprobe -r usbserial 2>/dev/null
60 modprobe usbserial "vendor=0x$v_id" "product=0x$p_id" 2>/dev/null
63 ) &
64 exit 0
66 --symlink-name)
67 device_in "link_list" $v_id $p_id
68 if [ "$?" = "1" ]; then
69 if [ -e "/usr/sbin/usb_modeswitch_dispatcher" ]; then
70 exec usb_modeswitch_dispatcher $1 $2 2>>/dev/null
73 exit 0
75 esac
76 exec 1<&- 2<&- 5<&- 7<&-
78 count=20
79 while [ $count != 0 ]; do
80 if [ ! -e "/usr/sbin/usb_modeswitch_dispatcher" ]; then
81 sleep 1
82 count=$(($count - 1))
83 else
84 if [ -e "/etc/init/usb-modeswitch-upstart.conf" ]; then
85 exec /sbin/initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=$1
86 elif [ -e "/etc/systemd/system/usb_modeswitch@.service" ]; then
87 exec /usr/bin/systemctl --no-block start usb_modeswitch@$1.service
88 else
89 exec /usr/sbin/usb_modeswitch_dispatcher --switch-mode $1 &
91 exit 0
93 done
94 ) &
95 exit 0