Harald Hoyer f97365
From f81c864eede2a11bfeb849cb2a2634be034ed7fb Mon Sep 17 00:00:00 2001
Harald Hoyer f97365
From: Kairui Song <kasong@redhat.com>
Harald Hoyer f97365
Date: Wed, 25 Jul 2018 16:34:08 +0800
Harald Hoyer f97365
Subject: [PATCH] lsinitrd: allow to only unpack certain files
Harald Hoyer f97365
Harald Hoyer f97365
Before this patch, "--unpack" will always unpack the whole image.
Harald Hoyer f97365
Make "--unpack" be able to unpack only certain files, it will be
Harald Hoyer f97365
easier to retrieve files from initramfs image.
Harald Hoyer f97365
Harald Hoyer f97365
Signed-off-by: Kairui Song <kasong@redhat.com>
Harald Hoyer f97365
---
Harald Hoyer f97365
 lsinitrd.sh | 16 +++++++++++++---
Harald Hoyer f97365
 1 file changed, 13 insertions(+), 3 deletions(-)
Harald Hoyer f97365
Harald Hoyer f97365
diff --git a/lsinitrd.sh b/lsinitrd.sh
Harald Hoyer f97365
index 80fbf922..1b9a93b6 100755
Harald Hoyer f97365
--- a/lsinitrd.sh
Harald Hoyer f97365
+++ b/lsinitrd.sh
Harald Hoyer f97365
@@ -159,8 +159,15 @@ list_files()
Harald Hoyer f97365
 
Harald Hoyer f97365
 unpack_files()
Harald Hoyer f97365
 {
Harald Hoyer f97365
-    $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose
Harald Hoyer f97365
-    ((ret+=$?))
Harald Hoyer f97365
+    if (( ${#filenames[@]} > 0 )); then
Harald Hoyer f97365
+        for f in "${!filenames[@]}"; do
Harald Hoyer f97365
+            $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose $f
Harald Hoyer f97365
+            ((ret+=$?))
Harald Hoyer f97365
+        done
Harald Hoyer f97365
+    else
Harald Hoyer f97365
+        $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose
Harald Hoyer f97365
+        ((ret+=$?))
Harald Hoyer f97365
+    fi
Harald Hoyer f97365
 }
Harald Hoyer f97365
 
Harald Hoyer f97365
 
Harald Hoyer f97365
@@ -175,7 +182,10 @@ case $bin in
Harald Hoyer f97365
         CAT="cat --"
Harald Hoyer f97365
         is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null)
Harald Hoyer f97365
         if [[ "$is_early" ]]; then
Harald Hoyer f97365
-            if [[ -n "$unpackearly" ]]; then
Harald Hoyer f97365
+            if [[ -n "$unpack" ]]; then
Harald Hoyer f97365
+                # should use --unpackearly for early CPIO
Harald Hoyer f97365
+                :
Harald Hoyer f97365
+            elif [[ -n "$unpackearly" ]]; then
Harald Hoyer f97365
                 unpack_files
Harald Hoyer f97365
             elif (( ${#filenames[@]} > 0 )); then
Harald Hoyer f97365
                 extract_files
Harald Hoyer f97365