{#
 # EFI is currently the only firmware where we have to stuff around with the
 # boot order. If efibootmgr fails, we assume this is not an EFI system.
 #
 # In addition, we skip the snippet for guest recipes because we don't need to
 # worry about boot order there, and efibootmgr can apparently crash ia64 Xen
 # domains (bug 1029681).
 #}
{% if not recipe|attr('hostrecipe') %}
if efibootmgr &>/dev/null ; then
    # The installer should have added a new boot entry for the OS
    # at the top of the boot order. We move it to the end of the order
    # and set it as BootNext instead.
{#
    # Some extra considerations for EFI:
    #   - We can't rely on the BootCurrent variable because some
    #     implementations do not provide it (bug 1031876)
    #   - We need to preserve all existing entries in the boot order. Some
    #     implementations will freak out if their built-in boot entries
    #     ("Vendor...") are removed from the order and will re-add them, making
    #     a mess of things in the process (bug 1030612)
    #   - We can't remove the OS boot entry from the order entirely, because
    #     some implementations will just delete it
#}
    boot_order=$(efibootmgr | awk '/BootOrder/ { print $2 }')
    os_boot_entry=$(cut -d, -f1 <<<"$boot_order")
    new_boot_order=$(cut -d, -f2- <<<"$boot_order"),"$os_boot_entry"
    efibootmgr -o "$new_boot_order"
    efibootmgr -n "$os_boot_entry"
    # save the boot entry for later, so that rhts-reboot can set BootNext as well
    echo "$os_boot_entry" >/root/EFI_BOOT_ENTRY.TXT
fi
{% endif %}
