#!/bin/bash # This script is a helper for the following udev rules: # # KERNEL=="ttyUSB*", PROGRAM="ttyUSB_id %p", SYMLINK+="tty-%c" # KERNEL=="ttyACM*", PROGRAM="ttyUSB_id %p", SYMLINK+="tty-%c" # # For use with these rules, copy or link this script to # /lib/udev/ttyUSB_id or provide an absolute path in the `PROGRAM' # parameter above. # # [ -z "$1" ] \ && echo -e "usage: $0 \nexample: $0 /class/tty/ttyUSB0" \ && exit 1 TTYDEV=$1 # We support both the full class name as passed by udev, or just the # tty name for command line convenience. DIR1=/sys/$TTYDEV/device DIR2=/sys/class/tty/$TTYDEV/device if [ -x $DIR1 ]; then cd $DIR1; elif [ -x $DIR2 ]; then cd $DIR2; else echo "Can't find $DIR1 nor $DIR2" >&2 exit 1 fi # bus/hub-port physical tree address. # Note that this is not unique if there are multiple interfaces per device! # use one less .. to get the :. tags too. DEVTREE=$(basename $(readlink -f ../../)) # echo $@ DEVTREE=$DEVTREE >>/tmp/ttyUSB_id.log # Follow symlink to usb device entry. cd `pwd -P` cd ../../ if [ -f serial ]; then ID=`cat serial`; elif [ ! -z "$DEVTREE" ]; then ID="$DEVTREE" elif [ -f idProduct ]; then ID=`cat idVendor``cat idProduct` else echo "No serial, and can't use idVendor, idProduct" >&2 exit 1 fi echo $ID exit 0