my $defaultdist = "sid";
my $refresh = &::getChanConfDefault("debianRefreshInterval",7)
* 60 * 60 * 24;
-my $debug = 1;
+my $debug = 0;
+my $debian_dir = "$::bot_state_dir/debian";
### ... old
#my %dists = (
);
my %urlcontents = (
- "debian/Contents-##DIST-i386.gz" =>
+ "Contents-##DIST-i386.gz" =>
"ftp://ftp.us.debian.org".
"/debian/dists/##DIST/Contents-i386.gz",
- "debian/Contents-##DIST-i386-non-US.gz" =>
+ "Contents-##DIST-i386-non-US.gz" =>
"ftp://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
);
my %urlpackages = (
- "debian/Packages-##DIST-main-i386.gz" =>
+ "Packages-##DIST-main-i386.gz" =>
"ftp://ftp.us.debian.org".
"/debian/dists/##DIST/main/binary-i386/Packages.gz",
- "debian/Packages-##DIST-contrib-i386.gz" =>
+ "Packages-##DIST-contrib-i386.gz" =>
"ftp://ftp.us.debian.org".
"/debian/dists/##DIST/contrib/binary-i386/Packages.gz",
- "debian/Packages-##DIST-non-free-i386.gz" =>
+ "Packages-##DIST-non-free-i386.gz" =>
"ftp://ftp.us.debian.org".
"/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
- "debian/Packages-##DIST-non-US-main-i386.gz" =>
+ "Packages-##DIST-non-US-main-i386.gz" =>
"ftp://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
- "debian/Packages-##DIST-non-US-contrib-i386.gz" =>
+ "Packages-##DIST-non-US-contrib-i386.gz" =>
"ftp://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
- "debian/Packages-##DIST-non-US-non-free-i386.gz" =>
+ "Packages-##DIST-non-US-non-free-i386.gz" =>
"ftp://non-us.debian.org".
"/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
);
#######################
####
-# Usage: &DebianDownload(%hash);
+# Usage: &DebianDownload($dist, %hash);
sub DebianDownload {
my ($dist, %urls) = @_;
my $bad = 0;
my $good = 0;
- if (! -d "debian/") {
+ if (! -d $debian_dir) {
&::status("Debian: creating debian dir.");
- mkdir("debian/",0755);
+ mkdir($debian_dir, 0755);
}
# fe dists.
$file =~ s/##DIST/$dist/g;
my $update = 0;
- if ( -f $file) {
+ if ( -f $file ) {
my $last_refresh = (stat $file)[9];
$update++ if (time() - $last_refresh > $refresh);
} else {
}
}
+ # ok... lets just run this.
+ &::miscCheck();
+
if ($good) {
&generateIndex($dist);
return 1;
# Usage: &searchContents($query);
sub searchContents {
my ($dist, $query) = &getDistroFromStr($_[0]);
- &::status("Debian: Contents search for '$query' on $dist.");
+ &::status("Debian: Contents search for '$query' in '$dist'.");
my $dccsend = 0;
$dccsend++ if ($query =~ s/^dcc\s+//i);
} else {
my %urls = &fixDist($dist, %urlcontents);
# download contents file.
- &::DEBUG("deb: download 1.");
+ &::DEBUG("deb: download 1.") if ($debug);
if (!&DebianDownload($dist, %urls)) {
&::WARN("Debian: could not download files.");
}
my $grepRE;
### TODO: search properly if /usr/bin/blah is done.
if ($query =~ s/\$$//) {
- &::DEBUG("search-regex found.");
+ &::DEBUG("deb: search-regex found.") if ($debug);
$grepRE = "$query\[ \t]";
} elsif ($query =~ s/^\^//) {
- &::DEBUG("front marker regex found.");
+ &::DEBUG("deb: front marker regex found.") if ($debug);
$front = 1;
$grepRE = $query;
} else {
foreach (keys %urlcontents) {
s/##DIST/$dist/g;
- next unless ( -f $_);
- push(@files,$_);
+ next unless ( -f "$debian_dir/$_" );
+ push(@files, "$debian_dir/$_");
}
if (!scalar @files) {
$regex =~ s/\?/./g;
open(IN,"zegrep -h '$grepRE' $files |");
+ # wonderful abuse of last and next and unless ;)
while (<IN>) {
- if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
- my ($file,$package) = ("/".$1,$2);
- if ($query =~ /[\/\*\\]/) {
- next unless (eval { $file =~ /$regex/ });
- return unless &checkEval($@);
- } else {
- my ($basename) = $file =~ /^.*\/(.*)$/;
- next unless (eval { $basename =~ /$regex/ });
- return unless &checkEval($@);
- }
- next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
- next if ($front and eval { $file !~ /^\/$query/ });
- return unless &checkEval($@);
+ last if ($found > 100);
+
+ next unless if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/);
- $contents{$package}{$file} = 1;
- $found++;
+ my ($file,$package) = ("/".$1,$2);
+ if ($query =~ /[\/\*\\]/) {
+ next unless (eval { $file =~ /$regex/ });
+ return unless &checkEval($@);
+ } else {
+ my ($basename) = $file =~ /^.*\/(.*)$/;
+ next unless (eval { $basename =~ /$regex/ });
+ return unless &checkEval($@);
}
+ next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
+ next if ($front and eval { $file !~ /^\/$query/ });
+ return unless &checkEval($@);
- last if ($found > 100);
+ $contents{$package}{$file} = 1;
+ $found++;
}
close IN;
}
my $file = "$::param{tempDir}/$::who.txt";
- if (!open(OUT,">$file")) {
+ if (!open OUT, ">$file") {
&::ERROR("Debian: cannot write file for dcc send.");
return;
}
&::pSReply( &::formListReply(0, $prefix, @list) );
} else { # !@list.
- &::DEBUG("ok, !\@list, searching desc for '$query'.");
+ &::DEBUG("deb: ok, !\@list, searching desc for '$query'.") if ($debug);
my @list = &searchDesc($query);
if (!scalar @list) {
&::pSReply( &::formListReply(0, $prefix, ) );
} elsif (scalar @list == 1) { # list = 1.
- &::DEBUG("list == 1; showing package info of '$list[0]'.");
+ &::DEBUG("deb: list == 1; showing package info of '$list[0]'.");
&infoPackages("info", $list[0]);
} else { # list > 1.
# Usage: &searchAuthor($query);
sub searchAuthor {
my ($dist, $query) = &getDistroFromStr($_[0]);
- &::DEBUG("searchAuthor: dist => '$dist', query => '$query'.");
+ &::DEBUG("deb: searchAuthor: dist => '$dist', query => '$query'.") if ($debug);
$query =~ s/^\s+|\s+$//g;
# start of search.
foreach (keys %urlpackages) {
s/##DIST/$dist/g;
- if (! -f $_) {
+ if (! -f "$debian_dir/$_" ) {
$bad++;
next;
}
$files .= " ".$_;
}
- &::DEBUG("good = $good, bad = $bad...");
+ &::DEBUG("deb: good = $good, bad = $bad...") if ($debug);
if ($good == 0 and $bad != 0) {
my %urls = &fixDist($dist, %urlpackages);
} elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
my($name,$email) = ($1,$2);
if ($package eq "") {
- &::DEBUG("sA: package == NULL.");
+ &::DEBUG("deb: sA: package == NULL.");
next;
}
$maint{$name}{$email} = 1;
$package = "";
} else {
- &::WARN("invalid line: '$_'.");
+ &::WARN("debian: invalid line: '$_' (1).");
}
}
close IN;
return 1;
}
- &::DEBUG("showing all packages by '$list[0]'...");
+ &::DEBUG("deb: showing all packages by '$list[0]'...") if ($debug);
my @pkg = sort keys %{ $pkg{$list[0]} };
# Usage: &searchDesc($query);
sub searchDesc {
my ($dist, $query) = &getDistroFromStr($_[0]);
- &::DEBUG("searchDesc: dist => '$dist', query => '$query'.");
+ &::DEBUG("deb: searchDesc: dist => '$dist', query => '$query'.") if ($debug);
$query =~ s/^\s+|\s+$//g;
# start of search.
foreach (keys %urlpackages) {
s/##DIST/$dist/g;
- if (! -f $_) {
+ if (! -f "$debian_dir/$_" ) {
$bad++;
next;
}
$good++;
- $files .= " ".$_;
+ $files .= " $debian_dir/$_";
}
- &::DEBUG("good = $good, bad = $bad...");
+ &::DEBUG("deb(2): good = $good, bad = $bad...") if ($debug);
if ($good == 0 and $bad != 0) {
my %urls = &fixDist($dist, %urlpackages);
- &::DEBUG("deb: download 2c.");
+ &::DEBUG("deb: download 2c.") if ($debug);
if (!&DebianDownload($dist, %urls)) {
- &::ERROR("Debian(sD): could not download files.");
+ &::ERROR("deb: sD: could not download files.");
return;
}
}
&::WARN("sD: package == NULL?");
next;
}
+
$desc{$package} = $desc;
$package = "";
+
} else {
- &::WARN("invalid line: '$_'.");
+ &::WARN("debian: invalid line: '$_'. (2)");
}
}
close IN;
####
# Usage: &generateIncoming();
sub generateIncoming {
- my $pkgfile = "debian/Packages-incoming";
+ my $pkgfile = $debian_dir."/Packages-incoming";
my $idxfile = $pkgfile.".idx";
my $stale = 0;
$stale++ if (&::isStale($pkgfile.".gz", $refresh));
$stale++ if (&::isStale($idxfile, $refresh));
- &::DEBUG("gI: stale => '$stale'.");
+ &::DEBUG("deb: gI: stale => '$stale'.") if ($debug);
return 0 unless ($stale);
### STATIC URL.
my %ftp = &::ftpList("llug.sep.bnl.gov", "/pub/debian/Incoming/");
- if (!open(PKG,">$pkgfile")) {
+ if (!open PKG, ">$pkgfile") {
&::ERROR("cannot write to pkg $pkgfile.");
return 0;
}
- if (!open(IDX,">$idxfile")) {
+ if (!open IDX, ">$idxfile") {
&::ERROR("cannot write to idx $idxfile.");
return 0;
}
if ($incoming) {
&::status("iP: info requested and pkg is in incoming, too.");
- my %incpkg = &getPackageInfo($query, "debian/Packages-incoming");
+ my %incpkg = &getPackageInfo($query, $debian_dir ."/Packages-incoming");
if (scalar keys %incpkg) {
$pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
}
}
} else {
- &::DEBUG("running debianCheck() due to problems (".scalar(keys %pkg).").");
+ &::DEBUG("deb: running debianCheck() due to problems (".scalar(keys %pkg).").");
&debianCheck();
- &::DEBUG("end of debianCheck()");
+ &::DEBUG("deb: end of debianCheck()");
&::msg($::who,"Debian: Package appears to exist but I could not retrieve info about it...");
return;
$dist = &getDistro($dist);
return unless (defined $dist);
- &::DEBUG("infoS: dist => '$dist'.");
+ &::DEBUG("deb: infoS: dist => '$dist'.");
# download packages file if needed.
my %urls = &fixDist($dist, %urlpackages);
my $file;
foreach $file (keys %urlpackages) {
$file =~ s/##DIST/$dist/g; # won't work for incoming.
- &::DEBUG("file => '$file'.");
+ &::DEBUG("deb: file => '$file'.");
if (exists $stats{$file}{'count'}) {
- &::DEBUG("hrm... duplicate open with $file???");
+ &::DEBUG("deb: hrm... duplicate open with $file???");
next;
}
- open(IN,"zcat $file 2>&1 |");
+ open(IN, "zcat $file 2>&1 |");
if (! -e $file) {
- &::DEBUG("iS: $file does not exist.");
+ &::DEBUG("deb: iS: $file does not exist.");
next;
}
return;
}
-
-
###
# HELPER FUNCTIONS FOR INFOPACKAGES...
###
# Usage: &generateIndex();
sub generateIndex {
my (@dists) = @_;
- &::status("Debian: !!! generateIndex($dists[0]) called !!!");
+ &::DEBUG("D: 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.");
+ my $idx = $debian_dir."/Packages-$dist.idx";
# TODO: check if any of the Packages file have been updated then
# regenerate it, even if it's not stale.
next unless (&::isStale($idx, $refresh));
if (/^incoming$/i) {
- &::DEBUG("gIndex: calling generateIncoming()!");
+ &::DEBUG("deb: gIndex: calling generateIncoming()!");
&generateIncoming();
next;
}
if (/^woody$/i) {
- &::DEBUG("Copying old index of woody to -old");
+ &::DEBUG("deb: Copying old index of woody to -old");
system("cp $idx $idx-old");
}
- &::DEBUG("gIndeX: calling DebianDownload($dist, ...).");
- &DebianDownload($dist, %urlpackages);
+ &::DEBUG("deb: gIndex: calling DebianDownload($dist, ...).") if ($debug);
+ &DebianDownload($dist, &fixDist($dist, %urlpackages) );
&::status("Debian: generating index for '$dist'.");
- if (!open(OUT,">$idx")) {
+ if (!open OUT, ">$idx") {
&::ERROR("cannot write to $idx.");
return 0;
}
my $packages;
foreach $packages (keys %urlpackages) {
$packages =~ s/##DIST/$dist/;
+ $packages = "$debian_dir/$packages";
if (! -e $packages) {
&::ERROR("gIndex: '$packages' does not exist?");
my $olddist = $dist;
$dist = &getDistro($dist);
- &::DEBUG("D: validPackage($package, $dist) called.") if ($debug);
+ &::DEBUG("deb: validPackage($package, $dist) called.") if ($debug);
my $error = 0;
- while (!open(IN, "debian/Packages-$dist.idx")) {
+ while (!open IN, $debian_dir."/Packages-$dist.idx") {
if ($error) {
&::ERROR("Packages-$dist.idx does not exist (#1).");
return;
sub searchPackage {
my ($dist, $query) = &getDistroFromStr($_[0]);
- my $file = "debian/Packages-$dist.idx";
+ my $file = $debian_dir."/Packages-$dist.idx";
my @files;
my $error = 0;
- my $warn = 0;
-
- if ($query =~ tr/A-Z/a-z/) {
- $warn++;
- }
+ my $warn = ($query =~ tr/A-Z/a-z/) ? 1 : 0;
&::status("Debian: Search package matching '$query' in '$dist'.");
- unlink $file if ( -z $file);
+ unlink $file if ( -z $file );
- while (!open(IN, $file)) {
+ while (!open IN, $file) {
if ($dist eq "incoming") {
- &::DEBUG("sP: dist == incoming; calling gI().");
+ &::DEBUG("deb: sP: dist == incoming; calling gI().");
&generateIncoming();
}
if ($error) {
- &::ERROR("could not generate index ($file)!!!");
+ &::ERROR("could not generate index ($file)!");
return;
}
$error++;
- &::DEBUG("should we be doing this?");
+ &::DEBUG("deb: should we be doing this?");
&generateIndex(($dist));
}
$file = $1;
if (&::isStale($file, $refresh)) {
- &::DEBUG("STALE $file! regen.");
+ &::DEBUG("deb: STALE $file! regen.") if ($debug);
&generateIndex(($dist));
### @files = searchPackage("$query $dist");
- &::DEBUG("EVIL HACK HACK HACK.");
+ &::DEBUG("deb: EVIL HACK HACK HACK.") if ($debug);
last;
}
my $dist = $_[0];
if (!defined $dist or $dist eq "") {
- &::DEBUG("gD: dist == NULL; dist = defaultdist.");
+ &::DEBUG("deb: gD: dist == NULL; dist = defaultdist.");
$dist = $defaultdist;
}
if ($dist =~ /^(slink|hamm|rex|bo)$/i) {
- &::DEBUG("Debian: deprecated version ($dist).");
+ &::DEBUG("deb: deprecated version ($dist).");
&::msg($::who, "Debian: deprecated distribution version.");
return;
}
$key =~ s/##DIST/$dist/;
$val =~ s/##DIST/$dist/;
### TODO: what should we do if the sar wasn't done.
- $new{$key} = $val;
+ $new{$debian_dir."/".$key} = $val;
}
+
return %new;
}
sub DebianFind {
- ### H-H-H-HACK HACK HACK :)
+ # HACK! HACK! HACK!
my ($str) = @_;
my ($dist, $query) = &getDistroFromStr($str);
my @results = sort &searchPackage($str);
}
sub debianCheck {
- my $dir = "debian/";
my $error = 0;
&::status("debianCheck() called.");
### TODO: remove the following loop (check if dir exists before)
while (1) {
- last if (opendir(DEBIAN, $dir));
+ last if (opendir(DEBIAN, $debian_dir));
+
if ($error) {
&::ERROR("dC: cannot opendir debian.");
return;
}
- mkdir $dir, 0755;
+
+ mkdir $debian_dir, 0755;
$error++;
}
while (defined($file = readdir DEBIAN)) {
next unless ($file =~ /(gz|bz2)$/);
- my $exit = system("gzip -t '$dir/$file'");
+ my $exit = system("gzip -t '$debian_dir/$file'");
next unless ($exit);
- &::DEBUG("hmr... => ".(time() - (stat($file))[8])."'.");
+ &::DEBUG("deb: hmr... => ".(time() - (stat($file))[8])."'.");
next unless (time() - (stat($file))[8] > 3600);
- &::DEBUG("dC: exit => '$exit'.");
- &::WARN("dC: '$dir/$file' corrupted? deleting!");
- unlink $dir."/".$file;
+ &::DEBUG("deb: dC: exit => '$exit'.");
+ &::WARN("dC: '$debian_dir/$file' corrupted? deleting!");
+ unlink $debian_dir."/".$file;
$retval++;
}
}
sub searchDescFE {
- &::DEBUG("FE called for searchDesc");
+# &::DEBUG("deb: FE called for searchDesc");
my ($query) = @_;
my @list = &searchDesc($query);
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]'.");
+ &::DEBUG("deb: list == 1; showing package info of '$list[0]'.");
&infoPackages("info", $list[0]);
} else { # list > 1.
my $prefix = "Debian Desc Search of '$query' ";