X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bin%2Flocal-debbugs;h=3e397f38999b8b9126b83e3d6e1e723ccd7cf0ef;hb=eeaa1c6b4d90ed620b53e92efef377446c0b9e8b;hp=4cfb7858fd4501d1f806d7d648d24286206a9fa2;hpb=4ac35e4fa622d066c1c370e76eeb645efce858c1;p=debbugs.git diff --git a/bin/local-debbugs b/bin/local-debbugs index 4cfb785..3e397f3 100755 --- a/bin/local-debbugs +++ b/bin/local-debbugs @@ -17,7 +17,7 @@ local-debbugs - use a local mirror of debbugs =head1 SYNOPSIS - [options] + local-debbugs [options] Options: --mirror, -M update local mirror @@ -113,16 +113,15 @@ use vars qw($DEBUG); use User; use Config::Simple; +use File::Basename qw(dirname); use File::Temp qw(tempdir); use Params::Validate qw(validate_with :types); use POSIX 'setsid'; -use Debbugs::Common qw(checkpid lockpid get_hashname); -use Debbugs::Mail qw(get_addresses); use SOAP::Lite; use IPC::Run; use IO::File; use File::Path; - +use File::Spec; my %options = (debug => 0, help => 0, @@ -130,8 +129,7 @@ my %options = (debug => 0, verbose => 0, quiet => 0, detach => 1, - cgi_bin => '/var/lib/debbugs/www/cgi', - css => '/var/lib/debbugs/www/bugs.css', + git_mode => -d (dirname(__FILE__).'/../.git') ? 1 : 0, bug_site => 'bugs.debian.org', bug_mirror => 'bugs-mirror.debian.org', ); @@ -151,6 +149,22 @@ GetOptions(\%options, 'bug_mirror|bug-mirror=s', 'debug|d+','help|h|?','man|m'); +if ($options{git_mode}) { + my $base_dir = dirname(File::Spec->rel2abs(dirname(__FILE__))); + $options{cgi_bin} = "$base_dir/cgi" unless defined $options{cgi_bin}; + $options{css} = "$base_dir/html/bugs.css" unless defined $options{css}; + $options{template_dir} = "$base_dir/templates"; + $options{base_dir} = $base_dir; + eval "use lib '$options{base_dir}'"; +} else { + $options{cgi_bin} = '/var/lib/debbugs/www/cgi'; + $options{css} = '/var/lib/debbugs/www/bugs.css'; + $options{template_dir} = "/usr/share/debbugs/templates"; +} + +eval "use Debbugs::Common qw(checkpid lockpid get_hashname)"; +eval "use Debbugs::Mail qw(get_addresses)"; + pod2usage() if $options{help}; pod2usage({verbose=>2}) if $options{man}; @@ -188,13 +202,14 @@ if ($options{daemon}) { print {$conf} <<"EOF"; \$gConfigDir = "$options{mirror_location}"; \$gSpoolDir = "$options{mirror_location}"; +\$gTemplateDir = "$options{template_dir}"; \$gWebHost = 'localhost:$options{port}'; -\$gPackageSource = ''; +\$gPackageSource = '$options{mirror_location}/sources'; \$gPseudoDescFile = ''; \$gPseudoMaintFile = ''; -\$gMaintainerFile = ''; +\$gMaintainerFile = '$options{mirror_location}/Maintainers'; \$gMaintainerFileOverride = ''; -\$config{source_maintainer_file} = ''; +\$config{source_maintainer_file} = '$options{mirror_location}/Source_maintainers'; \$config{source_maintainer_file_override} = ''; \$gProject = 'Local Debbugs'; 1; @@ -224,7 +239,8 @@ EOF package local_debbugs::server; use IO::File; use HTTP::Server::Simple; - use base qw(HTTP::Server::Simple::CGI); + use File::Basename qw(dirname); + use base qw(HTTP::Server::Simple::CGI HTTP::Server::Simple::CGI::Environment); sub net_server { return 'Net::Server::Fork'; @@ -279,11 +295,32 @@ EOF redirect($cgi,$base_uri."/cgi-bin/pkgreport.cgi?pkg=$1"); } elsif ($path =~ m{^/?cgi(?:-bin)?/((?:(?:bug|pkg)report|version)\.cgi)}) { - # dispatch to pkgreport.cgi - print "HTTP/1.1 200 OK\n"; - exec("$options{cgi_bin}/$1") or - die "Unable to execute $options{cgi_bin}/$1"; - } + my @exec_options = "$options{cgi_bin}/$1"; + if ($options{git_mode}) { + unshift @exec_options, + 'perl','-I',$options{base_dir},'-T'; + } + open(my $fh,'-|',@exec_options) or + die "Unable to execute $options{cgi_bin}/$1"; + my $status; + my $cache = ''; + while (<$fh>) { + if (/Status: (\d+\s+.+?)\n?$/) { + $status = $1; + print "HTTP/1.1 $status\n"; + print STDERR "'$status'\n"; + last; + } + $cache .= $_; + if (/^$/) { + print "HTTP/1.1 200 OK\n"; + last; + } + } + print $cache; + print <$fh>; + close($fh) or die "Unable to close"; + } elsif ($path =~ m{^/?css/bugs.css}) { my $fh = IO::File->new($options{css},'r') or die "Unable to open $options{css} for reading: $!"; @@ -530,7 +567,7 @@ sub select_bugs{ elsif (/\s\w+\:/) { push @bug_selections, $_; } - } + } } # Split archive:both into archive:1 and archive:0 @bug_selections = @@ -581,8 +618,16 @@ sub select_bugs{ $bugs{$archived_bugs}{$_} = 1 for @{$bugs}; } } + for my $bug (@bugs) { + $bugs{archived}{$bug} = 1; + $bugs{unarchived}{$bug} = 1; + } return \%bugs; } __END__ +# Local Variables: +# cperl-indent-level: 4 +# indent-tabs-mode: nil +# End: