-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubspace-run
More file actions
executable file
·79 lines (65 loc) · 1.97 KB
/
Copy pathsubspace-run
File metadata and controls
executable file
·79 lines (65 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -euo pipefail
SUBSPACE_DIR="/subspace"
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$UID}"
if [ "$EUID" -ne 0 ]; then
echo "This command requires superuser privileges."
exit 1
fi
if [ $# -lt 2 ]; then
echo "Usage: subspace-run <subspace> <command> [args...]" >&2
echo "" >&2
echo "Available subspaces:" >&2
for d in "$SUBSPACE_DIR"/*/; do
[ -d "$d/usr" ] && echo " $(basename "$d")" >&2
done
exit 1
fi
subspace="$1"
shift
root="$SUBSPACE_DIR/$subspace"
if [ ! -d "$root" ]; then
echo "Error: Subspace '$subspace' not found at $root" >&2
exit 1
fi
if ! command -v bwrap &>/dev/null; then
echo "Error: bubblewrap (bwrap) not found." >&2
echo "Install: sudo pacman -S bubblewrap" >&2
exit 1
fi
bwrap_args=(
--bind "$root" /
--dev-bind /dev /dev
--dev-bind /dev/dri /dev/dri
--proc /proc
--ro-bind /sys /sys
--ro-bind /tmp/.X11-unix /tmp/.X11-unix
--tmpfs /dev/shm
--setenv HOME /root
--setenv PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
--unshare-ipc
--unshare-pid
--unshare-uts
)
if [ -f "$root/etc/resolv.conf" ]; then
bwrap_args+=(--ro-bind /etc/resolv.conf /etc/resolv.conf)
fi
for d in /usr/lib/dri /usr/lib/xorg/modules/dri; do
[ -d "$d" ] && bwrap_args+=(--ro-bind "$d" "$d")
done
if [ -n "${DISPLAY:-}" ]; then
bwrap_args+=(--setenv DISPLAY "$DISPLAY")
fi
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
wayland_socket="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
if [ -S "$wayland_socket" ]; then
bwrap_args+=(--ro-bind "$wayland_socket" "$wayland_socket")
bwrap_args+=(--setenv WAYLAND_DISPLAY "$WAYLAND_DISPLAY")
bwrap_args+=(--setenv XDG_RUNTIME_DIR "$XDG_RUNTIME_DIR")
fi
fi
if [ -S "$XDG_RUNTIME_DIR/bus" ]; then
bwrap_args+=(--ro-bind "$XDG_RUNTIME_DIR/bus" "$XDG_RUNTIME_DIR/bus")
bwrap_args+=(--setenv DBUS_SESSION_BUS_ADDRESS "unix:path=$XDG_RUNTIME_DIR/bus")
fi
exec bwrap "${bwrap_args[@]}" "$@"