102 lines
2.8 KiB
Bash
102 lines
2.8 KiB
Bash
#! /bin/sh
|
|
# Ztest - Test integrity of compressed files.
|
|
# Copyright (C) 2009 Antonio Diaz Diaz.
|
|
#
|
|
# This script is free software: you have unlimited permission
|
|
# to copy, distribute and modify it.
|
|
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
args=
|
|
recursive=0
|
|
two_hyphens=0
|
|
|
|
# Loop over args until a filename is found
|
|
while [ -n "$1" ] ; do
|
|
|
|
case "$1" in
|
|
--help | --he* | -h)
|
|
echo "Ztest - Test integrity of compressed files."
|
|
echo
|
|
echo "Ztest verifies the integrity of the specified compressed files."
|
|
echo "Non-compressed files are ignored. If no files are specified, the"
|
|
echo "integrity of compressed data read from standard input is verified. Data"
|
|
echo "read from standard input must be all compressed with the same compressor."
|
|
echo "The supported compressors are bzip2, gzip, lzip and xz."
|
|
echo
|
|
echo "Usage: $0 [OPTIONS] [FILES]"
|
|
echo
|
|
echo "The exit status is 1 if any compressed file is corrupt, 0 otherwise."
|
|
echo
|
|
echo "Options:"
|
|
echo " -h, --help display this help and exit"
|
|
echo " -V, --version output version information and exit"
|
|
echo " -q, --quiet suppress all messages"
|
|
echo " -r, --recursive operate recursively on directories"
|
|
echo " -v, --verbose be verbose (a 2nd -v gives more)"
|
|
echo
|
|
echo "Report bugs to zutils-bug@nongnu.org"
|
|
echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html"
|
|
exit 0 ;;
|
|
--version | --ve* | -V)
|
|
echo "Ztest (zutils) VERSION"
|
|
echo "Copyright (C) 2009 Antonio Diaz Diaz."
|
|
echo "This script is free software: you have unlimited permission"
|
|
echo "to copy, distribute and modify it."
|
|
exit 0 ;;
|
|
-r | --re*)
|
|
recursive=1 ;;
|
|
-v | -vv | -vvv | --ve* | -q | --qu*)
|
|
args="${args} $1" ;;
|
|
--)
|
|
shift ; two_hyphens=1 ; break ;;
|
|
- | -?*)
|
|
;;
|
|
*)
|
|
break ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [ $# = 0 ] ; then
|
|
bindir=`echo "$0" | sed -e 's,[^/]*$,,'`
|
|
prog=`"${bindir}"zutils -t`
|
|
case "${prog}" in
|
|
bzip2 | gzip | lzip | xz)
|
|
;;
|
|
*) echo "$0: Unknown data format read from stdin" 1>&2
|
|
exit 1 ;;
|
|
esac
|
|
{ "${bindir}"zutils -m ${prog} ; cat ; } | ${prog} -t ${args}
|
|
exit $?
|
|
fi
|
|
|
|
retval=0
|
|
for i in "$@" ; do
|
|
if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1
|
|
else
|
|
if [ ! -f "$i" ] ; then
|
|
if [ ${recursive} = 1 ] && [ -d "$i" ] ; then
|
|
bad_files=`find "$i" -type f \( -exec "$0" ${args} '{}' ';' -o -print \)`
|
|
if [ ${retval} = 0 ] && [ -n "${bad_files}" ] ; then retval=1 ; fi
|
|
continue
|
|
else
|
|
echo "$0: File \"$i\" not found or not a regular file" 1>&2
|
|
if [ ${retval} = 0 ] ; then retval=1 ; fi
|
|
continue
|
|
fi
|
|
fi
|
|
bindir=`echo "$0" | sed -e 's,[^/]*$,,'`
|
|
prog=`"${bindir}"zutils -t -- "$i"`
|
|
case "${prog}" in
|
|
bzip2 | gzip | lzip | xz)
|
|
;;
|
|
*) continue ;;
|
|
esac
|
|
${prog} -t ${args} -- "$i"
|
|
r=$?
|
|
if [ $r != 0 ] ; then retval=$r ; fi
|
|
fi
|
|
done
|
|
|
|
exit ${retval}
|