2 # local-debbugs is part of debbugs, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
16 local-debbugs - use a local mirror of debbugs
23 --mirror, -M update local mirror
24 --daemon, -D start the daemon
25 --search, -S run a search
27 --debug, -d debugging level (Default 0)
28 --help, -h display this help
29 --man, -m display manual
37 Update the local mirror of debbugs bugs
41 Start up the daemon on the configured local port to serve bugs which
42 have been previously retried
46 Cause the running daemon to show the pkgreport.cgi page corresponding
47 to the search by invoking sensible-browser and an appropriate url
51 Cause the running daemon to show the bugreport.cgi page corresponding
52 to the bug by invoking sensible-browser and an appropriate url
56 The port that the daemon is running on (or will be running on.)
58 Defaults to the value of the currently running daemon, the value in
59 the configuration file, or 8080 if nothing is set.
61 =item B<--bugs-to-get>
63 File which contains the set of bugs to get.
64 Defaults to ~/.debbugs/bugs_to_get
68 Debug verbosity. (Default 0)
72 Display brief useage information.
90 use File::Temp qw(tempdir);
92 my %options = (debug => 0,
97 my %option_defaults = (port => 8080,
98 debbugs_config => User->Home.'/.debbugs/debbugs_config',
99 mirror_location => User->Home.'/.debbugs/mirror/',
100 bugs_to_get => User->Home.'/.debbugs/bugs_to_get',
103 GetOptions(\%options,
104 'daemon|D','show|s','search|select|S','mirror|M',
105 'debug|d+','help|h|?','man|m');
107 pod2usage() if $options{help};
108 pod2usage({verbose=>2}) if $options{man};
110 $DEBUG = $options{debug};
113 if (1 != scalar @options{qw(daemon show search mirror)}) {
114 push @USAGE_ERRORS,"You must pass one (and only one) of --daemon --show --search or --mirror";
117 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
120 # munge in local configuration
122 local_config(\%options);
124 if ($options{daemon}) {
125 # daemonize, do stuff
127 elsif ($options{mirror}) {
128 # run the mirror jobies
129 # figure out which bugs we need
130 my @bugs = select_bugs();
132 my $tempdir = tempdir(CLEANUP => 1);
133 my $mirror_log = IO::File->new($options{mirror_location}.'/mirror.log') or
134 die "Unable to open $options{mirror_location}/mirror.log for writing: $!";
135 my $inc_fh = IO::File->new("$tempdir/include_list",'w') or
136 die "Unable to open $tempdir/include_list for writing: $!";
137 foreach my $bug (@bugs) {
138 print {$inc_fh} "*/${bugs}.*\n" or
139 die "Unable to write to $tempdir/include_list: $!";
142 die "Unable to close $tempdir/include_list: $!";
144 run_rsync(log => $mirror_log,
145 ($options{debug}?(debug => \*STDERR):()),
146 options => ['-avz','--partial',
148 '--include-from',"$tempdir/include_list",
149 # skip things not specifically included
151 # skip the -1,-2,-3.log files
153 'rsync://'.$options{bug_mirror}.'/bts-spool-db/',
154 $options{mirror_location}.'/db-h/']
161 elsif ($options{show}) {
164 elsif ($options{search}) {
167 # you get here, you were an idiot in checking for @USAGE_ERRORS
169 die "No option that we understand was passed (the first check for this is now buggy, so shoot your maintainer)"
173 # determine the local configuration
177 if (-e '/etc/debbugs/local_debbugs.conf') {
178 Config::Simple->import_from('/etc/debbugs/local_debbugs.conf', $config) or
179 die "Unable to read configuration from /etc/debbugs/local_debbugs.conf: $!";
181 if (-e User->Home.'/.debbugs/local_debbugs.conf') {
182 Config::Simple->import_from(User->Home.'/.debbugs/local_debbugs.conf', $config) or
183 die "Unable to read configuration from ".User->Home.'/.debbugs/local_debbugs.conf: '.$!;
185 for (keys %default_options) {
186 if (exists $config->{$_} and not defined $options->{$_}) {
187 $options->{$_} = $config->{$_};
189 if (not defined $options->{$_}) {
190 $options->{$_} = $default_options{$_};
196 my ($output_fh,@rsync_options) = @_;
198 my $pid = open3($wfh,$rfh,
201 ) or die "Unable to start rsync: $!";
202 close $wfh or die "Unable to close the writer filehandle $?";