#!/bin/sh
# script/run: build bin/smallwebwaf with script/build and run it, with
# the settings in the environment. Unless SWWAF_STATE_DIR is set, the
# state files go in bin/state, beside the binary, and unless
# SWWAF_RULES_DIR is set, the rule files are those of share/rules.d,
# which the image ships.
set -eu

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"

main() {
    "$SCRIPT_DIR/build"
    if [ -z "${SWWAF_STATE_DIR+set}" ]; then
        SWWAF_STATE_DIR="$ROOT/bin/state"
        export SWWAF_STATE_DIR
        mkdir -p "$SWWAF_STATE_DIR"
    fi
    if [ -z "${SWWAF_RULES_DIR+set}" ]; then
        SWWAF_RULES_DIR="$ROOT/share/rules.d"
        export SWWAF_RULES_DIR
    fi
    exec "$ROOT/bin/smallwebwaf"
}

main "$@"
