diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-03-20 18:19:29 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-03-20 18:19:29 (GMT) |
commit | 2ee673e2238b9002cdb1d40ab3bd3f73af0782ca (patch) | |
tree | d9d5e1a993ec5e6c5dbceae4b95920213fd59b79 /openwrt/rhctl/files/rhctl-usbserial.hotplug | |
parent | 5988cbdd0b98251a4d23a72c0ee1c47e65824517 (diff) |
fixed hotplug script for USB serial converter
Diffstat (limited to 'openwrt/rhctl/files/rhctl-usbserial.hotplug')
-rwxr-xr-x | openwrt/rhctl/files/rhctl-usbserial.hotplug | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/openwrt/rhctl/files/rhctl-usbserial.hotplug b/openwrt/rhctl/files/rhctl-usbserial.hotplug index 5da2fd1..8d2f7bc 100755 --- a/openwrt/rhctl/files/rhctl-usbserial.hotplug +++ b/openwrt/rhctl/files/rhctl-usbserial.hotplug @@ -2,9 +2,11 @@ # # Persistent naming for usb serial devices. # -# Copyright 2013 Christian Pointner <equinox@helsinki.at> +# Copyright 2013-2014 Christian Pointner <equinox@helsinki.at> # +logger="logger -p daemon.info -t rhctl-usbserial" + idVendor=`echo $PRODUCT | awk -F '/' '{ print($1) }'` idProduct=`echo $PRODUCT | awk -F '/' '{ print($2) }'` bcdDevice=`echo $PRODUCT | awk -F '/' '{ print($3) }'` @@ -14,61 +16,63 @@ if [ "$idVendor" != "403" ] || [ "$idProduct" != "6011" ]; then fi DEVPATH="/sys$DEVPATH" -if [ ! -e "$DEVPATH/bInterfaceNumber" ]; then - exit 0 -fi +if [ $ACTION == "add" ]; then + if [ ! -e "$DEVPATH/bInterfaceNumber" ]; then + exit 0 + fi -PARENT=`dirname "$DEVPATH` -SERIAL=`cat $PARENT/serial` + PARENT=`dirname "$DEVPATH` + SERIAL=`cat $PARENT/serial` -if [ "$SERIAL" != "FTVSOXJP" ]; then - exit 0 + if [ "$SERIAL" != $(uci -q get rhctl.@global[0].ftdi_serial) ]; then + exit 0 + fi fi -logger="logger -p daemon.info -t rhctl-usbserial" - hotplug=/dev/.hotplug token=$hotplug/`echo $PRODUCT$DEVPATH | sed 's/\//=/g'` case "$ACTION" in -add) - ttydir=`echo "$DEVPATH/ttyUSB*` - tty=`basename $ttydir` - interface=`cat "$DEVPATH/bInterfaceNumber"` + add) + ttydir=`echo "$DEVPATH/ttyUSB*` + tty=`basename $ttydir` + interface=`cat "$DEVPATH/bInterfaceNumber"` - device="$interface" + device="$interface" - case "$interface" in - 00) device="ttyMasterCtl" - ;; - 01) device="ttyMasterHB" - ;; - 02) device="ttyStandbyCtl" - ;; - 03) device="ttyStandbyHB" - ;; - *) exit 0 - ;; - esac + case "$interface" in + 00) device="ttyMasterCtl" + ;; + 01) device="ttyMasterHB" + ;; + 02) device="ttyStandbyCtl" + ;; + 03) device="ttyStandbyHB" + ;; + *) exit 0 + ;; + esac - mkdir -p "$hotplug" - rm -f "/dev/$device" "$token" - ln -s "/dev/$device" "$token" - ln -s "/dev/$tty" "/dev/$device" - $logger "added: tty=$tty device=$device" - ;; -remove) - if [ -e "$token" ]; then - device=`ls -l $token | sed 's/.*-> //;/ /s/.*//'` - case "$device" in - "") # no symlink - $logger "failed: token=$token device=$device" - ;; - *) $debug rm -f $token $device - $logger "removed: $device" - ;; - esac - fi - ;; + mkdir -p "$hotplug" + rm -f "/dev/$device" "$token" + ln -s "/dev/$device" "$token" + ln -s "/dev/$tty" "/dev/$device" + $logger "added: tty=$tty device=$device" + ;; + remove) + if [ -h "$token" ]; then + device=$(ls -l $token | sed 's/.*-> //;/ /s/.*//') + case "$device" in + "") # no symlink + $logger "failed: token=$token device=$device" + ;; + *) + rm -f $token $device + $logger "removed: $device" + ;; + esac + fi + ;; esac +exit 0 |