#!/bin/sh
# DF-0001 — build the trigger sources on the DragonFlyBSD guest.
# Must be run from the host that can reach the guest via dfbsd-qemu/vm.sh
# (ssh aliases dfbsd=root, dfbsd-maxx=maxx uid 1001).
set -eu
cd "$(dirname "$0")"
DIR="$(pwd)"

# Ship the sources to the unprivileged user and compile there.
"$(dirname "$DIR")/../../dfbsd-qemu/vm.sh" run_user 'mkdir -p poc/DF-0001'
scp -F "$(dirname "$DIR")/../../dfbsd-qemu/config" -q \
    "$DIR/estale_trig.c" "$DIR/trunc_panic.c" "$DIR/trunc_only.c" \
    dfbsd-maxx:poc/DF-0001/

"$(dirname "$DIR")/../../dfbsd-qemu/vm.sh" run_user '
    cd poc/DF-0001 &&
    cc -O0 -g -o estale_trig estale_trig.c &&
    cc -O0 -g -o trunc_panic trunc_panic.c &&
    cc -O0 -g -o trunc_only  trunc_only.c &&
    echo BUILD_OK; ls -l estale_trig trunc_panic trunc_only
'
