#!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


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

cpair --foreground 3 --background 1 2

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


# =======================
# UEFI 启动（直接进 GRUB）
# =======================
:uefi
set  PLAT_FORM  UEFI
goto show_menu
# =======================
# BIOS 启动（显示菜单）
# =======================
:bios
set  PLAT_FORM  BIOS
goto show_menu

:show_menu
menu iPXE Rocky  Setup(${PLAT_FORM}) Menu
item --gap -- ---------------- Boot Options ----------------
item main     return main
item 810x64auto    Rocky 8.10x64 auto install
item 810x64inst    Rocky 8.10x64 install

choose target || goto cancel

goto ${target}

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

:810x64auto
set  img_dir  Rocky8.10x86_64
set ks_file  Rocky8.10x64_anaconda-ks.cfg
goto auto_rocky


:810x64inst
set  img_dir  Rocky8.10x86_64
set ks_file  Rocky8.10x64_anaconda-ks.cfg
goto inst_rocky


:auto_rocky
kernel http://dhcp-server/dev/tftpboot/vmlinuz/${img_dir}/vmlinuz \
    ks=nfs:nas-server:/data/SYS/linux/rockylinux/rocky-kickstart/${ks_file} \
    text ip=dhcp noipv6 network \
    ksdevice=bootif \
    BOOTIF=01-${net0/mac:hexhyp} \
    ramdisk_size=8192

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


:inst_rocky
kernel http://dhcp-server/dev/tftpboot/vmlinuz/${img_dir}/vmlinuz \
    ip=dhcp noipv6 network \
    ksdevice=bootif \
    BOOTIF=01-${net0/mac:hexhyp} \
    ramdisk_size=8192

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


:cancel
echo Cancelled
goto end


:end
echo Done
