#!/bin/bash
# virtme-ng prepare script for kernel testing with OCI images.
#
# Referenced from .cui-cui.toml as:
#   prepare = "@examples/vng-runner/vng-prepare.sh"
#
# Available variables (exported by cui-cui before this script runs):
#   $CI_JOB_IMAGE  - OCI container image to use as rootfs
#   $KERNEL        - path to the kernel bzImage to boot
#
# Required tools on the host: podman, vng (virtme-ng)
#
# Exports:
#   $ROOTFS - path to the mounted OCI image filesystem

set -eox pipefail

podman pull "$CI_JOB_IMAGE" 2>/dev/null || true
export ROOTFS=$($PODMAN_UNSHARE podman image mount "$CI_JOB_IMAGE")

echo "Mounted $CI_JOB_IMAGE at $ROOTFS"

timeout 5s $PODMAN_UNSHARE vng --run $KERNEL --root $ROOTFS --user root --exec "echo 'boot-ok'"
