package Debian;
use strict;
+no strict 'refs'; # FIXME: dstats aborts if set
-# format: "alias=real".
my $announce = 0;
my $defaultdist = "sid";
my $refresh = &::getChanConfDefault("debianRefreshInterval",7)
* 60 * 60 * 24;
my $debug = 0;
my $debian_dir = "$::bot_state_dir/debian";
+my $country = "us"; # well .config it yourself then. ;-)
+my $protocol = "http";
-### ... old
-#my %dists = (
-# "sid" => "unstable",
-# "woody" => "testing", # new since 20001219.
-# "potato" => "stable",
-# "incoming" => "incoming",
-#);
-
-### new... the right way.
+# format: "alias=real".
my %dists = (
"unstable" => "sid",
- "testing" => "woody", # new since 20001219.
- "stable" => "potato",
+ "testing" => "sarge",
+ "stable" => "woody",
+ "oldstable" => "potato",
"incoming" => "incoming",
);
my %urlcontents = (
"Contents-##DIST-i386.gz" =>
- "ftp://ftp.us.debian.org".
+ "$protocol://ftp.$country.debian.org".
"/debian/dists/##DIST/Contents-i386.gz",
"Contents-##DIST-i386-non-US.gz" =>
- "ftp://non-us.debian.org".
+ "$protocol://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
);
my %urlpackages = (
"Packages-##DIST-main-i386.gz" =>
- "ftp://ftp.us.debian.org".
+ "$protocol://ftp.$country.debian.org".
"/debian/dists/##DIST/main/binary-i386/Packages.gz",
"Packages-##DIST-contrib-i386.gz" =>
- "ftp://ftp.us.debian.org".
+ "$protocol://ftp.$country.debian.org".
"/debian/dists/##DIST/contrib/binary-i386/Packages.gz",
"Packages-##DIST-non-free-i386.gz" =>
- "ftp://ftp.us.debian.org".
+ "$protocol://ftp.$country.debian.org".
"/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
"Packages-##DIST-non-US-main-i386.gz" =>
- "ftp://non-us.debian.org".
+ "$protocol://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
"Packages-##DIST-non-US-contrib-i386.gz" =>
- "ftp://non-us.debian.org".
+ "$protocol://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
"Packages-##DIST-non-US-non-free-i386.gz" =>
- "ftp://non-us.debian.org".
+ "$protocol://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
);
if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
my ($host,$path,$thisfile) = ($1,$2,$3);
-### HACK 1
-# if ($file =~ /Contents-woody-i386-non-US/) {
-# &::DEBUG("Skipping Contents-woody-i386-non-US.");
-# $file =~ s/woody/potato/;
-# $path =~ s/woody/potato/;
-# next;
-# }
-
if (!&::ftpGet($host,$path,$thisfile,$file)) {
&::WARN("deb: down: $file == BAD.");
$bad++;
next;
}
- if (! -f $file) {
- &::WARN("deb: down: ftpGet: !file");
- $bad++;
- next;
- }
-
-### HACK2
-# if ($file =~ /Contents-potato-i386-non-US/) {
-# &::DEBUG("hack: using potato's non-US contents for woody.");
-# system("cp debian/Contents-potato-i386-non-US.gz debian/Contents-woody-i386-non-US.gz");
-# }
+ } elsif ($url =~ /^http:\/\/\S+\/\S+$/) {
- my $exit = CORE::system("/bin/gzip -t $file >/dev/null 2>&1");
- if ($exit) {
- &::WARN("deb: $file is corrupted :/");
- unlink $file;
+ if (!&::getURLAsFile($url,$file)) {
+ &::WARN("deb: down: http: $file == BAD.");
+ $bad++;
next;
}
- &::DEBUG("deb: download: good.") if ($debug);
- $good++;
} else {
&::ERROR("Debian: invalid format of url => ($url).");
$bad++;
next;
}
+
+ if (! -f $file) {
+ &::WARN("deb: down: http: !file");
+ $bad++;
+ next;
+ }
+
+ my $exit = CORE::system("/bin/gzip -t $file >/dev/null 2>&1");
+ if ($exit) {
+ &::WARN("deb: $file is corrupted :/");
+ unlink $file;
+ next;
+ }
+
+ &::DEBUG("deb: download: good.") if ($debug);
+ $good++;
}
# ok... lets just run this.
$regex =~ s/\?/./g;
open(IN,"zegrep -h '$grepRE' $files |");
- # wonderful abuse of last and next and unless ;)
+ # wonderful abuse of if, last, next, return, and, unless ;)
while (<IN>) {
last if ($found > 100);
my $prefix = "Debian Search of '$query' ";
if (scalar @list) { # @list.
&::pSReply( &::formListReply(0, $prefix, @list) );
+ return;
+ }
- } else { # !@list.
- &::DEBUG("deb: ok, !\@list, searching desc for '$query'.") if ($debug);
- my @list = &searchDesc($query);
+ # !@list.
+ &::DEBUG("deb: ok, !\@list, searching desc for '$query'.") if ($debug);
+ @list = &searchDesc($query);
- if (!scalar @list) {
- my $prefix = "Debian Package/File/Desc Search of '$query' ";
- &::pSReply( &::formListReply(0, $prefix, ) );
+ if (!scalar @list) {
+ my $prefix = "Debian Package/File/Desc Search of '$query' ";
+ &::pSReply( &::formListReply(0, $prefix, ) );
- } elsif (scalar @list == 1) { # list = 1.
- &::DEBUG("deb: list == 1; showing package info of '$list[0]'.");
- &infoPackages("info", $list[0]);
+ } elsif (scalar @list == 1) { # list = 1.
+ &::DEBUG("deb: list == 1; showing package info of '$list[0]'.");
+ &infoPackages("info", $list[0]);
- } else { # list > 1.
- my $prefix = "Debian Desc Search of '$query' ";
- &::pSReply( &::formListReply(0, $prefix, @list) );
- }
+ } else { # list > 1.
+ my $prefix = "Debian Desc Search of '$query' ";
+ &::pSReply( &::formListReply(0, $prefix, @list) );
}
}
my $found = 0;
my (%pkg, $pkg);
- open(IN, "zcat $file 2>&1 |");
+ open(IN, "/bin/zcat $file 2>&1 |");
my $done = 0;
while (!eof IN) {
if (!scalar @files) {
&::status("Debian: no valid package found; checking incoming.");
@files = &validPackage($package, "incoming");
+
if (scalar @files) {
&::status("Debian: cool, it exists in incoming.");
$incoming++;
if (! -f $files[0]) {
&::WARN("files[0] ($files[0]) doesn't exist.");
- &::msg($::who, "WARNING: $files[0] does not exist? FIXME");
+ &::msg($::who, "FIXME: $files[0] does not exist?");
return 'NULL';
}
}
my %pkg = &getPackageInfo($package, $file);
+ $query = "info" if ($query eq "dinfo");
+
# 'fm'-like output.
if ($query eq "info") {
- if (scalar keys %pkg > 5) {
- $pkg{'info'} = "\002(\002". $pkg{'desc'} ."\002)\002";
- $pkg{'info'} .= ", section ".$pkg{'section'};
- $pkg{'info'} .= ", is ".$pkg{'priority'};
-# $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
- $pkg{'info'} .= ". Version: \002$pkg{'version'}\002 ($dist)";
- $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
- $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
-
- if ($incoming) {
- &::status("iP: info requested and pkg is in incoming, too.");
- my %incpkg = &getPackageInfo($query, $debian_dir ."/Packages-incoming");
-
- if (scalar keys %incpkg) {
- $pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
- } else {
- &::ERROR("iP: pkg $query is in incoming but we couldn't get any info?");
- }
- }
- } else {
+ if (scalar keys %pkg <= 5) {
&::DEBUG("deb: running debianCheck() due to problems (".scalar(keys %pkg).").");
&debianCheck();
&::DEBUG("deb: end of debianCheck()");
&::msg($::who,"Debian: Package appears to exist but I could not retrieve info about it...");
return;
}
- }
+
+ $pkg{'info'} = "\002(\002". $pkg{'desc'} ."\002)\002";
+ $pkg{'info'} .= ", section ".$pkg{'section'};
+ $pkg{'info'} .= ", is ".$pkg{'priority'};
+# $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
+ $pkg{'info'} .= ". Version: \002$pkg{'version'}\002 ($dist)";
+ $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
+ $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
+
+ if ($incoming) {
+ &::status("iP: info requested and pkg is in incoming, too.");
+ my %incpkg = &getPackageInfo($query, $debian_dir ."/Packages-incoming");
+
+ if (scalar keys %incpkg) {
+ $pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
+ } else {
+ &::ERROR("iP: pkg $query is in incoming but we couldn't get any info?");
+ }
+ }
+ }
if ($dist eq "incoming") {
$pkg{'info'} .= "Version: \002$pkg{'version'}\002";
}
my %stats;
- my %total;
+ my %total = (count => 0, maint => 0, isize => 0, csize => 0);
my $file;
foreach $file (keys %urlpackages) {
$file =~ s/##DIST/$dist/g; # won't work for incoming.
next;
}
- open(IN, "zcat $file 2>&1 |");
+ open(IN, "zcat $debian_dir/$file 2>&1 |");
- if (! -e $file) {
- &::DEBUG("deb: iS: $file does not exist.");
+ if (! -e "$debian_dir/$file") {
+ &::DEBUG("deb: iS: $debian_dir/$file does not exist.");
next;
}
sub searchPackage {
my ($dist, $query) = &getDistroFromStr($_[0]);
- my $file = $debian_dir."/Packages-$dist.idx";
- my @files;
- my $error = 0;
+ my $file = $debian_dir."/Packages-$dist.idx";
my $warn = ($query =~ tr/A-Z/a-z/) ? 1 : 0;
+ my $error = 0;
+ my @files;
&::status("Debian: Search package matching '$query' in '$dist'.");
unlink $file if ( -z $file );
while (defined($file = readdir DEBIAN)) {
next unless ($file =~ /(gz|bz2)$/);
- my $exit = system("gzip -t '$debian_dir/$file'");
+ # TODO: add bzip2 support (debian doesn't do .bz2 anyway)
+ my $exit = system("/bin/gzip -t '$debian_dir/$file'");
next unless ($exit);
&::DEBUG("deb: hmr... => ".(time() - (stat($file))[8])."'.");
next unless (time() - (stat($file))[8] > 3600);