aboutsummaryrefslogtreecommitdiff
path: root/Tools/scripts/distinfochecker
blob: 86c3cecd0cca06654ef2bc24ccb8c6cfb144feea (plain) (blame)
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
#!/usr/bin/perl -w

#
# $FreeBSD$
#
# Author: Edwin Groothuis <edwin@FreeBSD.org>
#

#
# Small tool to find distinfo with missing MD5/SHA256/SIZE statements,
# based on the assumption that if there is one of the MD5/SHA256/SIZE
# statements, then there should be all of them (except for SIZE
# when MD5/SHA256 is set to IGNORE).
#
# Usage: distinfochecker [-v] [-d directory]
# -v	- verbose (print)
# -d	- use directory instead of /usr/ports
#

use Getopt::Std;
use strict;
use Data::Dumper;

my $UP="/usr/ports";
my $verbose=0;

my %opts=();
getopt('d:v',\%opts);

$UP=$opts{d} if (defined $opts{d});
$verbose=1 if (defined $opts{v});

my $errors=0;
my $checked=0;

opendir(DHUP,$UP);
while (my $c=readdir(DHUP)) {

    next if ($c=~/^\./);
    next if ($c=~/^[A-Z]/);
    next if ($c=~/^distfiles/);

    opendir(DHUPC,"$UP/$c");
    while (my $p=readdir(DHUPC)) {
	next if ($p=~/^\./);
	next if ($p=~/^Makefile/);

	if (!-f "$UP/$c/$p/distinfo") {
	    print "$c/$p - No distinfo found\n" if ($verbose);
	    next;
	}
	open(FIN,"$UP/$c/$p/distinfo");
	my @lines=<FIN>;
	chomp(@lines);
	close(FIN);

	my %MD5=();
	my %SHA256=();
	my %SIZE=();

	foreach my $line (@lines) {
	    if ($line=~/^MD5 \((.+?)\) = (.+?)$/) {
		if (defined $MD5{$1}) {
		    print "$c/$p - Duplicate MD5 for $1\n";
		    $errors++;
		}
		$MD5{$1}=$2;
	    }
	    if ($line=~/^SHA256 \((.+?)\) = (.+?)$/) {
		if (defined $SHA256{$1}) {
		    print "$c/$p - Duplicate SHA256 for $1\n";
		    $errors++;
		}
		$SHA256{$1}=$2;
	    }
	    if ($line=~/^SIZE \((.+?)\) = (.+?)$/) {
		if (defined $SIZE{$1}) {
		    print "$c/$p - Duplicate SIZE for $1\n";
		    $errors++;
		}
		$SIZE{$1}=$2;
	    }
	}

	foreach my $f (sort(keys(%MD5))) {
	    if (!defined ($SHA256{$f})) {
		print "$c/$p - Missing SHA256 for $f\n";
		$SHA256{$f}="missing";
		$errors++;
	    }
	    if ($MD5{$f} ne "IGNORE") {
		if (!defined ($SIZE{$f})) {
		    print "$c/$p - Missing SIZE for $f\n";
		    $SIZE{$f}="missing";
		    $errors++;
		}
	    }
	    $checked++;
	}

	foreach my $f (sort(keys(%SHA256))) {
	    if (!defined ($MD5{$f})) {
		print "$c/$p - Missing MD5 for $f\n";
		$MD5{$f}="missing";
		$errors++;
	    }
	    if ($SHA256{$f} ne "IGNORE") {
		if (!defined ($SIZE{$f})) {
		    print "$c/$p - Missing SIZE for $f\n";
		    $SIZE{$f}="missing";
		    $errors++;
		}
	    }
	}

	foreach my $f (sort(keys(%SIZE))) {
	    if (!defined ($MD5{$f})) {
		print "$c/$p - Missing MD5 for $f\n";
		$MD5{$f}="missing";
		$errors++;
	    }
	    if (!defined ($SHA256{$f})) {
		print "$c/$p - Missing SHA256 for $f\n";
		$SHA256{$f}="missing";
		$errors++;
	    }
	}


    }
    closedir(DHUPC);
}
closedir(DHUP);

print "Errors: $errors\nChecked: $checked\n";