| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
VERBOSE=0 |
| 4 |
|
| 5 |
if [ "$1" = "-v" ] ; then |
| 6 |
VERBOSE=1 |
| 7 |
shift |
| 8 |
fi |
| 9 |
|
| 10 |
cd $1 |
| 11 |
|
| 12 |
if [ "$2"x != ""x ] ; then |
| 13 |
EXT="$2" |
| 14 |
fi |
| 15 |
|
| 16 |
if [ "$CHECKSUMS"x = ""x ] ; then |
| 17 |
CHECKSUMS="sha512 sha256" |
| 18 |
fi |
| 19 |
|
| 20 |
for SUM in $CHECKSUMS; do |
| 21 |
UPSUM=$(echo $SUM | tr 'a-z' 'A-Z') |
| 22 |
FILE=$UPSUM"SUMS"$EXT |
| 23 |
if [ $VERBOSE -eq 1 ] ; then |
| 24 |
echo "Clearing $PWD/$FILE" |
| 25 |
fi |
| 26 |
:> $FILE |
| 27 |
done |
| 28 |
|
| 29 |
# Ordering is important, so we do separate "find" calls here - we |
| 30 |
# *really* want to get the jigdo files before the iso files, so we can |
| 31 |
# use the checksums there first instead of re-calculating them |
| 32 |
FILES="" |
| 33 |
FILES="$FILES "$(find * -name '*.jigdo') |
| 34 |
FILES="$FILES "$(find * -name '*.template') |
| 35 |
FILES="$FILES "$(find * -name '*.iso') |
| 36 |
FILES="$FILES "$(find * -name '*.torrent') |
| 37 |
|
| 38 |
for file in $FILES; do |
| 39 |
iso="" |
| 40 |
case $file in |
| 41 |
*.jigdo) |
| 42 |
iso=${file%%.jigdo}.iso |
| 43 |
JIGDO=1 |
| 44 |
;; |
| 45 |
*.iso) |
| 46 |
iso=$file |
| 47 |
JIGDO=0 |
| 48 |
;; |
| 49 |
*.template|*.torrent) |
| 50 |
;; |
| 51 |
*) |
| 52 |
echo "Found unexpected file $file!" |
| 53 |
exit 1 |
| 54 |
;; |
| 55 |
esac |
| 56 |
|
| 57 |
for SUM in $CHECKSUMS; do |
| 58 |
UPSUM=$(echo $SUM | tr 'a-z' 'A-Z') |
| 59 |
FILE=$UPSUM"SUMS"$EXT |
| 60 |
CMD="$SUM"sum |
| 61 |
|
| 62 |
if [ "$iso"x != ""x ]; then |
| 63 |
grep -q $iso $FILE |
| 64 |
if [ $? -ne 0 ] ; then |
| 65 |
CKSUM="" |
| 66 |
if [ "$JIGDO" == 1 ] ; then |
| 67 |
CKSUM=$(zcat -f $file | \ |
| 68 |
grep -i "Image Hex $CMD" | \ |
| 69 |
awk '{print $5}') |
| 70 |
fi |
| 71 |
if [ "$CKSUM"x != ""x ] ; then |
| 72 |
echo "$CKSUM $iso" >> $FILE |
| 73 |
grep $iso $FILE |
| 74 |
else |
| 75 |
echo "$JIGDO cannot provide jigdo help for $SUM for $iso, doing it the long way with $CMD" |
| 76 |
$CMD $iso >> $FILE |
| 77 |
grep $iso $FILE |
| 78 |
fi |
| 79 |
fi |
| 80 |
fi |
| 81 |
|
| 82 |
# Also add the template, jigdo and torrent files to the SUMS, |
| 83 |
# if they exist |
| 84 |
case $file in |
| 85 |
*.template|*.jigdo|*.torrent) |
| 86 |
$CMD $file >> $FILE |
| 87 |
grep $file $FILE |
| 88 |
;; |
| 89 |
esac |
| 90 |
done |
| 91 |
done |