-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
akms-runas
executable file
·40 lines (34 loc) · 874 Bytes
/
akms-runas
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
#!/bin/sh
set -eu
if [ $# -eq 0 ]; then
echo "Usage: $0 <user> [--sandbox <rootfs> [bwrap-opts]] (-- | [ENV_NAME=VALUE]...) <cmd> [cmd-args]" >&2
exit 1
fi
user=$1; shift
base_env="PATH=/usr/bin:/bin SHELL=/bin/sh USER=$user"
rootfs=''
if [ "$1" = '--sandbox' ]; then
rootfs=$2; shift 2
bwrap_opts=${BWRAP_OPTS:-}
while [ $# -gt 0 ]; do
case "$1" in
--) shift; break;;
*=*) break;;
*) bwrap_opts="$bwrap_opts $1"; shift;;
esac
done
if [ $# -eq 0 ]; then
echo 'akms-runas: missing <cmd>'; exit 1
fi
exec /bin/su "$user" -s /bin/sh -c 'exec /usr/bin/bwrap "$@"' -- -- \
--unshare-all \
--bind "$rootfs" / \
--proc /proc \
--dev-bind /dev /dev \
--die-with-parent \
$bwrap_opts \
-- /usr/bin/env -i $base_env "$@"
else
[ "$1" = '--' ] && shift
exec /bin/su "$user" -s /bin/sh -c 'exec /usr/bin/env -i "$@"' -- -- $base_env "$@"
fi