-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathusb-descriptor-collect.sh
More file actions
executable file
·77 lines (69 loc) · 2.67 KB
/
Copy pathusb-descriptor-collect.sh
File metadata and controls
executable file
·77 lines (69 loc) · 2.67 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# Copyright (C) 2016 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Daniel Kopecek <dkopecek@redhat.com>
#
set -e -o pipefail
SED=$(command -v sed)
FIND=$(command -v find)
LSUSB=$(command -v lsusb)
SHA1SUM=$(command -v sha1sum)
TAR=$(command -v tar)
MKTEMP=$(command -v mktemp)
CP=$(command -v cp)
WC=$(command -v wc)
RM=$(command -v rm)
TEMPDIR=$($MKTEMP -d --tmpdir usb-descriptor-collect.XXXXXX || (echo "Failed to create temporary directory"; exit 1))
ROOTDIR="$TEMPDIR/usb-descriptor-data"
mkdir $ROOTDIR || (echo "Failed to create data root directory: $ROOTDIR"; exit 1)
for dev_syspath in $($FIND /sys/bus/usb/devices/ -regex '.*/[0-9]+-[0-9]+\(\.[0-9]+\)*$' -o -regex '.*/usb[0-9]+$'); do
echo "Collecting data from $dev_syspath"
pushd "$dev_syspath"
dev_bus=$(< busnum)
dev_num=$(< devnum)
echo " busnum: $dev_bus"
echo " devnum: $dev_num"
count_c=$($LSUSB -s $dev_bus:$dev_num -v 2> /dev/null | $SED -n 's|Configuration Descriptor|&|p' | $WC -l)
count_i=$($LSUSB -s $dev_bus:$dev_num -v 2> /dev/null | $SED -n 's|Interface Descriptor|&|p' | $WC -l)
count_e=$($LSUSB -s $dev_bus:$dev_num -v 2> /dev/null | $SED -n 's|Endpoint Descriptor|&|p' | $WC -l)
echo " count_c: $count_c"
echo " count_i: $count_i"
echo " count_e: $count_e"
descriptor_hash=$($SHA1SUM descriptors | $SED -n 's|^\([a-fA-F0-9]\{40\}\).*$|\1|p')
echo " hash: $descriptor_hash"
echo "count_c: $count_c" > "$ROOTDIR/$descriptor_hash.log"
echo "count_i: $count_i" >> "$ROOTDIR/$descriptor_hash.log"
echo "count_e: $count_e" >> "$ROOTDIR/$descriptor_hash.log"
$CP -f descriptors "$ROOTDIR/$descriptor_hash.bin"
popd
done
ARCHIVE_PATH="$TEMPDIR/usb-descriptor-data.tar.gz"
echo "Creating data archive: $ARCHIVE_PATH"
pushd "$TEMPDIR"
$TAR zcvf $ARCHIVE_PATH usb-descriptor-data
popd
$RM -rf "$TEMPDIR/usb-descriptor-data"
echo "========================================="
echo
echo " Data collection complete!"
echo " Please send the data archive to dnk.usbdev@gmail.com"
echo
echo " Archive path: $ARCHIVE_PATH"
echo
echo " Thanks!"
echo
echo "========================================="