File: grab_checksums

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 (148 lines) | stat: -rwxr-xr-x 4,768 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
#
# grab_checksum
# (c) 2004-2019 Steve McIntyre <steve@einval.com>
#
# GPL v2
#
# Parse Packages and Sources files out of a mirror and pre-process
# them into a single list ready for mkisofs to check later

set -e

CHECKSUM=$1
MIRROR=$2
ARCHES="$3"
CODENAME=$4
DI_CODENAME=$5
OUT=$6

case $CHECKSUM in
    md5|sha256)
	# OK
        ;;
    *)
	echo "$0: Unsupported checksum specified: $CHECKSUM"
	echo "Abort"
	exit 1
	;;
esac

export CHECKSUM

for ARCH in $ARCHES
do
    LOCATIONS="$MIRROR/dists/$CODENAME/ $MIRROR/dists/$DI_CODENAME/"
    if [ "$BACKPORTS"x != ""x ] ; then
	LOCATIONS="$LOCATIONS $MIRROR/dists/$CODENAME-backports/"
    fi
    if [ "$UNRELEASED" = 1 ] ; then
	LOCATIONS="$LOCATIONS $MIRROR/dists/unreleased/"
    fi
    echo "Looking in $LOCATIONS"

    for LOCATION in $LOCATIONS; do
        if [ ! -d $LOCATION ]; then
            echo "Error: $LOCATION is not a directory"
            exit 1
        fi
    done

    case $ARCH in
        source)
            FILES=`find $LOCATIONS -follow -name Sources.gz -o -name Sources.xz`
            echo "Using $CHECKSUM sums from Sources files:"
            echo $FILES
            $BASEDIR/tools/catz $FILES | \
		MIRROR=$MIRROR CHECKSUM=$CHECKSUM perl -e '
                chomp;
                my %files;
                my $dir;
                my $filename;
                my $mirror = $ENV{"MIRROR"};
		my $checksum = $ENV{"CHECKSUM"};
                while (<>) {
                    if (m/^ ([[:xdigit:]]{32}) (\d+) (\S+)/sg) {
                        $files{$3}{"md5"} = $1;
                        $files{$3}{"size"} = $2;
                    }
                    if (m/^ ([[:xdigit:]]{64}) (\d+) (\S+)/sg) {
                        $files{$3}{"sha256"} = $1;
                        $files{$3}{"size"} = $2;
                    }
                    if (m/^Directory: (\S+)/sg) {
                        $dir = $1;
                    }
                    if (m/^$/) {
                        for $filename (keys %files) {
                            printf("%s  %12s  %s/%s/%s\n",
                                $files{$filename}{$checksum},
                                $files{$filename}{"size"},
                                $mirror, $dir, $filename);
                        }
                        undef %files;
                    }
                }' | sort | uniq >> $OUT
            ;;
        *)
            FILES=`find $LOCATIONS -follow -name Packages.gz \
                   -o -name Packages.xz | grep binary-$ARCH`
            echo "Using $CHECKSUM sums from Packages files:"
            echo $FILES
            NUM_FILES=`echo $FILES| wc -w`
            if [ $NUM_FILES -eq 1 ] ; then
                echo "No files found for arch $ARCH. Abort!"
                exit 1
            fi
            $BASEDIR/tools/catz $FILES | \
		MIRROR=$MIRROR CHECKSUM=$CHECKSUM perl -e '
                chomp;
                my $mirror = $ENV{"MIRROR"};
		my $checksum = $ENV{"CHECKSUM"};
                my $filename;
                my $size;
                my $sum;
                while (<>) {
                    if (m/^Filename: (\S+)/sg) {
                        $filename = $1;
                    }
                    if (m/^Size: (\S+)/sg) {
                        $size = $1;
                    }
		    if ($checksum eq "md5" and (m/^MD5sum: (\S+)/sg)) {
                        $sum = $1;
                    } elsif ($checksum eq "sha256" and (m/^SHA256: (\S+)/sg)) {
                        $sum = $1;
                    }
                    if (m/^$/) {
                        printf("%s  %12s  %s/%s\n", $sum, $size, $mirror, $filename);
			$sum = "";
                    }
                }' | sort | uniq >> $OUT
            # Use the new D-I images. Do NOT use the "current"
            # link; it causes problems with overlaid files...
            for VER in $MIRROR/dists/$DI_CODENAME/main/installer-$ARCH/*
            do
                if [ -d $VER ] && [ ! -L $VER ] ; then
		    if [ $CHECKSUM = md5 ]; then
			FILE=$VER/images/MD5SUMS
		    else
			FILE=$VER/images/SHA256SUMS
		    fi
                    echo "Using $CHECKSUM sums from d-i: $FILE"
                    LOC=dists/$DI_CODENAME/main/installer-$ARCH/`basename $VER`/images
                    for ENTRY in `cat $FILE | sed 's/  /:/g'`
                    do
                        PATH=`echo $ENTRY | /bin/sed "s?^.*:\./?$MIRROR/$LOC/?g"`
                        CSUM=`echo $ENTRY | /bin/sed 's/:.*$//g'`
                        SIZE=`/usr/bin/stat -c %s $PATH`
                        printf '%s  %12.12s  %s\n' $CSUM $SIZE $PATH
                    done | sort | uniq >> $OUT
                 fi
            done
            ;;             
    esac
done

exit 0