#!/bin/sh
# prep5845.sh -- one-time guest preparation for the DF-5845 rig.
# Files pushed to /root/fw5845.  Mirrors the DF-2293/96 prep.
set -e
cd /root/fw5845

install -m 644 fwharness.c fwharness.h /usr/src/sys/bus/firewire/
grep -q fwharness.c /usr/src/sys/conf/files || \
    printf 'bus/firewire/fwharness.c\toptional fwharness\n' >> /usr/src/sys/conf/files
if [ ! -f /usr/src/sys/config/FWH ]; then
    cp /usr/src/sys/config/X86_64_GENERIC /usr/src/sys/config/FWH
    printf '\n# fwdev.c audit rig (DF-2293..96, DF-5845)\ndevice\t\tfwharness\n' \
        >> /usr/src/sys/config/FWH
fi

grep -q debugger_on_panic /etc/sysctl.conf || \
    echo 'debug.debugger_on_panic=0' >> /etc/sysctl.conf
sysctl debug.debugger_on_panic=0 >/dev/null

pw useradd -n opuser -m -G operator -w none 2>/dev/null || true
id opuser

cc -O -Wall -pthread -o df5845 df5845.c
cc -O -Wall -pthread -o df5845rig df5845rig.c
cc -O -Wall -o pinexec pinexec.c
cc -O -Wall -o offsets5845 offsets5845.c \
    -D_KERNEL_STRUCTURES -I/usr/src/sys -I/usr/src
chmod 755 df5845 df5845rig pinexec offsets5845
ls -l df5845 df5845rig pinexec offsets5845
echo PREP5845_OK
