Skip to content

Commit

Permalink
usb-serial/list-ttys: Resolve shellcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bergzand committed Oct 30, 2020
1 parent 9e4dd8e commit cb66089
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions dist/tools/usb-serial/list-ttys.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

# Copyright (C) 2015 Eistec AB
# Copyright (C) 2015 Ludwig Knüpfer <[email protected]>
Expand All @@ -8,25 +8,26 @@
# details.

if [ ! -d /sys/bus/usb/devices ]; then
echo "$(basename $0): /sys/bus/usb/devices not a directory (/sys is not mounted?)" >&2
echo "$(basename "$0"): /sys/bus/usb/devices not a directory (/sys is not mounted?)" >&2
exit 1
fi

# iterate over usb-tty devices:
for basedev in $(find /sys/bus/usb/devices/ -regex "/sys/bus/usb/devices/[0-9]+[^:/]*" -maxdepth 2 -follow 2>/dev/null); do
ttydirs=$(find ${basedev} -regex "${basedev}/[^/]*:.*" -mindepth 2 -maxdepth 3 -name tty -follow 2>/dev/null)
while IFS= read -r -d '' basedev
do
ttydirs=$(find "${basedev}" -regex "${basedev}/[^/]*:.*" -mindepth 2 -maxdepth 3 -name tty -follow 2>/dev/null)
if [ -z "${ttydirs}" ]; then
continue
fi
# See if the device has any tty devices assigned to it.
ttys=$(find ${ttydirs} -maxdepth 1 -mindepth 1 -printf '%f, ' | sed -e 's/, $/\n/' 2>/dev/null)
ttys=$(find "${ttydirs}" -maxdepth 1 -mindepth 1 -printf '%f, ' | sed -e 's/, $/\n/' 2>/dev/null)
if [ -z "${ttys}" ]; then
continue
fi
# Get all info
parent=$(echo ${basedev} | sed -e 's%\(/sys/bus/usb/devices/[^/]*\)/.*%\1%')
parent=$(echo "${basedev}" | sed -e 's%\(/sys/bus/usb/devices/[^/]*\)/.*%\1%')
serial=$(cat "${parent}/serial" 2>/dev/null)
manuf=$(cat "${parent}/manufacturer" 2>/dev/null)
product=$(cat "${parent}/product" 2>/dev/null)
echo "${parent}: ${manuf} ${product}, serial: '${serial}', tty(s): ${ttys}"
done
done < <(find /sys/bus/usb/devices/ -regex "/sys/bus/usb/devices/[0-9]+[^:/]*" -maxdepth 2 -follow -print0 2>/dev/null);

0 comments on commit cb66089

Please sign in to comment.