#!ipxe

chain /ipxe/${ip:hexraw} ||

:main_menu
menu Beaker
item local (local)
{% for osmajor, osversions in osmajors.iteritems()|sort(reverse=True) %}
item {{ osmajor }} {{ osmajor }} ->
{% endfor %}
choose --default local --timeout 600000 target && goto ${target} || goto local

:local
echo Booting local disk...
iseq ${builtin/platform} pcbios && sanboot --no-describe --drive 0x80 ||
# exit 1 generates an error message but req'd for some systems to fall through
exit 1 || goto main_menu

{% for osmajor, osversions in osmajors.iteritems()|sort(reverse=True) %}
:{{ osmajor }}
menu {{ osmajor }}
{% for osversion, distro_trees in osversions.iteritems()|sort(reverse=True) %}
item {{ osversion }} {{ osversion }} ->
{% endfor %}
item main_menu back <-
choose target && goto ${target} || goto main_menu

{% for osversion, distro_trees in osversions.iteritems()|sort(reverse=True) %}
:{{ osversion }}
menu {{ osversion }}
{% for distro_tree in distro_trees %}
item {{ distro_tree.distro_name.replace(" ", "") }}-{{ distro_tree.variant.replace(" ", "") }}-{{ distro_tree.arch .replace(" ", "") }} {{ distro_tree.distro_name }} {{ distro_tree.variant }} {{ distro_tree.arch }}
{% endfor %}
item {{ osmajor }} back <-
choose target && goto ${target} || goto {{ osmajor }}

{% for distro_tree in distro_trees %}
:{{ distro_tree.distro_name.replace(" ", "") }}-{{ distro_tree.variant.replace(" ", "") }}-{{ distro_tree.arch.replace(" ", "") }}
set options kernel initrd=initrd method={{ distro_tree.available|get_url }} repo={{ distro_tree.available|get_url }} {{ distro_tree.kernel_options }}
echo Kernel command line: ${options}
prompt --timeout 5000 Press any key for additional options... && set opts 1 || clear opts
isset ${opts} && echo -n Additional options: ${} ||
isset ${opts} && read useropts ||
kernel /distrotrees/{{ distro_tree.distro_tree_id }}/kernel || goto {{ osversion }}
initrd /distrotrees/{{ distro_tree.distro_tree_id }}/initrd || goto {{ osversion }}
imgargs ${options} ${useropts}
boot || goto {{ osversion }}

{% endfor %}
{% endfor %}
{% endfor %}
