Files
chandra/scripts/as-root
T
Claude 9c0a794c2d
CI / test (push) Failing after 16s
run0: install via scripts/as-root, chandra-root for GUI apps as root, session refuses root
- scripts/as-root runs a command as root with run0 (systemd PID 1 + run0 present), else sudo,
  doas or pkexec; resolves the program to an absolute path since run0 doesn't inherit PATH.
  The install-session recipes use it and pass install.py by absolute path.
- session/chandra-root (installed to /usr/local/bin): run a graphical app as root inside
  Chandra, passing WAYLAND_DISPLAY (absolute) and the Wayland toolkit variables through
  run0 --setenv (or sudo/doas/pkexec env).
- chandra-session: refuses to run as root (CHANDRA_ALLOW_ROOT=1 overrides), fills in HOME and
  XDG_RUNTIME_DIR when started without a login environment, logs when the logind session has
  no seat (run0 --user / su / ssh), and starts an installed polkit agent once the socket is up
  so run0/pkexec from the launcher can prompt (CHANDRA_POLKIT_AGENT picks one or 'none').
- install.py: checks for root before --remove too; installs chandra-root.
- docs/run0.md: invocations for installing, starting from a TTY, apps as root, polkit agents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hkq6Hq7AXG85g5HyJU
2026-11-25 20:13:55 +00:00

26 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Run one command as root with whatever this system uses for that: run0 (systemd 256+), else
# sudo, doas, or pkexec. Used by `just install-session` and friends.
#
# scripts/as-root python3 session/install.py
#
# run0 starts the command as a transient systemd service: it does not inherit our environment
# (PATH included; only TERM and a few others get through) and it looks the program up in the
# service manager's own PATH. So the program is resolved to an absolute path here first, which
# also makes tools that are only on our PATH (pixi, ~/.moon/bin) work. The working directory is
# kept (run0 keeps it when the target user is root), so relative paths in the arguments are fine.
set -e
[ $# -gt 0 ] || { echo "usage: scripts/as-root COMMAND [ARG...]" >&2; exit 2; }
prog=$(command -v "$1") || { echo "as-root: $1: not found" >&2; exit 127; }
shift
[ "$(id -u)" = 0 ] && exec "$prog" "$@"
# CHANDRA_AS_ROOT picks the tool (run0, sudo, doas or pkexec) instead of the first one found.
for tool in ${CHANDRA_AS_ROOT:-run0 sudo doas pkexec}; do
command -v "$tool" >/dev/null 2>&1 || continue
# run0 needs systemd as PID 1 (and systemd 256+); on other inits fall through to sudo/doas.
[ "$tool" = run0 ] && [ ! -d /run/systemd/system ] && continue
exec "$tool" "$prog" "$@"
done
echo "as-root: none of run0, sudo, doas or pkexec is available; run this as root: $prog $*" >&2
exit 1