2 # -----------------------------------------------------------------
3 # FreeBSD Release Checking Utility - Package Index Check
5 # This program checks the packages/INDEX file to verify that
6 # the index is in the correct format and that every package
7 # needed by a release is included on the CD.
9 # Copyright(c) 2000 BSDi
11 # -----------------------------------------------------------------
14 # $FreeBSD: src/release/scripts/checkindex.pl,v 1.1.2.1 2003/03/03 09:49:13 murray Exp $
15 # $DragonFly: src/release/scripts/Attic/checkindex.pl,v 1.2 2003/06/17 04:27:21 dillon Exp $
21 # Display the usage instructions
26 usage : checkindex -s <sysinstall src dir> <INDEX>
28 This program checks the packages INDEX file to verify that the
29 index is correct and that every package needed by sysinstall is
30 included in the index.
34 -help Display usage instructions
35 -s <src dir> Specify the sysinstall source directory. Use
36 this so to make sure every package referenced
37 in the code is in your INDEX
38 -newindex Generate a new index consisting of only those
39 packages that actually exist in pkgdir/All
40 -depends <pkg> Lists all packages in the index that depend
47 ## Attempts to find the value of a variable in C code by backtracking
48 ## up the source looking for a previous declaration.
50 ## This is a bit overkill for the purpose of this script,
51 ## stick with grepping for likely packages for now.
53 sub findAssignment($$) {
54 ## This code deals with the small (5%) number of matches
55 ## in which package_add refers to a variable rather than
56 ## a inline string, so we have to find the value of that
57 ## variable so that we can push it onto the list
58 # my($fileName,$code) = split(/:/,$match);
59 # open(FILE,$fileName) || die "Could not open $fileName : $!\n";
60 # my(@lines) = <FILE>;
64 # foreach $line (@lines) {
65 # $lineMatch = $cnt if ($line eq $code);
68 # $code =~ /package_add\((\S+)\)/;
70 # print STDERR "$lineMatch of $fileName is wierd\n";
71 # print STDERR "Trying to find '$varName'\n";
80 ## Returns a list of all the packages referenced in the sysinstall source
86 my(@matches) = `grep package_add $opt_s/*.c`;
88 foreach $match (@matches) {
90 next if ($match =~ m|$opt_s/package.c|);
91 if ($match =~ /package_add\(\"(\S+)\"\)/) {
93 } elsif ($match =~ /package_add\(char/) {
94 # function definition or prototype
97 # package_add(variable or DEFINE)
98 my(@varMatches) = `grep variable_set2 $opt_s/*.c`;
100 foreach $varMatch (@varMatches) {
101 if ($varMatch =~ /variable_set2\(\S+_PACKAGE,\s+\"(\S+)\"/) {
111 &GetOptions("help","s=s","newindex","depends=s");
115 my ($indexName) = $ARGV[0];
118 print STDERR "Packages Referenced :\n---------------------\n";
119 open(INDEX,$indexName) || die "Could not open $indexName : $!";
123 ## Check to ensure that every file in the index exists physically.
124 print STDERR "Check to ensure that every file in the index exists physically\n";
125 foreach $line (@index) {
127 ($file,$pathto,$prefix,$comment,$descr,$maint,$cats,$junk,$rdeps,$junk) = split(/\|/,$line,10);
128 $DEPENDS{$file} = $rdeps if (-e "All/$file.tgz");
132 foreach $pkg (keys %DEPENDS) {
133 $new = quotemeta $pkg;
134 @lines = grep(/^$new\|/,@index);
136 ($#lines == 0) || die "Multiple lines for '$pkg' in index!";
137 printf "%s\n",$lines[0];
139 } elsif ($opt_depends) {
140 foreach $key (keys %DEPENDS) {
141 foreach $dependency (split ' ',$DEPENDS{$key}) {
142 if ($opt_depends eq $dependency) {
143 print "$opt_depends is needed by $key\n";
148 print "$opt_depends is not needed by any packages in the index!\n"
152 ## Check to ensure that all the dependencies are there.
153 print "Check to make sure that every dependency of every file exists\n",
154 "in the Index and physically.\n";
155 foreach $file (keys %DEPENDS) {
156 # print "Checking $file\n";
157 foreach $depend (split(' ',$DEPENDS{$file})) {
158 unless (-e "All/$depend.tgz") {
159 # instead of a hash counter, make it a hash of arrays
160 # where the arrays are the files depended on.
161 push @{ $MISSING{$depend} }, $file;
167 ## This makes sure that the index file contains everything
168 ## that sysinstall uses.
170 @packages = getPackages($opt_s);
171 foreach $pkg (@packages) {
172 unless (grep(/^$pkg/,@index)) {
173 push @{ $MISSING{$pkg} }, "sysinstall";
180 ## If there were mistakes, print out the missing packages.
182 print "--------------------------------------------------------\n",
183 " Packages Missing : \n",
184 "--------------------------------------------------------\n";
185 foreach $pkg (keys %MISSING) {
186 @files = @{ $MISSING{$pkg} };
187 print "$pkg (@files)\n";
190 print "Everything looks good!\n";