Blame 0039-lsinitrd-add-unpack-to-lsinitrd.patch

Harald Hoyer b38677
From 97bbba6938fc22605026b4cff3c5cc524c7bdf38 Mon Sep 17 00:00:00 2001
Harald Hoyer b38677
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer b38677
Date: Thu, 17 Mar 2016 14:45:24 +0100
Harald Hoyer b38677
Subject: [PATCH] lsinitrd: add "--unpack" to lsinitrd
Harald Hoyer b38677
Harald Hoyer b38677
also "--unpackearly" and "--verbose"
Harald Hoyer b38677
---
Harald Hoyer b38677
 lsinitrd.1.asc |  9 +++++++++
Harald Hoyer b38677
 lsinitrd.sh    | 43 ++++++++++++++++++++++++++++++++-----------
Harald Hoyer b38677
 2 files changed, 41 insertions(+), 11 deletions(-)
Harald Hoyer b38677
Harald Hoyer b38677
diff --git a/lsinitrd.1.asc b/lsinitrd.1.asc
Harald Hoyer b38677
index 4293910..b6a704c 100644
Harald Hoyer b38677
--- a/lsinitrd.1.asc
Harald Hoyer b38677
+++ b/lsinitrd.1.asc
Harald Hoyer b38677
@@ -34,6 +34,15 @@ OPTIONS
Harald Hoyer b38677
 **-k, --kver** _<kernel version>_::
Harald Hoyer b38677
     inspect the initramfs of <kernel version>.
Harald Hoyer b38677
 
Harald Hoyer b38677
+**--unpack**::
Harald Hoyer b38677
+    unpack the initramfs to the current directory, instead of displaying the contents.
Harald Hoyer b38677
+
Harald Hoyer b38677
+**--unpackearly**::
Harald Hoyer b38677
+    unpack the early microcode initramfs to the current directory, instead of displaying the contents.
Harald Hoyer b38677
+
Harald Hoyer b38677
+**-v, --verbose**::
Harald Hoyer b38677
+    unpack verbosely
Harald Hoyer b38677
+
Harald Hoyer b38677
 AVAILABILITY
Harald Hoyer b38677
 ------------
Harald Hoyer b38677
 The lsinitrd command is part of the dracut package and is available from
Harald Hoyer b38677
diff --git a/lsinitrd.sh b/lsinitrd.sh
Harald Hoyer b38677
index 441fb92..224b9c1 100755
Harald Hoyer b38677
--- a/lsinitrd.sh
Harald Hoyer b38677
+++ b/lsinitrd.sh
Harald Hoyer b38677
@@ -27,6 +27,9 @@ usage()
Harald Hoyer b38677
         echo "-s, --size                  sort the contents of the initramfs by size."
Harald Hoyer b38677
         echo "-m, --mod                   list modules."
Harald Hoyer b38677
         echo "-f, --file <filename>       print the contents of <filename>."
Harald Hoyer b38677
+        echo "--unpack                    unpack the initramfs, instead of displaying the contents."
Harald Hoyer b38677
+        echo "--unpackearly               unpack the early microcode part of the initramfs."
Harald Hoyer b38677
+        echo "-v, --verbose               unpack verbosely."
Harald Hoyer b38677
         echo "-k, --kver <kernel version> inspect the initramfs of <kernel version>."
Harald Hoyer b38677
         echo
Harald Hoyer b38677
     } >&2
Harald Hoyer b38677
@@ -37,16 +40,21 @@ usage()
Harald Hoyer b38677
 
Harald Hoyer b38677
 sorted=0
Harald Hoyer b38677
 modules=0
Harald Hoyer b38677
+unpack=0
Harald Hoyer b38677
+unset verbose
Harald Hoyer b38677
 declare -A filenames
Harald Hoyer b38677
 
Harald Hoyer b38677
 unset POSIXLY_CORRECT
Harald Hoyer b38677
 TEMP=$(getopt \
Harald Hoyer b38677
-    -o "shmf:k:" \
Harald Hoyer b38677
+    -o "vshmf:k:" \
Harald Hoyer b38677
     --long kver: \
Harald Hoyer b38677
     --long file: \
Harald Hoyer b38677
     --long mod \
Harald Hoyer b38677
     --long help \
Harald Hoyer b38677
     --long size \
Harald Hoyer b38677
+    --long unpack \
Harald Hoyer b38677
+    --long unpackearly \
Harald Hoyer b38677
+    --long verbose \
Harald Hoyer b38677
     -- "$@")
