Commit 42753fdf authored by thomas.forbriger's avatar thomas.forbriger

[TASK] (util): make csbulistcsfiles.sh operational

parent 1ac5d030
#!/bin/sh
#!/bin/bash
# this is <csbulistcsfiles.sh>
# ----------------------------------------------------------------------------
#
......@@ -22,7 +22,7 @@ cat << HERE
This is <csbulistcsfiles.sh>
version: $VERSION
usage: csbulistcsfiles.sh [-v] [-d] dir [dir ...]
usage: csbulistcsfiles.sh [-v] [-d] [-m] dir [dir ...]
or: csbulistcsfiles.sh -h
Lists all directories containing checksum files (or alternatively those where
......@@ -37,6 +37,7 @@ cat << HERE
-h print detailed usage information
-v be verbose
-d print debug output
-m report directories with missing checksum file
dir one or more directories to be checked recursively
......@@ -46,15 +47,17 @@ HERE
verbose=0
debug=0
missing=0
# fetch commandline arguments
while getopts 'hvd' Option;
while getopts 'hvdm' Option;
do
case ${Option} in
h) hflag=1
usage; longusage; exit 0;;
v) verbose=1;;
d) debug=1;;
m) missing=1;;
*) echo -e "ERROR: Unimplemented option chosen.\n"
usage; exit 2;;
esac
......@@ -69,5 +72,79 @@ then
exit 2
fi
# ============================================================================
# read directory names from standard input
# check for existing checksum file and report number of entries
checkexist() {
NPROBLEM=0
NEMPTY=0
read d
while test -n "$d"
do
if test -e $d/$CHECKSUMFILE
then
if test -r $d/$CHECKSUMFILE
then
nl=$(wc -l $d/$CHECKSUMFILE | cut -f 1 -d ' ')
printf "%4d entries in %s\n" $nl $d/$CHECKSUMFILE
if test $nl -lt 1
then
let NEMPTY++
fi
else
printf "checksum file %s is not readable!\n" $d/$CHECKSUMFILE
let NPROBLEM++
fi
fi
read d
done
if test $NPROBLEM -gt 0
then
printf "%d files are not readable.\n" $NPROBLEM
fi
if test $NEMPTY -gt 0
then
printf "%d files are empty.\n" $NEMPTY
fi
}
# ----------------------------------------------------------------------------
# read directory names from standard input
# check for missing checksum files
checkmiss() {
NMISS=0
read d
while test -n "$d"
do
if test ! -e $d/$CHECKSUMFILE
then
printf "checksum file %s is missing!\n" $d/$CHECKSUMFILE
let NMISS++
fi
read d
done
if test $NMISS -gt 0
then
printf "%d directories with missing %s file are detected.\n" \
$NMISS $CHECKSUMFILE
else
printf "no missing %s file was detected\n" $CHECKSUMFILE
fi
}
# ============================================================================
for dir in $*
do
printf "\nSearch for files %s in subdirectories of %s\n" $CHECKSUMFILE $dir
if test $missing -eq 0
then
find $dir -type d | sort | checkexist
else
find $dir -type d | sort | checkmiss
fi
done
# ----- END OF csbulistcsfiles.sh -----
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment