netboot.xyz.j2 5.0 KB

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