#!/bin/sh
# init=/usr/bin/desk-bridge : the route that needs no new kernel interfaces.
# Headless compositor + pomelo-calc + pomelo-fbbridge (screencopy -> /dev/fb0, tty -> keys).
. /usr/bin/desk-env
export WLR_BACKENDS=headless
[ -n "${DESK_DEBUG:-}" ] || unset POMELO_WLR_DEBUG
/usr/bin/pomelo-compositor 2>/tmp/compositor.log &
cpid=$!
i=0
while [ $i -lt 100 ] && [ ! -S "$XDG_RUNTIME_DIR/wayland-0" ]; do sleep 0.2; i=$((i+1)); done
export WAYLAND_DISPLAY=wayland-0
/usr/bin/pomelo-calc 2>/tmp/calc.log &
kpid=$!
sleep 1
/usr/bin/pomelo-fbbridge ${DESK_RUN_SECONDS:-60}
echo "desk-bridge: fbbridge exit status $?; compositor alive=$(kill -0 $cpid 2>/dev/null && echo yes || echo no) calc alive=$(kill -0 $kpid 2>/dev/null && echo yes || echo no)"
kill $kpid $cpid 2>/dev/null; wait
echo "--- compositor log"; tail -${DESK_LOG_LINES:-15} /tmp/compositor.log; echo "--- calc log"; tail -5 /tmp/calc.log
exit 0
