askrobots / network-computer
Public
Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.
Dan Quellhorst
Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353)
a1d92f3
1 month, 3 weeks ago
History
nc-as-user · 1.1 KB · 21 lines
| 1 | #!/bin/sh |
| 2 | # Run a command inside the desk user's desktop session (display, session bus, |
| 3 | # home), from root (nc-host, provisioning) or from the user. |
| 4 | # nc-as-user COMMAND [ARGS...] |
| 5 | [ $# -gt 0 ] || { echo "usage: nc-as-user COMMAND [ARGS...]"; exit 2; } |
| 6 | [ -r /etc/nc/env ] && . /etc/nc/env |
| 7 | U=${NC_DESK_USER:-user} |
| 8 | [ "$(id -u)" = 0 ] || U=$(id -un) # not root: it can only be our own session |
| 9 | PID=$(pgrep -u "$U" -x xfce4-session | head -1) |
| 10 | [ -n "$PID" ] || { echo "nc-as-user: no desktop session for $U" >&2; exit 1; } |
| 11 | ENVS=$(tr '\0' '\n' < "/proc/$PID/environ") |
| 12 | BUS=$(echo "$ENVS" | sed -n 's/^DBUS_SESSION_BUS_ADDRESS=//p') |
| 13 | RUN=$(echo "$ENVS" | sed -n 's/^XDG_RUNTIME_DIR=//p') |
| 14 | H=$(getent passwd "$U" | cut -d: -f6) |
| 15 | # start in the person's home, not wherever root happened to be: apps |
| 16 | # started by voice or a script opened terminals in /root |
| 17 | cd "$H" 2>/dev/null || true |
| 18 | if [ "$(id -un)" = "$U" ]; then |
| 19 | exec env DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS="$BUS" XDG_RUNTIME_DIR="$RUN" "$@" |
| 20 | fi |
| 21 | exec runuser -u "$U" -- env DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS="$BUS" HOME="$H" XDG_RUNTIME_DIR="$RUN" "$@" |