~ubuntu-branches/ubuntu/raring/lurker/raring

« back to all changes in this revision

Viewing changes to debian/mailman2lurker

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Meurer
  • Date: 2006-12-20 05:05:31 UTC
  • mfrom: (3.1.6 feisty)
  • Revision ID: james.westby@ubuntu.com-20061220050531-79inzy7o6uu95qx7
Tags: 2.1-7
* updated vi debconf translations, thanks to Clytie Siddall
  <clytie@riverland.net.au>
* fixed typo in one template (that you would like, not that
  would you like), thanks as well to Clytie Siddall
  - unfuzzied all translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
 
4
  if 0; # not running under some shell
 
5
 
 
6
# to create a manpage for mailman2lurker, invoke the following command:
 
7
# pod2man --section=8 --center="Administrative commands" --release="" mailman2lurker mailman2lurker.8
 
8
 
 
9
=head1 NAME
 
10
 
 
11
mailman2lurker - Import mailman lists and their archives into a lurker database.
 
12
 
 
13
=head1 SYNOPSIS
 
14
 
 
15
Z<> B<mailman2lurker> B<-i>|B<-p> [I<options>]
 
16
 
 
17
=head1 DESCRIPTION
 
18
 
 
19
B<mailman2lurker> has mainly two functions. First, it parses mailman's lists
 
20
and creates a lurker configuration include out of them. Second, it imports
 
21
archives from mailman lists into a lurker database.
 
22
 
 
23
To build a new lurker database from mailmans archives, first run
 
24
'B<mailman2lurker -p>'. Next you need to add 'B<include =
 
25
/etc/lurker/lurker.conf.mailman>' into /etc/lurker/lurker.conf.local.
 
26
Finally import mailmans mboxes by running 'B<mailman2lurker -i>'.
 
27
 
 
28
If you want to add new lists to an already existing lurker configuration, run
 
29
'B<mailman2lurker -p -w newlists>' and afterwards 'B<mailman2lurker -i -f
 
30
newlists>'. This will import only the mbox files of mailman lists that have been
 
31
added to the lurker configuration because they were new to lurker.
 
32
 
 
33
=head1 COMMANDS
 
34
 
 
35
=over 4
 
36
 
 
37
=item B<-p>, B<--parse>
 
38
 
 
39
Parse mailman lists, and create a lurker configuration include file containing
 
40
all parsed lists. Lists that are already configured in lurker are ignored.
 
41
 
 
42
=item B<-i>, B<--import>
 
43
 
 
44
Import archives of all lists. This parses the lurker configuration and imports
 
45
the mailman mbox at /var/lib/mailman/archives/private/<list>.mbox/<list>.mbox
 
46
for every list.
 
47
 
 
48
=head1 OPTIONS
 
49
 
 
50
=over 4
 
51
 
 
52
=item B<-c>, B<--config> <I<config>>
 
53
 
 
54
Use <I<config>> as lurker configuration file. Default: /etc/lurker/lurker.conf
 
55
 
 
56
=item B<-o>, B<--outfile> <I<outfile>>
 
57
 
 
58
Write list configuration to <I<outfile>>. If this is not specified,
 
59
<lurker.conf>.mailman will be used.
 
60
This option is only useful in conjunction with B<-p>.
 
61
 
 
62
=item B<-g>, B<--group> <I<group>>
 
63
 
 
64
Use <I<group>> for new lists. Default is 'undef'.
 
65
This option is only useful in conjunction with B<-p>.
 
66
 
 
67
=item B<-a>, B<--listhost> <I<listhost>>
 
68
 
 
69
Use <I<listhost>> as host for new list addresses. If a new list is called
 
70
'mylist' and <I<listhost>> is lists.org, then the list address will be
 
71
mylist@lists.org. Default is 'example.org'.
 
72
This option is only useful in conjunction with B<-p>.
 
73
 
 
74
=item B<-l>, B<--link> <I<url link>>
 
75
 
 
76
Use <I<url link>> as base for links of new lists. If a list is called 'mylist',
 
77
and <I<url link>> is 'http://lists.org', then the link address will be
 
78
http://lists.org/mylist. Default is 'http://example.org'.
 
79
This option is only useful in conjunction with B<-p>.
 
80
 
 
81
=item B<-s>, B<--lang> <I<language>>
 
