# format: "alias=real".
my $announce = 0;
-my $defaultdist = "unstable";
+my $defaultdist = "sid";
my $refresh = &::getChanConfDefault("debianRefreshInterval",7)
* 60 * 60 * 24;
+my $debug = 1;
+### ... old
+#my %dists = (
+# "sid" => "unstable",
+# "woody" => "testing", # new since 20001219.
+# "potato" => "stable",
+# "incoming" => "incoming",
+#);
+
+### new... the right way.
my %dists = (
"unstable" => "sid",
"testing" => "woody", # new since 20001219.
"stable" => "potato",
"incoming" => "incoming",
-### the following don't work. too much effort to get 3 types of distros
-### to work harmoniously :-)
- "slink" => "archive-2.1",
- "hamm" => "archive-2.0",
- "rex" => "archive-1.?",
- "bo" => "archive-1.?",
);
my %urlcontents = (
"debian/Contents-##DIST-i386.gz" =>
"ftp://ftp.us.debian.org".
"/debian/dists/##DIST/Contents-i386.gz",
-### APPEARS TO BE FIXED?
-# => strip control chars just to be safe.
"debian/Contents-##DIST-i386-non-US.gz" =>
"ftp://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
# fe dists.
# Download the files.
my $file;
-## my %ret;
foreach $file (keys %urls) {
my $url = $urls{$file};
$url =~ s/##DIST/$dist/g;
my $update = 0;
if ( -f $file) {
- my $last_refresh = (stat($file))[9];
+ my $last_refresh = (stat $file)[9];
$update++ if (time() - $last_refresh > $refresh);
} else {
$update++;
next unless ($update);
- &::DEBUG("announce == $announce.");
+ &::DEBUG("announce == $announce.") if ($debug);
if ($good + $bad == 0 and !$announce) {
&::status("Debian: Downloading files for '$dist'.");
&::msg($::who, "Updating debian files... please wait.");
}
if (exists $::debian{$url}) {
- &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh");
+ &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh") if ($debug);
next if (time() - $::debian{$url} <= $refresh);
- &::DEBUG("stale for url $url; updating!");
+ &::DEBUG("stale for url $url; updating!") if ($debug);
}
if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
my ($host,$path,$thisfile) = ($1,$2,$3);
- # error internally to ftp.
- # hope it doesn't do anything bad.
- if ($file =~ /Contents-woody-i386-non-US/) {
- &::DEBUG("Skipping Contents-woody-i386-non-US.");
+### 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;
- }
+# next;
+# }
if (!&::ftpGet($host,$path,$thisfile,$file)) {
&::WARN("deb: down: $file == BAD.");
}
if (! -f $file) {
- &::DEBUG("deb: down: ftpGet: !file");
+ &::WARN("deb: down: ftpGet: !file");
$bad++;
next;
}
- 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");
- }
+### 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");
+# }
- &::DEBUG("deb: download: good.");
-## $ret{$
+ &::DEBUG("deb: download: good.") if ($debug);
$good++;
} else {
&::ERROR("Debian: invalid format of url => ($url).");
my $dccsend = 0;
$dccsend++ if ($query =~ s/^dcc\s+//i);
- ### larne's regex.
- # $query = $query.'(\.so\.)?([.[[:digit:]]+\.]+)?$';
$query =~ s/\\([\^\$])/$1/g; # hrm?
$query =~ s/^\s+|\s+$//g;
# start of search.
my $start_time = &::timeget();
- my $found = 0;
+ my $found = 0;
+ my $front = 0;
my %contents;
my $grepRE;
- my $front = 0;
### TODO: search properly if /usr/bin/blah is done.
if ($query =~ s/\$$//) {
&::DEBUG("search-regex found.");
$grepRE = "$query*\[ \t]";
}
- ### fix up grepRE for "*".
+ # fix up grepRE for "*".
$grepRE =~ s/\*/.*/g;
my @files;
my $files = join(' ', @files);
+ my $regex = $query;
+ $regex =~ s/\./\\./g;
+ $regex =~ s/\*/\\S*/g;
+ $regex =~ s/\?/./g;
+
open(IN,"zegrep -h '$grepRE' $files |");
while (<IN>) {
if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
my ($file,$package) = ("/".$1,$2);
- if ($query =~ /\//) {
- next unless ($file =~ /\Q$query\E/);
+ if ($query =~ /[\/\*\\]/) {
+ next unless (eval { $file =~ /$regex/ });
+ return unless &checkEval($@);
} else {
my ($basename) = $file =~ /^.*\/(.*)$/;
- next unless ($basename =~ /\Q$query\E/);
+ next unless (eval { $basename =~ /$regex/ });
+ return unless &checkEval($@);
}
next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
- next if ($front and $file !~ /^\/\Q$query\E/);
+ next if ($front and eval { $file !~ /^\/$query/ });
+ return unless &checkEval($@);
$contents{$package}{$file} = 1;
$found++;
}
foreach $pkg (keys %contents) {
- foreach (keys %{$contents{$pkg}}) {
+ foreach (keys %{ $contents{$pkg} }) {
# TODO: correct padding.
print OUT "$_\t\t\t$pkg\n";
}
my @list;
foreach $pkg (keys %contents) {
- my @tmplist = &::fixFileList(keys %{$contents{$pkg}});
+ my @tmplist = &::fixFileList(keys %{ $contents{$pkg} });
my @sublist = sort { length $a <=> length $b } @tmplist;
pop @sublist while (scalar @sublist > 3);
my $prefix = "Debian Search of '$query' ";
if (scalar @list) { # @list.
&::pSReply( &::formListReply(0, $prefix, @list) );
+
} else { # !@list.
&::DEBUG("ok, !\@list, searching desc for '$query'.");
- &searchDesc($query);
+ my @list = &searchDesc($query);
+
+ if (!scalar @list) {
+ my $prefix = "Debian Package/File/Desc Search of '$query' ";
+ &::pSReply( &::formListReply(0, $prefix, ) );
+
+ } elsif (scalar @list == 1) { # list = 1.
+ &::DEBUG("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) );
+ }
}
}
if ($good == 0 and $bad != 0) {
my %urls = &fixDist($dist, %urlpackages);
&::DEBUG("deb: download 2.");
+
if (!&DebianDownload($dist, %urls)) {
&::ERROR("Debian(sA): could not download files.");
return;
while (<IN>) {
if (/^Package: (\S+)$/) {
$package = $1;
+
} elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
my($name,$email) = ($1,$2);
if ($package eq "") {
$maint{$name}{$email} = 1;
$pkg{$name}{$package} = 1;
$package = "";
+
} else {
&::WARN("invalid line: '$_'.");
}
# TODO: should we only search email if '@' is used?
if (scalar keys %hash < 15) {
my $name;
+
foreach $name (keys %maint) {
my $email;
- foreach $email (keys %{$maint{$name}}) {
+
+ foreach $email (keys %{ $maint{$name} }) {
next unless ($email =~ /\Q$query\E/i);
next if (exists $hash{$name});
$hash{$name} = 1;
&::DEBUG("showing all packages by '$list[0]'...");
- my @pkg = sort keys %{$pkg{$list[0]}};
+ my @pkg = sort keys %{ $pkg{$list[0]} };
# show how long it took.
my $delta_time = &::timedelta($start_time);
&::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
- my $email = join(', ', keys %{$maint{$list[0]}});
+ my $email = join(', ', keys %{ $maint{$list[0]} });
my $prefix = "Debian Packages by $list[0] \002<\002$email\002>\002 ";
&::pSReply( &::formListReply(0, $prefix, @pkg) );
}
if ($good == 0 and $bad != 0) {
my %urls = &fixDist($dist, %urlpackages);
&::DEBUG("deb: download 2c.");
+
if (!&DebianDownload($dist, %urls)) {
&::ERROR("Debian(sD): could not download files.");
return;
}
}
+ my $regex = $query;
+ $regex =~ s/\./\\./g;
+ $regex =~ s/\*/\\S*/g;
+ $regex =~ s/\?/./g;
+
my (%desc, $package);
open(IN,"zegrep -h '^Package|^Description' $files |");
- $query =~ s/\*/\\S*/g; # regex.
while (<IN>) {
if (/^Package: (\S+)$/) {
$package = $1;
} elsif (/^Description: (.*)$/) {
my $desc = $1;
- next unless ($desc =~ /\Q$query\E/i);
+ next unless (eval { $desc =~ /$regex/i });
+ return unless &checkEval($@);
+
if ($package eq "") {
&::WARN("sD: package == NULL?");
next;
}
close IN;
- my @list = keys %desc;
- if (!scalar @list) {
- my $prefix = "Debian Desc Search of '$query' ";
- &::pSReply( &::formListReply(0, $prefix, ) );
- } elsif (scalar @list == 1) { # list = 1.
- &::DEBUG("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) );
- }
-
# show how long it took.
my $delta_time = &::timedelta($start_time);
&::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
+
+ return keys %desc;
}
####
# hrm...
my %urls = &fixDist($dist, %urlpackages);
if ($dist ne "incoming") {
- &::DEBUG("deb: download 3.");
+ &::DEBUG("deb: download 3.") if ($debug);
+
if (!&DebianDownload($dist, %urls)) { # no good download.
&::WARN("Debian(iP): could not download ANY files.");
}
$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";
+ $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";
&::pSReply(
"Debian Distro Stats on $dist... ".
"\002$total{'count'}\002 packages, ".
- "\002".scalar(keys %{$total{'maint'}})."\002 maintainers, ".
+ "\002".scalar(keys %{ $total{'maint'} })."\002 maintainers, ".
"\002". int($total{'isize'}/1024)."\002 MB installed size, ".
"\002". int($total{'csize'}/1024/1024)."\002 MB compressed size."
);
### TODO: do individual stats? if so, we need _another_ arg.
# foreach $file (keys %stats) {
-# foreach (keys %{$stats{$file}}) {
+# foreach (keys %{ $stats{$file} }) {
# &::DEBUG(" '$file' '$_' '$stats{$file}{$_}'.");
# }
# }
# Usage: &generateIndex();
sub generateIndex {
my (@dists) = @_;
- &::status("Debian: !!! generateIndex() called !!!");
+ &::status("Debian: !!! generateIndex($dists[0]) called !!!");
if (!scalar @dists or $dists[0] eq '') {
&::ERROR("gI: no dists to generate index.");
return 1;
foreach (@dists) {
my $dist = &getDistro($_); # incase the alias is returned, possible?
my $idx = "debian/Packages-$dist.idx";
+ &::DEBUG("gI: dist => $dist.");
+ &::DEBUG("gI: idx => $idx.");
+ &::DEBUG("gI: r => $refresh.");
# TODO: check if any of the Packages file have been updated then
# regenerate it, even if it's not stale.
# TODO: also, regenerate the index if the packages file is newer
# than the index.
- next unless (&::isStale($idx, $::param{'debianRefreshInterval'}));
+ next unless (&::isStale($idx, $refresh));
+
if (/^incoming$/i) {
&::DEBUG("gIndex: calling generateIncoming()!");
&generateIncoming();
my @files;
my $file;
- &::DEBUG("D: validPackage($package, $dist) called.");
+ ### this majorly sucks, we need some standard in place.
+ # why is this needed... need to investigate later.
+ my $olddist = $dist;
+ $dist = &getDistro($dist);
+
+ &::DEBUG("D: validPackage($package, $dist) called.") if ($debug);
my $error = 0;
while (!open(IN, "debian/Packages-$dist.idx")) {
}
close IN;
- &::DEBUG("vP: scanned $count items in index.");
+ &::VERB("vP: scanned $count items in index.",2);
return @files;
}
}
if ($error) {
- &::ERROR("could not generate index!!!");
+ &::ERROR("could not generate index ($file)!!!");
return;
}
if (/^\*(.*)$/) {
$file = $1;
- if (&::isStale($file, $::param{'debianRefreshInterval'})) {
+ if (&::isStale($file, $refresh)) {
&::DEBUG("STALE $file! regen.");
&generateIndex(($dist));
### @files = searchPackage("$query $dist");
}
if (exists $dists{$dist}) {
+ &::VERB("gD: returning dists{$dist} ($dists{$dist})",2);
return $dists{$dist};
+
} else {
if (!grep /^\Q$dist\E$/i, %dists) {
&::msg($::who, "invalid dist '$dist'.");
return;
}
+ &::VERB("gD: returning $dist (no change or conversion)",2);
return $dist;
}
}
&::status("searchPackage returned one result; getting info of package instead!");
&::Forker("debian", sub { &infoPackages("info", "$results[0] $dist"); } );
} else {
- my $prefix = "Debian Package Listing of '$str' ";
+ my $prefix = "Debian Package Listing of '$query' ";
&::pSReply( &::formListReply(0, $prefix, @results) );
}
}
return $retval;
}
+sub checkEval {
+ my($str) = @_;
+
+ if ($str) {
+ &::WARN("cE: $str");
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+sub searchDescFE {
+ &::DEBUG("FE called for searchDesc");
+ my ($query) = @_;
+ my @list = &searchDesc($query);
+
+ if (!scalar @list) {
+ my $prefix = "Debian Desc Search of '$query' ";
+ &::pSReply( &::formListReply(0, $prefix, ) );
+ } elsif (scalar @list == 1) { # list = 1.
+ &::DEBUG("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) );
+ }
+}
+
1;