32 lines
2.7 KiB
Bash
32 lines
2.7 KiB
Bash
#!/bin/sh
|
|
# B14: Cage + aurora-ui (SDL2, Wayland) on the ST7735S. Usage: ui-up.sh [--stop-gui]
|
|
uipid() { for p in /proc/[0-9]*; do [ "$(readlink $p/exe 2>/dev/null)" = /usr/local/bin/aurora-ui ] && echo ${p#/proc/}; done; } # not pidof: /etc/init.d/aurora-ui has the same comm
|
|
# Refuses if Xorg / Cage / Sway already hold the panel, unless --stop-gui (then aurora-x / b13 cage / b13 sway are stopped cleanly).
|
|
# One instance only; state in /run/aurora-ui. Equivalent to `cage -- /usr/local/bin/aurora-ui` with the Pixman/seatd environment.
|
|
D=/run/aurora-ui; mkdir -p $D; L=$D/ui.log
|
|
now() { cut -d' ' -f1 /proc/uptime; }
|
|
log() { echo "[$(now)] $*" | tee -a $L; }
|
|
[ -f /etc/aurora/aurora-ui.conf ] && . /etc/aurora/aurora-ui.conf
|
|
export TZ LIBGL_ALWAYS_SOFTWARE SDL_VIDEODRIVER=wayland
|
|
export XDG_RUNTIME_DIR=/run/user/0; mkdir -p -m 0700 $XDG_RUNTIME_DIR
|
|
export WLR_RENDERER=pixman WLR_BACKENDS=drm,libinput WLR_DRM_DEVICES=/dev/dri/card0 WLR_LIBINPUT_NO_DEVICES=1 LIBSEAT_BACKEND=seatd
|
|
[ -f $D/cage.pid ] && kill -0 "$(cat $D/cage.pid)" 2>/dev/null && { log "aurora-ui already running (cage $(cat $D/cage.pid))"; exit 0; }
|
|
busy=$(for p in Xorg cage sway; do pidof $p >/dev/null && echo $p; done | tr '\n' ' ')
|
|
if [ -n "$busy" ]; then
|
|
[ "$1" = --stop-gui ] || { log "FAIL: display held by: $busy(use --stop-gui)"; exit 1; }
|
|
pidof wayvnc >/dev/null && sh /usr/local/lib/b13/run/wayvnc-down.sh >/dev/null 2>&1
|
|
pidof Xorg >/dev/null && { log "stopping X11"; /usr/local/bin/aurora-x stop >> $L 2>&1; }
|
|
pidof sway >/dev/null && sh /usr/local/lib/b13/run/sway-down.sh >> $L 2>&1
|
|
pidof cage >/dev/null && sh /usr/local/lib/b13/run/cage-down.sh >> $L 2>&1
|
|
sleep 1; for p in Xorg cage sway; do pidof $p >/dev/null && { log "FAIL: $p still running"; exit 1; }; done
|
|
fi
|
|
[ -x /usr/local/bin/aurora-ui ] || { log "FAIL: /usr/local/bin/aurora-ui missing"; exit 1; }
|
|
pidof seatd >/dev/null || { seatd -g video > $D/seatd.log 2>&1 & i=0; while [ ! -S /run/seatd.sock ] && [ $i -lt 50 ]; do sleep 0.1; i=$((i+1)); done; }
|
|
t0=$(now)
|
|
setsid cage -d -- /usr/local/bin/aurora-ui > $D/cage.log 2>&1 < /dev/null &
|
|
echo $! > $D/cage.pid
|
|
i=0; while ! grep -q "aurora-ui: first frame" $D/cage.log 2>/dev/null && [ $i -lt 300 ]; do kill -0 $(cat $D/cage.pid) 2>/dev/null || break; sleep 0.1; i=$((i+1)); done
|
|
if grep -q "aurora-ui: first frame" $D/cage.log; then
|
|
for w in $XDG_RUNTIME_DIR/wayland-*; do case $w in *.lock) ;; *) [ -S $w ] && basename $w > $D/wayland-display;; esac; done
|
|
log "UI UP cage=$(cat $D/cage.pid) aurora-ui=$(uipid) socket=$(cat $D/wayland-display) start=$(awk -v a=$t0 -v b=$(now) 'BEGIN{printf "%.2f", b-a}')s $(grep -E 'video driver|renderer|first frame' $D/cage.log | sed 's/aurora-ui: //' | tr '\n' ';')"
|
|
else log "FAIL: aurora-ui did not draw (see $D/cage.log)"; tail -15 $D/cage.log; exit 1; fi
|