2 # Debian.pl: Frontend to debian contents and packages files
4 # Version: v0.8 (20000918)
12 # format: "alias=real".
14 my $defaultdist = "unstable";
15 my $refresh = &::getChanConfDefault("debianRefreshInterval",7)
20 "woody" => "testing", # new since 20001219.
22 "incoming" => "incoming",
26 "debian/Contents-##DIST-i386.gz" =>
27 "ftp://ftp.us.debian.org".
28 "/debian/dists/##DIST/Contents-i386.gz",
29 "debian/Contents-##DIST-i386-non-US.gz" =>
30 "ftp://non-us.debian.org".
31 "/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
35 "debian/Packages-##DIST-main-i386.gz" =>
36 "ftp://ftp.us.debian.org".
37 "/debian/dists/##DIST/main/binary-i386/Packages.gz",
38 "debian/Packages-##DIST-contrib-i386.gz" =>
39 "ftp://ftp.us.debian.org".
40 "/debian/dists/##DIST/contrib/binary-i386/Packages.gz",
41 "debian/Packages-##DIST-non-free-i386.gz" =>
42 "ftp://ftp.us.debian.org".
43 "/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
45 "debian/Packages-##DIST-non-US-main-i386.gz" =>
46 "ftp://non-us.debian.org".
47 "/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
48 "debian/Packages-##DIST-non-US-contrib-i386.gz" =>
49 "ftp://non-us.debian.org".
50 "/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
51 "debian/Packages-##DIST-non-US-non-free-i386.gz" =>
52 "ftp://non-us.debian.org".
53 "/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
57 ### COMMON FUNCTION....
58 #######################
61 # Usage: &DebianDownload(%hash);
63 my ($dist, %urls) = @_;
68 &::status("Debian: creating debian dir.");
69 mkdir("debian/",0755);
75 foreach $file (keys %urls) {
76 my $url = $urls{$file};
77 $url =~ s/##DIST/$dist/g;
78 $file =~ s/##DIST/$dist/g;
82 my $last_refresh = (stat $file)[9];
83 $update++ if (time() - $last_refresh > $refresh);
88 next unless ($update);
90 &::DEBUG("announce == $announce.");
91 if ($good + $bad == 0 and !$announce) {
92 &::status("Debian: Downloading files for '$dist'.");
93 &::msg($::who, "Updating debian files... please wait.");
97 if (exists $::debian{$url}) {
98 &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh");
99 next if (time() - $::debian{$url} <= $refresh);
100 &::DEBUG("stale for url $url; updating!");
103 if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
104 my ($host,$path,$thisfile) = ($1,$2,$3);
107 # if ($file =~ /Contents-woody-i386-non-US/) {
108 # &::DEBUG("Skipping Contents-woody-i386-non-US.");
109 # $file =~ s/woody/potato/;
110 # $path =~ s/woody/potato/;
114 if (!&::ftpGet($host,$path,$thisfile,$file)) {
115 &::WARN("deb: down: $file == BAD.");
121 &::DEBUG("deb: down: ftpGet: !file");
127 # if ($file =~ /Contents-potato-i386-non-US/) {
128 # &::DEBUG("hack: using potato's non-US contents for woody.");
129 # system("cp debian/Contents-potato-i386-non-US.gz debian/Contents-woody-i386-non-US.gz");
132 &::DEBUG("deb: download: good.");
135 &::ERROR("Debian: invalid format of url => ($url).");
142 &generateIndex($dist);
145 return -1 unless ($bad); # no download.
146 &::DEBUG("DD: !good and bad($bad). :(");
151 ###########################
152 # DEBIAN CONTENTS SEARCH FUNCTIONS.
156 # Usage: &searchContents($query);
158 my ($dist, $query) = &getDistroFromStr($_[0]);
159 &::status("Debian: Contents search for '$query' on $dist.");
162 $dccsend++ if ($query =~ s/^dcc\s+//i);
164 $query =~ s/\\([\^\$])/$1/g; # hrm?
165 $query =~ s/^\s+|\s+$//g;
167 if (!&::validExec($query)) {
168 &::msg($::who, "search string looks fuzzy.");
172 if ($dist eq "incoming") { # nothing yet.
173 &::DEBUG("sC: dist = 'incoming'. no contents yet.");
176 my %urls = &fixDist($dist, %urlcontents);
177 # download contents file.
178 &::DEBUG("deb: download 1.");
179 if (!&DebianDownload($dist, %urls)) {
180 &::WARN("Debian: could not download files.");
185 my $start_time = &::timeget();
191 ### TODO: search properly if /usr/bin/blah is done.
192 if ($query =~ s/\$$//) {
193 &::DEBUG("search-regex found.");
194 $grepRE = "$query\[ \t]";
195 } elsif ($query =~ s/^\^//) {
196 &::DEBUG("front marker regex found.");
200 $grepRE = "$query*\[ \t]";
203 # fix up grepRE for "*".
204 $grepRE =~ s/\*/.*/g;
207 foreach (keys %urlcontents) {
210 next unless ( -f $_);
214 if (!scalar @files) {
215 &::ERROR("sC: no files?");
216 &::msg($::who, "failed.");
220 my $files = join(' ', @files);
223 $regex =~ s/\./\\./g;
224 $regex =~ s/\*/\\S*/g;
227 open(IN,"zegrep -h '$grepRE' $files |");
229 if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
230 my ($file,$package) = ("/".$1,$2);
231 if ($query =~ /[\/\*\\]/) {
232 next unless (eval { $file =~ /$regex/ });
233 return unless &checkEval($@);
235 my ($basename) = $file =~ /^.*\/(.*)$/;
236 next unless (eval { $basename =~ /$regex/ });
237 return unless &checkEval($@);
239 next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
240 next if ($front and eval { $file !~ /^\/$query/ });
241 return unless &checkEval($@);
243 $contents{$package}{$file} = 1;
247 last if ($found > 100);
253 ### send results with dcc.
255 if (exists $::dcc{'SEND'}{$::who}) {
256 &::msg($::who, "DCC already active!");
260 if (!scalar %contents) {
261 &::msg($::who,"search returned no results.");
265 my $file = "$::param{tempDir}/$::who.txt";
266 if (!open(OUT,">$file")) {
267 &::ERROR("Debian: cannot write file for dcc send.");
271 foreach $pkg (keys %contents) {
272 foreach (keys %{$contents{$pkg}}) {
273 # TODO: correct padding.
274 print OUT "$_\t\t\t$pkg\n";
279 &::shmWrite($::shm, "DCC SEND $::who $file");
284 &::status("Debian: $found contents results found.");
287 foreach $pkg (keys %contents) {
288 my @tmplist = &::fixFileList(keys %{$contents{$pkg}});
289 my @sublist = sort { length $a <=> length $b } @tmplist;
291 pop @sublist while (scalar @sublist > 3);
293 $pkg =~ s/\,/\037\,\037/g; # underline ','.
294 push(@list, "(". join(', ',@sublist) .") in $pkg");
296 # sort the total list from shortest to longest...
297 @list = sort { length $a <=> length $b } @list;
299 # show how long it took.
300 my $delta_time = &::timedelta($start_time);
301 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
303 my $prefix = "Debian Search of '$query' ";
304 if (scalar @list) { # @list.
305 &::pSReply( &::formListReply(0, $prefix, @list) );
307 &::DEBUG("ok, !\@list, searching desc for '$query'.");
308 my @list = &searchDesc($query);
311 my $prefix = "Debian Package/File/Desc Search of '$query' ";
312 &::pSReply( &::formListReply(0, $prefix, ) );
313 } elsif (scalar @list == 1) { # list = 1.
314 &::DEBUG("list == 1; showing package info of '$list[0]'.");
315 &infoPackages("info", $list[0]);
317 my $prefix = "Debian Desc Search of '$query' ";
318 &::pSReply( &::formListReply(0, $prefix, @list) );
324 # Usage: &searchAuthor($query);
326 my ($dist, $query) = &getDistroFromStr($_[0]);
327 &::DEBUG("searchAuthor: dist => '$dist', query => '$query'.");
328 $query =~ s/^\s+|\s+$//g;
331 my $start_time = &::timeget();
332 &::status("Debian: starting author search.");
335 my ($bad,$good) = (0,0);
336 my %urls = %urlpackages;
338 foreach (keys %urlpackages) {
350 &::DEBUG("good = $good, bad = $bad...");
352 if ($good == 0 and $bad != 0) {
353 my %urls = &fixDist($dist, %urlpackages);
354 &::DEBUG("deb: download 2.");
355 if (!&DebianDownload($dist, %urls)) {
356 &::ERROR("Debian(sA): could not download files.");
361 my (%maint, %pkg, $package);
362 open(IN,"zegrep -h '^Package|^Maintainer' $files |");
364 if (/^Package: (\S+)$/) {
366 } elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
367 my($name,$email) = ($1,$2);
368 if ($package eq "") {
369 &::DEBUG("sA: package == NULL.");
372 $maint{$name}{$email} = 1;
373 $pkg{$name}{$package} = 1;
376 &::WARN("invalid line: '$_'.");
382 # TODO: can we use 'map' here?
383 foreach (grep /\Q$query\E/i, keys %maint) {
387 # TODO: should we only search email if '@' is used?
388 if (scalar keys %hash < 15) {
390 foreach $name (keys %maint) {
392 foreach $email (keys %{$maint{$name}}) {
393 next unless ($email =~ /\Q$query\E/i);
394 next if (exists $hash{$name});
400 my @list = keys %hash;
401 if (scalar @list != 1) {
402 my $prefix = "Debian Author Search of '$query' ";
403 &::pSReply( &::formListReply(0, $prefix, @list) );
407 &::DEBUG("showing all packages by '$list[0]'...");
409 my @pkg = sort keys %{$pkg{$list[0]}};
411 # show how long it took.
412 my $delta_time = &::timedelta($start_time);
413 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
415 my $email = join(', ', keys %{$maint{$list[0]}});
416 my $prefix = "Debian Packages by $list[0] \002<\002$email\002>\002 ";
417 &::pSReply( &::formListReply(0, $prefix, @pkg) );
421 # Usage: &searchDesc($query);
423 my ($dist, $query) = &getDistroFromStr($_[0]);
424 &::DEBUG("searchDesc: dist => '$dist', query => '$query'.");
425 $query =~ s/^\s+|\s+$//g;
428 my $start_time = &::timeget();
429 &::status("Debian: starting desc search.");
432 my ($bad,$good) = (0,0);
433 my %urls = %urlpackages;
435 foreach (keys %urlpackages) {
447 &::DEBUG("good = $good, bad = $bad...");
449 if ($good == 0 and $bad != 0) {
450 my %urls = &fixDist($dist, %urlpackages);
451 &::DEBUG("deb: download 2c.");
452 if (!&DebianDownload($dist, %urls)) {
453 &::ERROR("Debian(sD): could not download files.");
459 $regex =~ s/\./\\./g;
460 $regex =~ s/\*/\\S*/g;
463 my (%desc, $package);
464 open(IN,"zegrep -h '^Package|^Description' $files |");
466 if (/^Package: (\S+)$/) {
468 } elsif (/^Description: (.*)$/) {
470 next unless (eval { $desc =~ /$regex/i });
471 return unless &checkEval($@);
473 if ($package eq "") {
474 &::WARN("sD: package == NULL?");
477 $desc{$package} = $desc;
480 &::WARN("invalid line: '$_'.");
485 # show how long it took.
486 my $delta_time = &::timedelta($start_time);
487 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
493 # Usage: &generateIncoming();
494 sub generateIncoming {
495 my $pkgfile = "debian/Packages-incoming";
496 my $idxfile = $pkgfile.".idx";
498 $stale++ if (&::isStale($pkgfile.".gz", $refresh));
499 $stale++ if (&::isStale($idxfile, $refresh));
500 &::DEBUG("gI: stale => '$stale'.");
501 return 0 unless ($stale);
504 my %ftp = &::ftpList("llug.sep.bnl.gov", "/pub/debian/Incoming/");
506 if (!open(PKG,">$pkgfile")) {
507 &::ERROR("cannot write to pkg $pkgfile.");
510 if (!open(IDX,">$idxfile")) {
511 &::ERROR("cannot write to idx $idxfile.");
515 print IDX "*$pkgfile.gz\n";
517 foreach $file (sort keys %ftp) {
518 next unless ($file =~ /deb$/);
520 if ($file =~ /^(\S+)\_(\S+)\_(\S+)\.deb$/) {
522 print PKG "Package: $1\n";
523 print PKG "Version: $2\n";
524 print PKG "Architecture: ", (defined $4) ? $4 : "all", "\n";
526 print PKG "Filename: $file\n";
527 print PKG "Size: $ftp{$file}\n";
533 system("gzip -9fv $pkgfile"); # lame fix.
535 &::status("Debian: generateIncoming() complete.");
539 ##############################
540 # DEBIAN PACKAGE INFO FUNCTIONS.
543 # Usage: &getPackageInfo($query,$file);
545 my ($package, $file) = @_;
548 &::status("gPI: file $file does not exist?");
555 open(IN, "zcat $file 2>&1 |");
561 next if (/^ \S+/); # package long description.
564 if (/^Package: (.*)\n$/) {
566 if ($pkg =~ /^$package$/i) {
567 $found++; # we can use pkg{'package'} instead.
568 $pkg{'package'} = $pkg;
577 if (/^Version: (.*)$/) {
578 $pkg{'version'} = $1;
579 } elsif (/^Priority: (.*)$/) {
580 $pkg{'priority'} = $1;
581 } elsif (/^Section: (.*)$/) {
582 $pkg{'section'} = $1;
583 } elsif (/^Size: (.*)$/) {
585 } elsif (/^Installed-Size: (.*)$/i) {
586 $pkg{'installed'} = $1;
587 } elsif (/^Description: (.*)$/) {
589 } elsif (/^Filename: (.*)$/) {
591 } elsif (/^Pre-Depends: (.*)$/) {
592 $pkg{'depends'} = "pre-depends on $1";
593 } elsif (/^Depends: (.*)$/) {
594 if (exists $pkg{'depends'}) {
595 $pkg{'depends'} .= "; depends on $1";
597 $pkg{'depends'} = "depends on $1";
599 } elsif (/^Maintainer: (.*)$/) {
601 } elsif (/^Provides: (.*)$/) {
602 $pkg{'provides'} = $1;
603 } elsif (/^Suggests: (.*)$/) {
604 $pkg{'suggests'} = $1;
605 } elsif (/^Conflicts: (.*)$/) {
606 $pkg{'conflicts'} = $1;
609 ### &::DEBUG("=> '$_'.");
619 next if (defined $pkg);
627 # Usage: &infoPackages($query,$package);
629 my ($query,$dist,$package) = ($_[0], &getDistroFromStr($_[1]));
631 &::status("Debian: Searching for package '$package' in '$dist'.");
633 # download packages file.
635 my %urls = &fixDist($dist, %urlpackages);
636 if ($dist ne "incoming") {
637 &::DEBUG("deb: download 3.");
638 if (!&DebianDownload($dist, %urls)) { # no good download.
639 &::WARN("Debian(iP): could not download ANY files.");
643 # check if the package is valid.
645 my @files = &validPackage($package, $dist);
646 if (!scalar @files) {
647 &::status("Debian: no valid package found; checking incoming.");
648 @files = &validPackage($package, "incoming");
650 &::status("Debian: cool, it exists in incoming.");
653 &::msg($::who, "Package '$package' does not exist.");
658 if (scalar @files > 1) {
659 &::WARN("same package in more than one file; random.");
660 &::DEBUG("THIS SHOULD BE FIXED SOMEHOW!!!");
661 $files[0] = &::getRandom(@files);
664 if (! -f $files[0]) {
665 &::WARN("files[0] ($files[0]) doesn't exist.");
666 &::msg($::who, "WARNING: $files[0] does not exist? FIXME");
670 ### TODO: if specific package is requested, note down that a version
671 ### exists in incoming.
674 my $file = $files[0];
677 ### TODO: use fe, dump to a hash. if only one version of the package
678 ### exists. do as normal otherwise list all versions.
680 &::ERROR("D:iP: file '$file' DOES NOT EXIST!!! should never happen.");
683 my %pkg = &getPackageInfo($package, $file);
686 if ($query eq "info") {
687 if (scalar keys %pkg > 5) {
688 $pkg{'info'} = "\002(\002". $pkg{'desc'} ."\002)\002";
689 $pkg{'info'} .= ", section ".$pkg{'section'};
690 $pkg{'info'} .= ", is ".$pkg{'priority'};
691 $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
692 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
693 $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
696 &::status("iP: info requested and pkg is in incoming, too.");
697 my %incpkg = &getPackageInfo($query, "debian/Packages-incoming");
699 if (scalar keys %incpkg) {
700 $pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
702 &::ERROR("iP: pkg $query is in incoming but we couldn't get any info?");
706 &::DEBUG("running debianCheck() due to problems (".scalar(keys %pkg).").");
708 &::DEBUG("end of debianCheck()");
710 &::msg($::who,"Debian: Package appears to exist but I could not retrieve info about it...");
715 if ($dist eq "incoming") {
716 $pkg{'info'} .= "Version: \002$pkg{'version'}\002";
717 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
718 $pkg{'info'} .= ", is in incoming!!!";
721 if (!exists $pkg{$query}) {
722 if ($query eq "suggests") {
723 $pkg{$query} = "has no suggestions";
724 } elsif ($query eq "conflicts") {
725 $pkg{$query} = "does not conflict with any other package";
726 } elsif ($query eq "depends") {
727 $pkg{$query} = "does not depend on anything";
728 } elsif ($query eq "maint") {
729 $pkg{$query} = "has no maintainer";
731 $pkg{$query} = "has nothing about $query";
735 &::pSReply("$package: $pkg{$query}");
738 # Usage: &infoStats($dist);
741 $dist = &getDistro($dist);
742 return unless (defined $dist);
744 &::DEBUG("infoS: dist => '$dist'.");
746 # download packages file if needed.
747 my %urls = &fixDist($dist, %urlpackages);
748 &::DEBUG("deb: download 4.");
749 if (!&DebianDownload($dist, %urls)) {
750 &::WARN("Debian(iS): could not download ANY files.");
751 &::msg($::who, "Debian(iS): internal error.");
758 foreach $file (keys %urlpackages) {
759 $file =~ s/##DIST/$dist/g; # won't work for incoming.
760 &::DEBUG("file => '$file'.");
761 if (exists $stats{$file}{'count'}) {
762 &::DEBUG("hrm... duplicate open with $file???");
766 open(IN,"zcat $file 2>&1 |");
769 &::DEBUG("iS: $file does not exist.");
776 next if (/^ \S+/); # package long description.
778 if (/^Package: (.*)\n$/) { # counter.
779 $stats{$file}{'count'}++;
781 } elsif (/^Maintainer: .* <(\S+)>$/) {
782 $stats{$file}{'maint'}{$1}++;
783 $total{'maint'}{$1}++;
784 } elsif (/^Size: (.*)$/) { # compressed size.
785 $stats{$file}{'csize'} += $1;
786 $total{'csize'} += $1;
787 } elsif (/^i.*size: (.*)$/i) { # installed size.
788 $stats{$file}{'isize'} += $1;
789 $total{'isize'} += $1;
792 ### &::DEBUG("=> '$_'.");
797 ### TODO: don't count ppl with multiple email addresses.
800 "Debian Distro Stats on $dist... ".
801 "\002$total{'count'}\002 packages, ".
802 "\002".scalar(keys %{$total{'maint'}})."\002 maintainers, ".
803 "\002". int($total{'isize'}/1024)."\002 MB installed size, ".
804 "\002". int($total{'csize'}/1024/1024)."\002 MB compressed size."
807 ### TODO: do individual stats? if so, we need _another_ arg.
808 # foreach $file (keys %stats) {
809 # foreach (keys %{$stats{$file}}) {
810 # &::DEBUG(" '$file' '$_' '$stats{$file}{$_}'.");
820 # HELPER FUNCTIONS FOR INFOPACKAGES...
823 # Usage: &generateIndex();
826 &::status("Debian: !!! generateIndex($dists[0]) called !!!");
827 if (!scalar @dists or $dists[0] eq '') {
828 &::ERROR("gI: no dists to generate index.");
833 my $dist = &getDistro($_); # incase the alias is returned, possible?
834 my $idx = "debian/Packages-$dist.idx";
835 &::DEBUG("gI: dist => $dist.");
836 &::DEBUG("gI: idx => $idx.");
837 &::DEBUG("gI: r => $refresh.");
839 # TODO: check if any of the Packages file have been updated then
840 # regenerate it, even if it's not stale.
841 # TODO: also, regenerate the index if the packages file is newer
843 next unless (&::isStale($idx, $refresh));
846 &::DEBUG("gIndex: calling generateIncoming()!");
852 &::DEBUG("Copying old index of woody to -old");
853 system("cp $idx $idx-old");
856 &::DEBUG("gIndeX: calling DebianDownload($dist, ...).");
857 &DebianDownload($dist, %urlpackages);
859 &::status("Debian: generating index for '$dist'.");
860 if (!open(OUT,">$idx")) {
861 &::ERROR("cannot write to $idx.");
866 foreach $packages (keys %urlpackages) {
867 $packages =~ s/##DIST/$dist/;
869 if (! -e $packages) {
870 &::ERROR("gIndex: '$packages' does not exist?");
874 print OUT "*$packages\n";
875 open(IN,"zcat $packages |");
878 next unless (/^Package: (.*)\n$/);
889 # Usage: &validPackage($package, $dist);
891 my ($package,$dist) = @_;
895 ### this majorly sucks, we need some standard in place.
896 # why is this needed... need to investigate later.
898 $dist = &getDistro($dist);
900 &::DEBUG("D: validPackage($package, $dist) called.");
903 while (!open(IN, "debian/Packages-$dist.idx")) {
905 &::ERROR("Packages-$dist.idx does not exist (#1).");
909 &generateIndex($dist);
921 if (/^\Q$package\E\n$/) {
928 &::DEBUG("vP: scanned $count items in index.");
934 my ($dist, $query) = &getDistroFromStr($_[0]);
935 my $file = "debian/Packages-$dist.idx";
940 if ($query =~ tr/A-Z/a-z/) {
944 &::status("Debian: Search package matching '$query' in '$dist'.");
945 unlink $file if ( -z $file);
947 while (!open(IN, $file)) {
948 if ($dist eq "incoming") {
949 &::DEBUG("sP: dist == incoming; calling gI().");
954 &::ERROR("could not generate index ($file)!!!");
959 &::DEBUG("should we be doing this?");
960 &generateIndex(($dist));
969 if (&::isStale($file, $refresh)) {
970 &::DEBUG("STALE $file! regen.");
971 &generateIndex(($dist));
972 ### @files = searchPackage("$query $dist");
973 &::DEBUG("EVIL HACK HACK HACK.");
986 if (scalar @files and $warn) {
987 &::msg($::who, "searching for package name should be fully lowercase!");
996 if (!defined $dist or $dist eq "") {
997 &::DEBUG("gD: dist == NULL; dist = defaultdist.");
998 $dist = $defaultdist;
1001 if ($dist =~ /^(slink|hamm|rex|bo)$/i) {
1002 &::DEBUG("Debian: deprecated version ($dist).");
1003 &::msg($::who, "Debian: deprecated distribution version.");
1007 if (exists $dists{$dist}) {
1008 &::DEBUG("gD: returning dists{$dist} ($dists{$dist})");
1009 return $dists{$dist};
1011 if (!grep /^\Q$dist\E$/i, %dists) {
1012 &::msg($::who, "invalid dist '$dist'.");
1016 &::DEBUG("gD: returning $dist (no change or conversion)");
1021 sub getDistroFromStr {
1023 my $dists = join '|', %dists;
1024 my $dist = $defaultdist;
1026 if ($str =~ s/\s+($dists)$//i) {
1027 $dist = &getDistro(lc $1);
1030 $str =~ s/\\([\$\^])/$1/g;
1036 my ($dist, %urls) = @_;
1040 while (($key,$val) = each %urls) {
1041 $key =~ s/##DIST/$dist/;
1042 $val =~ s/##DIST/$dist/;
1043 ### TODO: what should we do if the sar wasn't done.
1050 ### H-H-H-HACK HACK HACK :)
1052 my ($dist, $query) = &getDistroFromStr($str);
1053 my @results = sort &searchPackage($str);
1055 if (!scalar @results) {
1056 &::Forker("debian", sub { &searchContents($str); } );
1057 } elsif (scalar @results == 1) {
1058 &::status("searchPackage returned one result; getting info of package instead!");
1059 &::Forker("debian", sub { &infoPackages("info", "$results[0] $dist"); } );
1061 my $prefix = "Debian Package Listing of '$str' ";
1062 &::pSReply( &::formListReply(0, $prefix, @results) );
1067 my $dir = "debian/";
1070 &::status("debianCheck() called.");
1072 ### TODO: remove the following loop (check if dir exists before)
1074 last if (opendir(DEBIAN, $dir));
1076 &::ERROR("dC: cannot opendir debian.");
1085 while (defined($file = readdir DEBIAN)) {
1086 next unless ($file =~ /(gz|bz2)$/);
1088 my $exit = system("gzip -t '$dir/$file'");
1089 next unless ($exit);
1090 &::DEBUG("hmr... => ".(time() - (stat($file))[8])."'.");
1091 next unless (time() - (stat($file))[8] > 3600);
1093 &::DEBUG("dC: exit => '$exit'.");
1094 &::WARN("dC: '$dir/$file' corrupted? deleting!");
1095 unlink $dir."/".$file;
1106 &::WARN("cE: $str");
1114 &::DEBUG("FE called for searchDesc");
1116 my @list = &searchDesc($query);
1118 if (!scalar @list) {
1119 my $prefix = "Debian Desc Search of '$query' ";
1120 &::pSReply( &::formListReply(0, $prefix, ) );
1121 } elsif (scalar @list == 1) { # list = 1.
1122 &::DEBUG("list == 1; showing package info of '$list[0]'.");
1123 &infoPackages("info", $list[0]);
1124 } else { # list > 1.
1125 my $prefix = "Debian Desc Search of '$query' ";
1126 &::pSReply( &::formListReply(0, $prefix, @list) );