aboutsummaryrefslogtreecommitdiff
path: root/script/run-midbro.sh
diff options
context:
space:
mode:
authorAndreas Lindhé <andreas@lindhe.io>2017-10-31 08:33:46 +0100
committerAndreas Lindhé <andreas@lindhe.io>2017-10-31 08:41:40 +0100
commitbc5ecd6da7f068a12b9ee5397178723481c7a3ea (patch)
tree6ac5bb33df7c3aacde8eb254c4aee1ce1df9dd29 /script/run-midbro.sh
parent2d5d5be5702867a7a719312a5a148489c3b68f31 (diff)
downloadmidbro-bc5ecd6da7f068a12b9ee5397178723481c7a3ea.tar.gz
midbro-bc5ecd6da7f068a12b9ee5397178723481c7a3ea.tar.bz2
Move all files one level down
Diffstat (limited to 'script/run-midbro.sh')
-rw-r--r--script/run-midbro.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/script/run-midbro.sh b/script/run-midbro.sh
new file mode 100644
index 0000000..a9bb008
--- /dev/null
+++ b/script/run-midbro.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+if [ $# -ne 2 ]
+then
+ echo "Starts Bro with the given arguments in the background and, when"
+ echo "it’s ready, starts Midbro."
+ echo
+ echo "Usage: $0 INTERFACE SCRIPT"
+ echo "Example: $0 lo modbus.bro"
+ exit
+fi
+
+INTERFACE=$1
+SCRIPT=$(realpath $2)
+
+BRODIR=$(realpath "$(dirname "$0")/../..")
+BROLOG=$(realpath bro.log)
+
+MIDBRO=${BRODIR}/broccoli/bin/midbropasad
+MIDBROLOG=$(realpath midbro.log)
+
+TMPDIR=$(mktemp --directory --tmpdir pasad.XXXX)
+
+echo "* Starting Bro in background ..."
+cd "${TMPDIR}" && sudo bro -i "${INTERFACE}" "${SCRIPT}" > ${BROLOG} 2>&1 &
+BROPID=$!
+
+echo "* Waiting for Bro to listen ..."
+sleep 1
+tail -f ${BROLOG} | while read LOGLINE
+do
+ [[ "${LOGLINE}" == "listening on "* ]] && pkill -P $$ tail
+done
+
+echo "* Starting Midbro ..."
+${MIDBRO}
+
+kill $BROPID
+
+rm -r "${TMPDIR}"