blob: 9048b528a127f29b01864c03574f822a2f224ae8 (
plain)
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
|
#!/usr/bin/env bash
# This takes the following positional arguments
# 1. tart VM name
# 2. Script to execute in the VM
# 3. Passthrough directory path, formatted like "$guest_mount_name:$host_dir_path"
#
# The script expects that with the current SSH agent, it's possible to SSH into
# the `admin` user on the VM without any user interaction. The script will
# bring the VM up, execute the specified script via SSH and shut down the VM.
#
# The script returns the exit code of the SSH command.
set -o pipefail
VM_NAME=${1:?"No VM name provided"}
SCRIPT=${2:?"No script path provided"}
PASSTHROUGH_DIR=${3:?"No passthrough directory provided"}
tart run --no-graphics "--dir=${PASSTHROUGH_DIR}" "$VM_NAME" &
vm_pid=$!
# Sleep to wait until VM is up
sleep 10
ssh admin@"$(tart ip "$VM_NAME")" bash /dev/stdin < "$SCRIPT"
script_status=$?
kill $vm_pid
exit $script_status
|