-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubspace-enter
More file actions
executable file
·47 lines (37 loc) · 967 Bytes
/
Copy pathsubspace-enter
File metadata and controls
executable file
·47 lines (37 loc) · 967 Bytes
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
#!/bin/bash
set -euo pipefail
SUBSPACE_DIR="/subspace"
if [ "$EUID" -ne 0 ]; then
echo "Entering a subspace requires superuser privileges."
exit 1
fi
if [ $# -lt 1 ]; then
echo "Usage: subspace-enter <subspace> [shell]" >&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"
root="$SUBSPACE_DIR/$subspace"
if [ ! -d "$root" ]; then
echo "Error: Subspace '$subspace' not found at $root" >&2
exit 1
fi
if [ $# -ge 2 ]; then
shell="$2"
else
for sh in /bin/bash /bin/sh /usr/bin/bash /usr/bin/sh /sbin/sh /bin/ash /usr/bin/ash; do
if [ -L "$root/$sh" ] || [ -x "$root/$sh" ]; then
shell="$sh"
break
fi
done
fi
if [ -z "${shell:-}" ]; then
echo "Error: No shell found in $subspace" >&2
exit 1
fi
exec "$SUBSPACE_DIR/subspace-run" "$subspace" "$shell"