Harald Hoyer b38677
 
Harald Hoyer b38677
 if (( $? != 0 )); then
Harald Hoyer b38677
@@ -58,13 +66,16 @@ eval set -- "$TEMP"
Harald Hoyer b38677
 
Harald Hoyer b38677
 while (($# > 0)); do
Harald Hoyer b38677
     case $1 in
Harald Hoyer b38677
-        -k|--kver)  KERNEL_VERSION="$2"; shift;;
Harald Hoyer b38677
-        -f|--file)  filenames[${2#/}]=1; shift;;
Harald Hoyer b38677
-        -s|--size)  sorted=1;;
Harald Hoyer b38677
-        -h|--help)  usage; exit 0;;
Harald Hoyer b38677
-        -m|--mod)   modules=1;;
Harald Hoyer b38677
-        --)         shift;break;;
Harald Hoyer b38677
-        *)          usage; exit 1;;
Harald Hoyer b38677
+        -k|--kver)     KERNEL_VERSION="$2"; shift;;
Harald Hoyer b38677
+        -f|--file)     filenames[${2#/}]=1; shift;;
Harald Hoyer b38677
+        -s|--size)     sorted=1;;
Harald Hoyer b38677
+        -h|--help)     usage; exit 0;;
Harald Hoyer b38677
+        -m|--mod)      modules=1;;
Harald Hoyer b38677
+        -v|--verbose)  verbose="--verbose";;
Harald Hoyer b38677
+        --unpack)      unpack=1;;
Harald Hoyer b38677
+        --unpackearly) unpackearly=1;;
Harald Hoyer b38677
+        --)            shift;break;;
Harald Hoyer b38677
+        *)             usage; exit 1;;
Harald Hoyer b38677
     esac
Harald Hoyer b38677
     shift
Harald Hoyer b38677
 done
Harald Hoyer b38677
@@ -147,8 +158,14 @@ list_files()
Harald Hoyer b38677
     echo "========================================================================"
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
+unpack_files()
Harald Hoyer b38677
+{
Harald Hoyer b38677
+    $CAT "$image" | cpio -id --quiet $verbose
Harald Hoyer b38677
+    ((ret+=$?))
Harald Hoyer b38677
+}
Harald Hoyer b38677
+
Harald Hoyer b38677
 
Harald Hoyer b38677
-if (( ${#filenames[@]} <= 0 )); then
Harald Hoyer b38677
+if (( ${#filenames[@]} <= 0 )) && [[ -z "$unpack" ]] && [[ -z "$unpackearly" ]]; then
Harald Hoyer b38677
     echo "Image: $image: $(du -h $image | while read a b || [ -n "$a" ]; do echo $a;done)"
Harald Hoyer b38677
     echo "========================================================================"
Harald Hoyer b38677
 fi
Harald Hoyer b38677
@@ -159,7 +176,9 @@ case $bin in
Harald Hoyer b38677
         CAT="cat --"
Harald Hoyer b38677
         is_early=$(cpio --extract --verbose --quiet --to-stdout -- 'early_cpio' < "$image" 2>/dev/null)
Harald Hoyer b38677
         if [[ "$is_early" ]]; then
Harald Hoyer b38677
-            if (( ${#filenames[@]} > 0 )); then
Harald Hoyer b38677
+            if [[ -n "$unpackearly" ]]; then
Harald Hoyer b38677
+                unpack_files
Harald Hoyer b38677
+            elif (( ${#filenames[@]} > 0 )); then
Harald Hoyer b38677
                 extract_files
Harald Hoyer b38677
             else
Harald Hoyer b38677
                 echo "Early CPIO image"
Harald Hoyer b38677
@@ -218,7 +237,9 @@ fi
Harald Hoyer b38677
 
Harald Hoyer b38677
 ret=0
Harald Hoyer b38677
 
Harald Hoyer b38677
-if (( ${#filenames[@]} > 0 )); then
Harald Hoyer b38677
+if [[ -n "$unpack" ]]; then
Harald Hoyer b38677
+    unpack_files
Harald Hoyer b38677
+elif (( ${#filenames[@]} > 0 )); then
Harald Hoyer b38677
     extract_files
Harald Hoyer b38677
 else
Harald Hoyer b38677
     version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \