Home | History | Annotate | Download | only in scripts
      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 
     10 WIRESHARK="${WIRESHARK:-wireshark}"
     11 BTSNOOZ="${BTSNOOZ:-btsnooz.py}"
     12 
     13 if ! hash "${WIRESHARK}" 2>/dev/null;
     14 then
     15     echo "Please make sure wireshark is in your path before running."
     16     exit 1;
     17 fi
     18 
     19 if ! hash btsnooz.py 2>/dev/null;
     20 then
     21     echo "Please make sure btsnooz.py is in your path before running."
     22     exit 2;
     23 fi
     24 
     25 if [ $# -eq 0 ];
     26 then
     27     echo "Usage: $0 bugreport(.txt|.zip)"
     28     exit 3;
     29 fi
     30 
     31 BUGREPORT="$1"
     32 FILENAME="$(basename ${BUGREPORT})"
     33 TMPDIR=$(mktemp --tmpdir -d "viewbtsnooz_XXXXX")
     34 LOGFILE="${TMPDIR}/${FILENAME%.*}.btsnooz"
     35 
     36 trap ctrl_c INT
     37 function ctrl_c() {
     38     rm -rf "${TMPDIR}"
     39 }
     40 
     41 if [ ! -f "${BUGREPORT}" ];
     42 then
     43     echo "File ${BUGREPORT} does not exist."
     44     exit 4;
     45 fi
     46 
     47 if [ ! -d "${TMPDIR}" ];
     48 then
     49     echo "Unable to create temp. dir (${TMPDIR}) :("
     50     exit 5;
     51 fi
     52 
     53 if [ "${BUGREPORT: -4}" == ".zip" ];
     54 then
     55     unzip "${BUGREPORT}" -d "${TMPDIR}"
     56     BUGREPORT="${TMPDIR}/${FILENAME%.*}.txt"
     57 fi
     58 
     59 if [ -f "${BUGREPORT}" ];
     60 then
     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}"
     70 else
     71     echo "Looks like there is no plain text bugreport (${BUGREPORT})?"
     72 fi
     73 
     74 rm -rf "${TMPDIR}"
     75