File 0006-mkinitramfs-Improve-the-find_busybox-algorithm.patch of Package virtme

From 0c733ddb1ef4952bda0614cc68ce80f1c8433ffc Mon Sep 17 00:00:00 2001
From: Andy Lutomirski <luto@kernel.org>
Date: Fri, 18 Oct 2019 11:03:31 -0700
Subject: [PATCH 6/9] mkinitramfs: Improve the find_busybox algorithm

Now the algorithm prefers the 'static' versions regardless of path,
and it searches PATH first (for native) as advertised.

See issue #52.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 virtme/mkinitramfs.py | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/virtme/mkinitramfs.py b/virtme/mkinitramfs.py
index 193f510..98c7528 100644
--- a/virtme/mkinitramfs.py
+++ b/virtme/mkinitramfs.py
@@ -167,16 +167,22 @@ def mkinitramfs(out, config) -> None:
     cw.write_trailer()
 
 def find_busybox(root, is_native) -> Optional[str]:
-    for p in itertools.product(['usr/local', 'usr', ''],
-                               ['bin', 'sbin'],
-                               ['-static', '.static', '']):
-        path = os.path.join(root, p[0], p[1], 'busybox' + p[2])
-        if os.path.isfile(path):
-            return path
-
-    if is_native:
-        # Try the host's busybox, if any
-        return shutil.which('busybox')
+    names = ['busybox-static', 'busybox.static', 'busybox']
+    dirs = [os.path.join(*i) for i in itertools.product(
+        ['usr/local', 'usr', ''],
+        ['bin', 'sbin'])]
+
+    for n in names:
+        if is_native:
+            # Search PATH first
+            path = shutil.which(n)
+            if path is not None:
+                return path
+
+        for d in dirs:
+            path = os.path.join(root, d, n)
+            if os.path.isfile(path):
+                return path
 
     # We give up.
     return None
-- 
2.26.2

openSUSE Build Service is sponsored by