Debian Codegraph @

tools/grab_checksums

raw
1 #!/bin/sh
2 #
3 # grab_checksum
4 # (c) 2004-2019 Steve McIntyre <[email protected]>
5 #
6 # GPL v2
7 #
8 # Parse Packages and Sources files out of a mirror and pre-process
9 # them into a single list ready for mkisofs to check later
10
11 set -e
12
13 CHECKSUM=$1
14 MIRROR=$2
15 ARCHES="$3"
16 CODENAME=$4
17 DI_CODENAME=$5
18 OUT=$6
19
20 case $CHECKSUM in
21 md5|sha256)
22 # OK
23 ;;
24 *)
25 echo "$0: Unsupported checksum specified: $CHECKSUM"
26 echo "Abort"
27 exit 1
28 ;;
29 esac
30
31 export CHECKSUM
32
33 for ARCH in $ARCHES
34 do
35 LOCATIONS="$MIRROR/dists/$CODENAME/ $MIRROR/dists/$DI_CODENAME/"
36 if [ "$BACKPORTS"x != ""x ] ; then
37 LOCATIONS="$LOCATIONS $MIRROR/dists/$CODENAME-backports/"
38 fi
39 if [ "$UNRELEASED" = 1 ] ; then
40 LOCATIONS="$LOCATIONS $MIRROR/dists/unreleased/"
41 fi
42 echo "Looking in $LOCATIONS"
43
44 for LOCATION in $LOCATIONS; do
45 if [ ! -d $LOCATION ]; then
46 echo "Error: $LOCATION is not a directory"
47 exit 1
48 fi
49 done
50
51 case $ARCH in
52 source)
53 FILES=`find $LOCATIONS -follow -name Sources.gz -o -name Sources.xz`
54 echo "Using $CHECKSUM sums from Sources files:"
55 echo $FILES
56 $BASEDIR/tools/catz $FILES | \
57 MIRROR=$MIRROR CHECKSUM=$CHECKSUM perl -e '
58 chomp;
59 my %files;
60 my $dir;
61 my $filename;
62 my $mirror = $ENV{"MIRROR"};
63 my $checksum = $ENV{"CHECKSUM"};
64 while (<>) {
65 if (m/^ ([[:xdigit:]]{32}) (\d+) (\S+)/sg) {
66 $files{$3}{"md5"} = $1;
67 $files{$3}{"size"} = $2;
68 }
69 if (m/^ ([[:xdigit:]]{64}) (\d+) (\S+)/sg) {
70 $files{$3}{"sha256"} = $1;
71 $files{$3}{"size"} = $2;
72 }
73 if (m/^Directory: (\S+)/sg) {
74 $dir = $1;
75 }
76 if (m/^$/) {
77 for $filename (keys %files) {
78 printf("%s %12s %s/%s/%s\n",
79 $files{$filename}{$checksum},
80 $files{$filename}{"size"},
81 $mirror, $dir, $filename);
82 }
83 undef %files;
84 }
85 }' | sort | uniq >> $OUT
86 ;;
87 *)
88 FILES=`find $LOCATIONS -follow -name Packages.gz \
89 -o -name Packages.xz | grep binary-$ARCH`
90 echo "Using $CHECKSUM sums from Packages files:"
91 echo $FILES
92 NUM_FILES=`echo $FILES| wc -w`
93 if [ $NUM_FILES -eq 1 ] ; then
94 echo "No files found for arch $ARCH. Abort!"
95 exit 1
96 fi
97 $BASEDIR/tools/catz $FILES | \
98 MIRROR=$MIRROR CHECKSUM=$CHECKSUM perl -e '
99 chomp;
100 my $mirror = $ENV{"MIRROR"};
101 my $checksum = $ENV{"CHECKSUM"};
102 my $filename;
103 my $size;
104 my $sum;
105 while (<>) {
106 if (m/^Filename: (\S+)/sg) {
107 $filename = $1;
108 }
109 if (m/^Size: (\S+)/sg) {
110 $size = $1;
111 }
112 if ($checksum eq "md5" and (m/^MD5sum: (\S+)/sg)) {
113 $sum = $1;
114 } elsif ($checksum eq "sha256" and (m/^SHA256: (\S+)/sg)) {
115 $sum = $1;
116 }
117 if (m/^$/) {
118 printf("%s %12s %s/%s\n", $sum, $size, $mirror, $filename);
119 $sum = "";
120 }
121 }' | sort | uniq >> $OUT
122 # Use the new D-I images. Do NOT use the "current"
123 # link; it causes problems with overlaid files...
124 for VER in $MIRROR/dists/$DI_CODENAME/main/installer-$ARCH/*
125 do
126 if [ -d $VER ] && [ ! -L $VER ] ; then
127 if [ $CHECKSUM = md5 ]; then
128 FILE=$VER/images/MD5SUMS
129 else
130 FILE=$VER/images/SHA256SUMS
131 fi
132 echo "Using $CHECKSUM sums from d-i: $FILE"
133 LOC=dists/$DI_CODENAME/main/installer-$ARCH/`basename $VER`/images
134 for ENTRY in `cat $FILE | sed 's/ /:/g'`
135 do
136 PATH=`echo $ENTRY | /bin/sed "s?^.*:\./?$MIRROR/$LOC/?g"`
137 CSUM=`echo $ENTRY | /bin/sed 's/:.*$//g'`
138 SIZE=`/usr/bin/stat -c %s $PATH`
139 printf '%s %12.12s %s\n' $CSUM $SIZE $PATH
140 done | sort | uniq >> $OUT
141 fi
142 done
143 ;;
144 esac
145 done
146
147 exit 0
148