netboot.xyz.j2 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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} && isset ${filename} && goto tftpmenu ||
  38. goto menu
  39. :failsafe
  40. menu ${boot_domain} Failsafe Menu
  41. item localboot Boot to local drive
  42. item netconfig Manual network configuration
  43. item vlan Manual VLAN configuration
  44. item retry Retry boot
  45. item debug iPXE Debug Shell
  46. item reboot Reboot System
  47. choose failsafe_choice || exit
  48. goto ${failsafe_choice}
  49. :netconfig
  50. echo Network Configuration:
  51. echo Available interfaces...
  52. ifstat
  53. imgfree
  54. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  55. isset ${net} || set net 0
  56. echo -n IP: && read net${net}/ip
  57. echo -n Subnet mask: && read net${net}/netmask
  58. echo -n Gateway: && read net${net}/gateway
  59. echo -n DNS: && read dns
  60. ifopen net${net}
  61. echo Attempting chainload of ${boot_domain}...
  62. goto menu || goto failsafe
  63. :vlan
  64. echo VLAN Configuration:
  65. echo Available interfaces...
  66. ifstat
  67. imgfree
  68. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  69. isset ${net} || set net 0
  70. echo -n Set VLAN 802.1Q tag [0 to 4094]: ${} && read vlan
  71. vcreate --tag ${vlan} net${net}
  72. ifconf --configurator dhcp net${net}-${vlan} || echo DHCP failed trying manual && goto netvlan
  73. echo Attempting chainload of ${boot_domain}...
  74. goto menu || goto failsafe
  75. :netvlan
  76. echo -n IP: && read net${net}-${vlan}/ip
  77. echo -n Subnet mask: && read net${net}-${vlan}/netmask
  78. echo -n Gateway: && read net${net}-${vlan}/gateway
  79. echo -n DNS: && read dns
  80. ifopen net${net}-${vlan}
  81. echo Attempting chainload of ${boot_domain}...
  82. goto menu || goto failsafe
  83. :tftpmenu
  84. chain tftp://${tftp-server}/local-vars.ipxe || echo ${VARS_ERR}
  85. isset ${hostname} && chain --autofree tftp://${tftp-server}/HOSTNAME-${hostname}.ipxe || echo Custom boot by Hostname not found trying MAC...
  86. chain --autofree tftp://${tftp-server}/MAC-${mac:hexraw}.ipxe || echo Custom boot by MAC not found booting default...
  87. chain --autofree tftp://${tftp-server}/menu.ipxe || echo ${TFTP_ERR} && goto menu
  88. :menu
  89. {% if bootloader_https_enabled | bool %}
  90. :menu_https
  91. set conn_type https
  92. goto menu_start
  93. {% endif %}
  94. {% if bootloader_http_enabled | bool %}
  95. :menu_http
  96. set conn_type http
  97. goto menu_start
  98. {% endif %}
  99. :menu_start
  100. isset ${netX/dns6} && goto menu_v6 || goto menu_v4
  101. :menu_v6
  102. isset ${netX/dns6_bak} && set netX/dns6 ${netX/dns6_bak} ||
  103. set netX/dns6_bak ${netX/dns6}
  104. echo Attempting ${conn_type} boot over IPv6...
  105. chain --autofree ${conn_type}://${boot_domain}/menu.ipxe || echo ${conn_type} IPv6 failed... attempting IPv4...
  106. clear netX/dns6
  107. :menu_v4
  108. echo Attempting ${conn_type} boot over IPv4...
  109. chain --autofree ${conn_type}://${boot_domain}/menu.ipxe || echo ${conn_type} IPv4 failed...
  110. iseq ${conn_type} https && goto menu_http || goto localboot
  111. :localboot
  112. exit
  113. :retry
  114. goto start
  115. :reboot
  116. reboot
  117. goto start
  118. :debug
  119. echo Type "exit" to return to menu
  120. shell
  121. goto failsafe