File run of Package suse-AGL

#!/bin/bash

set -e

ARGUMENT_LIST=(
    "camera:"
)

# Functions
usage() {
    echo "run"
    echo "  --camera <BUS:HOST>"
    echo "      Attach given USB bus:host camera to the instance"
    echo "      Run lsusb to get the right numbers"
}

# Read Arguments
if ! opts=$(getopt \
    --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
    --name "$(basename "$0")" \
    --options "" \
    -- "$@"
); then
    usage
    exit 1
fi

eval set --"${opts}"

while [[ $# -gt 0 ]]; do
    case "$1" in
        --camera)
            argCamera=$2
            shift 2
            ;;
        *)
            break
            ;;
    esac
done

if [ ! -d binaries ];then
    echo "run osc getbinaries first..."
    exit 1
fi

if [ ! -e binaries/mysdcard.raw ];then
    qemu-img create binaries/mysdcard.raw 32g
    size_bytes=$(
        xz -lv binaries/suse-AGL*.raw.xz |\
            grep "Uncompressed size:" |\
            cut -f2 -d\( | cut -f1 -d " " | tr -d ,
    )
    xz -dc binaries/suse-AGL*.raw.xz | pv --size "${size_bytes}" | \
        dd of=binaries/mysdcard.raw conv=notrunc
fi

if [ "${argCamera}" ];then
    webcam_bus=$(echo "${argCamera}" | cut -f1 -d:)
    webcam_hostaddr=$(echo "${argCamera}" | cut -f2 -d:)
fi

# core
qemu_options="-m 4096 -boot menu=on -cpu host -smp 2"

# graphics
qemu_options="${qemu_options} -vga qxl"

# USB
qemu_options="${qemu_options} -usb"

# Firmware
qemu_options="${qemu_options} -bios /usr/share/qemu/ovmf-x86_64.bin"

# network
qemu_options="${qemu_options} -netdev user,id=user0,hostfwd=tcp::10022-:22,hostfwd=tcp::5000-:5000"
qemu_options="${qemu_options} -device virtio-net-pci,netdev=user0,mac=52:54:00:6a:40:f8"

# USB
qemu_options="${qemu_options} -device usb-ehci,id=ehci"
if [ "${argCamera}" ];then
    qemu_options="${qemu_options} -device usb-host,hostbus=${webcam_bus},hostaddr=${webcam_hostaddr}"
fi

# console
qemu_options="${qemu_options} -serial stdio"

# storage
qemu_options="${qemu_options} -drive file=binaries/mysdcard.raw,if=virtio,format=raw"

xhost local:root

sudo DISPLAY="${DISPLAY}" qemu-kvm ${qemu_options}
openSUSE Build Service is sponsored by