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