1
0

netboot.xyz.j2 4.5 KB

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