summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Prokop <mika@debian.org>2010-06-17 01:49:09 +0200
committermaximilian attems <maks@debian.org>2010-06-17 13:59:49 +0200
commitecb8416d5ede3e5eae463802721c2a12216b61a4 (patch)
tree3b43cace1c2cba87daff3028ab6bbd6da41363ef
parenta39db63500c4482aad7d2fc17ad83edd3a56bb8f (diff)
downloadinitramfs-tools-ecb8416d5ede3e5eae463802721c2a12216b61a4.tar.gz
initramfs-tools-ecb8416d5ede3e5eae463802721c2a12216b61a4.zip
lsinitramfs: be more defensive against cmdline options
* make sure the specified file(s) can be read * redirect error message to stderr * support -h/--help option * variable quoting Signed-off-by: Michael Prokop <mika@debian.org>
-rwxr-xr-xlsinitramfs22
1 files changed, 17 insertions, 5 deletions
diff --git a/lsinitramfs b/lsinitramfs
index aea7747..809445f 100755
--- a/lsinitramfs
+++ b/lsinitramfs
@@ -3,12 +3,24 @@
usage()
{
echo "Usage: $(basename $0) <initramfs file>"
- exit 1
}
-[ $# -eq 0 ] && usage
+if [ "$#" -eq 0 ] ; then
+ usage >&2
+ exit 1
+fi
+
+if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
+ usage
+ exit 0
+fi
-for i in $*; do
- echo $i
- zcat $i | cpio --extract --verbose --quiet --list
+for i in "$*" ; do
+ if ! [ -r "$i" ] ; then
+ echo "Specified file could not be read." >&2
+ exit 1
+ else
+ echo "$i"
+ zcat "$i" | cpio --extract --verbose --quiet --list
+ fi
done