diff options
author | Andy Lutomirski <luto@kernel.org> | 2019-10-18 11:03:31 -0700 |
---|---|---|
committer | Andy Lutomirski <luto@kernel.org> | 2019-10-18 11:03:31 -0700 |
commit | 0c733ddb1ef4952bda0614cc68ce80f1c8433ffc (patch) | |
tree | d3f05d5e5a864eae85fd3dba499c621cb292b65d | |
parent | 7dde93e7cb6eea325f5bcb04d43ea5f3ee97e433 (diff) | |
download | virtme-0c733ddb1ef4952bda0614cc68ce80f1c8433ffc.tar.gz |
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>
-rw-r--r-- | virtme/mkinitramfs.py | 26 |
1 files 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 |