netboot.xyz.j2 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 V6_ERR IPv6 appears to have failed... attempting IPv4...
  11. set HTTPS_ERR HTTPS appears to have failed... attempting HTTP
  12. set HTTP_ERR HTTP has failed, localbooting...
  13. set site_name {{ site_name }}
  14. set boot_domain {{ boot_domain }}
  15. set ipxe_version ${version}
  16. set version {{ boot_version }}
  17. set conn_type https
  18. set tftp-root-path /
  19. :start
  20. echo ${bold}${fg_gre}${site_name} - ${fg_whi}v${version}${boldoff}
  21. iseq ${site_name} netboot.xyz || echo ${bold}${fg_whi}Powered by ${fg_gre}netboot.xyz${fg_whi}${boldoff}
  22. prompt --key m --timeout 4000 Hit the ${bold}m${boldoff} key to open failsafe menu... && goto failsafe || goto dhcp
  23. :dhcp
  24. echo
  25. dhcp || goto netconfig
  26. isset ${next-server} && isset ${proxydhcp/next-server} && goto choose-tftp || set tftp-server ${next-server} && goto load-custom-ipxe
  27. :choose-tftp
  28. # Load "proxy settings" from root server
  29. chain tftp://${next-server}/local-vars.ipxe || echo ${VARS_ERR}
  30. # Check if the proxy-dhcp-vars script has made any usable command about how to progress with a next-server and a proxy-next-server being set
  31. isset ${use_proxydhcp_settings} && iseq ${use_proxydhcp_settings} true && goto set-next-server ||
  32. prompt --key p --timeout 4000 DHCP proxy detected, press ${bold}p${boldoff} to boot from ${proxydhcp/next-server}... && set use_proxydhcp_settings true || set use_proxydhcp_settings false
  33. goto set-next-server
  34. :set-next-server
  35. iseq ${use_proxydhcp_settings} true && set tftp-server ${proxydhcp/next-server} || set tftp-server ${next-server}
  36. goto load-custom-ipxe
  37. :load-custom-ipxe
  38. isset ${tftp-server} && iseq ${filename} {{ bootloader_filename }}.kpxe && goto tftpmenu ||
  39. isset ${tftp-server} && iseq ${filename} {{ bootloader_filename }}-undionly.kpxe && goto tftpmenu ||
  40. isset ${tftp-server} && iseq ${filename} {{ bootloader_filename }}.efi && goto tftpmenu ||
  41. isset ${tftp-server} && iseq ${filename} {{ bootloader_filename }}-snp.efi && goto tftpmenu ||
  42. isset ${tftp-server} && iseq ${filename} {{ bootloader_filename }}-snponly.efi && goto tftpmenu ||
  43. isset ${tftp-server} && iseq ${filename} {{ bootloader_filename }}-arm64.efi && goto tftpmenu ||
  44. isset ${tftp-server} && iseq ${filename} ${tftp-root-path}{{ bootloader_filename }}.kpxe && goto tftpmenu ||
  45. isset ${tftp-server} && iseq ${filename} ${tftp-root-path}{{ bootloader_filename }}-undionly.kpxe && goto tftpmenu ||
  46. isset ${tftp-server} && iseq ${filename} ${tftp-root-path}{{ bootloader_filename }}.efi && goto tftpmenu ||
  47. isset ${tftp-server} && iseq ${filename} ${tftp-root-path}{{ bootloader_filename }}-snp.efi && goto tftpmenu ||
  48. isset ${tftp-server} && iseq ${filename} ${tftp-root-path}{{ bootloader_filename }}-snponly.efi && goto tftpmenu ||
  49. isset ${tftp-server} && iseq ${filename} ${tftp-root-path}{{ bootloader_filename }}-arm64.efi && goto tftpmenu ||
  50. goto menu
  51. :failsafe
  52. menu ${boot_domain} Failsafe Menu
  53. item localboot Boot to local drive
  54. item netconfig Manual network configuration
  55. item vlan Manual VLAN configuration
  56. item retry Retry boot
  57. item debug iPXE Debug Shell
  58. item reboot Reboot System
  59. choose failsafe_choice || exit
  60. goto ${failsafe_choice}
  61. :netconfig
  62. echo Network Configuration:
  63. echo Available interfaces...
  64. ifstat
  65. imgfree
  66. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  67. isset ${net} || set net 0
  68. echo -n IP: && read net${net}/ip
  69. echo -n Subnet mask: && read net${net}/netmask
  70. echo -n Gateway: && read net${net}/gateway
  71. echo -n DNS: && read dns
  72. ifopen net${net}
  73. echo Attempting chainload of ${boot_domain}...
  74. goto menu || goto failsafe
  75. :vlan
  76. echo VLAN Configuration:
  77. echo Available interfaces...
  78. ifstat
  79. imgfree
  80. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  81. isset ${net} || set net 0
  82. echo -n Set VLAN 802.1Q tag [0 to 4094]: ${} && read vlan
  83. vcreate --tag ${vlan} net${net}
  84. ifconf --configurator dhcp net${net}-${vlan} || echo DHCP failed trying manual && goto netvlan
  85. echo Attempting chainload of ${boot_domain}...
  86. goto menu || goto failsafe
  87. :netvlan
  88. echo -n IP: && read net${net}-${vlan}/ip
  89. echo -n Subnet mask: && read net${net}-${vlan}/netmask
  90. echo -n Gateway: && read net${net}-${vlan}/gateway
  91. echo -n DNS: && read dns
  92. ifopen net${net}-${vlan}
  93. echo Attempting chainload of ${boot_domain}...
  94. goto menu || goto failsafe
  95. :tftpmenu
  96. chain tftp://${tftp-server}/local-vars.ipxe || echo ${VARS_ERR}
  97. isset ${hostname} && chain --autofree tftp://${tftp-server}/HOSTNAME-${hostname}.ipxe || echo Custom boot by Hostname not found trying MAC...
  98. chain --autofree tftp://${tftp-server}/MAC-${mac:hexraw}.ipxe || echo Custom boot by MAC (hexraw) not found, attempting by MAC (hexhyp)...
  99. chain --autofree tftp://${tftp-server}/MAC-${mac:hexhyp}.ipxe || echo Custom boot by MAC (hexhyp) not found, booting default...
  100. chain --autofree tftp://${tftp-server}/menu.ipxe || echo ${TFTP_ERR} && goto menu
  101. :menu
  102. {% if bootloader_https_enabled | bool %}
  103. :menu_https
  104. set conn_type https
  105. goto menu_start
  106. {% endif %}
  107. {% if bootloader_http_enabled | bool %}
  108. :menu_http
  109. set conn_type http
  110. goto menu_start
  111. {% endif %}
  112. :menu_start
  113. isset ${netX/dns6} && goto menu_v6 || goto menu_v4
  114. :menu_v6
  115. isset ${netX/dns6_bak} && set netX/dns6 ${netX/dns6_bak} ||
  116. set netX/dns6_bak ${netX/dns6}
  117. echo Attempting ${conn_type} boot over IPv6...
  118. chain --autofree ${conn_type}://${boot_domain}/menu.ipxe || echo ${conn_type} IPv6 failed... attempting IPv4...
  119. clear netX/dns6
  120. :menu_v4
  121. echo Attempting ${conn_type} boot over IPv4...
  122. chain --autofree ${conn_type}://${boot_domain}/menu.ipxe || echo ${conn_type} IPv4 failed...
  123. iseq ${conn_type} https && goto menu_http || goto localboot
  124. :localboot
  125. exit
  126. :retry
  127. goto start
  128. :reboot
  129. reboot
  130. goto start
  131. :debug
  132. echo Type "exit" to return to menu
  133. shell
  134. goto failsafe