#!/bin/sh
# VMAT in its own window where the system's WebKitGTK is, the browser otherwise
# WebKitGTK shuts its page in a sandbox made by bwrap, and stops without it.
# Ubuntu 24.04 and later let bwrap make one only for programs they list.
# The .deb gives vmat-window a name there; bwrap alone, run from here, is
# still refused, so the name's file is what says the window can start.
sandbox_ok() {
	[ -e /etc/apparmor.d/vmat-window ] && return 0
	command -v bwrap >/dev/null 2>&1 || return 1
	bwrap --unshare-user --ro-bind / / true >/dev/null 2>&1
}
if [ -x /opt/vmat/lib/vmat-window ] && sandbox_ok &&
    ! ldd /opt/vmat/lib/vmat-window 2>/dev/null | grep -q 'not found'; then
	exec /opt/vmat/lib/vmat-window "$@"
fi
exec /opt/vmat/lib/vmat "$@"
