summary refs log tree commit diff
path: root/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in')
-rwxr-xr-xpkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in71
1 files changed, 71 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in b/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in
new file mode 100755
index 00000000000..a72c3896141
--- /dev/null
+++ b/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in
@@ -0,0 +1,71 @@
+#!@shell@
+set -ue
+
+ex_usage() {
+    cat <<EOF
+Usage: $(basename "$0") [OPTION]... [-- CROSVM_OPTIONS]
+
+  -c COMMAND         shell command to run inside VM
+  -C, --crosvm PATH  path to custom crosvm executable
+  -k, --kernel PATH  path to custom kernel image
+  -f, --rootfs PATH  path to custom root file system image
+  -- CROSVM_OPTIONS  extra arguments to pass to crosvm
+EOF
+    exit "$1"
+}
+
+args="$(@getopt@ -s sh -l crosvm:,help,kernel:,rootfs: -o c:C:hk:f: -- "$@" || exit 1)"
+eval set -- "$args"
+
+command=
+crosvm=@crosvm@
+kernel=@kernel@
+rootfs=@rootfs@
+
+while :
+do
+    case "$1" in
+	-c)
+	    shift
+	    command="$1"
+	    shift
+	    ;;
+        -C|--crosvm)
+            shift
+            crosvm="$1"
+	    shift
+            ;;
+	-h|--help)
+	    ex_usage 0
+	    ;;
+        -k|--kernel)
+            shift
+            kernel="$1"
+	    shift
+            ;;
+        -f|--rootfs)
+            shift
+            rootfs="$1"
+	    shift
+            ;;
+        --)
+            shift
+            break
+            ;;
+    esac
+done
+
+if [ -n "${XDG_RUNTIME_DIR-}" ]
+then
+    set -- -s "$XDG_RUNTIME_DIR" "$@"
+    if [ -n "${WAYLAND_DISPLAY-}" ]
+    then set -- --wayland-sock "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" "$@"
+    fi
+fi
+
+exec "$crosvm" run \
+    -p init=/sbin/init \
+    -p "spectrumcmd=$(printf %s "$command" | base64 -w0)" \
+    --root "$rootfs" \
+    "$@" \
+    "$kernel"