]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
lsinitrd: allow to only unpack certain files
authorKairui Song <kasong@redhat.com>
Wed, 25 Jul 2018 08:34:08 +0000 (16:34 +0800)
committerHarald Hoyer <harald@hoyer.xyz>
Thu, 26 Jul 2018 07:57:55 +0000 (09:57 +0200)
Before this patch, "--unpack" will always unpack the whole image.
Make "--unpack" be able to unpack only certain files, it will be
easier to retrieve files from initramfs image.

Signed-off-by: Kairui Song <kasong@redhat.com>
lsinitrd.sh

index 80fbf922ce256a9e5a8c73483178cbdb003cabd8..1b9a93b60203285d08560e88d1749a2294b73503 100755 (executable)
@@ -159,8 +159,15 @@ list_files()
 
 unpack_files()
 {
-    $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose
-    ((ret+=$?))
+    if (( ${#filenames[@]} > 0 )); then
+        for f in "${!filenames[@]}"; do
+            $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose $f
+            ((ret+=$?))
+        done
+    else
+        $CAT "$image" 2>/dev/null | cpio -id --quiet $verbose
+        ((ret+=$?))
+    fi
 }
 
 
@@ -175,7 +182,10 @@ case $bin in
         CAT="cat --"
         is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null)
         if [[ "$is_early" ]]; then
-            if [[ -n "$unpackearly" ]]; then
+            if [[ -n "$unpack" ]]; then
+                # should use --unpackearly for early CPIO
+                :
+            elif [[ -n "$unpackearly" ]]; then
                 unpack_files
             elif (( ${#filenames[@]} > 0 )); then
                 extract_files