#!/usr/bin/env bash
# Run on the Proxmox HOST (where USB is connected) to verify the reTerminal in boot mode is seen.
# Usage: ssh root@10.130.60.224 'bash -s' < scripts/check-usb-on-host.sh
# Or copy to host and run: ./check-usb-on-host.sh

echo "=== CM4 boot-mode USB (2b8e = RPi, 0a5c:2711 = Broadcom BCM2711) ==="
lsusb | grep -E "2b8e|0a5c" || echo "None found. Connect reTerminal in boot mode (eMMC disable jumper) and use the USB slave port."
echo ""
echo "=== All USB devices ==="
lsusb
echo ""
echo "=== Provisioning status ==="
cat /var/lib/cm4-provisioning/status.json 2>/dev/null || echo "No status.json (script has not run yet)."
echo ""
echo "=== Last flash log ==="
tail -15 /var/lib/cm4-provisioning/flash.log 2>/dev/null || echo "No flash.log"
echo ""
echo "=== udev rule and rpiboot ==="
test -f /etc/udev/rules.d/90-cm4-boot-mode.rules && echo "90-cm4-boot-mode.rules: present" || echo "90-cm4-boot-mode.rules: MISSING"
test -x /opt/usbboot/rpiboot && echo "rpiboot: present" || echo "rpiboot: MISSING"
test -f /etc/cm4-provisioning/enabled && echo "enabled: yes" || echo "enabled: no (provisioning disabled)"
