diff options
author | Michael Prokop <mika@debian.org> | 2010-06-17 01:49:09 +0200 |
---|---|---|
committer | maximilian attems <maks@debian.org> | 2010-06-17 13:59:49 +0200 |
commit | ecb8416d5ede3e5eae463802721c2a12216b61a4 (patch) | |
tree | 3b43cace1c2cba87daff3028ab6bbd6da41363ef | |
parent | a39db63500c4482aad7d2fc17ad83edd3a56bb8f (diff) | |
download | initramfs-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-x | lsinitramfs | 22 |
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 |