2018-08-06 01:49:45 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# 2018 Luke Shumaker
|
2018-08-11 22:46:04 +00:00
|
|
|
become_sudo() {
|
|
|
|
if is_sudo; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if is_root; then
|
|
|
|
needs_sudo
|
|
|
|
fi
|
|
|
|
exec sudo "${BASH_SOURCE[0]}" "$@"
|
|
|
|
}
|
|
|
|
|
2018-08-06 01:49:45 +00:00
|
|
|
{
|
|
|
|
set -euE
|
2018-08-11 21:15:13 +00:00
|
|
|
source "${BASH_SOURCE[0]%/*}/lib/osi.sh"
|
|
|
|
become_sudo "$@"
|
|
|
|
|
|
|
|
arg_image="$1"
|
2018-08-06 01:49:45 +00:00
|
|
|
qemu=(
|
|
|
|
qemu-system-x86_64
|
|
|
|
-machine accel=kvm
|
|
|
|
-m 512
|
|
|
|
)
|
|
|
|
|
|
|
|
mountpoint=$(mktemp -dt -- "${0##*/}.XXXXXXXXXX")
|
|
|
|
trap "rmdir -- ${mountpoint@Q}" EXIT
|
|
|
|
|
2018-08-11 21:23:12 +00:00
|
|
|
./osi-mount "$arg_image" "$mountpoint" install -Dm755 /dev/stdin "$mountpoint/etc/osi-run"
|
2018-08-11 21:15:13 +00:00
|
|
|
sudo -u "#${SUDO_UID}" -- "${qemu[@]}" -drive media=disk,format=raw,if=virtio,file="$arg_image"
|
2018-08-11 21:23:12 +00:00
|
|
|
./osi-mount "$arg_image" "$mountpoint" sh -c "cat ${mountpoint@Q}/var/log/osi-run.out; exit \$(cat ${mountpoint@Q}/var/log/osi-run.status)"
|
2018-08-06 01:49:45 +00:00
|
|
|
}
|