#! /usr/bin/env bash
#
# Run Bro on a trace file.
#
# run-bro-on-trace <use_installed_policies> <cwd> <trace> <bro_args>
#
# use_installed_policies:  1 to use local policy files installed by
#                          "broctl install", or 0 to use the original files
# cwd:  directory name to run Bro from
# trace:  pathname of a trace file
# bro_args:  string containing Bro cmd-line options

. `dirname $0`/broctl-config.sh

if [ $# -lt 4 ]; then
    echo "run-bro-on-trace: missing cmd-line arguments"
    exit 1
fi

use_installed_policies=$1
cwd=$2
trace=$3
shift 3

. "${scriptsdir}"/set-bro-path
if [ $? -ne 0 ]; then
    exit 1
fi

cd "$cwd"
if [ $? -ne 0 ]; then
    exit 1
fi

echo $@ >.cmdline

BROCTL_PROCESS_TRACE=1 "${bro}" -r "$trace" "$@"

