#!/bin/bash

# SPDX-FileCopyrightText: 2023 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@kicksecure.com>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

set -x
set -e

## We might get away with --no-install-recommends, fewer packages.
sudo apt-get install qemu-system-arm qemu-system-aarch64 qemu-efi-aarch64 qemu-utils

## user: root
## password: changeme

#qemu-system-x86_64 \
    #-nographic \
    #-bios /usr/share/ovmf/OVMF.fd \
    #-m 1024 \
    #-drive format=raw,file=/home/user/grml-debootstraptestbin/test.img

OVMF_CODE="/usr/share/OVMF/OVMF_CODE_4M.ms.fd"
#OVMF_CODE="/usr/share/OVMF/OVMF_CODE.fd"
OVMF_VARS_ORIG="/usr/share/OVMF/OVMF_VARS_4M.ms.fd"
OVMF_VARS=~/grml-debootstraptestbin/efi-bios-vars.fd

if [ ! -e "${OVMF_VARS}" ]; then
  cp "${OVMF_VARS_ORIG}" "${OVMF_VARS}"
fi

qemu-system-x86_64 \
  -nographic \
  -name test \
  -m 1024 \
  -object rng-random,filename=/dev/random,id=rng0 \
  -device virtio-rng-pci,rng=rng0 \
  -vga virtio \
  -machine q35,smm=on \
  -global driver=cfi.pflash01,property=secure,value=on \
  -drive if=pflash,format=raw,unit=0,file="${OVMF_CODE}",readonly=on \
  -drive if=pflash,format=raw,unit=1,file="${OVMF_VARS}" \
  -net none \
  -device virtio-rng-pci \
  -drive format=raw,file=/home/user/grml-debootstraptestbin/test.img
  "$@"
