debian-cd-clone/tools/imagesums

85 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2010-07-05 14:09:23 +00:00
VERBOSE=0
if [ "$1" = "-v" ] ; then
VERBOSE=1
shift
fi
cd $1
if [ "$2"x != ""x ] ; then
2008-12-26 00:08:44 -01:00
EXT="$2"
fi
if [ "$CHECKSUMS"x = ""x ] ; then
CHECKSUMS="sha1 md5 sha512 sha256"
fi
for SUM in $CHECKSUMS; do
UPSUM=$(echo $SUM | tr 'a-z' 'A-Z')
FILE=$UPSUM"SUMS"$EXT
2010-07-05 14:09:23 +00:00
if [ $VERBOSE -eq 1 ] ; then
2010-12-09 15:01:47 -01:00
echo "Clearing $PWD/$FILE"
2010-07-05 14:09:23 +00:00
fi
:> $FILE
done
# 2 calls to find here to get the ordering right - we *really* want to
# get the jigdo files first
for file in $(find * -name \*.jigdo -o -name \*.template -o -name \*.iso); do
iso=""
case $file in
*.template)
JIGDO=1
;;
*.jigdo)
iso=${file%%.jigdo}.iso
JIGDO=1
;;
*.iso)
iso=$file
JIGDO=0
;;
*)
echo "Found unexpected file $file!"
exit 1
;;
esac
for SUM in $CHECKSUMS; do
UPSUM=$(echo $SUM | tr 'a-z' 'A-Z')
FILE=$UPSUM"SUMS"$EXT
CMD="$SUM"sum
if [ "$iso"x != ""x ]; then
grep -q $iso $FILE
if [ $? -ne 0 ] ; then
CKSUM=""
if [ "$JIGDO" == 1 ] ; then
CKSUM=$(zcat -f $file | \
grep -i "Image Hex $CMD" | \
awk '{print $5}')
fi
if [ "$CKSUM"x != ""x ] ; then
echo "$CKSUM $iso" >> $FILE
grep $iso $FILE
else
echo "No Jigdo help for $SUM, doing it the long way with $CMD"
$CMD $iso >> $FILE
grep $iso $FILE
fi
fi
fi
# Also add the template file and jigdo file to the SUMS, if they exist
case $file in
*.template|*.jigdo)
$CMD $file >> $FILE
grep $file $FILE
;;
esac
done
done