#!/usr/bin/env bash
set -euo pipefail
# Arguments: base checkout, head checkout, evidence output root.
base_checkout=$1
head_checkout=$2
output_root=$3
script_directory=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
run_directory="$output_root/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$run_directory"
# Only remove the exact address this driver adds; leave the VPN interface intact.
sudo -n ip addr add 100.85.0.1/32 dev wg0
trap 'sudo -n ip addr del 100.85.0.1/32 dev wg0' EXIT
node "$script_directory/drive.mjs" "$base_checkout" before "$run_directory"
node "$script_directory/drive.mjs" "$head_checkout" after "$run_directory"
