Remove NOSECURE which no longer serves a purpose. Note: FreeBSD also removed
[dragonfly.git] / release / scripts / checkindex.pl
1 #!/usr/bin/perl
2 # -----------------------------------------------------------------
3 #  FreeBSD Release Checking Utility - Package Index Check
4 #
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.
8 #
9 #  Copyright(c) 2000 BSDi
10 #  Murray Stokely
11 # -----------------------------------------------------------------
12 # 08 Apr 2000
13 #
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 $
16 #
17
18 use Getopt::Long;
19
20 #
21 # Display the usage instructions
22 #
23
24 sub printHelp {
25     print<<end;
26 usage : checkindex -s <sysinstall src dir> <INDEX>
27
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.
31
32   Options
33
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
41                           on <pkg>.
42
43 end
44 }
45
46 ##
47 ## Attempts to find the value of a variable in C code by backtracking
48 ## up the source looking for a previous declaration.
49 ## 
50 ## This is a bit overkill for the purpose of this script,
51 ## stick with grepping for likely packages for now.
52
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>;
61 #           my($cnt)  = 1;
62 #           my($lineMatch) = 0;
63 #           chomp(@lines);
64 #           foreach $line (@lines) {
65 #               $lineMatch = $cnt if ($line eq $code);
66 #               $cnt++;
67 #           }
68 #           $code =~ /package_add\((\S+)\)/;
69 #           my($varName) = $1;
70 #           print STDERR "$lineMatch of $fileName is wierd\n";
71 #           print STDERR "Trying to find '$varName'\n";
72 #           while ($cnt > 0) {
73 #               $cnt--;
74 #           }
75
76
77 }
78
79 ##
80 ## Returns a list of all the packages referenced in the sysinstall source
81 ## code
82 ##
83
84 sub getPackages($) {
85     my($srcDir) = $_[0];
86     my(@matches) = `grep package_add $opt_s/*.c`;
87     my(@packages);
88     foreach $match (@matches) {
89         chomp $match;
90         next if ($match =~ m|$opt_s/package.c|);
91         if ($match =~ /package_add\(\"(\S+)\"\)/) {
92             push(@packages,$1);
93         } elsif ($match =~ /package_add\(char/) {
94             # function definition or prototype
95             next;
96         } else {
97             # package_add(variable or DEFINE)
98             my(@varMatches) = `grep variable_set2 $opt_s/*.c`;
99             chomp @varMatches;
100             foreach $varMatch (@varMatches) {
101                 if ($varMatch =~ /variable_set2\(\S+_PACKAGE,\s+\"(\S+)\"/) {
102                     push(@packages,$1);
103                 }
104             }
105         }
106     }
107     @packages;
108 }
109
110
111 &GetOptions("help","s=s","newindex","depends=s");
112 if ($opt_help) {
113     &printHelp;
114 } else{
115     my ($indexName) = $ARGV[0];
116     my ($mistakes) = 0;
117     my ($counter)  = 0;
118     print STDERR "Packages Referenced :\n---------------------\n";
119     open(INDEX,$indexName) || die "Could not open $indexName : $!";
120     @index = <INDEX>;
121     close(INDEX);
122
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) {
126         chomp $line;
127         ($file,$pathto,$prefix,$comment,$descr,$maint,$cats,$junk,$rdeps,$junk) = split(/\|/,$line,10);
128         $DEPENDS{$file} = $rdeps if (-e "All/$file.tgz");
129     }
130
131     if ($opt_newindex) {
132         foreach $pkg (keys %DEPENDS) {
133             $new = quotemeta $pkg;
134             @lines = grep(/^$new\|/,@index);
135             chomp $lines;
136             ($#lines == 0) || die "Multiple lines for '$pkg' in index!";
137             printf "%s\n",$lines[0];
138         }
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";
144                     $counter++;
145                 }
146             }
147         }
148         print "$opt_depends is not needed by any packages in the index!\n"
149             unless ($counter);
150     } else {
151
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;
162                 $mistakes++;
163             }
164         }
165     }
166
167     ## This makes sure that the index file contains everything
168     ## that sysinstall uses.
169     if ($opt_s) {
170         @packages = getPackages($opt_s);
171         foreach $pkg (@packages) {
172             unless (grep(/^$pkg/,@index)) {
173                 push @{ $MISSING{$pkg} }, "sysinstall";
174                 $mistakes++;
175             }
176         }
177     }
178
179
180     ## If there were mistakes, print out the missing packages.
181     if ($mistakes) {
182         print "--------------------------------------------------------\n",
183               " Packages Missing : \n",
184               "--------------------------------------------------------\n";
185         foreach $pkg (keys %MISSING) {
186             @files = @{ $MISSING{$pkg} };
187             print "$pkg (@files)\n";
188         }
189     } else {
190         print "Everything looks good!\n";
191     }
192 }
193 }