#!/usr/bin/env bash
# Agent S: gitleaks dir and git modes on the baseline and reference copies (default rules).
export MSYS_NO_PATHCONV=1
SCAN=<scratch>/sec/scan
OUT=<scratch>/sec/scan/out/gitleaks
mkdir -p "$OUT"
: > "$OUT/command.txt"
for d in baseline reference; do
  for mode in dir git; do
    args=(run --rm --name "sec-scan-gl-$d-$mode" -v "$SCAN/$d/PatientPortal:/src:ro" -v "$SCAN/out/gitleaks:/out" zricethezav/gitleaks:latest "$mode" /src --no-banner --no-color -v -f json -r "/out/$d-$mode.json")
    echo "docker ${args[*]}" >> "$OUT/command.txt"
    t0=$(date +%s%N)
    docker "${args[@]}" > "$OUT/$d-$mode.console.txt" 2>&1
    ec=$?
    t1=$(date +%s%N)
    echo "exit=$ec ms=$(( (t1 - t0) / 1000000 ))" >> "$OUT/$d-$mode.console.txt"
  done
done
