#!/bin/sh
# init=/usr/bin/desk-dotnet-gui : the compositor (with XWayland), then /x/run-gui.sh of the second virtio disk with DISPLAY set.
. /usr/bin/desk-env
export LC_ALL=C.UTF-8 TMPDIR=/tmp
mkdir -p /x /tmp /root /tmp/dn
mount -t ext2 /dev/vdb /x 2>/dev/null
/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
i=0; while [ $i -lt 50 ] && ! grep -q "XWayland" /tmp/compositor.log; do sleep 0.2; i=$((i+1)); done
export DISPLAY=$(sed -n 's/.*XWayland 就緒，DISPLAY=\(.*\)/\1/p' /tmp/compositor.log | tail -1); : ${DISPLAY:=:0}
echo "desk-dotnet-gui: compositor up, DISPLAY=$DISPLAY"
cd /x && sh /x/run-gui.sh
kill $cpid 2>/dev/null; wait
echo "--- compositor log"; tail -12 /tmp/compositor.log
exit 0
