#!/bin/bash
# Quick starter script for new session debugging PXE boot failure
# Usage: bash scripts/pxe-debug-start.sh

echo "=== PXE Debug Session Starter ==="
echo ""
echo "Critical context in scripts/pxe-debug-resume.md"
echo ""
echo "=== Current Beast State ==="
echo ""
echo "--- Deploy image on Beast ---"
ssh beast 'ls -lh /usr/local/var/deploy/images/win11-dell-3450-homewood.wim 2>/dev/null; ls -lh /usr/local/var/deploy/images/win11-dell-3450-homewood-*.wim 2>/dev/null'
echo ""
echo "--- Boot WIM on TFTP ---"
ssh beast 'ls -lh /usr/local/var/tftpboot/Boot/boot.wim 2>/dev/null'
echo ""
echo "--- PF rules (port 445 SMB) ---"
ssh beast 'sudo pfctl -sr 2>/dev/null | grep 445'
echo ""
echo "--- NAT rules loaded? ---"
ssh beast 'sudo pfctl -sn 2>/dev/null | grep -c "nat on en0"'
echo ""
echo "--- smbd running? ---"
ssh beast 'pgrep -q smbd && echo "YES" || echo "NO"'
echo ""
echo "--- dnsmasq (TFTP) running? ---"
ssh beast 'pgrep -q dnsmasq && echo "YES" || echo "NO"'
echo ""
echo "=== Recent Hash Uploads ==="
ssh mkl 'cd /var/www/html/mkl && node -e "require(\"dotenv\").config();const{query}=require(\"./core/db/connection\");(async()=>{try{const r=await query(\"SELECT serial_number, device_model, created_at FROM autopilot_hashes ORDER BY created_at DESC LIMIT 10\");console.log(JSON.stringify(r, null, 2));}catch(e){console.log(\"Table may not exist or DB unreachable:\",e.message);}process.exit();})()" 2>/dev/null' 2>/dev/null
echo ""
echo "=== Current /tmp/ Deploy Scripts ==="
ls -la /tmp/deploy-auto.bat /tmp/run-extract.cmd /tmp/extract-hash.ps1 /tmp/unattend-hash.xml /tmp/boot-pxe*.wim 2>/dev/null
echo ""
echo "=== Next Steps ==="
echo "1. Read scripts/pxe-debug-resume.md"
echo "2. Execute Step 1: image ONE device with deploy.bat MINUS the registry manipulation"
echo "3. If it reaches OOBE: confirmed registry is the problem, switch to unattend.xml"
echo "4. If it fails the same way: deeper issue (bcdboot, diskpart, or image itself)"
