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