File: imagesums

package info (click to toggle)
debian-cd 3.2.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,848 kB
  • sloc: sh: 6,129; perl: 4,129; makefile: 413
file content (91 lines) | stat: -rwxr-xr-x 2,252 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash

VERBOSE=0

if [ "$1" = "-v" ] ; then
    VERBOSE=1
    shift
fi

cd $1

if [ "$2"x != ""x ] ; then
    EXT="$2"
fi

if [ "$CHECKSUMS"x = ""x ] ; then
    CHECKSUMS="sha512 sha256"
fi

for SUM in $CHECKSUMS; do
    UPSUM=$(echo $SUM | tr 'a-z' 'A-Z')
    FILE=$UPSUM"SUMS"$EXT
    if [ $VERBOSE -eq 1 ] ; then
        echo "Clearing $PWD/$FILE"
    fi
    :> $FILE
done

# Ordering is important, so we do separate "find" calls here - we
# *really* want to get the jigdo files before the iso files, so we can
# use the checksums there first instead of re-calculating them
FILES=""
FILES="$FILES "$(find * -name '*.jigdo')
FILES="$FILES "$(find * -name '*.template')
FILES="$FILES "$(find * -name '*.iso')
FILES="$FILES "$(find * -name '*.torrent')

for file in $FILES; do
    iso=""
    case $file in
        *.jigdo)
            iso=${file%%.jigdo}.iso
            JIGDO=1
            ;;
        *.iso)
            iso=$file
            JIGDO=0
            ;;
        *.template|*.torrent)
            ;;
        *)
            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 "$JIGDO cannot provide jigdo help for $SUM for $iso, doing it the long way with $CMD"
                    $CMD $iso >> $FILE
                    grep $iso $FILE
                fi
            fi
        fi

        # Also add the template, jigdo and torrent files to the SUMS,
        # if they exist
        case $file in
            *.template|*.jigdo|*.torrent)
                $CMD $file >> $FILE
                grep $file $FILE
                ;;
        esac
    done
done