2 # Debian.pl: Frontend to debian contents and packages files
4 # Version: v0.8 (20000918)
12 # format: "alias=real".
14 my $defaultdist = "sid";
15 my $refresh = &::getChanConfDefault("debianRefreshInterval",7)
21 # "sid" => "unstable",
22 # "woody" => "testing", # new since 20001219.
23 # "potato" => "stable",
24 # "incoming" => "incoming",
27 ### new... the right way.
30 "testing" => "woody", # new since 20001219.
32 "incoming" => "incoming",
36 "debian/Contents-##DIST-i386.gz" =>
37 "ftp://ftp.us.debian.org".
38 "/debian/dists/##DIST/Contents-i386.gz",
39 "debian/Contents-##DIST-i386-non-US.gz" =>
40 "ftp://non-us.debian.org".
41 "/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
45 "debian/Packages-##DIST-main-i386.gz" =>
46 "ftp://ftp.us.debian.org".
47 "/debian/dists/##DIST/main/binary-i386/Packages.gz",
48 "debian/Packages-##DIST-contrib-i386.gz" =>
49 "ftp://ftp.us.debian.org".
50 "/debian/dists/##DIST/contrib/binary-i386/Packages.gz",
51 "debian/Packages-##DIST-non-free-i386.gz" =>
52 "ftp://ftp.us.debian.org".
53 "/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
55 "debian/Packages-##DIST-non-US-main-i386.gz" =>
56 "ftp://non-us.debian.org".
57 "/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
58 "debian/Packages-##DIST-non-US-contrib-i386.gz" =>
59 "ftp://non-us.debian.org".
60 "/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
61 "debian/Packages-##DIST-non-US-non-free-i386.gz" =>
62 "ftp://non-us.debian.org".
63 "/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
67 ### COMMON FUNCTION....
68 #######################
71 # Usage: &DebianDownload(%hash);
73 my ($dist, %urls) = @_;
78 &::status("Debian: creating debian dir.");
79 mkdir("debian/",0755);
85 foreach $file (keys %urls) {
86 my $url = $urls{$file};
87 $url =~ s/##DIST/$dist/g;
88 $file =~ s/##DIST/$dist/g;
92 my $last_refresh = (stat $file)[9];
93 $update++ if (time() - $last_refresh > $refresh);
98 next unless ($update);
100 &::DEBUG("announce == $announce.") if ($debug);
101 if ($good + $bad == 0 and !$announce) {
102 &::status("Debian: Downloading files for '$dist'.");
103 &::msg($::who, "Updating debian files... please wait.");
107 if (exists $::debian{$url}) {
108 &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh") if ($debug);
109 next if (time() - $::debian{$url} <= $refresh);
110 &::DEBUG("stale for url $url; updating!") if ($debug);
113 if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
114 my ($host,$path,$thisfile) = ($1,$2,$3);
117 # if ($file =~ /Contents-woody-i386-non-US/) {
118 # &::DEBUG("Skipping Contents-woody-i386-non-US.");
119 # $file =~ s/woody/potato/;
120 # $path =~ s/woody/potato/;
124 if (!&::ftpGet($host,$path,$thisfile,$file)) {
125 &::WARN("deb: down: $file == BAD.");
131 &::WARN("deb: down: ftpGet: !file");
137 # if ($file =~ /Contents-potato-i386-non-US/) {
138 # &::DEBUG("hack: using potato's non-US contents for woody.");
139 # system("cp debian/Contents-potato-i386-non-US.gz debian/Contents-woody-i386-non-US.gz");
142 &::DEBUG("deb: download: good.") if ($debug);
145 &::ERROR("Debian: invalid format of url => ($url).");
152 &generateIndex($dist);
155 return -1 unless ($bad); # no download.
156 &::DEBUG("DD: !good and bad($bad). :(");
161 ###########################
162 # DEBIAN CONTENTS SEARCH FUNCTIONS.
166 # Usage: &searchContents($query);
168 my ($dist, $query) = &getDistroFromStr($_[0]);
169 &::status("Debian: Contents search for '$query' on $dist.");
172 $dccsend++ if ($query =~ s/^dcc\s+//i);
174 $query =~ s/\\([\^\$])/$1/g; # hrm?
175 $query =~ s/^\s+|\s+$//g;
177 if (!&::validExec($query)) {
178 &::msg($::who, "search string looks fuzzy.");
182 if ($dist eq "incoming") { # nothing yet.
183 &::DEBUG("sC: dist = 'incoming'. no contents yet.");
186 my %urls = &fixDist($dist, %urlcontents);
187 # download contents file.
188 &::DEBUG("deb: download 1.");
189 if (!&DebianDownload($dist, %urls)) {
190 &::WARN("Debian: could not download files.");
195 my $start_time = &::timeget();
201 ### TODO: search properly if /usr/bin/blah is done.
202 if ($query =~ s/\$$//) {
203 &::DEBUG("search-regex found.");
204 $grepRE = "$query\[ \t]";
205 } elsif ($query =~ s/^\^//) {
206 &::DEBUG("front marker regex found.");
210 $grepRE = "$query*\[ \t]";
213 # fix up grepRE for "*".
214 $grepRE =~ s/\*/.*/g;
217 foreach (keys %urlcontents) {
220 next unless ( -f $_);
224 if (!scalar @files) {
225 &::ERROR("sC: no files?");
226 &::msg($::who, "failed.");
230 my $files = join(' ', @files);
233 $regex =~ s/\./\\./g;
234 $regex =~ s/\*/\\S*/g;
237 open(IN,"zegrep -h '$grepRE' $files |");
239 if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
240 my ($file,$package) = ("/".$1,$2);
241 if ($query =~ /[\/\*\\]/) {
242 next unless (eval { $file =~ /$regex/ });
243 return unless &checkEval($@);
245 my ($basename) = $file =~ /^.*\/(.*)$/;
246 next unless (eval { $basename =~ /$regex/ });
247 return unless &checkEval($@);
249 next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
250 next if ($front and eval { $file !~ /^\/$query/ });
251 return unless &checkEval($@);
253 $contents{$package}{$file} = 1;
257 last if ($found > 100);
263 ### send results with dcc.
265 if (exists $::dcc{'SEND'}{$::who}) {
266 &::msg($::who, "DCC already active!");
270 if (!scalar %contents) {
271 &::msg($::who,"search returned no results.");
275 my $file = "$::param{tempDir}/$::who.txt";
276 if (!open(OUT,">$file")) {
277 &::ERROR("Debian: cannot write file for dcc send.");
281 foreach $pkg (keys %contents) {
282 foreach (keys %{ $contents{$pkg} }) {
283 # TODO: correct padding.
284 print OUT "$_\t\t\t$pkg\n";
289 &::shmWrite($::shm, "DCC SEND $::who $file");
294 &::status("Debian: $found contents results found.");
297 foreach $pkg (keys %contents) {
298 my @tmplist = &::fixFileList(keys %{ $contents{$pkg} });
299 my @sublist = sort { length $a <=> length $b } @tmplist;
301 pop @sublist while (scalar @sublist > 3);
303 $pkg =~ s/\,/\037\,\037/g; # underline ','.
304 push(@list, "(". join(', ',@sublist) .") in $pkg");
306 # sort the total list from shortest to longest...
307 @list = sort { length $a <=> length $b } @list;
309 # show how long it took.
310 my $delta_time = &::timedelta($start_time);
311 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
313 my $prefix = "Debian Search of '$query' ";
314 if (scalar @list) { # @list.
315 &::pSReply( &::formListReply(0, $prefix, @list) );
318 &::DEBUG("ok, !\@list, searching desc for '$query'.");
319 my @list = &searchDesc($query);
322 my $prefix = "Debian Package/File/Desc Search of '$query' ";
323 &::pSReply( &::formListReply(0, $prefix, ) );
325 } elsif (scalar @list == 1) { # list = 1.
326 &::DEBUG("list == 1; showing package info of '$list[0]'.");
327 &infoPackages("info", $list[0]);
330 my $prefix = "Debian Desc Search of '$query' ";
331 &::pSReply( &::formListReply(0, $prefix, @list) );
337 # Usage: &searchAuthor($query);
339 my ($dist, $query) = &getDistroFromStr($_[0]);
340 &::DEBUG("searchAuthor: dist => '$dist', query => '$query'.");
341 $query =~ s/^\s+|\s+$//g;
344 my $start_time = &::timeget();
345 &::status("Debian: starting author search.");
348 my ($bad,$good) = (0,0);
349 my %urls = %urlpackages;
351 foreach (keys %urlpackages) {
363 &::DEBUG("good = $good, bad = $bad...");
365 if ($good == 0 and $bad != 0) {
366 my %urls = &fixDist($dist, %urlpackages);
367 &::DEBUG("deb: download 2.");
369 if (!&DebianDownload($dist, %urls)) {
370 &::ERROR("Debian(sA): could not download files.");
375 my (%maint, %pkg, $package);
376 open(IN,"zegrep -h '^Package|^Maintainer' $files |");
378 if (/^Package: (\S+)$/) {
381 } elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
382 my($name,$email) = ($1,$2);
383 if ($package eq "") {
384 &::DEBUG("sA: package == NULL.");
387 $maint{$name}{$email} = 1;
388 $pkg{$name}{$package} = 1;
392 &::WARN("invalid line: '$_'.");
398 # TODO: can we use 'map' here?
399 foreach (grep /\Q$query\E/i, keys %maint) {
403 # TODO: should we only search email if '@' is used?
404 if (scalar keys %hash < 15) {
407 foreach $name (keys %maint) {
410 foreach $email (keys %{ $maint{$name} }) {
411 next unless ($email =~ /\Q$query\E/i);
412 next if (exists $hash{$name});
418 my @list = keys %hash;
419 if (scalar @list != 1) {
420 my $prefix = "Debian Author Search of '$query' ";
421 &::pSReply( &::formListReply(0, $prefix, @list) );
425 &::DEBUG("showing all packages by '$list[0]'...");
427 my @pkg = sort keys %{ $pkg{$list[0]} };
429 # show how long it took.
430 my $delta_time = &::timedelta($start_time);
431 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
433 my $email = join(', ', keys %{ $maint{$list[0]} });
434 my $prefix = "Debian Packages by $list[0] \002<\002$email\002>\002 ";
435 &::pSReply( &::formListReply(0, $prefix, @pkg) );
439 # Usage: &searchDesc($query);
441 my ($dist, $query) = &getDistroFromStr($_[0]);
442 &::DEBUG("searchDesc: dist => '$dist', query => '$query'.");
443 $query =~ s/^\s+|\s+$//g;
446 my $start_time = &::timeget();
447 &::status("Debian: starting desc search.");
450 my ($bad,$good) = (0,0);
451 my %urls = %urlpackages;
453 foreach (keys %urlpackages) {
465 &::DEBUG("good = $good, bad = $bad...");
467 if ($good == 0 and $bad != 0) {
468 my %urls = &fixDist($dist, %urlpackages);
469 &::DEBUG("deb: download 2c.");
471 if (!&DebianDownload($dist, %urls)) {
472 &::ERROR("Debian(sD): could not download files.");
478 $regex =~ s/\./\\./g;
479 $regex =~ s/\*/\\S*/g;
482 my (%desc, $package);
483 open(IN,"zegrep -h '^Package|^Description' $files |");
485 if (/^Package: (\S+)$/) {
487 } elsif (/^Description: (.*)$/) {
489 next unless (eval { $desc =~ /$regex/i });
490 return unless &checkEval($@);
492 if ($package eq "") {
493 &::WARN("sD: package == NULL?");
496 $desc{$package} = $desc;
499 &::WARN("invalid line: '$_'.");
504 # show how long it took.
505 my $delta_time = &::timedelta($start_time);
506 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
512 # Usage: &generateIncoming();
513 sub generateIncoming {
514 my $pkgfile = "debian/Packages-incoming";
515 my $idxfile = $pkgfile.".idx";
517 $stale++ if (&::isStale($pkgfile.".gz", $refresh));
518 $stale++ if (&::isStale($idxfile, $refresh));
519 &::DEBUG("gI: stale => '$stale'.");
520 return 0 unless ($stale);
523 my %ftp = &::ftpList("llug.sep.bnl.gov", "/pub/debian/Incoming/");
525 if (!open(PKG,">$pkgfile")) {
526 &::ERROR("cannot write to pkg $pkgfile.");
529 if (!open(IDX,">$idxfile")) {
530 &::ERROR("cannot write to idx $idxfile.");
534 print IDX "*$pkgfile.gz\n";
536 foreach $file (sort keys %ftp) {
537 next unless ($file =~ /deb$/);
539 if ($file =~ /^(\S+)\_(\S+)\_(\S+)\.deb$/) {
541 print PKG "Package: $1\n";
542 print PKG "Version: $2\n";
543 print PKG "Architecture: ", (defined $4) ? $4 : "all", "\n";
545 print PKG "Filename: $file\n";
546 print PKG "Size: $ftp{$file}\n";
552 system("gzip -9fv $pkgfile"); # lame fix.
554 &::status("Debian: generateIncoming() complete.");
558 ##############################
559 # DEBIAN PACKAGE INFO FUNCTIONS.
562 # Usage: &getPackageInfo($query,$file);
564 my ($package, $file) = @_;
567 &::status("gPI: file $file does not exist?");
574 open(IN, "zcat $file 2>&1 |");
580 next if (/^ \S+/); # package long description.
583 if (/^Package: (.*)\n$/) {
585 if ($pkg =~ /^$package$/i) {
586 $found++; # we can use pkg{'package'} instead.
587 $pkg{'package'} = $pkg;
596 if (/^Version: (.*)$/) {
597 $pkg{'version'} = $1;
598 } elsif (/^Priority: (.*)$/) {
599 $pkg{'priority'} = $1;
600 } elsif (/^Section: (.*)$/) {
601 $pkg{'section'} = $1;
602 } elsif (/^Size: (.*)$/) {
604 } elsif (/^Installed-Size: (.*)$/i) {
605 $pkg{'installed'} = $1;
606 } elsif (/^Description: (.*)$/) {
608 } elsif (/^Filename: (.*)$/) {
610 } elsif (/^Pre-Depends: (.*)$/) {
611 $pkg{'depends'} = "pre-depends on $1";
612 } elsif (/^Depends: (.*)$/) {
613 if (exists $pkg{'depends'}) {
614 $pkg{'depends'} .= "; depends on $1";
616 $pkg{'depends'} = "depends on $1";
618 } elsif (/^Maintainer: (.*)$/) {
620 } elsif (/^Provides: (.*)$/) {
621 $pkg{'provides'} = $1;
622 } elsif (/^Suggests: (.*)$/) {
623 $pkg{'suggests'} = $1;
624 } elsif (/^Conflicts: (.*)$/) {
625 $pkg{'conflicts'} = $1;
628 ### &::DEBUG("=> '$_'.");
638 next if (defined $pkg);
646 # Usage: &infoPackages($query,$package);
648 my ($query,$dist,$package) = ($_[0], &getDistroFromStr($_[1]));
650 &::status("Debian: Searching for package '$package' in '$dist'.");
652 # download packages file.
654 my %urls = &fixDist($dist, %urlpackages);
655 if ($dist ne "incoming") {
656 &::DEBUG("deb: download 3.") if ($debug);
658 if (!&DebianDownload($dist, %urls)) { # no good download.
659 &::WARN("Debian(iP): could not download ANY files.");
663 # check if the package is valid.
665 my @files = &validPackage($package, $dist);
666 if (!scalar @files) {
667 &::status("Debian: no valid package found; checking incoming.");
668 @files = &validPackage($package, "incoming");
670 &::status("Debian: cool, it exists in incoming.");
673 &::msg($::who, "Package '$package' does not exist.");
678 if (scalar @files > 1) {
679 &::WARN("same package in more than one file; random.");
680 &::DEBUG("THIS SHOULD BE FIXED SOMEHOW!!!");
681 $files[0] = &::getRandom(@files);
684 if (! -f $files[0]) {
685 &::WARN("files[0] ($files[0]) doesn't exist.");
686 &::msg($::who, "WARNING: $files[0] does not exist? FIXME");
690 ### TODO: if specific package is requested, note down that a version
691 ### exists in incoming.
694 my $file = $files[0];
697 ### TODO: use fe, dump to a hash. if only one version of the package
698 ### exists. do as normal otherwise list all versions.
700 &::ERROR("D:iP: file '$file' DOES NOT EXIST!!! should never happen.");
703 my %pkg = &getPackageInfo($package, $file);
706 if ($query eq "info") {
707 if (scalar keys %pkg > 5) {
708 $pkg{'info'} = "\002(\002". $pkg{'desc'} ."\002)\002";
709 $pkg{'info'} .= ", section ".$pkg{'section'};
710 $pkg{'info'} .= ", is ".$pkg{'priority'};
711 # $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
712 $pkg{'info'} .= ". Version: \002$pkg{'version'}\002 ($dist)";
713 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
714 $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
717 &::status("iP: info requested and pkg is in incoming, too.");
718 my %incpkg = &getPackageInfo($query, "debian/Packages-incoming");
720 if (scalar keys %incpkg) {
721 $pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
723 &::ERROR("iP: pkg $query is in incoming but we couldn't get any info?");
727 &::DEBUG("running debianCheck() due to problems (".scalar(keys %pkg).").");
729 &::DEBUG("end of debianCheck()");
731 &::msg($::who,"Debian: Package appears to exist but I could not retrieve info about it...");
736 if ($dist eq "incoming") {
737 $pkg{'info'} .= "Version: \002$pkg{'version'}\002";
738 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
739 $pkg{'info'} .= ", is in incoming!!!";
742 if (!exists $pkg{$query}) {
743 if ($query eq "suggests") {
744 $pkg{$query} = "has no suggestions";
745 } elsif ($query eq "conflicts") {
746 $pkg{$query} = "does not conflict with any other package";
747 } elsif ($query eq "depends") {
748 $pkg{$query} = "does not depend on anything";
749 } elsif ($query eq "maint") {
750 $pkg{$query} = "has no maintainer";
752 $pkg{$query} = "has nothing about $query";
756 &::pSReply("$package: $pkg{$query}");
759 # Usage: &infoStats($dist);
762 $dist = &getDistro($dist);
763 return unless (defined $dist);
765 &::DEBUG("infoS: dist => '$dist'.");
767 # download packages file if needed.
768 my %urls = &fixDist($dist, %urlpackages);
769 &::DEBUG("deb: download 4.");
770 if (!&DebianDownload($dist, %urls)) {
771 &::WARN("Debian(iS): could not download ANY files.");
772 &::msg($::who, "Debian(iS): internal error.");
779 foreach $file (keys %urlpackages) {
780 $file =~ s/##DIST/$dist/g; # won't work for incoming.
781 &::DEBUG("file => '$file'.");
782 if (exists $stats{$file}{'count'}) {
783 &::DEBUG("hrm... duplicate open with $file???");
787 open(IN,"zcat $file 2>&1 |");
790 &::DEBUG("iS: $file does not exist.");
797 next if (/^ \S+/); # package long description.
799 if (/^Package: (.*)\n$/) { # counter.
800 $stats{$file}{'count'}++;
802 } elsif (/^Maintainer: .* <(\S+)>$/) {
803 $stats{$file}{'maint'}{$1}++;
804 $total{'maint'}{$1}++;
805 } elsif (/^Size: (.*)$/) { # compressed size.
806 $stats{$file}{'csize'} += $1;
807 $total{'csize'} += $1;
808 } elsif (/^i.*size: (.*)$/i) { # installed size.
809 $stats{$file}{'isize'} += $1;
810 $total{'isize'} += $1;
813 ### &::DEBUG("=> '$_'.");
818 ### TODO: don't count ppl with multiple email addresses.
821 "Debian Distro Stats on $dist... ".
822 "\002$total{'count'}\002 packages, ".
823 "\002".scalar(keys %{ $total{'maint'} })."\002 maintainers, ".
824 "\002". int($total{'isize'}/1024)."\002 MB installed size, ".
825 "\002". int($total{'csize'}/1024/1024)."\002 MB compressed size."
828 ### TODO: do individual stats? if so, we need _another_ arg.
829 # foreach $file (keys %stats) {
830 # foreach (keys %{ $stats{$file} }) {
831 # &::DEBUG(" '$file' '$_' '$stats{$file}{$_}'.");
841 # HELPER FUNCTIONS FOR INFOPACKAGES...
844 # Usage: &generateIndex();
847 &::status("Debian: !!! generateIndex($dists[0]) called !!!");
848 if (!scalar @dists or $dists[0] eq '') {
849 &::ERROR("gI: no dists to generate index.");
854 my $dist = &getDistro($_); # incase the alias is returned, possible?
855 my $idx = "debian/Packages-$dist.idx";
856 &::DEBUG("gI: dist => $dist.");
857 &::DEBUG("gI: idx => $idx.");
858 &::DEBUG("gI: r => $refresh.");
860 # TODO: check if any of the Packages file have been updated then
861 # regenerate it, even if it's not stale.
862 # TODO: also, regenerate the index if the packages file is newer
864 next unless (&::isStale($idx, $refresh));
867 &::DEBUG("gIndex: calling generateIncoming()!");
873 &::DEBUG("Copying old index of woody to -old");
874 system("cp $idx $idx-old");
877 &::DEBUG("gIndeX: calling DebianDownload($dist, ...).");
878 &DebianDownload($dist, %urlpackages);
880 &::status("Debian: generating index for '$dist'.");
881 if (!open(OUT,">$idx")) {
882 &::ERROR("cannot write to $idx.");
887 foreach $packages (keys %urlpackages) {
888 $packages =~ s/##DIST/$dist/;
890 if (! -e $packages) {
891 &::ERROR("gIndex: '$packages' does not exist?");
895 print OUT "*$packages\n";
896 open(IN,"zcat $packages |");
899 next unless (/^Package: (.*)\n$/);
910 # Usage: &validPackage($package, $dist);
912 my ($package,$dist) = @_;
916 ### this majorly sucks, we need some standard in place.
917 # why is this needed... need to investigate later.
919 $dist = &getDistro($dist);
921 &::DEBUG("D: validPackage($package, $dist) called.") if ($debug);
924 while (!open(IN, "debian/Packages-$dist.idx")) {
926 &::ERROR("Packages-$dist.idx does not exist (#1).");
930 &generateIndex($dist);
942 if (/^\Q$package\E\n$/) {
949 &::VERB("vP: scanned $count items in index.",2);
955 my ($dist, $query) = &getDistroFromStr($_[0]);
956 my $file = "debian/Packages-$dist.idx";
961 if ($query =~ tr/A-Z/a-z/) {
965 &::status("Debian: Search package matching '$query' in '$dist'.");
966 unlink $file if ( -z $file);
968 while (!open(IN, $file)) {
969 if ($dist eq "incoming") {
970 &::DEBUG("sP: dist == incoming; calling gI().");
975 &::ERROR("could not generate index ($file)!!!");
980 &::DEBUG("should we be doing this?");
981 &generateIndex(($dist));
990 if (&::isStale($file, $refresh)) {
991 &::DEBUG("STALE $file! regen.");
992 &generateIndex(($dist));
993 ### @files = searchPackage("$query $dist");
994 &::DEBUG("EVIL HACK HACK HACK.");
1007 if (scalar @files and $warn) {
1008 &::msg($::who, "searching for package name should be fully lowercase!");
1017 if (!defined $dist or $dist eq "") {
1018 &::DEBUG("gD: dist == NULL; dist = defaultdist.");
1019 $dist = $defaultdist;
1022 if ($dist =~ /^(slink|hamm|rex|bo)$/i) {
1023 &::DEBUG("Debian: deprecated version ($dist).");
1024 &::msg($::who, "Debian: deprecated distribution version.");
1028 if (exists $dists{$dist}) {
1029 &::VERB("gD: returning dists{$dist} ($dists{$dist})",2);
1030 return $dists{$dist};
1033 if (!grep /^\Q$dist\E$/i, %dists) {
1034 &::msg($::who, "invalid dist '$dist'.");
1038 &::VERB("gD: returning $dist (no change or conversion)",2);
1043 sub getDistroFromStr {
1045 my $dists = join '|', %dists;
1046 my $dist = $defaultdist;
1048 if ($str =~ s/\s+($dists)$//i) {
1049 $dist = &getDistro(lc $1);
1052 $str =~ s/\\([\$\^])/$1/g;
1058 my ($dist, %urls) = @_;
1062 while (($key,$val) = each %urls) {
1063 $key =~ s/##DIST/$dist/;
1064 $val =~ s/##DIST/$dist/;
1065 ### TODO: what should we do if the sar wasn't done.
1072 ### H-H-H-HACK HACK HACK :)
1074 my ($dist, $query) = &getDistroFromStr($str);
1075 my @results = sort &searchPackage($str);
1077 if (!scalar @results) {
1078 &::Forker("debian", sub { &searchContents($str); } );
1079 } elsif (scalar @results == 1) {
1080 &::status("searchPackage returned one result; getting info of package instead!");
1081 &::Forker("debian", sub { &infoPackages("info", "$results[0] $dist"); } );
1083 my $prefix = "Debian Package Listing of '$query' ";
1084 &::pSReply( &::formListReply(0, $prefix, @results) );
1089 my $dir = "debian/";
1092 &::status("debianCheck() called.");
1094 ### TODO: remove the following loop (check if dir exists before)
1096 last if (opendir(DEBIAN, $dir));
1098 &::ERROR("dC: cannot opendir debian.");
1107 while (defined($file = readdir DEBIAN)) {
1108 next unless ($file =~ /(gz|bz2)$/);
1110 my $exit = system("gzip -t '$dir/$file'");
1111 next unless ($exit);
1112 &::DEBUG("hmr... => ".(time() - (stat($file))[8])."'.");
1113 next unless (time() - (stat($file))[8] > 3600);
1115 &::DEBUG("dC: exit => '$exit'.");
1116 &::WARN("dC: '$dir/$file' corrupted? deleting!");
1117 unlink $dir."/".$file;
1128 &::WARN("cE: $str");
1136 &::DEBUG("FE called for searchDesc");
1138 my @list = &searchDesc($query);
1140 if (!scalar @list) {
1141 my $prefix = "Debian Desc Search of '$query' ";
1142 &::pSReply( &::formListReply(0, $prefix, ) );
1143 } elsif (scalar @list == 1) { # list = 1.
1144 &::DEBUG("list == 1; showing package info of '$list[0]'.");
1145 &infoPackages("info", $list[0]);
1146 } else { # list > 1.
1147 my $prefix = "Debian Desc Search of '$query' ";
1148 &::pSReply( &::formListReply(0, $prefix, @list) );