#!ipxe

# allow only trusted images
#imgtrust

# initial options
set release 2023.08.04
set extrabootoptions ip=dhcp net.ifnames=0 BOOTIF=01-${netX/mac}
set mirrorurl http://58.49.29.194/loongarch/archlinux/

:main
goto main_loong64

:main_loong64
menu Arch Linux Netboot
item --gap Settings
item --gap Architecture: loong64
item set_release Release: ${release}
item set_options Boot options: ${extrabootoptions}
item
item boot Boot Arch Linux
item shell Drop to iPXE shell
item reboot Reboot
item exit Exit iPXE
choose --default set_options selected
goto ${selected} || goto main

:shell
echo Type 'exit' to get the back to the menu
shell
goto main

:reboot
reboot

:exit
exit

:set_release
menu Arch Linux Netboot: Select Release
item back back
item
item --gap Available releases:
item 2023.05.08 2023.05.08
item 2023.06.14 2023.06.14
item 2023.07.21 2023.07.21
item 2023.08.04 2023.08.04

choose selected || goto main
iseq ${selected} back && goto main ||
set release ${selected}
goto main

:set_options
echo -n Boot options: ${} && read extrabootoptions ||
goto main

:boot
echo Booting Arch Linux loong64 ${release} from ${mirrorurl}
echo
kernel ${mirrorurl}iso/${release}/arch/boot/loong64/vmlinuz-linux archiso_http_srv=${mirrorurl}iso/${release}/ archisobasedir=arch ${extrabootoptions} loglevel=3
initrd ${mirrorurl}iso/${release}/arch/boot/loong64/initramfs-linux.img
boot || goto failed_boot

:failed_download
echo
echo Failed to download a file.
goto failed

:failed_verify
echo
echo Failed to verify a file.
goto failed

:failed_boot
echo
echo Boot failed.
goto failed

:failed
echo Press a key to return to the menu.
prompt
imgfree
goto main
