#!/usr/bin/env bash
set -euo pipefail
cd ~/EtherGold/dev
for f in hat_fixture_bridge.sh run_bridge_jun11_good.sh run_bridge_prod.sh; do
  sed -i 's/\r$//' "$f" 2>/dev/null || true
  chmod +x "$f" 2>/dev/null || true
done
python3 -c 'import pog422_fixture_core as c; print(c.EG_VERSION, c.FIXTURE_PARSER_BUILD)'
python3 -c 'import lab_gameplay_synth as m; m._selftest()'
if [[ -f inject-shim/pog422_uartd.c ]]; then
  if [[ -f install.sh ]]; then
    bash install.sh 2>&1 | tail -40
  elif [[ -f update.sh ]]; then
    bash update.sh 2>&1 | tail -40
  else
    echo "no install/update.sh"
  fi
fi
if [[ -x inject-shim/pog422_uartd ]]; then
  inject-shim/pog422_uartd --version 2>&1 | head -3 || true
fi
grep -E 'POG422_EG_VERSION|2\.2\.2' inject-shim/pog422_ipc.h | head -3
sudo systemctl stop fixture-prod
sleep 1
systemctl is-active fixture-prod || echo "fixture-prod stopped"
pkill -f pog422_fixture_bridge 2>/dev/null || true
pkill -f pog422_uartd 2>/dev/null || true
sleep 1
pgrep -af 'pog422' || echo "no pog422 procs"
echo "prep_done"
