Move to perl, and add support for grabbing source details too

This commit is contained in:
Steve McIntyre 2008-11-22 10:46:55 +00:00
parent 91b43114ab
commit 7a6ced3533
1 changed files with 100 additions and 38 deletions

View File

@ -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
;;
yaboot) my $pgz = "$pth/binary-$arch/Packages.gz";
DEB="$MIRROR/"`zcat $PTH/binary-powerpc/Packages.gz | \
awk '/\/yaboot.*deb/ {print $2}'`
;;
*) $/ = ''; # Browse by paragraph
# No idea what we should be doing here...
DEB="$MIRROR/"
;;
esac if (-e $pgz) {
open(PFILE, "zcat $pgz |") or
die "Failed to read Packages file $pgz";
if [ "$DEB"x = "$MIRROR/"x ] ; then while (defined($match = <PFILE>)) {
echo "$0: Failed to find a deb for package $PKG in $MIRROR/" if (($match =~ /^Package: \Q$pkgname\E$/m)) {
exit 1 $result = $match;
fi close PFILE;
return $result;
}
}
# Fell through
close PFILE;
}
return "";
}
echo $DEB sub grab_src_info {
my $pth = shift;
my $pkgname = shift;
my $old_split = $/;
my $match;
my $result = "";
my $pgz = "$pth/source/Sources.gz";
$/ = ''; # 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";
}
}
}