-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindUsbTty.sh
executable file
·53 lines (47 loc) · 1.02 KB
/
FindUsbTty.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "USAGE: $0 VID PID" >&2
echo "VID & PID specify the vendor and product ID of the desired USB device, given in hex." >&2
exit -1
fi
StartingDir=$PWD
Vendor=$1
Product=$2
cd /sys/bus/usb/devices
for file in ./*
do
if [[ "$file" != *":"* ]]
then
if [[ `cat $file/idVendor` == "$Vendor" ]]
then
if [[ "`cat $file/idProduct`" == "$Product" ]]
then
cd "$file"
file=${file:2}
for ep in ./$file*
do
# if [[ -d "./$file:1.0" ]]
# then
if [[ -d "./$ep/tty" ]]
then
cd "./$ep/tty"
for tty in *
do
# In rare circumstances, [[ -c "/dev/${tty}" ]] may fail to `stat`, and hence return false,
# even though the file exists. Hopefully bypassing this check doesn't introduce other issues.
#if [[ -c "/dev/${tty}" ]]
#then
echo "/dev/${tty}"
exit 0
#fi
done
fi
# fi
done
# Should I return an error if the USB was valid but has no TTY?
exit 2
fi
fi
fi
done
exit 1