]> code.delx.au - refind/blobdiff - refind-mkdefault
Misc small changes, mostly to refind-mkdefault
[refind] / refind-mkdefault
index 7f673db46edf25f8a275441935514908bb6117c4..39d7ef7e2ed571dbdcaddead32c1ccfda2660a49 100755 (executable)
@@ -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():
@@ -176,22 +180,23 @@ def main():
         print("This program must be run as root (or via sudo); exiting!")
         return(1)
 
-    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)