#!/bin/bash
# TEMPORARY live-session diagnostic. Reports why the bread desktop components
# do/don't start. Runs as liveuser (Hyprland exec-once, so it has the Wayland
# env), and writes the report to the serial port via sudo (the port is
# root-only) so it can be read on the VM host.
sleep 7
{
    echo "================ BOS LIVE DIAG ================"
    echo "user=$(id -un) WAYLAND_DISPLAY=$WAYLAND_DISPLAY XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR"
    echo "--- which bread bins ---"
    for b in breadd breadbar breadbox breadbox-sync breadcrumbs breadpad bos-settings; do
        printf '%s: ' "$b"; command -v "$b" || echo MISSING
    done
    echo "--- running bread procs ---"; pgrep -a bread || echo "(none running)"
    echo "--- ldd breadbar (missing libs) ---"
    ldd "$(command -v breadbar 2>/dev/null)" 2>&1 | grep -i "not found" || echo "(all libs resolved)"
    echo "--- breadbar foreground test (6s) ---"; timeout 6 breadbar 2>&1; echo "breadbar rc=$?"
    echo "--- breadd foreground test (4s) ---"; timeout 4 breadd 2>&1; echo "breadd rc=$?"
    echo "--- tail hyprland-live.log ---"; tail -60 /tmp/hyprland-live.log 2>/dev/null
    echo "================ END DIAG ================"
} 2>&1 | sudo tee /dev/ttyS0 >/dev/null
