#!ipxe    
#http://boot.ipxe.org/ipxe.iso
# Booting Windows PE using wimboot   http://git.ipxe.org/releases/wimboot/wimboot-latest.zip
# x86 or x64, pcbios or UEFI, PC or vmware

#-------------------------------------------------------------------------
#check platform (pcbios or efi), buildarch (i386 or X86_64)
echo Platform: ${platform}
echo Buildarch: ${buildarch}

set menu-timeout 6000
isset ${ip} || dhcp
isset ${next-server} || set next-server 192.168.1.133
iseq ${platform} pcbios && set start BIOS_Start || set start EFI_Start
goto ${start}


#>Begin iPXE uEFI Boot ===========================================
:EFI_Start
    cpuid --ext 29 && set arch X64 || set arch X86
    #iseq ${buildarch} i386 set arch X86 || set arch X64
    set menu-default EFI_Win10PE
    menu iPXE uEFI Boot Menu -- ${ip}
    item --gap --             ------------------------------------ WinPE ----------------------
    item --key a EFI_Win10PE         Boot Win10PE ${arch}               -------- Hotkey a
    item --gap --             -------------------------------- Advanced options --------------
    item --key c Config            Configure settings                   ---------------- Hotkey c
    item --key i Shell             Drop to iPXE shell                   ---------------- Hotkey i
    item --key r Reboot            Reboot the computer                   --------------- Hotkey r
    item --key s Power             Shutdown the computer                   ------------- Hotkey s
    item --key x Exit              Exit iPXE and continue boot                   ------- Hotkey x
    item --gap --             ------------------------------------------------------------------
    choose --timeout ${menu-timeout} --default ${menu-default} selected
    goto ${selected}

:EFI_Win10PE
    set bootfile bootx64.efi && set sbcdfile bcd && set pefile pe64.wim
    iseq ${arch} X86 && set bootfile bootia32.efi && set sbcdfile bcd && set pefile pe32.wim ||
    goto EFI_Wimboot

:EFI_Wimboot
    kernel -n wimboot http://${next-server}/boot/wimboot.efi
    initrd http://${next-server}/${bootfile}                
    initrd http://${next-server}/boot/${sbcdfile}           
    initrd http://${next-server}/boot/boot.sdi             
    initrd -n boot.wim http://${next-server}/boot/${pefile}            
    boot || goto Failed
    goto ${start}



#>Begin iPXE BIOS Boot =================================
:BIOS_Start
    #console --picture http://${next-server}/Black.png --top 100 --left 100 --bottom 100 ||
    #console --picture http://${next-server}/Black.png ||
    cpuid --ext 29 && set arch X64 || set arch X86
    set menu-default Win10PEX86
    menu iPXE Boot Menu -- ${ip}
    item --gap --             ----------------------------- WinPE ----------------------
    item --key a Win10PEX64        Boot Win10PE X64 (wim)                   ----- Hotkey a
    item --key b Win10PEX86        Boot Win10PE X86 (wim)                   ----- Hotkey b
    item --gap --             ---------------------------- DOS Tool -----------------
    item DGDOS                     Load DGDOS
    item Max93                     Load Max9.3
    item Mhdd                      Load Mhdd
    item --gap --             ---------------------------- EXT Boot ------------------
    item Exit                      Exit iPXE and continue boot
    item --gap --             ------------------------ Advanced options ------------
    item --key c Config            Configure settings                   --------- Hotkey c
    item --key i Shell             Drop to iPXE shell                   --------- Hotkey i
    item --key r Reboot            Reboot the computer                   -------- Hotkey r
    item --key s Power             Shutdown the computer                   ------ Hotkey s
    item --gap --             --------------------------------------------------------
    choose --timeout ${menu-timeout} --default ${menu-default} selected
    goto ${selected}

:DGDOS
    kernel http://${next-server}/memdisk img raw || goto Failed
    initrd http://${next-server}/dostools/DGDOS.IMG || goto Failed
    boot || goto Failed

:Max93
    kernel http://${next-server}/memdisk ima raw || goto Failed
    initrd http://${next-server}/dostools/max9.3.ima || goto Failed
    boot || goto Failed

:Mhdd
    kernel http://${next-server}/memdisk iso || goto Failed
    initrd http://${next-server}/dostools/mhdd.iso || goto Failed
    boot || goto Failed

:Win10PEX64
    set pefile pe64.wim
    goto BIOS_Wimboot

:Win10PEX86
    set pefile pe32.wim
    goto BIOS_Wimboot


:BIOS_Wimboot
    kernel http://${next-server}/boot/wimboot                      gui || goto Failed
    initrd http://${next-server}/boot/bootmgr.exe          bootmgr.exe || goto Failed
    initrd http://${next-server}/boot/bod                          bcd || goto Failed
    initrd http://${next-server}/boot/boot.sdi                boot.sdi || goto Failed
    initrd http://${next-server}/boot/${pefile}               boot.wim || goto Failed
    boot                                                               || goto Failed
    goto ${start}
#<End iPXE BIOS Boot =================================

:Failed
    echo Booting Failed, dropping to shell
    goto shell
    goto ${start}


:Config
    config
    goto ${start}

:Power
    poweroff

:Reboot
    reboot

:Exit
    exit
