~ubuntu-branches/ubuntu/utopic/usb-modeswitch/utopic

« back to all changes in this revision

Viewing changes to .pc/05_upstart_systemd_runtime_detection.patch/usb_modeswitch.sh

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-04-07 11:39:41 UTC
  • mfrom: (17.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20140407113941-b4dwfneyd07pgijf
Tags: 2.1.1+repack0-1ubuntu1
* Merge with Debian unstable; remaining changes: (LP: #1280546)
  - patch to rewrite dispatcher to C.
  - debian/patches/redirect_dispatcher_output.patch: redirect all dispatcher
    output when called from udev to /dev/null.
  - Replace libjim depends with libpipeline-dev, libudev-dev.
* Fixed some bugs in dispatcher rewrite. (LP: #1155975)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# part of usb_modeswitch 2.1.1
 
3
device_in()
 
4
{
 
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
 
12
                fi
 
13
        done </var/lib/usb_modeswitch/$1
 
14
        if [ $(expr "$line" : "$2:$3") != 0 ]; then
 
15
                return 1
 
16
        fi
 
17
        return 0
 
18
}
 
19
 
 
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
 
26
                fi
 
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"
 
33
                fi
 
34
                v_id="$(printf %04x $(($v_id)))"
 
35
                p_id="$(printf %04x $(($p_id)))"
 
36
        else
 
37
                v_id=$3
 
38
        fi
 
39
fi
 
40
PATH=/sbin:/usr/sbin:$PATH
 
41
case "$1" in
 
42
        --driver-bind)
 
43
                (
 
44
                dir=$(ls -d /sys$2/ttyUSB* 2>/dev/null)
 
45
                sleep 1
 
46
                if [ ! -z "$dir" ]; then
 
47
                        exit 0
 
48
                fi
 
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
 
55
                        fi
 
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
 
61
                        fi
 
62
                fi
 
63
                ) &
 
64
                exit 0
 
65
                ;;
 
66
        --symlink-name)
 
67
                device_in "link_list" $v_id $p_id
 
68
                if [ "$?" = "1" ]; then
 
69
                        . /lib/udev/hotplug.functions
 
70
                        wait_for_file /usr/sbin/usb_modeswitch_dispatcher
 
71
                        exec usb_modeswitch_dispatcher $1 $2 2>>/dev/null
 
72
                fi
 
73
                exit 0
 
74
                ;;
 
75
esac
 
76
exec 1<&- 2<&- 5<&- 7<&-
 
77
(
 
78
                . /lib/udev/hotplug.functions
 
79
                wait_for_file /usr/sbin/usb_modeswitch_dispatcher
 
80
                if [ -e "/etc/init/usb-modeswitch-upstart.conf" ]; then
 
81
                        exec /sbin/initctl emit --no-wait usb-modeswitch-upstart UMS_PARAM=$1
 
82
                elif [ -e "/etc/systemd/system/usb_modeswitch@.service" ]; then
 
83
                        exec /usr/bin/systemctl --no-block start usb_modeswitch@$1.service
 
84
                else
 
85
                        exec /usr/sbin/usb_modeswitch_dispatcher --switch-mode $1 &
 
86
                fi
 
87
                exit 0
 
88
) &
 
89
exit 0