summary refs log tree commit diff
path: root/pkgs/os-specific/linux/spectrum/spectrum-vm/spectrum-vm.in
blob: a72c3896141952141d56afbcaa05e5a976baefdb (plain) (blame)
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
#!@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"