#!/bin/sh
#
# Wrapper for running the host QEMU inside a tuxrun docker container.
# For this to work we need the container to:
#   - bind paths to host libraries in /opt/host
#   - bind paths to search for firmware under /opt/host/firmware
#   - bind QEMU itself over /usr/bin/qemu.real
#   - bind the expanded version of this wrapper to /usr/bin/qemu-system-ARCH
#
# We use LD_LIBRARY_PATH to ensure the host QEMU attempts to link to
# the host libraries before anything in the container. As there can be
# some incompatibilities between the loader and library we also invoke
# QEMU directly using the host loader.so.
#
# The wrapper makes the calling relatively transparent for the lava
# job itself which calls what it thinks is QEMU normally.
#
env LD_LIBRARY_PATH={{ search_path }} \
    {{ loader }} /opt/host/qemu.real -L {{ fw_paths }} "$@"
