zeek/testing/scripts/update-zeekygen-docs.sh
2019-05-02 21:39:21 -07:00

69 lines
1.8 KiB
Bash
Executable file

#! /usr/bin/env bash
unset BRO_DISABLE_BROXYGEN
# If running this from btest, unset any of the environment
# variables that alter default script values.
unset BRO_DEFAULT_LISTEN_ADDRESS
unset BRO_DEFAULT_LISTEN_RETRY
unset BRO_DEFAULT_CONNECT_RETRY
dir="$( cd "$( dirname "$0" )" && pwd )"
source_dir="$( cd $dir/../.. && pwd )"
build_dir=$source_dir/build
conf_file=$build_dir/zeekygen-test.conf
output_dir=$source_dir/doc
zeek_error_file=$build_dir/zeekygen-test-stderr.txt
if [ -n "$1" ]; then
output_dir=$1
fi
case $output_dir in
/*) ;;
*) output_dir=`pwd`/$output_dir ;;
esac
cd $build_dir
. bro-path-dev.sh
export BRO_SEED_FILE=$source_dir/testing/btest/random.seed
function run_zeek
{
ZEEK_ALLOW_INIT_ERRORS=1 bro -X $conf_file zeekygen >/dev/null 2>$zeek_error_file
if [ $? -ne 0 ]; then
echo "Failed running zeek with zeekygen config file $conf_file"
echo "See stderr in $zeek_error_file"
exit 1
fi
}
scripts_output_dir=$output_dir/scripts
rm -rf $scripts_output_dir
printf "script\t*\t$scripts_output_dir/" > $conf_file
echo "Generating $scripts_output_dir/"
run_zeek
script_ref_dir=$output_dir/script-reference
mkdir -p $script_ref_dir
function generate_index
{
echo "Generating $script_ref_dir/$2"
printf "$1\t*\t$script_ref_dir/$2\n" > $conf_file
run_zeek
}
generate_index "script_index" "autogenerated-script-index.rst"
generate_index "package_index" "autogenerated-package-index.rst"
generate_index "file_analyzer" "autogenerated-file-analyzer-index.rst"
generate_index "proto_analyzer" "autogenerated-protocol-analyzer-index.rst"
echo
if [ -n "$(cd $source_dir/doc && git status --porcelain)" ]; then
echo "*** There are changes in zeek-docs that need a review, commit, and push ***"
else
echo "No changes or further action needed"
fi