source: trunk/etc/openct_usb.in @ 1175

Revision 1175, 1.4 KB checked in by aj, 2 years ago (diff)

latest udev rules, thanks to the ubuntu developers.

Line 
1#!/bin/sh
2
3# maybe udev passes the device name to us.
4if [ -n "$1" ]; then
5        DEVNAME="$1"
6fi
7
8[ -n "$DEVPATH" ] || exit 0
9[ "$ACTION" = "add" ] || exit 0
10[ -e "@OPENCT_SOCKET_PATH@/status" ] || exit 0
11
12# try to get the device node from the parent device
13if [ -z "$DEVNAME" ]; then
14        #
15        # Guess udev info interface.
16        # Newer udev uses udevadm
17        #
18        if which udevinfo > /dev/null 2>&1; then
19                UDEVINFO="udevinfo"
20        else
21                UDEVINFO="udevadm info"
22        fi
23        DEVNAME=/dev/$($UDEVINFO --query=name --path=$(dirname $DEVPATH))
24fi
25
26# if udev supplied a device node directly from the usb-device, we use it,
27# because it is guaranteed to exist at the time we run
28if [ -n "$DEVNAME" -a -e "$DEVNAME" ]; then
29        DEVICE="$DEVNAME"
30fi
31
32[ -n "$DEVICE" ] || exit 0
33
34if [ -z "$PRODUCT" -a -n "$MODALIAS" ]; then
35        PRODUCT=$(echo $MODALIAS | sed -e 's/usb:v\(....\)p\(....\)d\(....\).*/\1\/\2\/\3/g' |tr A-F a-f)
36fi
37
38if [ -z "$PRODUCT" ]; then
39        V=$(cat /sys$(dirname $DEVPATH)/idVendor | sed -e 's/^0*//')
40        P=$(cat /sys$(dirname $DEVPATH)/idProduct | sed -e 's/^0*//')
41        D=$(cat /sys$(dirname $DEVPATH)/bcdDevice | sed -e 's/^0*//')
42        PRODUCT="$V/$P/$D"
43fi
44
45[ -n "$PRODUCT" ] || exit 0
46
47# we may neeed to wait for the device node, when usbfs is used
48for A in "0 1 2 3 4 5 6 7 8 9"; do
49        if [ -e "$DEVICE" ]; then
50                @sbindir@/openct-control attach usb:$PRODUCT usb $DEVICE
51                exit 0
52        fi
53        sleep 0.1
54done
55
56echo "$0 waited for $DEVICE but it did not appear." | logger -p daemon.error
57exit 0
Note: See TracBrowser for help on using the repository browser.