#!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 CentOs  Setup(${PLAT_FORM}) Menu
item --gap -- ---------------- Boot Options ----------------
item main     return main
item 83x64com    CentOs8.3x64 auto install 2(for compile kernel)
item 77x64com    CentOs7.7x64 auto install 2(for compile kernel)
item 77i386com    CentOs7.7_i386 auto install(for compile kernel)
item 76x64com    CentOs7.6x64 auto install 2(for compile kernel)
item 69i386com    CentOs6.9_i386 auto install(for compile)
item 69x64com    CentOs6.9x64 auto install 2(for compile kernel)
item 69i386img   CentOs6.9_i386 auto install(for make img)
item 69x64img   CentOs6.9x64 auto install 2(for make img)


choose target || goto cancel

goto ${target}

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

:83x64com
set  img_dir  CentOs8.3x86_64
set ks_file  CentOs8.3x64-compile_anaconda-ks.cfg
goto boot_centos

:77x64com
set  img_dir  CentOs7.7x86_64
set ks_file  CentOs7.7x64-compile_anaconda-ks.cfg
goto boot_centos

:77i386com
set  img_dir  CentOs7.7_i386
set ks_file  CentOs7.7_i386-compile_anaconda-ks.cfg
goto boot_centos

:76x64com
set  img_dir  CentOs7.6x86_64
set ks_file  CentOs7.6x64-compile_anaconda-ks.cfg
goto boot_centos

:69i386com
set  img_dir  CentOs6.9_i386
set ks_file  CentOs6.9_i386-compile_anaconda-ks.cfg
goto boot_centos

:69x64com
set  img_dir  CentOs6.9_x86_64
set ks_file  CentOs6.9x64-compile_anaconda-ks.cfg
goto boot_centos

:69i386img
set  img_dir  CentOs6.9_i386
set ks_file  CentOs6.9_i386-img_anaconda-ks.cfg
goto boot_centos

:69x64img
set  img_dir  CentOs6.9_x86_64
set ks_file  CentOs6.9x64-img_anaconda-ks.cfg
goto boot_centos


:boot_centos
kernel http://dhcp-server/dev/tftpboot/vmlinuz/${img_dir}/vmlinuz \
    ks=nfs:nas-server:/data/SYS/linux/CentOS/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


:cancel
echo Cancelled
goto end


:end
echo Done
