root/bin/pl-init

Revision 328:73e179721396, 7.3 KB (checked in by Anselm Lingnau <anselm@…>, 9 months ago)

Various changes to pl-init.
pl-init will now add the list owner to the list as a subscriber with admin
privileges. This is mainly to make life easier for deployments of many lists
with Project Guinevere.

Also, the --config=... command line option was changed to read configuration
parameter assignments from a file whose name is given as the argument.
Individual paramter assignments may now be passed as additional command-line
arguments after the list owner address.

  • Property exe set to *
Line 
1#!/usr/bin/perl -w
2
3=head1 NAME
4
5pl-init - Initialise a Lancelot mailing list
6
7=head1 SYNOPSIS
8
9 pl-init [-v?] [--clone=otherlist] [--config=FILE] ...
10        [--[no]mailfilter] [--our-isp] [--verbose]
11          list@domain owner-address key=value ...
12
13=head1 OVERVIEW
14
15The B<pl-init> command creates a new Lancelot mailing list with
16a sensible (if basic) configuration.
17
18=head1 DESCRIPTION
19
20The B<pl-init> command creates a new Lancelot mailing list with no
21subscribers. It installs a basic configuration (which should be
22sensible) and allows the list owner to change individual configuration
23settings and/or clone the configuration of another list.
24
25The initial configuration is derived from (1) hard-coded defaults, (2)
26the content of a system-wide defaults file (if available), (3) the
27content of the user-specific defaults file F<$HOME/.pl/defaults.conf>
28(if available), (4) any files whose names are passed on the command line
29by means of the B<--config> option, and (5) any configuration parameter
30assignments given on the command line, in that order. Later settings
31override earlier ones.  Between (3) and (4), the B<list.address> parameter
32is set to I<list@domain>, the B<list.owneraddress> parameter is set to
33I<owner-address>, the B<list.ownername> parameter is set to the list
34owner's name if one is passed as part of I<owner-address>, and the
35B<list.name> parameter is set to the local part of I<list@domain>,
36capitalised.
37
38Any command-line parameters passed after I<owner-address> will be
39considered configuration parameter assignments in the sense of (5) above.
40Note that these are pre-parsed by the shell, and USE QUOTES IF YOUR
41CONFIGURATION PARAMETER ASSIGNMENTS CONTAIN WHITESPACE.
42
43If a list configuration is "cloned" from that of another list, that
44list's configuration is copied to the new list after the defaults
45files have been processed but before the configuration files and
46parameter assignments given on the command line take effect.
47This makes it possible to copy a list's configuration "except for"
48some specific settings. The list and owner addresses are set immediately
49before the command-line parameter assignments are processed, so they will
50be correct for a "cloned" list; you overwrite them from the command line
51at your own peril.
52
53The I<owner-address> will also be subscribed to the list as an
54administrator. If you'd rather not have this, add the configuration
55parameter
56
57  list.subscribeowner = 0
58
59to one of the default files or invoke B<pl-init> like
60
61  pl-init list@domain owner@domain list.subscribeowner=0
62
63
64=head1 OPTIONS
65
66=over 4
67
68=item B<--clone>=I<otherlist@otherlistdomain>
69
70Copies I<otherlist@otherlistdomain>'s configuration as far as
71possible. I<otherlist@otherlistdomain> must belong to the same user
72as the new list.
73
74=item B<--config>=I<file>
75
76Reads configuration parameter assignments from I<file>. Empty lines
77and comment lines (starting with "#") in I<file> will be ignored.
78
79If B<--config> is used together with B<--clone>, the changes take
80place after the configuration has been cloned. There may be multiple
81B<--config> options on the same command line. Configuration parameters
82may be changed later using the B<pl-conf> command.
83
84=item B<--mailfilter>
85
86For Our-ISP style lists, generates a F<.mailfilter> file
87in the list directory which redirects the various list addresses to the
88pl-incoming(1) program.
89
90=item B<--nomailfilter>
91
92Causes the program to not generate a F<.mailfilter> file for an
93Our-ISP-style Lancelot list.
94
95=item B<--our-isp>
96
97Creates the mailing list according to the conventions of Our-ISP. In
98particular, this means that the list database will be created in
99F<$HOME/domains/>I<domain>F</>I<list>F</list.db> rather than
100F<$HOME/.pl/>I<list>F<@>I<domain>F</list.db>. Implies B<--mailfilter>.
101
102=back
103
104=head1 SEE ALSO
105
106pl-conf(1), pl-init(1), pl-incoming(1), pl-list(1), pl-subchange(1), pl-subscribe(1)
107
108=head1 AUTHOR
109
110Anselm Lingnau <anselm@anselms.net>
111
112=head1 COPYRIGHT AND LICENSE
113
114Copyright 2004-11 by Anselm Lingnau. This program is free software; you
115may redistribute it and/or modify it under the terms of the GNU
116General Public License as published by the Free Software Foundation;
117either version 2 of the License, or (at your option) any later version.
118
119This program is distributed in the hope that it will be useful, but
120WITHOUT ANY WARRANTY; without even the implied warranty of
121MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
122General Public License for more details.
123
124You should have received a copy of the GNU General Public License
125along with this program; if not, refer to
126<URL:http://www.gnu.org/copyleft/gpl.html>. You may also obtain it by
127writing to the Free Software Foundation, Inc., 59 Temple Place - Suite
128330, Boston, MA 02111-1307, USA.
129
130=cut
131
132use strict;
133
134# Make Binary find it's libraries for non standard installations ...
135use Config;
136use File::Basename;
137use vars qw($g_base_dir);
138BEGIN {
139    use FindBin qw($Bin);
140    $g_base_dir = dirname ($Bin);
141}
142use lib "$g_base_dir/lib";
143use lib "$g_base_dir/lib/perl5/$Config{version}";
144use lib "$g_base_dir/lib/perl5/site_perl/$Config{version}";
145
146use Lancelot::GetOpt qw/GetOptions/;
147
148use Lancelot::DB;
149use Lancelot::Log qw/log/;
150
151my %opts;
152
153GetOptions(\%opts, -defaults,
154           -argvmin => 2, "need list and owner address",
155           "our-isp?", "clone=", "config@", "mailfilter!");
156
157my $listaddr = shift;
158my $owneraddr = (Email::Address->parse(shift))[0];
159my $ownername = $owneraddr->phrase || $owneraddr->comment;
160
161my %options = ( create => 1, ourisp => $opts{"our-isp"} );
162
163my $db = new Lancelot::DB $listaddr, \%options
164    or die "$0: error creating list $listaddr\n";
165
166clone_list($db, $opts{clone}) if $opts{clone};
167
168$db->set_config("list.address", $listaddr);
169$db->set_config("list.owneraddress", $owneraddr->address);
170$db->set_config("list.ownername", $ownername) if $ownername;
171my $listname = $listaddr;
172$listname =~ s/\@.*$//;
173$db->set_config("list.name", ucfirst($listname));
174
175$db->set_configs_from_file($_, 0) foreach @{$opts{config}};
176$db->set_configs(@ARGV) if @ARGV;
177
178if ($opts{"our-isp"} && !($opts{mailfilter} == 0)) {
179    my ($mfname) = File::Spec->join($db->get_listdir, ".mailfilter");
180    log "info", "creating mailfilter file $mfname";
181    my ($mfh) = IO::File->new("> $mfname");
182
183    if ($mfh) {
184        print $mfh qq{to "|$Bin/pl-incoming $listaddr"\n};
185        $mfh->close;
186        chmod 0600, $mfname;
187    } else {
188        die "$0: couldn't create $mfname: $!\n";
189    }
190} else {
191    my $xlistaddr = $listaddr;
192    my $delim = $db->get_config("mail.delimiter");
193    $xlistaddr =~ s/\@/${delim}ANYTHING\@/;
194    my $user = getpwuid($<);
195
196    print "Make sure that within your MTA setup, messages to\n\n";
197    print "    $listaddr   as well as\n";
198    print "    $xlistaddr\n\n";
199    print "are piped into\n\n";
200    print "    $Bin/pl-incoming --user $user $listaddr\n\n";
201    print "Consult Project Lancelot's Deployment-HOWTO for details.\n";
202}
203
204my $subscribe_owner = $db->get_config("list.subscribeowner");
205if ($subscribe_owner) {
206    log "info", "subscribing owner address as list administrator";
207    unless ($db->add_address($owneraddr, { admin => 1 })) {
208        log "err", "error subscribing $owneraddr\n";
209    }
210}
211
212sub clone_list {
213    my ($db, $clonelist) = @_;
214
215    log "info", "cloning list $clonelist";
216    my ($db1) = new Lancelot::DB $clonelist
217        or die "$0: list $clonelist does not exist\n";
218    foreach my $c ($db1->config_names) {
219        $db->set_config($c, $db1->get_config($c));
220    }
221}
Note: See TracBrowser for help on using the browser.