82
 
 
83
Use <I<language>> as language for new lists. Needs to be a language token.
 
84
Default is 'en'. This option is only useful in conjunction with B<-p>.
 
85
 
 
86
=item B<-w>, B<--write-lists> <I<file>>
 
87
 
 
88
Write a list of all lists that have been added to the lurker configuration.
 
89
Safe that list in <I<file>>. Default is off.
 
90
This option is only useful in conjunction with B<-p>.
 
91
 
 
92
=item B<-x>, B<--list-cmd> <I<file>>
 
93
 
 
94
Use <I<command|file>> to get the list of mailman lists that should be parsed.
 
95
When <I<command|file>> is a command, it needs to end with ' |'.
 
96
Default is '/var/lib/mailman/bin/list_lists |'.
 
97
This option is only useful in conjunction with B<-p>.
 
98
 
 
99
=item B<-f>, B<--listfile> <I<file>>
 
100
 
 
101
Import only lists that are listed in <I<file>>.
 
102
This option is only useful in conjunction with B<-i>.
 
103
 
 
104
=item B<-d>, B<--lists> <I<one>[,I<two>,I<...>]>
 
105
 
 
106
Import only lists that are given as argument.
 
107
This option is only useful in conjunction with B<-i>.
 
108
 
 
109
=item B<-h>, B<--help>
 
110
 
 
111
Display a help message.
 
112
 
 
113
=item B<-v>, B<--version>
 
114
 
 
115
Display mailman2lurker's version number.
 
116
 
 
117
=head1 SEE ALSO
 
118
 
 
119
L<list_lists(8)>, L<lurker-index(8)>
 
120
 
 
121
=head1 AUTHOR
 
122
 
 
123
This program was written by Jonas Meurer <jonas@freesources.org>.
 
124
 
 
125
=head1 COPYRIGHT
 
126
 
 
127
mailman2lurker may be copied and modified under the terms of the GNU General
 
128
Public License.
 
129
 
 
130
=cut
 
131
 
 
132
our $Version="0.2";
 
133
 
 
134
use strict;
 
135
use Getopt::Long;
 
136
use File::Temp qw/ tempfile /;
 
137
 
 
138
# Display mailman2lurker's version number.
 
139
sub version {
 
140
  print "mailman2lurker version $Version\n";
 
141
  exit;
 
142
}
 
143
 
 
144
# Display usage help.
 
145
sub usage() {
 
146
    print STDERR <<EOF;
 
147
mailman2lurker - Import mailman lists and their archives into a lurker database
 
148
 
 
149
Usage: mailman2lurker -p|-i [options]
 
150
 
 
151
Options:
 
152
  -c, --config <config>    use this conffile (default: /etc/lurker/lurker.conf)
 
153
  -i, --import             import list archives from mailman's mbox files
 
154
     -f, --listfile <file>     import only lists in <file>.
 
155
     -d, --lists <one,two,..>  import only lists that are given as argument.
 
156
  -p, --parse              create a lurker conf include from mailman lists
 
157
     -o, --outfile <outfile>   write to this file. (default: <config>.mailman)
 
158
     -g, --group <group>       use this group for lists. (default: undef)
 
159
     -a, --listhost <host>     use this host for lists. (default: example.org)
 
160
     -l, --link <url link>     use for the url link. (default: listurl)
 
161
     -s, --lang <language>     use this language for new lists. (default: en)
 
162
     -w, --write-lists <file>  write a list of parsed lists to <file>.
 
163
     -x, --list-cmd <cmd|file> use this command/file as list of mailman lists.
 
164
                               (default: "/usr/lib/mailman/bin/list_lists |")
 
165
  -h, --help               Display this help message.
 
166
  -v, --version            Display mailman2lurker's version number.
 
167
 
 
168
EOF
 
169
    exit 1;
 
170
}
 
171
 
 
172
sub check_group {
 
173
  my ($group) = @_;
 
174
  my $lurkergroups = "/usr/bin/lurker-list -g |";
 
175
  open LURKERGROUPS, $lurkergroups or die "Could not open $lurkergroups: $!";
 
176
  while (<LURKERGROUPS>) {
 
177
    if (/^$group$/) {
 
178
      print STDERR "Group $group already exists in lurker configuration, you need to configure another one with -g.\n";
 
179
      exit 1;
 
180
    }
 
181
  }
 
182
  close LURKERGROUPS;
 
183
}
 
