netboot.xyz.j2 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!ipxe
  2. set esc:hex 1b
  3. set bold ${esc:string}[1m
  4. set boldoff ${esc:string}[22m
  5. set fg_gre ${esc:string}[32m
  6. set fg_cya ${esc:string}[36m
  7. set fg_whi ${esc:string}[37m
  8. set VARS_ERR Local vars file not found... attempting TFTP boot...
  9. set TFTP_ERR Local TFTP failed... attempting remote HTTPS
  10. set HTTPS_ERR HTTPS appears to have failed... attempting HTTP
  11. set HTTP_ERR HTTP has failed, localbooting...
  12. set site_name {{ site_name }}
  13. set boot_domain {{ boot_domain }}
  14. set ipxe_version ${version}
  15. set version {{ boot_version }}
  16. :start
  17. echo ${bold}${fg_gre}${site_name} - ${fg_whi}v${version}${boldoff}
  18. iseq ${site_name} netboot.xyz || echo ${bold}${fg_whi}Powered by ${fg_gre}netboot.xyz${fg_whi}${boldoff}
  19. prompt --key m --timeout 4000 Hit the ${bold}m${boldoff} key to open failsafe menu... && goto failsafe || goto dhcp
  20. :dhcp
  21. echo
  22. dhcp || goto netconfig
  23. isset ${next-server} && iseq ${filename} {{ site_name }}.kpxe && goto tftpmenu ||
  24. isset ${next-server} && iseq ${filename} {{ site_name }}-undionly.kpxe && goto tftpmenu ||
  25. isset ${next-server} && iseq ${filename} {{ site_name }}.efi && goto tftpmenu ||
  26. isset ${next-server} && iseq ${filename} {{ site_name }}-snp.efi && goto tftpmenu ||
  27. isset ${next-server} && iseq ${filename} {{ site_name }}-snponly.efi && goto tftpmenu ||
  28. isset ${next-server} && iseq ${filename} {{ site_name }}-arm64.efi && goto tftpmenu ||
  29. goto menu
  30. :failsafe
  31. menu ${boot_domain} Failsafe Menu
  32. item localboot Boot to local drive
  33. item netconfig Manual network configuration
  34. item vlan Manual VLAN configuration
  35. item retry Retry boot
  36. item debug iPXE Debug Shell
  37. item reboot Reboot System
  38. choose failsafe_choice || exit
  39. goto ${failsafe_choice}
  40. :netconfig
  41. echo Network Configuration:
  42. echo Available interfaces...
  43. ifstat
  44. imgfree
  45. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  46. isset ${net} || set net 0
  47. echo -n IP: && read net${net}/ip
  48. echo -n Subnet mask: && read net${net}/netmask
  49. echo -n Gateway: && read net${net}/gateway
  50. echo -n DNS: && read dns
  51. ifopen net${net}
  52. echo Attempting chainload of ${boot_domain}...
  53. goto menu || goto failsafe
  54. :vlan
  55. echo VLAN Configuration:
  56. echo Available interfaces...
  57. ifstat
  58. imgfree
  59. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  60. isset ${net} || set net 0
  61. echo -n Set VLAN 802.1Q tag [0 to 4094]: ${} && read vlan
  62. vcreate --tag ${vlan} net${net}
  63. ifconf --configurator dhcp net${net}-${vlan} || echo DHCP failed trying manual && goto netvlan
  64. echo Attempting chainload of ${boot_domain}...
  65. goto menu || goto failsafe
  66. :netvlan
  67. echo -n IP: && read net${net}-${vlan}/ip
  68. echo -n Subnet mask: && read net${net}-${vlan}/netmask
  69. echo -n Gateway: && read net${net}-${vlan}/gateway
  70. echo -n DNS: && read dns
  71. ifopen net${net}-${vlan}
  72. echo Attempting chainload of ${boot_domain}...
  73. goto menu || goto failsafe
  74. :tftpmenu
  75. chain tftp://${next-server}/local-vars.ipxe || echo ${VARS_ERR}
  76. isset ${hostname} && chain --autofree tftp://${next-server}/HOSTNAME-${hostname}.ipxe || echo Custom boot by Hostname not found trying MAC...
  77. chain --autofree tftp://${next-server}/MAC-${mac:hexraw}.ipxe || echo Custom boot by MAC not found booting default...
  78. chain --autofree tftp://${next-server}/menu.ipxe || echo ${TFTP_ERR} && goto menu
  79. :menu
  80. {% if bootloader_https_enabled | bool %}
  81. set conn_type https
  82. chain --autofree https://${boot_domain}/menu.ipxe || echo ${HTTPS_ERR}
  83. sleep 5
  84. {% endif %}
  85. {% if bootloader_http_enabled | bool %}
  86. set conn_type http
  87. chain --autofree http://${boot_domain}/menu.ipxe || echo ${HTTP_ERR}
  88. {% endif %}
  89. goto localboot
  90. :localboot
  91. exit
  92. :retry
  93. goto start
  94. :reboot
  95. reboot
  96. goto start
  97. :debug
  98. echo Type "exit" to return to menu
  99. shell
  100. goto failsafe