summaryrefslogtreecommitdiff
path: root/tools/scripts/viewbtsnoop.sh
blob: 61f2485661cdd6cd7c718434abcca46f082e9316 (plain)
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
#!/bin/bash

# This is a script that will allow you to open a btsnooz log
# in wireshark directly from a zip file. This script will handle
# the unzipping if it is a zip file, or will convert the btsnooz
# directly in the case of a plain text file for use with wireshark.
# After wireshark closes, it will clean up all the temporary files
# used.

WIRESHARK="${WIRESHARK:-wireshark}"
BTSNOOZ="${BTSNOOZ:-btsnooz.py}"

if ! hash "${WIRESHARK}" 2>/dev/null;
then
    echo "Please make sure wireshark is in your path before running."
    exit 1;
fi

if ! hash btsnooz.py 2>/dev/null;
then
    echo "Please make sure btsnooz.py is in your path before running."
    exit 2;
fi

if [ $# -eq 0 ];
then
    echo "Usage: $0 bugreport(.txt|.zip)"
    exit 3;
fi

BUGREPORT="$1"
FILENAME="$(basename ${BUGREPORT})"
TMPDIR=$(mktemp --tmpdir -d "viewbtsnooz_XXXXX")
LOGFILE="${TMPDIR}/${FILENAME%.*}.btsnooz"

trap ctrl_c INT
function ctrl_c() {
    rm -rf "${TMPDIR}"
}

if [ ! -f "${BUGREPORT}" ];
then
    echo "File ${BUGREPORT} does not exist."
    exit 4;
fi

if [ ! -d "${TMPDIR}" ];
then
    echo "Unable to create temp. dir (${TMPDIR}) :("
    exit 5;
fi

if [ "${BUGREPORT: -4}" == ".zip" ];
then
    unzip "${BUGREPORT}" -d "${TMPDIR}"
    BUGREPORT="${TMPDIR}/${FILENAME%.*}.txt"
fi

if [ -f "${BUGREPORT}" ];
then
    ${BTSNOOZ} "${BUGREPORT}" > "${LOGFILE}"
    if [ ! $? -eq 0 ];
    then
        echo "Could not extract btsnooz data from ${BUGREPORT}."
        rm -rf "${TMPDIR}"
        exit 6;
    fi

    ${WIRESHARK} "${LOGFILE}"
else
    echo "Looks like there is no plain text bugreport (${BUGREPORT})?"
fi

rm -rf "${TMPDIR}"