X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=bin%2Flocal-debbugs;h=0223da14ac7c3f4d0ca8f9bae8496e98fa3c2ddc;hb=7d03c7688ad03cc960cfb907af0ba282605d35b0;hp=cae7203285e34716000c9f2fde7bcf9d85df9442;hpb=f309743ffc0c9e762c6bc035edd7820c4d4b8d84;p=debbugs.git diff --git a/bin/local-debbugs b/bin/local-debbugs index cae7203..0223da1 100755 --- a/bin/local-debbugs +++ b/bin/local-debbugs @@ -143,7 +143,7 @@ my %option_defaults = (port => 8080, ); GetOptions(\%options, - 'daemon|D','show|s','search|select|S','mirror|M', 'stop', + 'daemon|D','show|s','search|select|S','mirror|M', 'stop|exit|quit', 'detach!', 'css=s','cgi_bin|cgi-bin|cgi=s', 'verbose|v+','quiet|q+', @@ -158,7 +158,7 @@ $DEBUG = $options{debug}; my @USAGE_ERRORS; if (1 != grep {exists $options{$_}} qw(daemon show search mirror stop)) { - push @USAGE_ERRORS,"You must pass one (and only one) of --daemon --show --search or --mirror"; + push @USAGE_ERRORS,"You must pass one (and only one) of --daemon --show --search --mirror or --stop"; } $options{verbose} = $options{verbose} - $options{quiet}; @@ -183,6 +183,24 @@ if ($options{daemon}) { print STDERR "Unable to determine if daemon is running: $!\n"; exit 1; } + my $conf = IO::File->new($options{mirror_location}.'/debbugs_config_local','w') or + die "Unable to open $options{mirror_location}/debbugs_config_local for writing: $!"; + print {$conf} <<"EOF"; +\$gConfigDir = "$options{mirror_location}"; +\$gSpoolDir = "$options{mirror_location}"; +\$gWebHost = 'localhost:$options{port}'; +\$gPackageSource = ''; +\$gPseudoDescFile = ''; +\$gPseudoMaintFile = ''; +\$gMaintainerFile = ''; +\$gMaintainerFileOverride = ''; +\$config{source_maintainer_file} = ''; +\$config{source_maintainer_file_override} = ''; +\$gProject = 'Local Debbugs'; +1; +EOF + close $conf; + $ENV{DEBBUGS_CONFIG_FILE} = $options{mirror_location}.'/debbugs_config_local'; # ok, now lets daemonize # XXX make sure that all paths have been turned into absolute @@ -206,7 +224,7 @@ if ($options{daemon}) { package local_debbugs::server; use IO::File; use HTTP::Server::Simple; - use base qw(HTTP::Server::Simple::CGI); + use base qw(HTTP::Server::Simple::CGI HTTP::Server::Simple::CGI::Environment); sub net_server { return 'Net::Server::Fork'; @@ -222,6 +240,7 @@ if ($options{daemon}) { sub handle_request { my ($self,$cgi) = @_; + $ENV{DEBBUGS_CONFIG_FILE} = $options{mirror_location}.'/debbugs_config_local'; my $base_uri = 'http://'.$cgi->virtual_host; if ($cgi->virtual_port ne 80) { $base_uri .= ':'.$cgi->virtual_port; @@ -261,10 +280,28 @@ if ($options{daemon}) { } 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"; - } + #print "HTTP/1.1 200 OK\n"; + open(my $fh,'-|',"$options{cgi_bin}/$1") 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: $!"; @@ -374,7 +411,7 @@ elsif ($options{search}) { my $pid = checkpid($options{mirror_location}.'/local-debbugs.pid'); if (not defined $pid or $pid == 0) { print STDERR "Unable to open pidfile or daemon not running: $!\n"; - print STDERR qq(Mr. T: "I pity da fool who tries to show a bug without a running daemon"\n); + print STDERR qq(Mr. T: "I pity da fool who tries to search for bugs without a running daemon"\n); print STDERR "Hint: try the --daemon option first\n"; exit 1; } @@ -438,9 +475,8 @@ sub run_rsync{ ); my ($output,$error) = ('',''); my $h = IPC::Run::start(['rsync',@{$param{options}}], - \undef,\$output,\$error); + \undef,$param{log},$param{log}); while ($h->pump) { - print {$param{log}} $output,$error; #print {$param{debug}} $error if defined $param{debug}; } $h->finish();