5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 use Getopt
::Long
qw(:config posix_default bundling no_ignorecase);
27 use Dpkg
::ErrorHandling
;
31 use Dpkg
::Source
::CompressedFile
;
34 textdomain
("dpkg-dev");
36 # Do not pollute STDOUT with info messages
37 report_options
(info_fh
=> \
*STDERR
);
39 my (@samemaint, @changedmaint);
44 my %options = (help
=> sub { usage
(); exit 0; },
47 udeb
=> \
&set_type_udeb
,
50 'extra-override'=> undef,
54 my $result = GetOptions
(\
%options,
55 'help|h|?', 'version', 'type|t=s', 'udeb|u!',
56 'arch|a=s', 'multiversion|m!', 'extra-override|e=s',
60 printf _g
("Debian %s version %s.\n"), $progname, $version;
66 "Usage: %s [<option> ...] <binarypath> [<overridefile> [<pathprefix>]] > Packages
69 -t, --type <type> scan for <type> packages (default is 'deb').
70 -u, --udeb scan for udebs (obsolete alias for -tudeb).
71 -a, --arch <arch> architecture to scan for.
72 -m, --multiversion allow multiple versions of a single package.
73 -e, --extra-override <file>
74 use extra override file.
75 -M, --medium <medium> add X-Medium field for dselect multicd access method
76 -h, --help show this help message.
77 --version show the version.
83 warning
(_g
("-u, --udeb option is deprecated (see README.feature-removal-schedule)"));
84 $options{type
} = 'udeb';
90 my $comp_file = Dpkg
::Source
::CompressedFile
->new(filename
=> $override);
91 my $override_fh = $comp_file->open_for_read();
93 while (<$override_fh>) {
98 my ($p, $priority, $section, $maintainer) = split(/\s+/, $_, 4);
100 if (not defined($packages{$p})) {
101 push(@spuriousover, $p);
105 for my $package (@
{$packages{$p}}) {
107 if ($maintainer =~ m/(.+?)\s*=\>\s*(.+)/) {
110 my $debmaint = $$package{Maintainer
};
111 if (!grep($debmaint eq $_, split(m
:\s
*//\s
*:, $oldmaint))) {
113 sprintf(_g
(" %s (package says %s, not %s)"),
114 $p, $$package{Maintainer
}, $oldmaint));
116 $$package{Maintainer
} = $newmaint;
118 } elsif ($$package{Maintainer
} eq $maintainer) {
119 push(@samemaint, " $p ($maintainer)");
121 warning
(_g
("Unconditional maintainer override for %s"), $p);
122 $$package{Maintainer
} = $maintainer;
125 $$package{Priority
} = $priority;
126 $$package{Section
} = $section;
132 $comp_file->cleanup_after_open();
135 sub load_override_extra
137 my $extra_override = shift;
138 my $comp_file = Dpkg
::Source
::CompressedFile
->new(filename
=> $extra_override);
139 my $override_fh = $comp_file->open_for_read();
141 while (<$override_fh>) {
146 my ($p, $field, $value) = split(/\s+/, $_, 3);
148 next unless defined($packages{$p});
150 for my $package (@
{$packages{$p}}) {
151 $$package{$field} = $value;
156 $comp_file->cleanup_after_open();
159 usage
() and exit 1 if not $result;
161 if (not @ARGV >= 1 && @ARGV <= 3) {
162 usageerr
(_g
("1 to 3 args expected"));
165 my $type = defined($options{type
}) ?
$options{type
} : 'deb';
166 my $arch = $options{arch
};
169 if ($options{arch
}) {
170 @find_args = ('(', '-name', "*_all.$type", '-o',
171 '-name', "*_${arch}.$type", ')');
174 @find_args = ('-name', "*.$type");
177 my ($binarydir, $override, $pathprefix) = @ARGV;
179 -d
$binarydir or error
(_g
("Binary dir %s not found"), $binarydir);
180 defined($override) and (-e
$override or
181 error
(_g
("Override file %s not found"), $override));
183 $pathprefix = '' if not defined $pathprefix;
185 my $find_h = new IO
::Handle
;
186 open($find_h, '-|', 'find', '-L', "$binarydir/", @find_args, '-print')
187 or syserr
(_g
("Couldn't open %s for reading"), $binarydir);
193 my $pid = fork_and_exec
('exec' => [ "dpkg-deb", "-I", $fn, "control" ],
194 'to_pipe' => \
$output);
195 my $fields = Dpkg
::Control
->new(type
=> CTRL_INDEX_PKG
);
196 $fields->parse_fh($output, $fn)
197 or error
(_g
("couldn't parse control information from %s."), $fn);
198 wait_child
($pid, no_check
=> 1);
200 warning
(_g
("\`dpkg-deb -I %s control' exited with %d, skipping package"),
205 defined($fields->{'Package'})
206 or error
(_g
("No Package field in control file of %s"), $fn);
207 my $p = $fields->{'Package'};
209 if (defined($packages{$p}) and not $options{multiversion
}) {
210 foreach (@
{$packages{$p}}) {
211 if (version_compare_relation
($fields->{'Version'}, REL_GT
,
214 warning
(_g
("Package %s (filename %s) is repeat but newer version;"),
216 warning
(_g
("used that one and ignored data from %s!"),
220 warning
(_g
("Package %s (filename %s) is repeat;"), $p, $fn);
221 warning
(_g
("ignored that one and using data from %s!"),
227 warning
(_g
("Package %s (filename %s) has Filename field!"), $p, $fn)
228 if defined($fields->{'Filename'});
230 $fields->{'Filename'} = "$pathprefix$fn";
234 getchecksums
($fn, $sums, \
$size);
235 foreach my $alg (@check_supported) {
237 $fields->{'MD5sum'} = $sums->{'md5'};
239 $fields->{$alg} = $sums->{$alg};
242 $fields->{'Size'} = $size;
243 $fields->{'X-Medium'} = $options{medium
} if defined $options{medium
};
245 push @
{$packages{$p}}, $fields;
249 load_override
($override) if defined $override;
250 load_override_extra
($options{'extra-override'}) if defined $options{'extra-override'};
254 my $records_written = 0;
255 for my $p (sort keys %packages) {
256 if (defined($override) and not defined($overridden{$p})) {
257 push(@missingover,$p);
259 for my $package (@
{$packages{$p}}) {
260 print(STDOUT
"$package\n") or syserr
(_g
("Failed when writing stdout"));
264 close(STDOUT
) or syserr
(_g
("Couldn't close stdout"));
267 warning
(_g
("Packages in override file with incorrect old maintainer value:"));
268 warning
($_) foreach (@changedmaint);
271 warning
(_g
("Packages specifying same maintainer as override file:"));
272 warning
($_) foreach (@samemaint);
275 warning
(_g
("Packages in archive but missing from override file:"));
276 warning
(" %s", join(' ', @missingover));
279 warning
(_g
("Packages in override file but not in archive:"));
280 warning
(" %s", join(' ', @spuriousover));
283 info
(_g
("Wrote %s entries to output Packages file."), $records_written);