Move to perl, and add support for grabbing source details too
This commit is contained in:
parent
91b43114ab
commit
7a6ced3533
138
tools/which_deb
138
tools/which_deb
|
@ -1,54 +1,116 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/perl -w
|
||||||
#
|
#
|
||||||
# which_deb
|
# which_deb
|
||||||
#
|
#
|
||||||
# Simple helper tool to find the appropriate version of a package in
|
# Simple helper tool to find the appropriate version of a package in
|
||||||
# the archive to meet a requirement in the debian-cd build
|
# the archive to meet a requirement in the debian-cd build
|
||||||
|
|
||||||
MIRROR=$1
|
use strict;
|
||||||
CODENAME=$2
|
|
||||||
PKG=$3
|
|
||||||
PTH=$MIRROR/dists/$CODENAME/main
|
|
||||||
|
|
||||||
case $PKG in
|
my ($mirror, $codename, $pkg, $pth, $output);
|
||||||
|
|
||||||
debootstrap)
|
$mirror = shift;
|
||||||
DEB="$MIRROR/"`zcat $PTH/binary-i386/Packages.gz | \
|
$codename = shift;
|
||||||
awk '/\/debootstrap_.*deb/ {print $2}'`
|
$pkg = shift;
|
||||||
;;
|
$output = shift;
|
||||||
|
$pth = "$mirror/dists/$codename/main";
|
||||||
|
|
||||||
silo)
|
if (!defined ($output)) {
|
||||||
DEB="$MIRROR/"`zcat $PTH/binary-sparc/Packages.gz | \
|
$output = "binary";
|
||||||
awk '/\/silo.*deb/ {print $2}'`
|
}
|
||||||
;;
|
|
||||||
|
|
||||||
syslinux)
|
sub grab_bin_info {
|
||||||
# More complex - look for syslinux-common, then fall back to
|
my $pth = shift;
|
||||||
# syslinux if we don't find that
|
my $arch = shift;
|
||||||
DEB="$MIRROR/"`zcat $PTH/binary-i386/Packages.gz | \
|
my $pkgname = shift;
|
||||||
awk '/\/syslinux-common.*deb/ {print $2}'`
|
my $old_split = $/;
|
||||||
if [ "$DEB"x = "$MIRROR/"x ] ; then
|
my $match;
|
||||||
DEB="$MIRROR/"`zcat $PTH/binary-i386/Packages.gz | \
|
my $result = "";
|
||||||
awk '/\/syslinux.*deb/ {print $2}'`
|
|
||||||
fi
|
my $pgz = "$pth/binary-$arch/Packages.gz";
|
||||||
;;
|
|
||||||
|
|
||||||
yaboot)
|
$/ = ''; # Browse by paragraph
|
||||||
DEB="$MIRROR/"`zcat $PTH/binary-powerpc/Packages.gz | \
|
|
||||||
awk '/\/yaboot.*deb/ {print $2}'`
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
if (-e $pgz) {
|
||||||
# No idea what we should be doing here...
|
open(PFILE, "zcat $pgz |") or
|
||||||
DEB="$MIRROR/"
|
die "Failed to read Packages file $pgz";
|
||||||
;;
|
|
||||||
|
|
||||||
esac
|
while (defined($match = <PFILE>)) {
|
||||||
|
if (($match =~ /^Package: \Q$pkgname\E$/m)) {
|
||||||
|
$result = $match;
|
||||||
|
close PFILE;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Fell through
|
||||||
|
close PFILE;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
if [ "$DEB"x = "$MIRROR/"x ] ; then
|
sub grab_src_info {
|
||||||
echo "$0: Failed to find a deb for package $PKG in $MIRROR/"
|
my $pth = shift;
|
||||||
exit 1
|
my $pkgname = shift;
|
||||||
fi
|
my $old_split = $/;
|
||||||
|
my $match;
|
||||||
|
my $result = "";
|
||||||
|
|
||||||
|
my $pgz = "$pth/source/Sources.gz";
|
||||||
|
|
||||||
echo $DEB
|
$/ = ''; # Browse by paragraph
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Fell through
|
||||||
|
close PFILE;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $bin_deb = "";
|
||||||
|
my $pkgdata = "";
|
||||||
|
my $srcname = "";
|
||||||
|
|
||||||
|
if ($pkg eq "debootstrap") {
|
||||||
|
$pkgdata = grab_bin_info($pth, "i386", $pkg);
|
||||||
|
|
||||||
|
} elsif ($pkg eq "silo") {
|
||||||
|
$pkgdata = grab_bin_info($pth, "sparc", $pkg);
|
||||||
|
|
||||||
|
} elsif ($pkg eq "syslinux") {
|
||||||
|
$pkgdata = grab_bin_info($pth, "i386", "syslinux-common");
|
||||||
|
if (length($pkgdata) < 3) {
|
||||||
|
$pkgdata = grab_bin_info($pth, "i386", "syslinux");
|
||||||
|
}
|
||||||
|
} elsif ($pkg eq "yaboot") {
|
||||||
|
$pkgdata = grab_bin_info($pth, "powerpc", $pkg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length($pkgdata) > 2) {
|
||||||
|
if ($output eq "binary") {
|
||||||
|
$pkgdata =~ m/^Filename: (\S+)/m and $bin_deb = $1;
|
||||||
|
print "$mirror/$bin_deb\n";
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
$pkgdata =~ m/^ (\S+) (\S+) ((\S+).*dsc)/m and print "$mirror/$dir/$3\n";
|
||||||
|
$pkgdata =~ m/^ (\S+) (\S+) ((\S+).*diff.gz)/m and print "$mirror/$dir/$3\n";
|
||||||
|
$pkgdata =~ m/^ (\S+) (\S+) ((\S+).*tar.gz)/m and print "$mirror/$dir/$3\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue