2020-10-30 16:08:13 +01:00
|
|
|
#!/usr/bin/env bash
|
2015-01-10 15:50:56 +01:00
|
|
|
|
|
|
|
# Copyright (C) 2015 Eistec AB
|
2015-09-27 18:58:30 +02:00
|
|
|
# Copyright (C) 2015 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
2015-01-10 15:50:56 +01:00
|
|
|
#
|
|
|
|
# This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
# Public License v2.1. See the file LICENSE in the top level directory for more
|
|
|
|
# details.
|
|
|
|
|
|
|
|
if [ ! -d /sys/bus/usb/devices ]; then
|
2020-10-30 16:08:13 +01:00
|
|
|
echo "$(basename "$0"): /sys/bus/usb/devices not a directory (/sys is not mounted?)" >&2
|
2015-01-10 15:50:56 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# iterate over usb-tty devices:
|
2020-10-30 16:08:13 +01:00
|
|
|
while IFS= read -r -d '' basedev
|
|
|
|
do
|
|
|
|
ttydirs=$(find "${basedev}" -regex "${basedev}/[^/]*:.*" -mindepth 2 -maxdepth 3 -name tty -follow 2>/dev/null)
|
2015-01-10 15:50:56 +01:00
|
|
|
if [ -z "${ttydirs}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# See if the device has any tty devices assigned to it.
|
2020-10-30 16:08:13 +01:00
|
|
|
ttys=$(find "${ttydirs}" -maxdepth 1 -mindepth 1 -printf '%f, ' | sed -e 's/, $/\n/' 2>/dev/null)
|
2015-01-10 15:50:56 +01:00
|
|
|
if [ -z "${ttys}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# Get all info
|
2020-10-30 16:08:13 +01:00
|
|
|
parent=$(echo "${basedev}" | sed -e 's%\(/sys/bus/usb/devices/[^/]*\)/.*%\1%')
|
2015-01-10 15:50:56 +01:00
|
|
|
serial=$(cat "${parent}/serial" 2>/dev/null)
|
|
|
|
manuf=$(cat "${parent}/manufacturer" 2>/dev/null)
|
|
|
|
product=$(cat "${parent}/product" 2>/dev/null)
|
2019-09-30 18:28:32 +02:00
|
|
|
echo "${parent}: ${manuf} ${product}, serial: '${serial}', tty(s): ${ttys}"
|
2020-10-30 16:08:13 +01:00
|
|
|
done < <(find /sys/bus/usb/devices/ -regex "/sys/bus/usb/devices/[0-9]+[^:/]*" -maxdepth 2 -follow -print0 2>/dev/null);
|