#!/bin/sh
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Zygmunt Krynicki
set -eu

GARDEN_QEMU_SYSTEM=aarch64
GARDEN_COMPONENT=qemu-"$GARDEN_QEMU_SYSTEM"

# If the component is not installed, fail with an error message.
if [ ! -d "$SNAP"/../components/"$SNAP_REVISION"/"$GARDEN_COMPONENT" ]; then
	echo "install $GARDEN_COMPONENT component to use $GARDEN_QEMU_SYSTEM emulation" >&2
	exit 1
fi

# Execute qemu-system-$GARDEN_QEMU_SYSTEM through the symbolic link created above.
exec "$SNAP"/components/"$GARDEN_COMPONENT"/bin/qemu-system-$GARDEN_QEMU_SYSTEM "$@"
