2008-11-22 09:46:55 -01:00
|
|
|
#!/usr/bin/perl -w
|
2008-09-15 23:09:18 +00:00
|
|
|
#
|
|
|
|
# which_deb
|
|
|
|
#
|
|
|
|
# Simple helper tool to find the appropriate version of a package in
|
|
|
|
# the archive to meet a requirement in the debian-cd build
|
|
|
|
|
2008-11-22 09:46:55 -01:00
|
|
|
use strict;
|
2009-02-11 23:22:17 -01:00
|
|
|
use List::Util qw{first};
|
|
|
|
# Give prefernce to i386 and amd64, if specified, or if building a
|
|
|
|
# source-only CD.
|
|
|
|
my @ARCHES;
|
|
|
|
if ( $ENV{ARCHES} ) {
|
|
|
|
push @ARCHES, 'i386' if $ENV{ARCHES} =~ /i386/;
|
|
|
|
push @ARCHES, 'amd64' if $ENV{ARCHES} =~ /amd64/;
|
|
|
|
push @ARCHES, grep { !/source|i386|amd64/ } split /\s+/, $ENV{ARCHES};
|
|
|
|
}
|
|
|
|
@ARCHES = qw{i386 amd64} unless @ARCHES;
|
2008-09-15 23:09:18 +00:00
|
|
|
|
2008-11-22 09:46:55 -01:00
|
|
|
my ($mirror, $codename, $pkg, $pth, $output);
|
|
|
|
|
|
|
|
$mirror = shift;
|
|
|
|
$codename = shift;
|
|
|
|
$pkg = shift;
|
|
|
|
$output = shift;
|
2009-02-11 23:22:17 -01:00
|
|
|
$pth = "$mirror/dists/$codename";
|
|
|
|
|
|
|
|
my @components = qw(main);
|
|
|
|
push @components, 'contrib' if $ENV{CONTRIB};
|
|
|
|
push @components, 'non-free' if $ENV{NONFREE};
|
|
|
|
push @components, 'local' if $ENV{LOCAL};
|
2008-11-22 09:46:55 -01:00
|
|
|
|
|
|
|
if (!defined ($output)) {
|
|
|
|
$output = "binary";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub grab_bin_info {
|
|
|
|
my $pth = shift;
|
|
|
|
my $arch = shift;
|
|
|
|
my $pkgname = shift;
|
|
|
|
my $old_split = $/;
|
|
|
|
my $match;
|
|
|
|
my $result = "";
|
|
|
|
|
|
|
|
$/ = ''; # Browse by paragraph
|
|
|
|
|
2009-02-11 23:22:17 -01:00
|
|
|
for my $component ( @components ) {
|
|
|
|
my $pgz = "$pth/$component/binary-$arch/Packages.gz";
|
|
|
|
if ( $component eq 'local' and $ENV{LOCALDEBS} ) {
|
|
|
|
$pgz = "$ENV{LOCALDEBS}/dists/$codename/local/binary-$arch/Packages.gz";
|
|
|
|
}
|
|
|
|
if (-e $pgz) {
|
|
|
|
open(PFILE, "zcat $pgz |") or
|
|
|
|
die "Failed to read Packages file $pgz";
|
|
|
|
|
|
|
|
while (defined($match = <PFILE>)) {
|
|
|
|
if (($match =~ /^Package: \Q$pkgname\E$/m)) {
|
|
|
|
$result = $match;
|
|
|
|
close PFILE;
|
|
|
|
return $result;
|
|
|
|
}
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
2009-02-11 23:22:17 -01:00
|
|
|
# Fell through
|
|
|
|
close PFILE;
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub grab_src_info {
|
|
|
|
my $pth = shift;
|
|
|
|
my $pkgname = shift;
|
|
|
|
my $old_split = $/;
|
|
|
|
my $match;
|
|
|
|
my $result = "";
|
|
|
|
|
|
|
|
$/ = ''; # Browse by paragraph
|
|
|
|
|
2009-02-11 23:22:17 -01:00
|
|
|
for my $component ( @components ) {
|
|
|
|
my $pgz = "$pth/$component/source/Sources.gz";
|
2008-11-22 09:46:55 -01:00
|
|
|
|
2009-02-11 23:22:17 -01:00
|
|
|
if (-e $pgz) {
|
|
|
|
open(PFILE, "zcat $pgz |") or
|
|
|
|
die "Failed to read Sources file $pgz";
|
|
|
|
|
|
|
|
while (defined($match = <PFILE>)) {
|
|
|
|
if (($match =~ /^Package: \Q$pkgname\E$/m)) {
|
|
|
|
$result = $match;
|
|
|
|
close PFILE;
|
|
|
|
return $result;
|
|
|
|
}
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
2009-02-11 23:22:17 -01:00
|
|
|
# Fell through
|
|
|
|
close PFILE;
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $bin_deb = "";
|
|
|
|
my $pkgdata = "";
|
|
|
|
my $srcname = "";
|
|
|
|
|
2009-02-11 23:22:17 -01:00
|
|
|
if ($pkg eq "silo") {
|
2008-11-22 09:46:55 -01:00
|
|
|
$pkgdata = grab_bin_info($pth, "sparc", $pkg);
|
|
|
|
|
|
|
|
} elsif ($pkg eq "syslinux") {
|
2009-02-11 23:22:17 -01:00
|
|
|
first { $pkgdata = grab_bin_info($pth, $_, "syslinux-common") } @ARCHES;
|
|
|
|
if (length($pkgdata) < 3) {
|
|
|
|
first { $pkgdata = grab_bin_info($pth, $_, "syslinux") } @ARCHES;
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
} elsif ($pkg eq "yaboot") {
|
|
|
|
$pkgdata = grab_bin_info($pth, "powerpc", $pkg);
|
2009-02-11 23:22:17 -01:00
|
|
|
} else { # Fallthrough for all other packages
|
|
|
|
first { $pkgdata = grab_bin_info($pth, $_, $pkg) } @ARCHES;
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (length($pkgdata) > 2) {
|
|
|
|
if ($output eq "binary") {
|
|
|
|
$pkgdata =~ m/^Filename: (\S+)/m and $bin_deb = $1;
|
2008-11-23 17:19:25 -01:00
|
|
|
print "$bin_deb\n";
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
elsif ($output eq "source") {
|
|
|
|
$srcname = $pkg;
|
|
|
|
$pkgdata =~ m/^Source: (\S+)/m and $srcname = $1;
|
|
|
|
$pkgdata = grab_src_info($pth, $srcname);
|
|
|
|
if (length($pkgdata) > 2) {
|
|
|
|
my $dir;
|
|
|
|
$pkgdata =~ m/^Directory: (\S+)/m and $dir = $1;
|
2011-06-09 15:25:38 +00:00
|
|
|
# Explicitly use the md5 lines in the Sources stanza, hence the xdigit(32) here
|
|
|
|
while ($pkgdata =~ m/^ ([[:xdigit:]]{32}) (\d+) (\S+)/msg) { print "$dir/$3\n"; }
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|