#! /usr/bin/perl

# test if all package names in package_config files are available in a certain distribution
# packages from dists/proposed-updates are not listed in allpackages.html
# usage: chkdebnames stable *
#
# (c) 2001 by Thomas Lange, lange@informatik.uni-koeln.de

$dist=shift;
$tmp="/tmp/$dist.html";

-f $tmp || do {
   print "Getting package list from packages.debian.org\n";
   system "wget -P/tmp packages.debian.org/$dist/allpackages.html";
   rename "/tmp/allpackages.html",$tmp || die "Can't rename allpackages.html to $tmp\n";
};

open (PACK,$tmp);
while (<PACK>) {
  next unless m#<dt><a href=.+>([-+.\w]+)</a> #;
  $avail{$1}=1;
}

# now read a configuration files and check if packages are known
while (<>) {
  next if /^#/;
  next if /^PACKAGES/;
  next if /`/;
  s/#.$//;
  chomp;
  foreach $p (split) {
    $p =~ s/[+-]$//;
    push @notavail,$p unless $avail{$p};
  }
}

print "Following packages are not known for the distribution $dist:\n";
foreach (@notavail) {
  print "$_\n";
}