184
 
 
185
sub lurker_lists {
 
186
  my ($list, @lists);
 
187
  my $lurkerlist = "/usr/bin/lurker-list -c $glob::lurkerconf -i |";
 
188
  open LURKERLIST, $lurkerlist or die "Could not open $lurkerlist: $!";
 
189
  while (<LURKERLIST>) {
 
190
    chomp;
 
191
    if (($list) = /^([0-9-_\w]*)$/) {
 
192
      push @lists, $list;
 
193
    }
 
194
  }
 
195
  close LURKERLIST;
 
196
  return @lists;
 
197
}
 
198
 
 
199
sub mailman_lists {
 
200
  my ($list_cmd, $defgroup, $listhost, $listurl, $lang) = @_;
 
201
  my ($list, $desc, %mmlists);
 
202
  my ($fh, $filename) = tempfile();
 
203
  open my $ll_exec, $list_cmd or die "Could not open $list_cmd: $!";
 
204
  while (<$ll_exec>) { print $fh $_; };
 
205
  close $ll_exec;
 
206
  close $fh;
 
207
 
 
208
  my $ll_charset = uc(`/usr/bin/file -i $filename | sed -e 's/^.*charset=//g'`);
 
209
  chomp ($ll_charset);
 
210
 
 
211
  my @list_lists = `/usr/bin/iconv -f $ll_charset -t UTF-8 $filename`;
 
212
  unlink($filename);
 
213
 
 
214
  for (@list_lists) {
 
215
    chomp;
 
216
    next unless (($list, $desc) = /^\s*([0-9-_\w]*)\s-\s(.*)\s*$/);
 
217
    if ($desc eq "[no description available]") {
 
218
      $desc = "";
 
219
    }
 
220
    my $list_lc = lc($list);
 
221
    if (not (grep(/$list_lc/, @glob::lurkerlists))) {
 
222
      $mmlists{$list_lc} = { id => $list_lc,
 
223
                            group => $defgroup,
 
224
                            title => $list,
 
225
                            address => $list . '@' . $listhost,
 
226
                            link => $listurl . '/' . $list,
 
227
                            desc => $desc,
 
228
                            lang => $lang };
 
229
    }
 
230
  }
 
231
  my $mmlref = \%mmlists;
 
232
  return $mmlref;
 
233
}
 
234
 
 
235
sub dump_lists {
 
236
  my ($dlref) = shift;
 
237
  my %dlists = %$dlref;
 
238
  my ($group, $writeflag) = "";
 
239
  open LOCALCONF, ">> $glob::localconf" or die "Could not open $glob::localconf: $!";
 
240
  if ($glob::writefile ne "") {
 
241
    $writeflag = "yes";
 
242
    open WRITEFILE, "> $glob::writefile" or die "Could not open $glob::writefile: $!";
 
243
  }
 
244
  #for $_ (sort { $dlists{$a}{id} cmp $dlists{$b}{id} } keys %dlists) {
 
245
  for $_ (sort {($dlists{$a}{group} cmp $dlists{$b}{group} ) or ($dlists{$a}{id} cmp $dlists{$b}{id} ) } keys %dlists) {
 
246
    unless ($dlists{$_}{group} eq $group)
 
247
    {
 
248
      $group = $dlists{$_}{group};
 
249
      print LOCALCONF "\n";
 
250
      print LOCALCONF "group = $group\n";
 
251
      print LOCALCONF "        heading = $group\n";
 
252
      print LOCALCONF "\n";
 
253
    }
 
254
    print LOCALCONF "        list = $dlists{$_}{id}\n";
 
255
    print LOCALCONF "                title = $dlists{$_}{title}\n";
 
256
    print LOCALCONF "                language = $dlists{$_}{lang}\n";
 
257
    print LOCALCONF "                address = $dlists{$_}{address}\n";
 
258
    print LOCALCONF "                link = $dlists{$_}{link}\n";
 
259
    print LOCALCONF "                description = $dlists{$_}{desc}\n";
 
260
    print LOCALCONF "\n";
 
261
    if ($writeflag) { print WRITEFILE "$dlists{$_}{id}\n"; }
 
262
  }
 
263
  if ($writeflag) { close WRITEFILE; }
 
264
  close LOCALCONF;
 
265
}
 
