#!ipxe

# allow only trusted images
#imgtrust

# initial options
set release 2026.05.02
set extrabootoptions ip=dhcp net.ifnames=0 BOOTIF=01-${netX/mac}
set countrycode

:main
goto main_loong64

:main_loong64
menu Arch Linux Netboot
item --gap Settings
item --gap Architecture: loong64
item set_release Release: ${release}
isset ${mirrorurl} && item set_mirror Mirror: ${mirrorurl} || item set_mirror Choose a mirror
item set_options Boot options: ${extrabootoptions}
item
isset ${mirrorurl} && item boot Boot Arch Linux || item --gap Boot Arch Linux
item shell Drop to iPXE shell
item reboot Reboot
item exit Exit iPXE
isset ${mirrorurl} && choose --default set_options selected || choose --default set_mirror selected || goto shell
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 2026.04.01 2026.04.01
item 2026.05.02 2026.05.02
item 2026.06.02 2026.06.02

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

:set_mirror
goto select_mirror_country

:select_mirror_country
menu Arch Linux Netboot: Select Mirror
item back back
item
item --gap Custom Configuration:
item custom Enter mirror URL
item
item --gap Select Mirror By Country:


item CN China


isset ${countrycode} && choose --default ${countrycode} selected || choose selected || goto main
iseq ${selected} back && goto main ||
iseq ${selected} custom && goto enter_mirror_url ||
set countrycode ${selected}
goto select_mirror_url

:enter_mirror_url
set countrycode
echo Enter the mirror URL including the trailing slash.
echo Example: http://some.host/archlinux/
echo
echo -n Mirror URL: ${} && read mirrorurl || goto select_mirror_country
goto main

:select_mirror_url
goto select_mirror_url_${countrycode} || goto select_mirror_country


:select_mirror_url_CN
set countryname China

menu Arch Linux Netboot: Select Mirror
item back back
item
item --gap Available mirrors in ${countryname}
item http://mirrors.wsyu.edu.cn/loongarch/archlinux/ wsyu.edu.cn
item http://mirrors.pku.edu.cn/loongarch/archlinux/ pku.edu.cn
item http://mirrors.nju.edu.cn/loongarch/archlinux/ nju.edu.cn
item http://mirror.iscas.ac.cn/loongarch/archlinux/ iscas.ac.cn

choose selected || goto select_mirror_country
iseq ${selected} back && goto select_mirror_country ||
set mirrorurl ${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 || goto failed_download
initrd ${mirrorurl}iso/${release}/arch/boot/loong64/initramfs-linux.img || goto failed_download
imgargs vmlinuz-linux initrd=initramfs-linux.img archiso_http_srv=${mirrorurl}iso/${release}/ archisobasedir=arch ${extrabootoptions} loglevel=3
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
