netboot.xyz.j2 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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} && isset ${proxydhcp/next-server} && goto choose-tftp || set tftp-server ${next-server} && goto load-custom-ipxe
  24. :choose-tftp
  25. # Load "proxy settings" from root server
  26. chain tftp://${next-server}/local-vars.ipxe || echo ${VARS_ERR}
  27. # 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
  28. isset ${use_proxydhcp_settings} && iseq ${use_proxydhcp_settings} true && goto set-next-server ||
  29. 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
  30. goto set-next-server
  31. :set-next-server
  32. iseq ${use_proxydhcp_settings} true && set tftp-server ${proxydhcp/next-server} || set tftp-server ${next-server}
  33. goto load-custom-ipxe
  34. :load-custom-ipxe
  35. isset ${tftp-server} && iseq ${filename} {{ site_name }}.kpxe && goto tftpmenu ||
  36. isset ${tftp-server} && iseq ${filename} {{ site_name }}-undionly.kpxe && goto tftpmenu ||
  37. isset ${tftp-server} && iseq ${filename} {{ site_name }}.efi && goto tftpmenu ||
  38. isset ${tftp-server} && iseq ${filename} {{ site_name }}-snp.efi && goto tftpmenu ||
  39. isset ${tftp-server} && iseq ${filename} {{ site_name }}-snponly.efi && goto tftpmenu ||
  40. isset ${tftp-server} && iseq ${filename} {{ site_name }}-arm64.efi && goto tftpmenu ||
  41. goto menu
  42. :failsafe
  43. menu ${boot_domain} Failsafe Menu
  44. item localboot Boot to local drive
  45. item netconfig Manual network configuration
  46. item vlan Manual VLAN configuration
  47. item retry Retry boot
  48. item debug iPXE Debug Shell
  49. item reboot Reboot System
  50. choose failsafe_choice || exit
  51. goto ${failsafe_choice}
  52. :netconfig
  53. echo Network Configuration:
  54. echo Available interfaces...
  55. ifstat
  56. imgfree
  57. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  58. isset ${net} || set net 0
  59. echo -n IP: && read net${net}/ip
  60. echo -n Subnet mask: && read net${net}/netmask
  61. echo -n Gateway: && read net${net}/gateway
  62. echo -n DNS: && read dns
  63. ifopen net${net}
  64. echo Attempting chainload of ${boot_domain}...
  65. goto menu || goto failsafe
  66. :vlan
  67. echo VLAN Configuration:
  68. echo Available interfaces...
  69. ifstat
  70. imgfree
  71. echo -n Set network interface number [0 for net0, defaults to 0]: ${} && read net
  72. isset ${net} || set net 0
  73. echo -n Set VLAN 802.1Q tag [0 to 4094]: ${} && read vlan
  74. vcreate --tag ${vlan} net${net}
  75. ifconf --configurator dhcp net${net}-${vlan} || echo DHCP failed trying manual && goto netvlan
  76. echo Attempting chainload of ${boot_domain}...
  77. goto menu || goto failsafe
  78. :netvlan
  79. echo -n IP: && read net${net}-${vlan}/ip
  80. echo -n Subnet mask: && read net${net}-${vlan}/netmask
  81. echo -n Gateway: && read net${net}-${vlan}/gateway
  82. echo -n DNS: && read dns
  83. ifopen net${net}-${vlan}
  84. echo Attempting chainload of ${boot_domain}...
  85. goto menu || goto failsafe
  86. :tftpmenu
  87. chain tftp://${tftp-server}/local-vars.ipxe || echo ${VARS_ERR}
  88. isset ${hostname} && chain --autofree tftp://${tftp-server}/HOSTNAME-${hostname}.ipxe || echo Custom boot by Hostname not found trying MAC...
  89. chain --autofree tftp://${tftp-server}/MAC-${mac:hexraw}.ipxe || echo Custom boot by MAC not found booting default...
  90. chain --autofree tftp://${tftp-server}/menu.ipxe || echo ${TFTP_ERR} && goto menu
  91. :menu
  92. {% if bootloader_https_enabled | bool %}
  93. set conn_type https
  94. chain --autofree https://${boot_domain}/menu.ipxe || echo ${HTTPS_ERR}
  95. sleep 5
  96. {% endif %}
  97. {% if bootloader_http_enabled | bool %}
  98. set conn_type http
  99. chain --autofree http://${boot_domain}/menu.ipxe || echo ${HTTP_ERR}
  100. {% endif %}
  101. goto localboot
  102. :localboot
  103. exit
  104. :retry
  105. goto start
  106. :reboot
  107. reboot
  108. goto start
  109. :debug
  110. echo Type "exit" to return to menu
  111. shell
  112. goto failsafe