9f65cc
From 0c2ac6b7503661948ead031f745736e35fef2e3f Mon Sep 17 00:00:00 2001
9f65cc
From: Kairui Song <kasong@redhat.com>
9f65cc
Date: Wed, 26 Dec 2018 17:38:02 +0800
9f65cc
Subject: [PATCH] lsinitrd: list squash content as well
9f65cc
9f65cc
When the initramfs is built with squash module enabled, the content
9f65cc
inside squash image will be invisible from the lsinitrd tool. This
9f65cc
commit make lsinitrd detect and list the content of the squash image as
9f65cc
well to avoid possible confusion.
9f65cc
9f65cc
Signed-off-by: Kairui Song <kasong@redhat.com>
9f65cc
(cherry picked from commit 1ff306a3964840fc548188a8aa4862143b347e8a)
9f65cc
9f65cc
Resolves: #1959336
9f65cc
---
9f65cc
 lsinitrd.sh | 16 ++++++++++++++++
9f65cc
 1 file changed, 16 insertions(+)
9f65cc
9f65cc
diff --git a/lsinitrd.sh b/lsinitrd.sh
9f65cc
index a2fa4d7a..0b42b9a4 100755
9f65cc
--- a/lsinitrd.sh
9f65cc
+++ b/lsinitrd.sh
9f65cc
@@ -160,6 +160,21 @@ list_files()
9f65cc
     echo "========================================================================"
9f65cc
 }
9f65cc
 
9f65cc
+list_squash_content()
9f65cc
+{
9f65cc
+    SQUASH_IMG="squash/root.img"
9f65cc
+    SQUASH_TMPFILE="$(mktemp -t --suffix=.root.sqsh lsinitrd.XXXXXX)"
9f65cc
+    trap "rm -f '$SQUASH_TMPFILE'" EXIT
9f65cc
+    $CAT "$image" 2>/dev/null | cpio --extract --verbose --quiet --to-stdout -- \
9f65cc
+        $SQUASH_IMG > "$SQUASH_TMPFILE" 2>/dev/null
9f65cc
+    if [[ -s $SQUASH_TMPFILE ]]; then
9f65cc
+        echo "Squashed content ($SQUASH_IMG):"
9f65cc
+        echo "========================================================================"
9f65cc
+        unsquashfs -ll "$SQUASH_TMPFILE" | tail -n +4
9f65cc
+        echo "========================================================================"
9f65cc
+    fi
9f65cc
+}
9f65cc
+
9f65cc
 unpack_files()
9f65cc
 {
9f65cc
     if (( ${#filenames[@]} > 0 )); then
9f65cc
@@ -287,6 +302,7 @@ else
9f65cc
         echo
9f65cc
         list_modules
9f65cc
         list_files
9f65cc
+        list_squash_content
9f65cc
     fi
9f65cc
 fi
9f65cc
 
9f65cc