#!ipxe
# Entry point for every iPXE client. dnsmasq hands this URL to any client that
# is already running iPXE (option 175).
#
# Resolution order, most specific first:
#   1. this device's own assignment   boot/<mac>.ipxe
#   2. the default for its arch       boot/default-<arch>.ipxe
#   3. the interactive menu below
#
# Step 2 is what makes a never-seen board boot something usable with nobody
# touching it. Step 3 only happens when neither has been configured.

set base http://192.168.1.85:8088
isset ${net0/mac} || set net0/mac 00:00:00:00:00:00

# iPXE reports i386 for BIOS and x86_64 for UEFI; both run amd64 images.
iseq ${buildarch} x86_64 && set arch amd64 ||
iseq ${buildarch} i386   && set arch amd64 ||
iseq ${buildarch} arm64  && set arch arm64 ||
isset ${arch} || set arch ${buildarch}

echo Netboot: ${net0/mac:hexhyp} (${arch})

chain --autofree ${base}/boot/${net0/mac:hexhyp}.ipxe ||
chain --autofree ${base}/boot/default-${arch}.ipxe ||
goto menu

:menu
menu Netboot -- ${net0/mac} -- ${arch}
item --gap No image is assigned to this device and no ${arch} default is set.
item --gap
item local   Boot from local disk
item nbxyz   netboot.xyz (mirrored locally)
item shell   iPXE shell
item reboot  Reboot
choose --timeout 30000 --default local target && goto ${target}

:local
sanboot --no-describe --drive 0x80 || goto menu

:nbxyz
iseq ${buildarch} i386 && set nbx netboot.xyz.kpxe || set nbx netboot.xyz.efi
chain tftp://192.168.1.85/netboot.xyz/${nbx} || goto menu

:shell
shell
goto menu

:reboot
reboot
