[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH initramfs-tools 1/3] lsinitramfs: Move the decompress | cpio pipeline into a function



Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 lsinitramfs | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/lsinitramfs b/lsinitramfs
index f66d970..db179ca 100755
--- a/lsinitramfs
+++ b/lsinitramfs
@@ -40,24 +40,30 @@ while true; do
 	esac
 done
 
+listarchive()
+{
+	archive="$1"
+	if zcat -t "${archive}" >/dev/null 2>&1 ; then
+		zcat "${archive}" | cpio ${cpio_args}
+	elif xzcat -t "${archive}" >/dev/null 2>&1 ; then
+		xzcat "${archive}" | cpio ${cpio_args}
+	elif bzip2 -t "${archive}" >/dev/null 2>&1 ; then
+		bzip2 -c -d "${archive}" | cpio ${cpio_args}
+	elif lzop -t "${archive}" >/dev/null 2>&1 ; then
+		lzop -c -d "${archive}" | cpio ${cpio_args}
+	elif file "$initramfs" 2>/dev/null | grep -q "cpio archive" ; then
+		echo "lsinitramfs does not yet support cpio archive initramfs files." >&2
+		echo "See http://bugs.debian.org/717805 for more information." >&2
+	fi
+}
+
 for initramfs in "$@" ; do
 	if ! [ -r "${initramfs}" ] ; then
 		echo "Specified file could not be read." >&2
 		exit 1
 	else
 		echo "${initramfs}"
-		if zcat -t "${initramfs}" >/dev/null 2>&1 ; then
-			zcat "${initramfs}" | cpio ${cpio_args}
-		elif xzcat -t "$initramfs" >/dev/null 2>&1 ; then
-			xzcat "$initramfs" | cpio ${cpio_args}
-		elif bzip2 -t "$initramfs" >/dev/null 2>&1 ; then
-			bzip2 -c -d "$initramfs" | cpio ${cpio_args}
-		elif lzop -t "$initramfs" >/dev/null 2>&1 ; then
-			lzop -c -d "$initramfs" | cpio ${cpio_args}
-		elif file "$initramfs" 2>/dev/null | grep -q "cpio archive" ; then
-			echo "lsinitramfs does not yet support cpio archive initramfs files." >&2
-			echo "See http://bugs.debian.org/717805 for more information." >&2
-		fi
+		listarchive "${initramfs}"
 
 	fi
 done


-- 
Ben Hutchings
The two most common things in the universe are hydrogen and stupidity.

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: