Blame SOURCES/0096-lsinitrd.sh-make-use-of-the-skipcpio-utility.patch

712866
From 815b9c16a4e90b67bab008da678d73faa74f8e0c Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Fri, 24 Jan 2014 15:30:22 +0100
712866
Subject: [PATCH] lsinitrd.sh: make use of the skipcpio utility
712866
712866
With the skipcpio utility, the whole contents of an initramfs with an
712866
early cpio image can be displayed.
712866
---
712866
 lsinitrd.sh | 96 +++++++++++++++++++++++++++++++++++++++++++++++--------------
712866
 1 file changed, 75 insertions(+), 21 deletions(-)
712866
712866
diff --git a/lsinitrd.sh b/lsinitrd.sh
5c6c2a
index f9f243bb..70e12f81 100755
712866
--- a/lsinitrd.sh
712866
+++ b/lsinitrd.sh
712866
@@ -33,6 +33,9 @@ usage()
712866
     } >&2
712866
 }
712866
 
712866
+
712866
+[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
712866
+
712866
 sorted=0
712866
 declare -A filenames
712866
 
712866
@@ -103,14 +106,72 @@ if ! [[ -f "$image" ]]; then
712866
     exit 1
712866
 fi
712866
 
712866
+extract_files()
712866
+{
712866
+    (( ${#filenames[@]} == 1 )) && nofileinfo=1
712866
+    for f in ${!filenames[@]}; do
712866
+        [[ $nofileinfo ]] || echo "initramfs:/$f"
712866
+        [[ $nofileinfo ]] || echo "========================================================================"
712866
+        $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null
712866
+        ((ret+=$?))
712866
+        [[ $nofileinfo ]] || echo "========================================================================"
712866
+        [[ $nofileinfo ]] || echo
712866
+    done
712866
+}
712866
+
712866
+list_files()
712866
+{
712866
+    echo "========================================================================"
712866
+    if [ "$sorted" -eq 1 ]; then
712866
+        $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
712866
+    else
712866
+        $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9
712866
+    fi
712866
+    ((ret+=$?))
712866
+    echo "========================================================================"
712866
+}
712866
+
712866
+
712866
+if (( ${#filenames[@]} <= 0 )); then
712866
+    echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)"
712866
+    echo "========================================================================"
712866
+fi
712866
+
712866
 read -N 6 bin < "$image"
5c6c2a
+case $bin in
712866
+    $'\x71\xc7'*|070701)
712866
+        CAT="cat --"
712866
+        is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null)
712866
+        if [[ "$is_early" ]]; then
712866
+            if (( ${#filenames[@]} > 0 )); then
712866
+                extract_files
712866
+            else
712866
+                echo "Early CPIO image"
712866
+                list_files
712866
+            fi
712866
+            SKIP="$dracutbasedir/skipcpio"
712866
+            if ! [[ -x $SKIP ]]; then
712866
+                echo
712866
+                echo "'$SKIP' not found, cannot display remaining contents!" >&2
712866
+                echo
712866
+                exit 0
712866
+            fi
712866
+        fi
712866
+        ;;
712866
+esac
712866
+
712866
+if [[ $SKIP ]]; then
712866
+    read -N 6 bin < <($SKIP "$image")
712866
+fi
712866
+
5c6c2a
 case $bin in
712866
     $'\x1f\x8b'*)
712866
         CAT="zcat --";;
712866
     BZh*)
712866
         CAT="bzcat --";;
712866
     $'\x71\xc7'*|070701)
712866
-        CAT="cat --";;
712866
+        CAT="cat --"
712866
+        ;;
712866
     $'\x04\x22'*)
712866
         CAT="lz4 -d -c";;
712866
     *)
712866
@@ -121,34 +182,27 @@ case $bin in
712866
         ;;
712866
 esac
712866
 
712866
+skipcpio()
712866
+{
712866
+    $SKIP "$@" | $ORIG_CAT
712866
+}
712866
+
712866
+if [[ $SKIP ]]; then
712866
+    ORIG_CAT="$CAT"
712866
+    CAT=skipcpio
712866
+fi
712866
+
712866
 ret=0
712866
 
712866
 if (( ${#filenames[@]} > 0 )); then
712866
-    (( ${#filenames[@]} == 1 )) && nofileinfo=1
712866
-    for f in ${!filenames[@]}; do
712866
-        [[ $nofileinfo ]] || echo "initramfs:/$f"
712866
-        [[ $nofileinfo ]] || echo "========================================================================"
712866
-        $CAT $image | cpio --extract --verbose --quiet --to-stdout $f 2>/dev/null
712866
-        ((ret+=$?))
712866
-        [[ $nofileinfo ]] || echo "========================================================================"
712866
-        [[ $nofileinfo ]] || echo
712866
-    done
712866
+    extract_files
712866
 else
712866
-    echo "Image: $image: $(du -h $image | while read a b; do echo $a;done)"
712866
-    echo "========================================================================"
712866
-    version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/dracut-*' 2>/dev/null)
712866
+    version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- 'lib/dracut/dracut-*' 'usr/lib/dracut/dracut-*' 2>/dev/null)
712866
     ((ret+=$?))
712866
     echo "$version with dracut modules:"
712866
     $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- '*lib/dracut/modules.txt' 2>/dev/null
712866
     ((ret+=$?))
712866
-    echo "========================================================================"
712866
-    if [ "$sorted" -eq 1 ]; then
712866
-        $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
712866
-    else
712866
-        $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9
712866
-    fi
712866
-    ((ret+=$?))
712866
-    echo "========================================================================"
712866
+    list_files
712866
 fi
712866
 
712866
 exit $ret