• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# This is a script that will allow you to open a btsnooz log
4# in wireshark directly from a zip file. This script will handle
5# the unzipping if it is a zip file, or will convert the btsnooz
6# directly in the case of a plain text file for use with wireshark.
7# After wireshark closes, it will clean up all the temporary files
8# used.
9
10WIRESHARK="${WIRESHARK:-wireshark}"
11BTSNOOZ="${BTSNOOZ:-btsnooz.py}"
12
13if ! hash "${WIRESHARK}" 2>/dev/null;
14then
15    echo "Please make sure wireshark is in your path before running."
16    exit 1;
17fi
18
19if ! hash btsnooz.py 2>/dev/null;
20then
21    echo "Please make sure btsnooz.py is in your path before running."
22    exit 2;
23fi
24
25if [ $# -eq 0 ];
26then
27    echo "Usage: $0 bugreport(.txt|.zip)"
28    exit 3;
29fi
30
31BUGREPORT="$1"
32FILENAME="$(basename ${BUGREPORT})"
33TMPDIR=$(mktemp --tmpdir -d "viewbtsnooz_XXXXX")
34LOGFILE="${TMPDIR}/${FILENAME%.*}.btsnooz"
35
36trap ctrl_c INT
37function ctrl_c() {
38    rm -rf "${TMPDIR}"
39}
40
41if [ ! -f "${BUGREPORT}" ];
42then
43    echo "File ${BUGREPORT} does not exist."
44    exit 4;
45fi
46
47if [ ! -d "${TMPDIR}" ];
48then
49    echo "Unable to create temp. dir (${TMPDIR}) :("
50    exit 5;
51fi
52
53if [ "${BUGREPORT: -4}" == ".zip" ];
54then
55    unzip "${BUGREPORT}" -d "${TMPDIR}"
56    BUGREPORT="${TMPDIR}/${FILENAME%.*}.txt"
57fi
58
59if [ -f "${BUGREPORT}" ];
60then
61    ${BTSNOOZ} "${BUGREPORT}" > "${LOGFILE}"
62    if [ ! $? -eq 0 ];
63    then
64        echo "Could not extract btsnooz data from ${BUGREPORT}."
65        rm -rf "${TMPDIR}"
66        exit 6;
67    fi
68
69    ${WIRESHARK} "${LOGFILE}"
70else
71    echo "Looks like there is no plain text bugreport (${BUGREPORT})?"
72fi
73
74rm -rf "${TMPDIR}"
75