From fdec1d37468d1b74b0ea4792599c5e7822d6c0e1 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sat, 27 Sep 2014 19:22:11 +0100 Subject: lsinitramfs: Move the decompress | cpio pipeline into a function Signed-off-by: Ben Hutchings --- lsinitramfs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'lsinitramfs') 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 -- cgit v1.2.3