266
 
 
267
sub import_lists {
 
268
  my $iulref = shift;
 
269
  my @ulists = @$iulref;
 
270
  my $ulfile = pop(@ulists);
 
271
  my @lists;
 
272
  if ($ulfile ne " ") {
 
273
    if (-f $ulfile) {
 
274
      open ULFILE, $ulfile or die "Could not open $ulfile: $!";
 
275
      while (<ULFILE>) {
 
276
        chomp;
 
277
        push @lists, $_;
 
278
      }
 
279
      close ULFILE;
 
280
    }
 
281
    else {
 
282
      print STDERR "file $ulfile does not exist.\n";
 
283
      exit 1;
 
284
    }
 
285
  }
 
286
  elsif (@ulists) {
 
287
    @lists = @ulists;
 
288
  }
 
289
  else {
 
290
    @lists = @glob::lurkerlists;
 
291
  }
 
292
  for my $list (@lists) {
 
293
    my $mbox = "/var/lib/mailman/archives/private/$list.mbox/$list.mbox";
 
294
    if (-f $mbox) {
 
295
      if(system("/usr/bin/lurker-index", "-c", "$glob::lurkerconf",  "-l", "$list", "-i", "$mbox") != 0) {
 
296
        print STDERR "archives for $list could not be imported.\n";
 
297
      }
 
298
    }
 
299
    else {
 
300
      print STDERR "no archives available for $list at $mbox.\n";
 
301
    }
 
302
  }
 
303
}
 
304
 
 
305
my ($listhost, $defgroup, $listurl, $language, $ll_cmd) =
 
306
                ("example.org", "undef", "http://example.org", "en",
 
307
                 "/usr/lib/mailman/bin/list_lists |");
 
308
my ($import, $parse, $uselistfile, @uselists);
 
309
$glob::lurkerconf = "/etc/lurker/lurker.conf";
 
310
$glob::localconf = "$glob::lurkerconf.mailman";
 
311
$glob::writefile = "";
 
312
@glob::lurkerlists = ();
 
313
my @list_props = qw/title address link language description/;
 
314
 
 
315
# Bundling is nice anyway, and it is required or Getopt::Long will confuse
 
316
# -V and -v.
 
317
Getopt::Long::Configure("bundling");
 
318
 
 
319
GetOptions(
 
320
  'a|listhost=s'    => \$listhost,
 
321
  'i|import'        => sub { $import=1 },
 
322
  'f|listfile=s'    => \$uselistfile,
 
323
  'd|lists=s'       => \@uselists,
 
324
  'c|config=s'      => \$glob::lurkerconf,
 
325
  'g|group=s'       => \$defgroup,
 
326
  'h|help'          => \&usage,
 
327
  'l|link=s'        => \$listurl,
 
328
  'o|outfile=s'     => \$glob::localconf,
 
329
  'p|parse'         => sub { $parse=1 },
 
330
  's|language=s'    => \$language,
 
331
  'v|version'       => \&version,
 
332
  'w|write-lists=s' => \$glob::writefile,
 
333
  'x|list-cmd=s'    => \$ll_cmd );
 
334
@uselists = split(/,/,join(',',@uselists));
 
335
 
 
336
@glob::lurkerlists = lurker_lists();
 
337
 
 
338
if ($parse && $import) {
 
339
  print STDERR "--parse and --import cannot be used together.\n";
 
340
  exit 1;
 
341
}
 
342
elsif ($parse) {
 
343
  check_group($defgroup);
 
344
  my $mmmlref = mailman_lists($ll_cmd, $defgroup, $listhost, $listurl, $language);
 
345
  dump_lists($mmmlref);
 
346
}
 
347
elsif ($import && $uselistfile && @uselists) {
 
348
  print STDERR "--listfile and --lists cannot be used together.\n";
 
349
  exit 1;
 
350
}
 
351
elsif ($import) {
 
352
  if (not ($uselistfile)) { $uselistfile = " "; }
 
353
  push @uselists, $uselistfile;
 
354
  my $ulref = \@uselists;
 
355
  import_lists($ulref);
 
356
}
 
357
else {
 
358
  usage();
 
359
}