X-Git-Url: https://code.delx.au/refind/blobdiff_plain/1f5b3c00f34cd3bfa077b2110d383632295efbd0..69c4acfcdc7121bc0d4f5386910545f4caf134f2:/refind-mkdefault diff --git a/refind-mkdefault b/refind-mkdefault index 7f673db..a48ac5d 100755 --- a/refind-mkdefault +++ b/refind-mkdefault @@ -104,10 +104,12 @@ def set_refind_first(boot_entries, boot_order, label): :param label: String used to identify rEFInd entry in efibootmgr output :returns: - True if order adjusted, False otherwise + * -1 if order already OK + * 0 if order adjusted + * 3 if label was not found in available entries """ first_refind_number = i = -1 - changed_order = False + retval = 0 found_first_refind = "" show_multiple_warning = True for entry in boot_order: @@ -123,21 +125,20 @@ def set_refind_first(boot_entries, boot_order, label): found_first_refind = entry first_refind_number = i if first_refind_number == -1: - if add_unordered_entry(boot_entries, boot_order, label): - changed_order = True - else: + if not add_unordered_entry(boot_entries, boot_order, label): print("{} was not found in the boot options list!".format(label)) print("You should create a {} entry with efibootmgr or by re-installing".format(label)) print("(with refind-install, for example)") + retval = 3 elif first_refind_number == 0: print("{} is already the first entry".format(label)) + retval = -1 elif first_refind_number > 0: del boot_order[first_refind_number] boot_order.insert(0, found_first_refind) - changed_order = True print("{} is not the first boot entry; adjusting....".format(label)) - return changed_order + return retval def save_changes(boot_order): @@ -146,8 +147,9 @@ def save_changes(boot_order): :param boot_order: List of boot numbers as strings, in boot order :returns: - True if there were no problems, False otherwise + 0 if there were no problems, 1 otherwise """ + retval = 0 order_string = ",".join(boot_order) command = "efibootmgr -o {}".format(order_string) print("Setting a boot order of {}".format(order_string)) @@ -155,6 +157,8 @@ def save_changes(boot_order): Popen(shlex.split(command), stdout=PIPE).communicate()[0] except: print("An error occurred setting the new boot order!") + retval = 1 + return retval def main(): @@ -168,30 +172,31 @@ def main(): if sys.platform != "linux": print("This program is useful only under Linux; exiting!") - return(1) + return(4) if shutil.which("efibootmgr") is None: print("The efibootmgr utility is not installed; exiting!") - return(1) + return(4) if not os.geteuid() == 0: print("This program must be run as root (or via sudo); exiting!") - return(1) + return(4) - problems = False retval = 0 boot_entries, boot_order = discover_data() if boot_entries == {}: - problems = True print("No EFI boot entries are available. This may indicate a firmware problem.") + retval = 2 if boot_order == []: - problems = True print("The EFI BootOrder variable is not available. This may indicate a firmware") print("problem.") - if (not problems and - set_refind_first(boot_entries, boot_order, args.label)): - save_changes(boot_order) + if (retval == 0): + changed = set_refind_first(boot_entries, boot_order, args.label) + if (changed == 0): + retval = save_changes(boot_order) + else: + print("No changes saved.") + if changed > 0: + retval = changed else: - if problems: - retval = 1 print("No changes saved.") return(retval)