forked from sympa-community/sympa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk-sympa-dist.pl.in
116 lines (97 loc) · 3.1 KB
/
mk-sympa-dist.pl.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2019 The Sympa Community. See the AUTHORS.md file at the
# top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use lib 'src/lib/';
use strict;
use warnings;
use English qw(-no_match_vars);
use Pod::Usage;
use Sympa::ConfDef;
use Sympa::Constants;
my $modfail; # any of required modules are not installed.
BEGIN {
$modfail = !eval {
require Conf;
require Sympa::Tools::Text;
};
}
# Set language context if possible.
*gettext = sub { $_[1] ? sprintf('%*s', $_[1], $_[0]) : $_[0] };
if ($modfail) {
no warnings;
eval { require Text::Wrap; };
if ($EVAL_ERROR) {
*Sympa::Tools::Text::wrap_text = sub {"$_[1]$_[0]\n"};
} else {
$Text::Wrap::columns = 78;
*Sympa::Tools::Text::wrap_text =
sub { Text::Wrap::wrap($_[1], $_[2], $_[0]) . "\n"; };
}
}
## sympa dist configuration file
my $dist_conf = 'sympa.conf-dist';
my $umask = umask 037;
my $fh;
unless (open $fh, '>', $dist_conf) {
umask $umask;
die "$0: "
. sprintf(gettext("Unable to open %s : %s"), $dist_conf, $ERRNO)
. "\n";
}
umask $umask;
my $title;
foreach my $param (@Sympa::ConfDef::params) {
unless ($param->{'name'}) {
$title = gettext($param->{'gettext_id'})
if $param->{'gettext_id'};
next;
}
next unless $param->{'file'};
if ($title) {
printf $fh "###\\\\\\\\ %s ////###\n\n", $title;
undef $title;
}
printf $fh "## %s\n", $param->{'name'};
if ($param->{'gettext_id'}) {
print $fh Sympa::Tools::Text::wrap_text(
gettext($param->{'gettext_id'}),
'## ', '## ');
}
print $fh Sympa::Tools::Text::wrap_text(
gettext($param->{'gettext_comment'}),
'## ', '## ')
if $param->{'gettext_comment'};
if (defined $param->{'sample'}) {
printf $fh '## ' . gettext('Example: ') . "%s\t%s\n",
$param->{'name'}, $param->{'sample'};
}
if (defined $param->{'default'}) {
printf $fh "#%s\t%s\n", $param->{'name'}, $param->{'default'};
} elsif ($param->{'optional'}) {
printf $fh "#%s\t\n", $param->{'name'};
} else {
printf $fh "#%s\t%s\n", $param->{'name'},
gettext("(You must define this parameter)");
}
print $fh "\n";
}
close $fh;
print STDERR "$dist_conf file has been created\n";