Changeset 1003

Show
Ignore:
Timestamp:
08/27/07 10:38:16 (15 months ago)
Author:
aj
Message:

fixed typo ("-u" instead of "-z") and other improvements by Kay Sievers.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/etc/openct_usb.in

    r997 r1003  
    11#!/bin/sh 
    22 
    3 test "$ACTION" = "add" || exit 0 
    4 test -e /var/run/openct/status || exit 0 
     3[ -n "$DEVPATH" ] || exit 0 
     4[ "$ACTION" = "add" ] || exit 0 
     5[ -e /var/run/openct/status ] || exit 0 
    56 
    6 ( 
     7# try to get the device node from the parent device 
     8if [ -z "$DEVNAME" ]; then 
     9        DEVNAME=/dev/$(udevinfo --query=name --path=$(dirname $DEVPATH)) 
     10fi 
    711 
    8 # try to get the device path from udevinfo. 
    9 if [ -z "$DEVICE" -a -u "$DEVNAME" ] 
    10 then 
    11         if [ -z "$DEVPATH" ] 
    12         then 
     12# if udev supplied a device node directly from the usb-device, we use it, 
     13# because it is guaranteed to exist at the time we run 
     14if [ -n "$DEVNAME" -a -e "$DEVNAME" ]; then 
     15        DEVICE="$DEVNAME" 
     16fi 
     17 
     18[ -n "$DEVICE" ] || exit 0 
     19 
     20if [ -z "$PRODUCT" -a -n "$MODALIAS" ]; then 
     21        PRODUCT=$(echo $MODALIAS | sed -e 's/usb:v\(....\)p\(....\)d\(....\).*/\1\/\2\/\3/g' |tr A-F a-f) 
     22fi 
     23 
     24if [ -z "$PRODUCT" ]; then 
     25        V=$(cat /sys$(dirname $DEVPATH)/idVendor | sed -e 's/^0*//') 
     26        P=$(cat /sys$(dirname $DEVPATH)/idProduct | sed -e 's/^0*//') 
     27        D=$(cat /sys$(dirname $DEVPATH)/bcdDevice | sed -e 's/^0*//') 
     28        PRODUCT="$V/$P/$D" 
     29fi 
     30 
     31[ -n "$PRODUCT" ] || exit 0 
     32 
     33# we may neeed to wait for the device node, when usbfs is used 
     34for A in "0 1 2 3 4 5 6 7 8 9"; do 
     35        if [ -e "$DEVICE" ]; then 
     36                SBINDIR/openct-control attach usb:$PRODUCT usb $DEVICE 
    1337                exit 0 
    1438        fi 
    15         UDEVINFO="`udevinfo --query=name --path=$(dirname $DEVPATH)`" 
    16         if [ -z "$UDEVINFO" ] 
    17         then 
    18                 exit 0 
    19         fi 
    20         DEVICE="/dev/$UDEVINFO" 
    21 fi 
     39        sleep 0.1 
     40done 
    2241 
    23 if [ -n "$DEVICE" ] 
    24 then 
    25         for A in `seq 10` 
    26         do 
    27                 if test -e $DEVICE 
    28                 then 
    29                         if test -z "$PRODUCT" 
    30                         then 
    31                                 PRODUCT="`echo $MODALIAS |sed -e "s/usb:v\(....\)p\(....\)d\(....\).*/\1\/\2\/\3/g" |tr A-F a-f`" 
    32                         fi 
    33  
    34                         # if you see two ifdhandlers for one device, then you can 
    35                         # either comment out the next line here ... 
    36                         SBINDIR/openct-control attach usb:$PRODUCT usb $DEVICE 
    37                         exit 0 
    38                 fi 
    39                 sleep 0.1 
    40         done 
    41         echo "$0 waited for $DEVICE but it did not appear." \ 
    42                 |logger -p daemon.error 
    43         exit 1 
    44 fi 
    45  
    46 if [ -n "$DEVNAME" ] 
    47 then 
    48         for A in `seq 10` 
    49         do 
    50                 if test -e $DEVNAME 
    51                 then 
    52                         V="`cat /sys/$DEVPATH/device/idVendor |sed -e "s/^0*//"`" 
    53                         P="`cat /sys/$DEVPATH/device/idProduct|sed -e "s/^0*//"`" 
    54                         D="`cat /sys/$DEVPATH/device/bcdDevice |sed -e "s/^0*//"`" 
    55                         PRODUCT="$V/$P/$D" 
    56                         # or the following line. both should disable that effect. 
    57                         SBINDIR/openct-control attach usb:$PRODUCT usb $DEVNAME 
    58  
    59                         exit 0 
    60                 fi 
    61                 sleep 0.1 
    62         done 
    63         echo "$0 waited for $DEVNAME but it did not appear." \ 
    64                 |logger -p daemon.error 
    65         exit 1 
    66 fi 
    67  
    68 ) & 
    69 disown %1 
    70  
     42echo "$0 waited for $DEVICE but it did not appear." | logger -p daemon.error 
    7143exit 0