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};
|
2008-09-15 23:09:18 +00:00
|
|
|
|
2012-12-06 16:39:34 -01:00
|
|
|
my ($mirror, $codename, $pkg, $pth, $output, $text_out);
|
2008-11-22 09:46:55 -01:00
|
|
|
|
|
|
|
$mirror = shift;
|
|
|
|
$codename = shift;
|
|
|
|
$pkg = shift;
|
|
|
|
$output = shift;
|
2009-02-11 23:22:17 -01:00
|
|
|
$pth = "$mirror/dists/$codename";
|
2012-12-06 16:36:28 -01:00
|
|
|
$text_out = "";
|
2009-02-11 23:22:17 -01:00
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2012-12-06 16:36:28 -01:00
|
|
|
# Give preference to i386 and amd64, if specified
|
|
|
|
my @ARCHES;
|
|
|
|
if ( $ENV{ARCHES} ) {
|
2017-04-12 16:19:28 +00:00
|
|
|
push @ARCHES, 'i386' if $ENV{ARCHES} =~ /(^|\s)i386(\s|$)/;
|
|
|
|
push @ARCHES, 'amd64' if $ENV{ARCHES} =~ /(^|\s)amd64(\s|$)/;
|
|
|
|
push @ARCHES, grep { !/^(source|i386|amd64)$/ } split /\s+/, $ENV{ARCHES};
|
2012-12-06 16:36:28 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
# We seem to be building a source-only CD. Check for whatever binary
|
|
|
|
# arches exist in the archive; #695244
|
|
|
|
if (!@ARCHES) {
|
|
|
|
my %found_arches;
|
|
|
|
my $dh;
|
|
|
|
for my $component(@components) {
|
|
|
|
opendir ($dh, "$pth/$component");
|
|
|
|
if ($dh) {
|
|
|
|
while (my $entry = readdir $dh) {
|
|
|
|
$entry =~ /^binary-(.*)/ and $1 !~ /all/ and $found_arches{$1} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $dh;
|
|
|
|
}
|
|
|
|
if ($found_arches{"i386"}) {
|
|
|
|
push @ARCHES, 'i386';
|
|
|
|
}
|
|
|
|
if ($found_arches{"amd64"}) {
|
|
|
|
push @ARCHES, 'amd64';
|
|
|
|
}
|
|
|
|
for my $arch (sort keys %found_arches) {
|
|
|
|
push @ARCHES, $arch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-22 09:46:55 -01:00
|
|
|
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";
|
|
|
|
}
|
2016-11-15 08:06:41 -01:00
|
|
|
my $pxz = "$pth/$component/binary-$arch/Packages.xz";
|
|
|
|
if ( $component eq 'local' and $ENV{LOCALDEBS} ) {
|
2021-02-03 15:13:18 -01:00
|
|
|
$pxz = "$ENV{LOCALDEBS}/dists/$codename/local/binary-$arch/Packages.xz";
|
2016-11-15 08:06:41 -01:00
|
|
|
}
|
2009-02-11 23:22:17 -01:00
|
|
|
if (-e $pgz) {
|
|
|
|
open(PFILE, "zcat $pgz |") or
|
|
|
|
die "Failed to read Packages file $pgz";
|
2016-11-15 08:06:41 -01:00
|
|
|
} elsif (-e $pxz) {
|
|
|
|
open(PFILE, "xzcat $pxz |") or
|
|
|
|
die "Failed to read Packages file $pxz";
|
|
|
|
} else {
|
|
|
|
die "Can't find a working Packages file, tried $pgz and $pxz\n";
|
|
|
|
}
|
|
|
|
while (defined($match = <PFILE>)) {
|
|
|
|
if (($match =~ /^Package: \Q$pkgname\E$/m)) {
|
|
|
|
$result = $match;
|
|
|
|
close PFILE;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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";
|
2016-11-15 08:06:41 -01:00
|
|
|
my $pxz = "$pth/$component/source/Sources.xz";
|
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";
|
2016-11-15 08:06:41 -01:00
|
|
|
} elsif (-e $pxz) {
|
|
|
|
open(PFILE, "xzcat $pxz |") or
|
|
|
|
die "Failed to read Sources file $pxz";
|
|
|
|
} else {
|
|
|
|
die "Can't find a working Sources file, tried $pgz and $pxz\n";
|
|
|
|
}
|
|
|
|
while (defined($match = <PFILE>)) {
|
|
|
|
if (($match =~ /^Package: \Q$pkgname\E$/m)) {
|
2017-10-20 22:26:28 +00:00
|
|
|
$result = "$result" . $match;
|
2016-11-15 08:06:41 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close PFILE;
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
2017-10-20 22:26:28 +00:00
|
|
|
return $result;
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
my $bin_deb = "";
|
|
|
|
my $pkgdata = "";
|
|
|
|
my $srcname = "";
|
|
|
|
|
2017-09-06 11:20:00 +00:00
|
|
|
if ($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
|
|
|
}
|
2013-03-07 05:34:07 -01:00
|
|
|
} elsif ($pkg eq "delo") {
|
|
|
|
$pkgdata = grab_bin_info($pth, "mipsel", $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;
|
2012-12-06 16:36:28 -01:00
|
|
|
$text_out = "$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
|
2012-12-06 16:36:28 -01:00
|
|
|
while ($pkgdata =~ m/^ ([[:xdigit:]]{32}) (\d+) (\S+)/msg) {
|
|
|
|
$text_out = $text_out . "$dir/$3\n";
|
|
|
|
}
|
2008-11-22 09:46:55 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-06 16:36:28 -01:00
|
|
|
|
|
|
|
if (length($text_out) < 2) {
|
|
|
|
die "which_deb: can't find $output file(s) for $pkg in $codename\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print $text_out;
|