#!/bin/sh # The nRF9151 station's X session: the front end, full screen under matchbox-wm. # The station image selects this as x-session-manager, so /etc/X11/Xsession runs # it in place of a desktop session. # # The front end's own output, and every command it runs, goes to # /tmp/nrf-station-ui.log. It is started again whenever it exits, for as long as # the session runs: at once after a run of 10 s or more, and after 1, 2, 4 ... up # to 60 s after one that ended sooner, so a front end that cannot start does not # spin. The console beside the session keeps working either way. # NRF_STATION_UI and NRF_STATION_LOG name another front end and log. UI=${NRF_STATION_UI:-/usr/bin/nrf-station-ui} LOG=${NRF_STATION_LOG:-/tmp/nrf-station-ui.log} # A session without a display has nothing to run; a stray call (with --version, # say) must not start the front end's restart loop. [ -n "${DISPLAY:-}" ] || { echo "nrf-station-session: no DISPLAY; this is an X session" >&2; exit 1; } # BRINTOS-WORKAROUND: brintos/linux#153 remove -- programs started together can take each other's staged libraries; staging the window manager's and the front end's once, one after the other, before either starts leaves nothing to race on. # No DISPLAY, so a program that does not know --version refuses rather than runs. env -u DISPLAY /usr/bin/matchbox-window-manager --version /dev/null 2>&1 env -u DISPLAY "$UI" --version /dev/null 2>&1 up() { read -r u _ < /proc/uptime; echo "${u%.*}"; } # BRINTOS-WORKAROUND: brintos/linux-in-the-browser#120 revisit -- sleep can return at once in the guest, so a wait is a deadline on /proc/uptime, not one sleep. wait_s() { w_e=$(( $(up) + $1 )); while [ "$(up)" -lt "$w_e" ]; do sleep 1; done; } ( delay=0 while :; do t0=$(up) "$UI" --announce /dev/console rc=$? if [ $(( $(up) - t0 )) -lt 10 ]; then if [ "$delay" -eq 0 ]; then delay=1; else delay=$((delay * 2)); fi [ "$delay" -le 60 ] || delay=60 else delay=0 fi echo "nrf-station-ui exited with status $rc at uptime $(up) s; starting it again in $delay s" wait_s "$delay" done ) >>"$LOG" 2>&1 & # The image ships no fontconfig cache and its root is read-only, so the window # manager's font setup would rescan every font and never finish: it gets one # font and a cache it can write. FC=/tmp/nrf-station-fc mkdir -p "$FC/fonts" "$FC/cache" ln -sf /usr/share/fonts/X11/misc/6x13-ISO8859-1.pcf.gz "$FC/fonts/" cat > "$FC/fonts.conf" < $FC/fonts$FC/cache EOF FONTCONFIG_FILE="$FC/fonts.conf" exec matchbox-window-manager -use_titlebar no -use_cursor yes