#!ipxe
# initrd tftp://dhcp-server/tftpboot/ipxe/grub/grub.cfg
# chain tftp://dhcp-server/tftpboot/ipxe/grubx64.efi
# chain http://dhcp-server/local/ipxe/grubx64.efi


# 获取网络
dhcp



# 判断启动模式
iseq ${platform} efi && goto uefi || goto bios


# =======================
# UEFI 启动（直接进 GRUB）
# =======================
:uefi
set  PLAT_FORM  UEFI
goto show_menu



# =======================
# BIOS 启动（显示菜单）
# =======================
:bios

cpair --foreground 3 --background 6 1
cpair --foreground 0 --background 6 3

cpair --foreground 3 --background 1 2


set  PLAT_FORM  BIOS
goto show_menu

:show_menu
menu iPXE Linux  Setup(${PLAT_FORM}) Menu
item --gap -- ---------------- Boot Options ----------------
item main     return main
item linux32    linux_install32
item linux64    linux_install64

choose target || goto cancel

goto ${target}

:main
chain http://dhcp-server/local/boot.ipxe
boot
goto end

:linux32
set  img_dir  alpine32
goto auto_linux


:linux64
set  img_dir  alpine64
goto auto_linux


:auto_linux
kernel http://dhcp-server/dev/tftpboot/vmlinuz/${img_dir}/vmlinuz \
    modloop=http://nas-server/dev/tftpboot/vmlinuz/${img_dir}/modloop \
    rootfs_net=http://nas-server/dev/tftpboot/vmlinuz/${img_dir}/rootfs.img \
    ip=dhcp \
    CUSTOM_PROFILE=http://nas-server/dev/setup/distr_opt/customize.sh

initrd http://dhcp-server/dev/tftpboot/vmlinuz/${img_dir}/initfs.img
boot
goto end


:cancel
echo Cancelled
goto end


:end
echo Done
