-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-command-sandbox.in
executable file
·70 lines (55 loc) · 1.29 KB
/
vm-command-sandbox.in
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
#!/bin/sh -efu
[ -z "@MKLOCAL@" ] ||
export PATH="@PREFIX@/libshell:${PATH#@PREFIX@/libshell:}"
case "${VM_HELP-}" in
USAGE)
printf 'sandbox <profile>\n'
printf 'sandbox <profile> PROG [ARGS...]\n'
;;
SUMMARY)
printf 'Runs a command in a sandboxed guest\n'
;;
DESCRIPTION)
cat <<-EOF
Run a command in a sandboxed guest. vm will inject a special init binary which
will do an initial setup of the guest Linux and then lauch a shell script with
the specified command. Upon this command ending, the guest will be shutdown.
EOF
;;
OPTIONS)
;;
esac
[ -z "${VM_HELP-}" ] ||
exit 0
if [ -z "${vm_profile-}" ]; then
[ "$#" -gt 0 ] ||
show_usage "Profile name required"
vm_profile="$1"
shift
export vm_profile
fi
. shell-error
. shell-quote
. shell-git-config
. "@PREFIX@/vm-sh-config"
vm_read_profile_config
vm_check_kernel_config
rootfs=
git_config_get rootfs "$vm_config_file" "vm.$vm_profile.rootfs"
subst_globals rootfs "$rootfs"
[ -d "$rootfs" ] ||
fatal "Rootfs not found"
[ "$#" -gt 0 ] ||
set -- /bin/bash
{
printf '#!/bin/sh -i\n'
printf 'cd "%s"\n' "/host/$cwddir"
printf 'exec'
printf ' "%s"' "$@"
printf '\n'
} > "$rootfs/virt/sandbox.sh"
chmod +x -- "$rootfs/virt/sandbox.sh"
rc=0
(. "@PREFIX@/vm-command-run") || rc=$?
rm -f -- "$rootfs/virt/sandbox.sh"
exit $rc