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

if ! echo "$SNAP_REVISION" | grep -E -q 'x[0-9]+'; then
	GARDEN_COMPONENT=qemu-"$(uname -m | sed -e 's/_/-/')"
	if [ ! -d "$SNAP"/../components/"$SNAP_REVISION"/"$GARDEN_COMPONENT" ]; then
		echo "Installing qemu component for host CPU architecture..." >&2
		exec snapctl install +"$GARDEN_COMPONENT" >&2
	fi
fi
