flybrain/infra/bin/wait-for-x
acamilo 660c3cf00d
Some checks failed
ci / node 22 (test + typecheck) (push) Has been cancelled
ci / rust stable (cargo test --workspace --release) (push) Has been cancelled
ci / infra/tests/lint.sh (push) Has been cancelled
ci / playwright apps/stage (allowed to fail) (push) Has been cancelled
flybrain v0.4.0: public tree (history retained privately)
2026-09-21 15:09:46 +00:00

29 lines
709 B
Bash
Executable file

#!/usr/bin/env bash
# infra/bin/wait-for-x DISPLAY TIMEOUT_SECONDS
#
# Poll until Xvfb on DISPLAY (e.g. ":99") accepts connections, or exit 1
# after TIMEOUT_SECONDS. Used as flystage's ExecStartPre
# (docs/design/infra.md section 3).
set -euo pipefail
usage() { echo "usage: $0 DISPLAY TIMEOUT_SECONDS" >&2; exit 2; }
[ $# -eq 2 ] || usage
display="$1"
timeout="$2"
case "$timeout" in
''|*[!0-9]*) usage ;;
esac
deadline=$(( $(date +%s) + timeout ))
while true; do
if DISPLAY="$display" xdpyinfo >/dev/null 2>&1; then
exit 0
fi
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "wait-for-x: $display not ready after ${timeout}s" >&2
exit 1
fi
sleep 0.5
done