# Pastebin N9YISpKV #!/bin/sh if [ "$(id -u)" -ne 0 ]; then echo "session-tool needs to be invoked as root" >&2 exit 1 fi if [ -z "$(command -v busctl)" ]; then echo "session-tool requires busctl" >&2 exit 1 fi if [ $# -eq 0 ]; then echo "usag: session-tool [-u user] [--] " exit 1 fi pid=$PPID user=root while [ $# -gt 0 ]; do case "$1" in --) shift break ;; -u) user="$2" shift 2 ;; -*) echo "session-tool: unsupported argument $1" >&2 exit 1 ;; *) break ;; esac done unit_name="service-tool-$(cat /proc/sys/kernel/random/uuid).service" exec busctl \ --allow-interactive-authorization=no \ --quiet \ --system \ -- \ call \ org.freedesktop.systemd1 \ /org/freedesktop/systemd1 \ org.freedesktop.systemd1.Manager \ StartTransientUnit "ssa(sv)a(sa(sv))" \ "$unit_name" fail 3 \ Description s "service-tool running $* as $user" \ Type s oneshot \ ExecStart "a(sasb)" 1 \ /bin/sh 3 /bin/sh -c "exec runuser -l - $user -c \"$*\" /proc/$pid/fd/1 2>/proc/$pid/fd/2" false \ 0