image: "opensuse/leap:15.5"

prelude:
{{if .Values.arch }}
  {{if eq .Values.arch "amd64"}}
- zypper in -y --no-recommends syslinux
  {{end}}
{{end}}
- zypper in -y --no-recommends grub2 grub2-i386-pc grub2-x86_64-efi grub2-arm64-efi shim
- zypper cc
- grub2-mkimage -O i386-pc -o /usr/share/grub2/i386-pc/core.img -p /boot/grub2 -d /usr/share/grub2/i386-pc ext2 iso9660 linux echo configfile search_label search_fs_file search search_fs_uuid ls normal gzio png fat gettext font minicmd gfxterm gfxmenu all_video xfs btrfs lvm luks gcry_rijndael gcry_sha256 gcry_sha512 crypto cryptodisk test true loadenv part_gpt part_msdos biosdisk vga vbe chain boot
- cat /usr/share/grub2/i386-pc/cdboot.img /usr/share/grub2/i386-pc/core.img > /usr/share/grub2/i386-pc/eltorito.img

steps:
{{if eq .Values.name "grub2"}}
- mkdir -p /boot/x86_64/loader
  {{if .Values.arch }}
    {{if eq .Values.arch "amd64"}}
- mkdir -p /boot/x86_64/loader/grub2/fonts && cp -p /usr/share/grub2/unicode.pf2 /boot/x86_64/loader/grub2/fonts
- mkdir -p /boot/grub2/x86_64-efi/ && cp -p /usr/share/grub2/x86_64-efi/* /boot/grub2/x86_64-efi/
- mkdir -p /boot/arm64/loader/grub2/fonts && cp -p /usr/share/grub2/unicode.pf2 /boot/arm64/loader/grub2/fonts
- mkdir -p /boot/grub2/i386-pc && cp -p /usr/share/grub2/i386-pc/* /boot/grub2/i386-pc/
- cp -p /usr/share/grub2/i386-pc/eltorito.img /usr/share/grub2/i386-pc/boot_hybrid.img /usr/share/syslinux/isolinux.bin /usr/share/syslinux/menu.c32 /usr/share/syslinux/chain.c32 /usr/share/syslinux/mboot.c32 /boot/x86_64/loader
    {{end}}
    {{if eq .Values.arch "arm64"}}
# arm64 doesn't have bios boot, but the installer(elemental-cli) still builds hybrid isos for all arches, so we need to provide these files in the arm64 package
- cp -p /usr/share/grub2/i386-pc/eltorito.img /usr/share/grub2/i386-pc/boot_hybrid.img /boot/x86_64/loader
    {{end}}
  {{end}}
- cp -p config/grub_live_bios.cfg /boot/grub2/grub.cfg
{{end}}

{{if eq .Values.name "grub2-efi-image"}}
- mkdir -p /EFI/BOOT
  {{if .Values.arch }}
    {{if eq .Values.arch "amd64"}}
# For removable drives the name of the efi needs to be bootx64.efi
- cp /usr/share/efi/x86_64/shim.efi /EFI/BOOT/bootx64.efi
- cp /usr/share/efi/x86_64/grub.efi /EFI/BOOT/grub.efi
- cp /usr/share/efi/x86_64/MokManager.efi /EFI/BOOT/MokManager.efi
    {{end}}
  {{if eq .Values.arch "arm64"}}
- ls -ltra /usr/share/grub2/arm64-efi/
# For removable drives the name of the efi needs to be bootaa64.efi
- cp /usr/share/efi/aarch64/shim.efi /EFI/BOOT/bootaa64.efi
- cp /usr/share/efi/aarch64/grub.efi /EFI/BOOT/grub.efi
- cp /usr/share/efi/aarch64/MokManager.efi /EFI/BOOT/MokManager.efi
    {{end}}
  {{end}}
- cp config/grub_live_efi.cfg /EFI/BOOT/grub.cfg
{{end}}