#!/bin/bash

set -euxo pipefail

declare -A efi_arch=(
  ["x86_64"]="X64"
  ["aarch64"]="AA64"
  )

for arch in "${!efi_arch[@]}"; do
  
  DEST=/tmp/esp-${arch}.img

  dd bs=1024 count=6400 if=/dev/zero of=$DEST
  mkfs.msdos -F 12 -n 'ESP_IMAGE' $DEST

  mmd -i $DEST EFI
  mmd -i $DEST EFI/BOOT

  mcopy -i $DEST -v /usr/share/efi/${arch}/shim.efi ::EFI/BOOT/BOOT${efi_arch[$arch]}.EFI
  mcopy -i $DEST -v /usr/share/efi/${arch}/grub.efi ::EFI/BOOT/GRUB.EFI

  mdir -i $DEST ::EFI/BOOT;
done



