Merge branch 'main' into stretch-to-panel

This commit is contained in:
Magarto authored and GitHub committed 2026-09-30 09:30:37 +02:00
commit db8928f7ce
76 files changed
+6441 -305

No files matched your search

@@ -0,0 +1,63 @@
#!/bin/bash
# An AppImage imported from the front end (AppImageManager), extracted once at import into
# /opt/appimages/user/<id>/app
# and started from there: proot has no FUSE to mount the image, and extracting it at every
# start (APPIMAGE_EXTRACT_AND_RUN) would cost the whole image in /tmp each time.
# bannerlator-appimage-run /opt/appimages/user/<id> [args...]
set -u
dir=${1:?usage: bannerlator-appimage-run <imported AppImage directory> [args...]}
shift
export APPDIR=$dir/app
# APPIMAGE is left unset on purpose: with it an app believes it runs from an image file and offers
# to add itself to the menu (DuckStation) or update the file in place - DroidDeck already does the
# one, and there is no image file for the other.
unset APPIMAGE
export ARGV0=$(cat "$dir/name" 2>/dev/null || basename "$dir")
if [ ! -x "$APPDIR/AppRun" ]; then
echo "bannerlator-appimage-run: $APPDIR/AppRun is missing; import the AppImage again" >&2
exit 127
fi
# Browsers sandbox their own children with namespaces and a setuid helper, neither of which proot
# can give them (the Flatpak sandboxes get the same; see BwrapSpawner): Firefox and its forks (Zen,
# LibreWolf) by these switches, Electron and Chromium builds by --no-sandbox. Chromium on Wayland
# also asks the render node for a DRM version KGSL cannot give, so with an X server up it stays on
# X11, which it picks from the session type.
export MOZ_DISABLE_CONTENT_SANDBOX=1 MOZ_DISABLE_GMP_SANDBOX=1 MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_DISABLE_SOCKET_PROCESS_SANDBOX=1 MOZ_DISABLE_UTILITY_SANDBOX=1
flags=()
if [ -e "$APPDIR/chrome-sandbox" ] || compgen -G "$APPDIR/*/chrome-sandbox" >/dev/null; then
flags+=(--no-sandbox)
if [ -n "${DISPLAY:-}" ]; then
export XDG_SESSION_TYPE=x11
unset WAYLAND_DISPLAY
flags+=(--ozone-platform=x11)
fi
fi
echo "== appimage $ARGV0 ($APPDIR) ${flags[*]}"
cd "$APPDIR" || exit 1
# Apps expect a session bus; Electron's main process traps (SIGTRAP) on an address it cannot
# parse. A run mode has none, so one is started for the app, as for Flatpak apps.
case ${DBUS_SESSION_BUS_ADDRESS:-} in
unix:*) "$APPDIR/AppRun" "${flags[@]}" "$@" ;;
*) unset DBUS_SESSION_BUS_ADDRESS
if command -v dbus-run-session >/dev/null 2>&1; then
dbus-run-session -- "$APPDIR/AppRun" "${flags[@]}" "$@"
else
"$APPDIR/AppRun" "${flags[@]}" "$@"
fi ;;
esac
rc=$?
# The program a session was started for may hand over to another process and exit: Electron apps
# relaunch themselves (Obsidian on its first start), launchers fork their real program. The
# session ends with this script, and takes the rest with it - so it waits while anything running
# from the image is still up.
image_running() {
local p exe
for p in /proc/[0-9]*; do
exe=$(readlink "$p/exe" 2>/dev/null) || continue
case $exe in "$APPDIR"/*) return 0 ;; esac
done
return 1
}
while image_running; do sleep 2; done
exit $rc
@@ -0,0 +1,318 @@
#!/usr/bin/python3
# bubblewrap for Flatpak (FLATPAK_BWRAP), in a runtime that cannot have it.
#
# bwrap builds each sandbox from mount namespaces, which Android gives no app. proot gives the same
# picture - Flatpak's runtime as /usr, the app as /app, host paths bound where Flatpak asks - but a
# proot nested inside the session's proot runs every system call through two tracers, some thirty
# times slower on a program's start. So a sandbox is described to the app instead, over a socket
# only this app's uid may use, and the app starts it as a proot of its own beside the session's
# (BwrapSpawner). This process stands in for the sandbox until it ends: its output, its pid for
# --info-fd, and its exit status come back here.
#
# Sandboxes that remap nothing - Flatpak's install triggers (`--ro-bind / /` and the directory they
# update) and the D-Bus proxy (every top-level directory bound onto itself) - need no proot at all
# and run here directly, with the file descriptors Flatpak handed them.
import base64
import json
import os
import signal
import socket
import struct
import sys
SOCKET = "\0com.droiddeck.launcher.bwrap"
VERSION = "bubblewrap 0.11.0 (droiddeck)"
# Options and how many arguments each takes; bwrap(1).
NO_ARG = {
"--unshare-user", "--unshare-user-try", "--unshare-ipc", "--unshare-pid", "--unshare-net",
"--unshare-uts", "--unshare-cgroup", "--unshare-cgroup-try", "--unshare-all", "--share-net",
"--disable-userns", "--assert-userns-disabled", "--clearenv", "--new-session",
"--die-with-parent", "--as-pid-1", "--level-prefix", "--tmp-overlay", "--ro-overlay",
}
ONE_ARG = {
"--args", "--argv0", "--userns", "--userns2", "--pidns", "--uid", "--gid", "--hostname",
"--chdir", "--unsetenv", "--lock-file", "--sync-fd", "--remount-ro", "--exec-label",
"--file-label", "--proc", "--dev", "--tmpfs", "--mqueue", "--dir", "--seccomp",
"--add-seccomp-fd", "--block-fd", "--userns-block-fd", "--info-fd", "--json-status-fd",
"--cap-add", "--cap-drop", "--perms", "--size", "--overlay-src",
}
TWO_ARG = {
"--setenv", "--bind", "--bind-try", "--dev-bind", "--dev-bind-try", "--ro-bind",
"--ro-bind-try", "--bind-fd", "--ro-bind-fd", "--file", "--bind-data", "--ro-bind-data",
"--symlink", "--chmod",
}
THREE_ARG = {"--overlay"}
def read_fd(fd):
chunks = []
while True:
b = os.read(fd, 65536)
if not b:
break
chunks.append(b)
os.close(fd)
return b"".join(chunks)
def fd_path(fd):
return os.readlink("/proc/self/fd/%d" % fd)
def expand(argv):
"""argv with every --args FD replaced by the NUL-separated arguments read from FD."""
out = []
i = 0
while i < len(argv):
a = argv[i]
if a == "--args" and i + 1 < len(argv):
data = read_fd(int(argv[i + 1]))
# Each argument ends in a NUL; an empty one (--setenv LD_LIBRARY_PATH "") is kept.
parts = data.split(b"\0")
if parts and parts[-1] == b"":
parts.pop()
out.extend(x.decode("utf-8", "surrogateescape") for x in parts)
i += 2
continue
out.append(a)
i += 1
return out
class Spec:
def __init__(self):
self.ops = []
self.env = dict(os.environ)
self.cwd = None
self.info_fds = []
self.json_fds = []
self.keep_fds = []
self.command = []
self.argv0 = None
def parse(argv):
s = Spec()
perms = None
i = 0
while i < len(argv):
a = argv[i]
if a == "--":
s.command = argv[i + 1:]
break
if not a.startswith("--"):
s.command = argv[i:]
break
if a in ("--version",):
print(VERSION)
sys.exit(0)
if a == "--help":
print("usage: bwrap [OPTIONS...] [--] COMMAND [ARGS...]")
sys.exit(0)
n = 0 if a in NO_ARG else 1 if a in ONE_ARG else 2 if a in TWO_ARG else 3 if a in THREE_ARG else -1
if n < 0:
sys.stderr.write("bwrap: Unknown option %s\n" % a)
sys.exit(1)
args = argv[i + 1:i + 1 + n]
if len(args) < n:
sys.stderr.write("bwrap: %s takes %d arguments\n" % (a, n))
sys.exit(1)
i += 1 + n
op_perms, perms = perms, None
if a == "--perms":
perms = int(args[0], 8)
elif a == "--clearenv":
s.env = {"PWD": os.getcwd()} if "PWD" in os.environ else {}
elif a == "--setenv":
s.env[args[0]] = args[1]
elif a == "--unsetenv":
s.env.pop(args[0], None)
elif a == "--chdir":
s.cwd = args[0]
elif a == "--argv0":
s.argv0 = args[0]
elif a in ("--bind", "--bind-try", "--dev-bind", "--dev-bind-try", "--ro-bind", "--ro-bind-try"):
s.ops.append({"t": "bind", "src": args[0], "dest": args[1], "try": a.endswith("-try"),
"ro": a.startswith("--ro")})
elif a in ("--bind-fd", "--ro-bind-fd"):
fd = int(args[0])
s.ops.append({"t": "bind", "src": fd_path(fd), "dest": args[1], "try": False,
"ro": a.startswith("--ro")})
os.close(fd)
elif a in ("--file", "--bind-data", "--ro-bind-data"):
s.ops.append({"t": "file", "dest": args[1], "data": read_fd(int(args[0])),
"perms": op_perms if op_perms is not None else 0o666 if a == "--file" else 0o600})
elif a == "--symlink":
s.ops.append({"t": "symlink", "target": args[0], "dest": args[1]})
elif a == "--dir":
s.ops.append({"t": "dir", "dest": args[0], "perms": op_perms if op_perms is not None else 0o755})
elif a in ("--tmpfs", "--mqueue"):
s.ops.append({"t": "dir", "dest": args[0], "perms": op_perms if op_perms is not None else 0o755,
"empty": True})
elif a == "--proc":
s.ops.append({"t": "proc", "dest": args[0]})
elif a == "--dev":
s.ops.append({"t": "dev", "dest": args[0]})
elif a in ("--seccomp", "--add-seccomp-fd"):
# proot is the sandbox; there is no filter to install under it.
os.close(int(args[0]))
elif a == "--block-fd":
read_fd(int(args[0]))
elif a == "--sync-fd":
s.keep_fds.append(int(args[0]))
elif a == "--info-fd":
s.info_fds.append(int(args[0]))
elif a == "--json-status-fd":
s.json_fds.append(int(args[0]))
# Everything else - namespaces, capabilities, labels, locks, --remount-ro, --chmod - has
# nothing to act on under proot.
if not s.command:
sys.stderr.write("bwrap: No command specified\n")
sys.exit(1)
return s
def real(path):
try:
return os.path.realpath(path)
except OSError:
return path
def remaps_nothing(s):
"""True when every path in the sandbox is what it is out here already."""
for op in s.ops:
t = op["t"]
if t == "bind":
src = real(op["src"])
if not os.path.exists(src):
if op["try"]:
continue
return False
if src != real(op["dest"]) and not (op["src"] == "/" and op["dest"] == "/"):
return False
elif t == "symlink":
if not os.path.islink(op["dest"]) or os.readlink(op["dest"]) != op["target"]:
return False
elif t == "file":
# The D-Bus proxy's /.flatpak-info names the app to the bus; nothing here reads it.
if op["dest"] != "/.flatpak-info":
return False
elif t == "dir":
if not os.path.isdir(op["dest"]) or op.get("empty") and op["dest"] not in ("/tmp", "/var/tmp", "/run"):
return False
elif t in ("proc", "dev"):
if op["dest"] != "/" + t:
return False
return True
def report_pid(s, pid):
for fd in s.info_fds:
try:
os.write(fd, json.dumps({"child-pid": pid}).encode() + b"\n")
os.close(fd)
except OSError:
pass
for fd in s.json_fds:
try:
os.write(fd, json.dumps({"child-pid": pid}).encode() + b"\n")
except OSError:
pass
def run_here(s):
report_pid(s, os.getpid())
for fd in s.json_fds:
os.close(fd)
if s.cwd:
os.chdir(s.cwd)
argv = list(s.command)
program = argv[0]
if s.argv0:
argv[0] = s.argv0
try:
os.execvpe(program, argv, s.env)
except OSError as e:
sys.stderr.write("bwrap: execvp %s: %s\n" % (program, e.strerror))
sys.exit(1)
def send(sock, kind, payload):
sock.sendall(kind + struct.pack(">I", len(payload)) + payload)
def recv_exact(sock, n):
buf = b""
while len(buf) < n:
b = sock.recv(n - len(buf))
if not b:
return None
buf += b
return buf
def run_by_app(s):
ops = []
for op in s.ops:
op = dict(op)
if op["t"] == "bind":
# The app resolves no guest symlinks; hand it the path they lead to.
op["src"] = real(op["src"])
if op["t"] == "file":
op["data"] = base64.b64encode(op["data"]).decode()
ops.append(op)
argv = list(s.command)
if s.argv0:
argv[0] = s.argv0
request = {"argv": argv, "env": s.env, "cwd": s.cwd or "/", "ops": ops}
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
sock.connect(SOCKET)
except OSError as e:
sys.stderr.write("bwrap: DroidDeck is not answering (%s); open DroidDeck and try again\n" % e)
sys.exit(1)
send(sock, b"R", json.dumps(request).encode())
# This process is the sandbox as far as Flatpak is concerned: ended, it takes the sandbox down.
for sig in (signal.SIGTERM, signal.SIGINT, signal.SIGHUP):
signal.signal(sig, lambda *_: os._exit(128 + 15))
status = 1
out = sys.stdout.buffer
while True:
head = recv_exact(sock, 5)
if head is None:
sys.stderr.write("bwrap: DroidDeck closed the sandbox\n")
break
kind, size = head[:1], struct.unpack(">I", head[1:])[0]
payload = recv_exact(sock, size) if size else b""
if payload is None:
break
if kind == b"P":
report_pid(s, int(payload))
elif kind == b"O":
out.write(payload)
out.flush()
elif kind == b"E":
sys.stderr.write("bwrap: %s\n" % payload.decode("utf-8", "replace"))
elif kind == b"X":
status = int(payload)
break
for fd in s.json_fds:
try:
os.write(fd, json.dumps({"exit-code": status}).encode() + b"\n")
except OSError:
pass
sys.exit(status)
def main():
s = parse(expand(sys.argv[1:]))
if remaps_nothing(s):
run_here(s)
else:
run_by_app(s)
if __name__ == "__main__":
main()
@@ -0,0 +1,237 @@
#!/usr/bin/python3
# The app's store talks to Flatpak through this: one JSON object per line on stdout, so progress
# reaches the front end as numbers rather than a terminal's redrawn bar. Per-user installation,
# Flathub as the remote, this device's architecture.
#
# bannerlator-flatpak install <app-id> the app and whatever runtimes it needs
# bannerlator-flatpak uninstall <app-id> the app, then runtimes nothing uses any more
# bannerlator-flatpak update [<app-id>] one app, or everything with an update
# bannerlator-flatpak updates what has one (a "updates" line)
#
# Lines: {"e":"op","i":1,"n":3,"kind":"install","ref":"..."} as each step starts,
# {"e":"progress","i":1,"n":3,"percent":45,"status":"..."} while it runs,
# {"e":"error","message":"..."} and {"e":"done"} at the end. Exit status 0 on success.
import json
import os
import sys
os.environ.setdefault("FLATPAK_BWRAP", "/usr/local/bin/bannerlator-bwrap")
import gi # noqa: E402
gi.require_version("Flatpak", "1.0")
from gi.repository import Flatpak, GLib # noqa: E402
REMOTE = "flathub"
def prepare_rootfs():
"""Some runtimes (KDE 6.10) ship etc/resolv.conf as a link to /run/host/monitor/resolv.conf.
Deploying one, Flatpak removes that link only if GIO reports it existing, and GIO follows it:
dangling here, it was left in place and making Flatpak's own link failed ("File exists").
With the target present in the rootfs the link resolves and the deploy goes through."""
target = "/run/host/monitor/resolv.conf"
try:
if not os.path.exists(target):
os.makedirs(os.path.dirname(target), exist_ok=True)
try:
with open("/etc/resolv.conf", "rb") as src:
data = src.read()
except OSError:
data = b""
with open(target, "wb") as dst:
dst.write(data)
except OSError as err:
emit(e="warning", message="could not prepare %s: %s" % (target, err))
def emit(**kw):
sys.stdout.write(json.dumps(kw) + "\n")
sys.stdout.flush()
def installation():
return Flatpak.Installation.new_user(None)
def app_ref(inst, app_id):
"""The installed ref of an app, or None."""
for ref in inst.list_installed_refs_by_kind(Flatpak.RefKind.APP, None):
if ref.get_name() == app_id:
return ref
return None
def transaction(inst):
t = Flatpak.Transaction.new_for_installation(inst, None)
t.set_no_interaction(True)
state = {"i": 0, "n": 0, "error": None}
def on_ready(tr):
state["n"] = len(tr.get_operations())
return True
def on_new_operation(tr, op, progress):
state["i"] += 1
emit(e="op", i=state["i"], n=state["n"], kind=op.get_operation_type().value_nick, ref=op.get_ref())
progress.set_update_frequency(500)
def changed(p):
emit(e="progress", i=state["i"], n=state["n"], percent=p.get_progress(), status=p.get_status() or "")
progress.connect("changed", changed)
def on_operation_error(tr, op, err, details):
# A runtime extension that fails to install (a missing translation, an unneeded GL
# driver) is not worth losing the app over; anything else ends the transaction.
# FLATPAK_TRANSACTION_ERROR_DETAILS_NON_FATAL is 1, but PyGObject does not always hand the
# flags over ("g_value_get_flags: assertion ... failed" and a 0). An extension installed
# alongside an app - its translations, debug data, a GL or codecs runtime - is what Flatpak
# marks non-fatal, as the flatpak CLI does: its failure costs that extension, not the app.
try:
non_fatal = bool(int(details) & 1)
except (TypeError, ValueError):
non_fatal = False
if not non_fatal:
try:
related = bool(op.get_related_to_ops())
except (AttributeError, TypeError):
related = False
ref_id = (op.get_ref() or "").split("/")[1:2]
ref_id = ref_id[0] if ref_id else ""
non_fatal = related or ref_id.endswith((".Locale", ".Debug")) or ".GL." in ref_id or "codecs" in ref_id
emit(e="warning" if non_fatal else "error", message="%s: %s" % (op.get_ref(), err.message))
if not non_fatal:
state["error"] = err.message
return non_fatal
t.connect("ready", on_ready)
t.connect("new-operation", on_new_operation)
t.connect("operation-error", on_operation_error)
# A dependency found on more than one remote comes from the first (Flathub, the only one).
t.connect("choose-remote-for-ref", lambda tr, ref, runtime_ref, remotes: 0)
t.connect("end-of-lifed-with-rebase", lambda *a: False)
t.connect("add-new-remote", lambda *a: False)
return t, state
def run(t, state, report_done=True):
try:
t.run(None)
except GLib.Error as err:
if state["error"] is None and not err.matches(Flatpak.error_quark(), Flatpak.Error.ABORTED):
state["error"] = err.message
if state["error"]:
emit(e="error", message=state["error"])
return 1
if report_done:
emit(e="done")
return 0
def install(app_id):
inst = installation()
arch = Flatpak.get_default_arch()
if app_ref(inst, app_id) is not None:
emit(e="done", note="already installed")
return 0
# Flathub publishes apps on "stable"; libflatpak's default branch is "master".
branch, last = None, None
for candidate in ("stable", "master"):
try:
branch = inst.fetch_remote_ref_sync(REMOTE, Flatpak.RefKind.APP, app_id, arch, candidate, None).get_branch()
break
except GLib.Error as err:
last = err
if branch is None:
emit(e="error", message="%s is not on Flathub for %s (%s)" % (app_id, arch, last.message if last else "no branch"))
return 1
t, state = transaction(inst)
t.add_install(REMOTE, "app/%s/%s/%s" % (app_id, arch, branch), None)
rc = run(t, state, report_done=False)
# A failure the transaction did not report (an error handler that raised, say) must not read
# as an install: the app is there, or it is not.
if rc == 0 and app_ref(installation(), app_id) is None:
emit(e="error", message="%s did not install; see flatpak-install.log" % app_id)
return 1
if rc == 0:
emit(e="done")
return rc
def uninstall(app_id):
inst = installation()
ref = app_ref(inst, app_id)
if ref is None:
emit(e="done", note="not installed")
return 0
t, state = transaction(inst)
t.add_uninstall(ref.format_ref())
rc = run(t, state)
if rc == 0:
# Runtimes only this app used; Flatpak's own `uninstall --unused`.
try:
unused = inst.list_unused_refs(None, None)
except GLib.Error:
unused = []
if unused:
t, state = transaction(inst)
for r in unused:
t.add_uninstall(r.format_ref())
run(t, state)
return rc
def updatable(inst):
try:
return inst.list_installed_refs_for_update(None)
except GLib.Error as err:
emit(e="error", message=err.message)
return None
def update(app_id=None):
inst = installation()
refs = updatable(inst)
if refs is None:
return 1
if app_id:
refs = [r for r in refs if r.get_name() == app_id or r.get_kind() == Flatpak.RefKind.RUNTIME]
if not refs:
emit(e="done", note="up to date")
return 0
t, state = transaction(inst)
for r in refs:
t.add_update(r.format_ref(), None, None)
return run(t, state)
def updates():
refs = updatable(installation())
if refs is None:
return 1
emit(e="updates", apps=sorted({r.get_name() for r in refs if r.get_kind() == Flatpak.RefKind.APP}),
runtimes=len([r for r in refs if r.get_kind() == Flatpak.RefKind.RUNTIME]))
return 0
def main():
if len(sys.argv) < 2:
sys.stderr.write(__doc__ or "usage: bannerlator-flatpak install|uninstall|update|updates [app-id]\n")
return 2
cmd, args = sys.argv[1], sys.argv[2:]
if cmd in ("install", "update"):
prepare_rootfs()
if cmd == "install" and args:
return install(args[0])
if cmd == "uninstall" and args:
return uninstall(args[0])
if cmd == "update":
return update(args[0] if args else None)
if cmd == "updates":
return updates()
sys.stderr.write("usage: bannerlator-flatpak install|uninstall|update|updates [app-id]\n")
return 2
if __name__ == "__main__":
sys.exit(main())
@@ -0,0 +1,28 @@
#!/bin/bash
# A Flatpak app from the front end, full screen under gamescope like an emulator:
# bannerlator-flatpak-run <app-id> [args...]
set -u
export FLATPAK_BWRAP=/usr/local/bin/bannerlator-bwrap
case ":${XDG_DATA_DIRS:-}:" in
*"/flatpak/exports/share:"*) ;;
*) export XDG_DATA_DIRS=$HOME/.local/share/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} ;;
esac
# Under gamescope - a program's session (BL_INSIDE), or droiddeck-gpu from the desktop
# (GAMESCOPE_WAYLAND_DISPLAY) - windows have to reach gamescope's X server. Flatpak would hand an
# app wayland-0 (it finds it in the runtime directory even with WAYLAND_DISPLAY unset) and the
# window would open behind gamescope. gamescope's own Wayland socket is no way out: Chromium on
# Wayland asks the render node it names for its DRM version, which KGSL cannot answer, and exits.
# The session is X11 as far as an app can tell; Electron picks its platform from that.
# Its own flatpak options (--branch, --command, from a menu entry) come first, then the app id.
socket=()
if [ -n "${BL_INSIDE:-}" ] || [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then
unset WAYLAND_DISPLAY
export XDG_SESSION_TYPE=x11
socket=(--nosocket=wayland --socket=x11)
fi
echo "== flatpak run ${socket[*]} $*"
# Apps expect a session bus (settings, portals, single-instance checks); a run mode has none.
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && command -v dbus-run-session >/dev/null 2>&1; then
exec dbus-run-session -- flatpak run "${socket[@]}" "$@"
fi
exec flatpak run "${socket[@]}" "$@"
@@ -0,0 +1,121 @@
#!/bin/bash
# Puts Flatpak into the runtime, with Flathub as a per-user remote. Run by the app under proot's
# fake root (pacman and pacman-key refuse any other uid), outside a session.
#
# The runtime's pacman database lists only the base image: the desktop and emulator packages were
# unpacked over it without registering. Asked for flatpak the usual way, pacman "reinstalls" about
# a hundred of those - Mesa among them, over the runtime's own Turnip build with its KGSL backend -
# and then runs every hook in the image, mkinitcpio included. So pacman only fetches and checks the
# few packages Flatpak needs on top of this image, verifying each against the Arch Linux ARM
# keyring, and they are unpacked here without hooks or scripts, like the desktop package itself.
#
# bannerlator-flatpak-setup install or repair; prints "== STEP ..." milestones
set -u
export LANG=C.UTF-8
step() { echo "== STEP $*"; }
fail() { echo "== FAIL $*"; exit 1; }
# Flatpak, the libraries it and appstream add to this image, and the D-Bus proxy flatpak run puts
# between an app and the session bus. bubblewrap is not among them: Android gives an app no user
# namespaces, and bannerlator-bwrap stands in for it (FLATPAK_BWRAP).
PACKAGES="flatpak ostree appstream libxmlb libmalcontent libfyaml accountsservice composefs xdg-dbus-proxy"
# Libraries Flatpak and the store's helper also need, which the Desktop package brings but a
# runtime without it may lack: each is fetched only when its file is not already there.
while read -r pkg probe; do
[ -n "$pkg" ] || continue
compgen -G "$probe" >/dev/null || PACKAGES="$PACKAGES $pkg"
done <<'NEEDS'
json-glib /usr/lib/libjson-glib-1.0.so.0
fuse3 /usr/lib/libfuse3.so.4
fuse-common /etc/fuse.conf
libsodium /usr/lib/libsodium.so.*
libstemmer /usr/lib/libstemmer.so.*
polkit /usr/lib/libpolkit-gobject-1.so.0
mpdecimal /usr/lib/libmpdec.so.*
python /usr/bin/python3
libgirepository /usr/lib/libgirepository-2.0.so.0
gobject-introspection-runtime /usr/lib/girepository-1.0/GObject-2.0.typelib
python-gobject /usr/lib/python3*/site-packages/gi/__init__.py
NEEDS
WORK=/var/cache/droiddeck-flatpak
CONF=$WORK/pacman.conf
mkdir -p "$WORK/pkg" "$WORK/db" || fail "cannot create $WORK"
# The image's pacman.conf names a download user this rootfs does not have (only root exists) and a
# sandbox proot cannot set up. Its one mirror is plain HTTP; these serve the same repos over TLS.
{ for m in https://ca.us.mirror.archlinuxarm.org https://fl.us.mirror.archlinuxarm.org \
https://de3.mirror.archlinuxarm.org https://nl.mirror.archlinuxarm.org; do
echo "Server = $m/\$arch/\$repo"; done
grep '^Server' /etc/pacman.d/mirrorlist 2>/dev/null; } > "$WORK/mirrorlist"
sed -e 's/^DownloadUser/#DownloadUser/' \
-e 's/^\[options\]/[options]\nDisableSandbox/' \
-e "s#^Include *= */etc/pacman.d/mirrorlist#Include = $WORK/mirrorlist#" \
/etc/pacman.conf > "$CONF" || fail "no /etc/pacman.conf"
if [ ! -f /etc/pacman.d/gnupg/pubring.gpg ] && [ ! -f /etc/pacman.d/gnupg/pubring.kbx ]; then
step "Preparing the package keyring"
pacman-key --init >/dev/null 2>&1 || fail "pacman-key --init failed"
pacman-key --populate archlinuxarm >/dev/null 2>&1 || fail "pacman-key --populate failed"
fi
# A database of our own, so the image's stays exactly as it was built: -Sy on it would leave the
# rest of the image a partial upgrade behind the repos.
step "Reading the package lists"
pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy >/dev/null 2>&1 \
|| pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1 | tail -3 \
|| fail "could not reach the Arch Linux ARM mirrors"
[ -f "$WORK/db/sync/extra.db" ] || fail "could not reach the Arch Linux ARM mirrors"
step "Downloading Flatpak"
# -w only downloads; pacman still checks each package's signature against the keyring. -dd: the
# dependencies are already in the image (and checked below by what the binaries actually link).
out=$(pacman --config "$CONF" --dbpath "$WORK/db" --cachedir "$WORK/pkg" --noconfirm -Sw -dd $PACKAGES 2>&1)
rc=$?
echo "$out" | grep -vE '^\s*$' | tail -4
[ $rc -eq 0 ] || fail "download failed"
step "Installing Flatpak"
for name in $PACKAGES; do
ver=$(pacman --config "$CONF" --dbpath "$WORK/db" -Sp --print-format '%v' -dd "$name" 2>/dev/null | tail -1)
file=$(ls "$WORK/pkg/$name-$ver-"*.pkg.tar.* 2>/dev/null | grep -v '\.sig$' | head -1)
[ -n "$file" ] || fail "no package file for $name $ver"
bsdtar -xpf "$file" -C / --exclude .PKGINFO --exclude .BUILDINFO --exclude .MTREE --exclude .INSTALL \
|| fail "could not unpack $name"
echo "$name $ver" >> "$WORK/installed.new"
done
mv -f "$WORK/installed.new" "$WORK/installed"
# Only the newest file of each package is worth keeping for a repair.
find "$WORK/pkg" -type f -mtime +1 -delete 2>/dev/null
# What the binaries link is the real dependency list: anything this image lacks shows here.
missing=$(for f in /usr/bin/flatpak /usr/lib/libflatpak.so.0 /usr/lib/libostree-1.so.1 /usr/bin/xdg-dbus-proxy; do
ldd "$f" 2>&1 | grep -E 'not found|version .* not found'
done | sort -u)
[ -z "$missing" ] || { echo "$missing"; fail "Flatpak is missing libraries"; }
flatpak --version >/dev/null 2>&1 || fail "flatpak does not start"
python3 -c 'import gi; gi.require_version("Flatpak", "1.0"); from gi.repository import Flatpak' 2>/dev/null \
|| fail "the store helper cannot load libflatpak from Python"
step "Adding Flathub"
export FLATPAK_BWRAP=/usr/local/bin/bannerlator-bwrap
# Flathub's descriptor - its URL and the key its commits are signed with - is carried here rather
# than fetched: adding the remote then needs no network, and a descriptor that did not arrive
# whole cannot be what failed. Flathub's own copy: https://dl.flathub.org/repo/flathub.flatpakrepo
cat > "$WORK/flathub.flatpakrepo" <<'REPO'
[Flatpak Repo]
Title=Flathub
Url=https://dl.flathub.org/repo/
Homepage=https://flathub.org/
Comment=Central repository of Flatpak applications
Description=Central repository of Flatpak applications
Icon=https://dl.flathub.org/repo/logo.svg
GPGKey=mQINBFlD2sABEADsiUZUOYBg1UdDaWkEdJYkTSZD68214m8Q1fbrP5AptaUfCl8KYKFMNoAJRBXn9FbE6q6VBzghHXj/rSnA8WPnkbaEWR7xltOqzB1yHpCQ1l8xSfH5N02DMUBSRtD/rOYsBKbaJcOgW0K21sX+BecMY/AI2yADvCJEjhVKrjR9yfRX+NQEhDcbXUFRGt9ZT+TI5yT4xcwbvvTu7aFUR/dH7+wjrQ7lzoGlZGFFrQXSs2WI0WaYHWDeCwymtohXryF8lcWQkhH8UhfNJVBJFgCY8Q6UHkZG0FxMu8xnIDBMjBmSZKwKQn0nwzwM2afskZEnmNPYDI8nuNsSZBZSAw+ThhkdCZHZZRwzmjzyRuLLVFpOj3XryXwZcSefNMPDkZAuWWzPYjxS80cm2hG1WfqrG0Gl8+iX69cbQchb7gbEb0RtqNskTo9DDmO0bNKNnMbzmIJ3/rTbSahKSwtewklqSP/01o0WKZiy+n/RAkUKOFBprjJt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bY4XagbnCqve6PvQb5G2Z55qhWphd6f4B6DGed86zJEa/RhS
REPO
if ! flatpak remote-list --user --columns=name 2>/dev/null | grep -qx flathub; then
out=$(flatpak remote-add --user --if-not-exists flathub "$WORK/flathub.flatpakrepo" 2>&1)
rc=$?
echo "$out"
# What Flatpak said goes up with the failure, so the app can show it rather than a guess.
[ $rc -eq 0 ] || fail "could not add the Flathub remote: $(echo "$out" | grep -v '^[[:space:]]*$' | tail -1)"
fi
echo "== DONE $(flatpak --version)"
@@ -73,14 +73,29 @@ if [ -n "${BL_VK_DRIVER:-}" ]; then
fi
unset bl_icd_lib
fi
# The app's gamescope build (tools/gamescope) takes realtime-priority Vulkan queues on this
# The app's gamescope build (tools/gamescope) asks for realtime-priority Vulkan queues on this
# switch instead of on CAP_SYS_NICE, which proot never has; it falls back to normal priority
# where the driver refuses, and the runtime's own build ignores it.
export GAMESCOPE_FORCE_VULKAN_REALTIME=${BL_GAMESCOPE_REALTIME:-1}
# where the driver refuses, and the runtime's own build ignores it. On KGSL Turnip (Mesa 26.2) it
# changes nothing yet: the driver reports one submit-queue priority and creates every KGSL context
# with the same flags, so no priority reaches the GPU. Kept for a driver that maps it, and off
# unless the app's Performance page turns it on (BL_GAMESCOPE_REALTIME=1).
export GAMESCOPE_FORCE_VULKAN_REALTIME=${BL_GAMESCOPE_REALTIME:-0}
# A sleep that starts no process. Under proot every exec is a traced execve plus the loader's
# opens and maps, and the watchers below poll for the whole session: `sleep 1` in a loop was 60
# execs a minute each. read -t on a pipe nothing ever writes to waits in bash itself.
nap() {
[ -n "${bl_nap_fd:-}" ] || exec {bl_nap_fd}<> <(:)
read -r -t "$1" -u "$bl_nap_fd" _ 2>/dev/null || :
}
export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
mkdir -p "$XDG_DATA_HOME" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
# Flatpak (the store's apps): its sandboxes through the app instead of bubblewrap, which needs the
# user namespaces Android keeps from apps, and its apps' menu entries and icons on the desktop.
export FLATPAK_BWRAP=/usr/local/bin/bannerlator-bwrap
export XDG_DATA_DIRS=$XDG_DATA_HOME/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
# The cores a program runs on outside Steam (the desktop and everything started from it, a
# program from the rail): the user's game cores when set (BL_GAME_CPUS), else every core but the
@@ -275,7 +290,7 @@ case $mode in
for _p in $(pgrep -f 'steamwebhelper|steamrtarm64/steam|gamescope' 2>/dev/null); do
taskset -cp "$BL_CLIENT_CPUS" "$_p" >/dev/null 2>&1 || true
done
sleep 5
nap 5
done
) &
fi
@@ -383,8 +398,9 @@ case $mode in
[ -z "${BL_DESKTOP:-}" ] && (
last=${BL_GAMESCOPE_FORCE_FULLSCREEN:-1}
while :; do
sleep 1
want=$(cat "$HOME/.droiddeck-fill" 2>/dev/null) || continue
nap 1
want=
{ read -r want || [ -n "$want" ]; } < "$HOME/.droiddeck-fill" 2>/dev/null || continue
case $want in 0|1) ;; *) continue ;; esac
[ "$want" = "$last" ] && continue
if xprop -root -f GAMESCOPE_FORCE_WINDOWS_FULLSCREEN 32c -set GAMESCOPE_FORCE_WINDOWS_FULLSCREEN "$want" 2>/dev/null; then
@@ -393,10 +409,30 @@ case $mode in
fi
done
) &
# Resume from the Steam menu. The menu is an overlay that takes input, and a fullscreen game that
# loses input minimizes itself; gamescope only takes a window out of that state when the focused
# window changes, which the menu never does, so the game stayed minimized after Resume (a black
# screen with its small caption in the top-left corner). gamescope-3.16.29-p4 restores it itself;
# this asks it again a moment after input comes back from the client (app 769) to anything else,
# which covers a game that minimizes late. Harmless when nothing is minimized.
# BL_RESTORE_ON_RESUME=0 turns it off.
[ -z "${BL_DESKTOP:-}" ] && [ "${BL_RESTORE_ON_RESUME:-1}" = 1 ] && (
prev=
xprop -spy -root GAMESCOPE_FOCUSED_APP 2>/dev/null | while read -r line; do
app=${line##*= }
case $app in ''|*[!0-9]*) prev=; continue ;; esac
if [ "$prev" = 769 ] && [ "$app" != 769 ]; then
nap 1
xprop -root -f GAMESCOPE_RESTORE_FOCUS_WINDOW 32c -set GAMESCOPE_RESTORE_FOCUS_WINDOW 1 2>/dev/null \
&& echo "== resume: asked gamescope to restore the game window (app $app)"
fi
prev=$app
done
) &
(
beat=0
for _ in $(seq 1 720); do
sleep 5
nap 5
bannerlator-seed-redists "$steam_root" >/dev/null 2>&1 || true
beat=$((beat + 1))
if [ "$((beat % 3))" -eq 0 ]; then
@@ -567,7 +603,7 @@ BUSCONF
"$steam_root/steamrtarm64/steam" -shutdown >/dev/null 2>&1 || true
exit 0
fi
sleep 0.5
nap 0.5
done
) &
stop_watcher=$!
@@ -146,6 +146,26 @@ bl_game_cpus() {
# game never gets OpenGL; left at its own size in a window, it draws small in a corner. So these
# titles are told to stay windowed at the session's own size - unless the user's launch options
# already say something about the video mode, which are left as they are.
# The session puts the client's own libraries (steamrtarm64, its panorama/) ahead of everything for
# the client, and a game inherits that: Wine then resolved gnutls, SDL, FFmpeg and the rest against
# the client's private copies instead of the rootfs it was built for. Inside Steam's runtime
# container that path never reaches Proton either. (WinNative's winnative-proton-launch.)
BL_LIBPATH_SETUP = """
bl_libpath() {
[ -n "${LD_LIBRARY_PATH:-}" ] || return 0
local kept= dir old_ifs=$IFS
IFS=:
for dir in $LD_LIBRARY_PATH; do
case $dir in
"" | */steamrtarm64 | */steamrtarm64/*) ;;
*) kept=${kept:+$kept:}$dir ;;
esac
done
IFS=$old_ifs
if [ -n "$kept" ]; then export LD_LIBRARY_PATH="$kept"; else unset LD_LIBRARY_PATH; fi
}
"""
BL_IDTECH3_SETUP = """
bl_idtech3() {
BL_EXTRA_ARGS=()
@@ -233,6 +253,7 @@ for name in %s; do
bl_directaudio "$depot"
bl_game_cpus
bl_idtech3 "$@"
bl_libpath
exec ${BL_TASKSET:-} /usr/local/bin/bannerlator-game-env "$depot/proton" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
fi
done
@@ -244,7 +265,7 @@ exit 1
# something else.
LAUNCHER_SH = LAUNCHER_SH.replace(
"verb=$1; shift", "verb=$1; shift\n" + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
+ BL_COMPONENTS_SETUP, 1)
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1)
# A third-party Proton dropped into compatibilitytools.d - GE-Proton, proton-cachyos, anything of
# that shape - is adopted rather than used as shipped, for the same two reasons Valve's ARM64 depot
@@ -280,6 +301,7 @@ bl_components "$here"
bl_directaudio "$here"
bl_game_cpus
bl_idtech3 "$@"
bl_libpath
# Proton takes its base directory from dirname(sys.argv[0]) without resolving it, so it has to be
# started from its own tree.
exec ${BL_TASKSET:-} /usr/local/bin/bannerlator-game-env "$here/%s" "$verb" "$@" "${BL_EXTRA_ARGS[@]}"
@@ -369,6 +391,28 @@ def serialize(tokens):
return "\n".join(out) + "\n"
def write_changed(path, text, mode=None):
"""Writes `text` to `path` only when it differs, through a rename so a reader never sees half a
file. The session runs this script every 15 s for as long as the client does; rewriting files
that have not changed cost a python start's worth of writes each time, and config.vdf is the
client's own, which it may be writing at that moment. Returns whether anything was written."""
try:
with open(path, encoding="utf-8", errors="replace") as f:
same = f.read() == text
except OSError:
same = False
if not same:
tmp = path + ".bannerlator"
with open(tmp, "w", encoding="utf-8") as f:
f.write(text)
if mode is not None:
os.chmod(tmp, mode)
os.replace(tmp, path)
elif mode is not None and (os.stat(path).st_mode & 0o7777) != mode:
os.chmod(path, mode)
return not same
def first_key(path, section):
"""The single key naming a block inside `section`, or None. Used to keep a third-party tool's
own internal name, so a mapping the user already made against it keeps working."""
@@ -442,14 +486,10 @@ def adopt_extras(tools):
body = (EXTRA_WRAPPER_SH % entry_point).replace(
'here=$(dirname "$0")',
'here=$(dirname "$0")\n' + BL_DIRECTAUDIO_SETUP + BL_GAME_CPUS_SETUP + BL_IDTECH3_SETUP
+ BL_COMPONENTS_SETUP, 1)
with open(wrapper, "w", encoding="utf-8") as f:
f.write(body)
os.chmod(wrapper, 0o755)
with open(manifest, "w", encoding="utf-8") as f:
f.write(EXTRA_MANIFEST_VDF)
with open(compat_vdf, "w", encoding="utf-8") as f:
f.write(EXTRA_COMPAT_TOOL_VDF % (name, entry))
+ BL_COMPONENTS_SETUP + BL_LIBPATH_SETUP, 1)
write_changed(wrapper, body, 0o755)
write_changed(manifest, EXTRA_MANIFEST_VDF)
write_changed(compat_vdf, EXTRA_COMPAT_TOOL_VDF % (name, entry))
except OSError as e:
print("bannerlator-steam-compat: could not adopt %s (%s)" % (entry, e))
continue
@@ -494,7 +534,8 @@ def register_default(config_path, apps=(), name=None, protect=()):
# Tool names the user may deliberately have chosen (see adopt_extras); never repointed.
keep = {n.lower() for n in protect}
with open(config_path, encoding="utf-8", errors="replace") as f:
tokens = tokenize(f.read())
original = f.read()
tokens = tokenize(original)
steam = find_block(tokens, ["InstallConfigStore", "Software", "Valve", "Steam"])
if steam is None:
return
@@ -521,10 +562,10 @@ def register_default(config_path, apps=(), name=None, protect=()):
continue
tokens[mapping + 1:mapping + 1] = [
'"%s"' % app, "{", '"name"', '"%s"' % tool, '"config"', '""', '"priority"', '"250"', "}"]
tmp = config_path + ".bannerlator"
with open(tmp, "w", encoding="utf-8") as f:
f.write(serialize(tokens))
os.replace(tmp, config_path)
# Nothing to change is the usual case on the session's beat: the client's own file is left alone.
text = serialize(tokens)
if text != serialize(tokenize(original)):
write_changed(config_path, text)
def find_source(steam_root):
@@ -542,18 +583,14 @@ def build_tool(tool_dir):
"""Our own manifests and the launcher. The depot is found at launch time, not here."""
if os.path.islink(tool_dir):
os.unlink(tool_dir)
elif os.path.isdir(tool_dir):
# Earlier versions mirrored the depot in here as symlinks; start clean.
elif os.path.isdir(tool_dir) and set(os.listdir(tool_dir)) - set(OWN_FILES):
# Earlier versions mirrored the depot in here as symlinks; start clean. A directory holding
# only our own files is kept, and each file rewritten only when it changed.
shutil.rmtree(tool_dir)
os.makedirs(tool_dir)
with open(os.path.join(tool_dir, "toolmanifest.vdf"), "w", encoding="utf-8") as f:
f.write(TOOL_MANIFEST_VDF)
with open(os.path.join(tool_dir, "compatibilitytool.vdf"), "w", encoding="utf-8") as f:
f.write(COMPAT_TOOL_VDF % TOOL)
launcher = os.path.join(tool_dir, LAUNCHER)
with open(launcher, "w", encoding="utf-8") as f:
f.write(LAUNCHER_SH)
os.chmod(launcher, 0o755)
os.makedirs(tool_dir, exist_ok=True)
write_changed(os.path.join(tool_dir, "toolmanifest.vdf"), TOOL_MANIFEST_VDF)
write_changed(os.path.join(tool_dir, "compatibilitytool.vdf"), COMPAT_TOOL_VDF % TOOL)
write_changed(os.path.join(tool_dir, LAUNCHER), LAUNCHER_SH, 0o755)
def main():
@@ -135,6 +135,10 @@ def watch(steam_root, listing):
candidates, sources = {}, {}
next_lookup = 0
last_status = None
# The probe is a fresh python that loads steamclient.so, seconds of CPU under proot. Ownership
# only moves with a purchase or a new match, so it runs when the matches or their sources
# change, after a failed probe, and otherwise every five minutes - not on every 30 s beat.
probed, next_probe = None, 0
while True:
now = time.monotonic()
for game in games:
@@ -150,13 +154,16 @@ def watch(steam_root, listing):
if now >= next_lookup:
next_lookup = now + 300
status = "waiting for a matching Steam title"
if candidates:
key = (dict(candidates), dict(sources))
if candidates and (key != probed or now >= next_probe):
probed, next_probe = key, now + 300
try:
result = subprocess.run([sys.executable, __file__, "probe", steam_root,
*map(str, sorted(set(candidates.values())))],
capture_output=True, text=True, timeout=15)
if result.returncode != 0:
status = "ownership probe failed: " + (result.stderr.strip()[-300:] or str(result.returncode))
probed = None
else:
line = next(line for line in result.stdout.splitlines() if line.startswith("DROIDDECK_OWNERSHIP="))
snapshot = json.loads(line.removeprefix("DROIDDECK_OWNERSHIP="))
@@ -168,6 +175,9 @@ def watch(steam_root, listing):
status = "matched %d/%d games; %d owned" % (len(candidates), len(games), sum(snapshot["owned"].values()))
except (OSError, ValueError, KeyError, StopIteration, subprocess.TimeoutExpired) as error:
status = "ownership check unavailable: " + str(error)
probed = None
elif candidates:
status = last_status
if status != last_status:
print("bannerlator-steam-games: " + status, flush=True)
last_status = status