Unverified Commit d4264e67 authored by IKEDA Soji's avatar IKEDA Soji Committed by GitHub
Browse files

Merge pull request #1370 from ikedas/issue-508_601 by ikedas

Break sympa_wizard.pl to "sympa config…" commands
parents 7b54482e ab69eaae
......@@ -18,7 +18,6 @@ Makefile
/po/sympa/POTFILES
/po/web_help/POTFILES
/sympa.conf
/sympa.conf-dist
# make
......@@ -31,7 +30,6 @@ Makefile
*.o
*.po~
/previous_sympa_version
/mk-sympa-dist.pl
/src/bin/*.pl
/src/cgi/*.fcgi
/src/libexec/*.pl
......@@ -55,7 +53,6 @@ Makefile
# make install
/data_structure.version
/sympa_wizard.pl.inst
# make dist
......
......@@ -101,8 +101,7 @@ EXTRA_DIST = \
$(noinst_SCRIPTS) \
$(nobase_modules_DATA)
CLEANFILES = \
sympa.conf-dist
CLEANFILES =
MSGFMT=@MSGFMT@
.po.mo:
......@@ -158,11 +157,6 @@ installconfig: installdir
chown $(USER) $(DESTDIR)$(confdir)/sympa.conf; \
chgrp $(GROUP) $(DESTDIR)$(confdir)/sympa.conf; \
fi
@echo "Installing configuration template ..."
-@echo "installing sympa.conf-dist"; \
$(INSTALL) -m 644 -T sympa.conf-dist $(DESTDIR)$(confdir)/sympa.conf-dist; \
chown $(USER) $(DESTDIR)$(confdir)/sympa.conf-dist; \
chgrp $(GROUP) $(DESTDIR)$(confdir)/sympa.conf-dist
-@if [ ! -f $(DESTDIR)$(sysconfdir)/data_structure.version ]; then \
cd $(DESTDIR)$(sysconfdir); \
echo "# automatically created file" >> data_structure.version; \
......@@ -204,13 +198,6 @@ nextstep:
@echo "# * Edit this file to define initial configuration:"
@echo "# $(confdir)/sympa.conf"
@echo "#"
@echo "# ADDITIONAL SETTINGS:"
@echo "# * You will find all available configuration settings in:"
@echo "# $(confdir)/sympa.conf-dist"
@echo "#"
@echo "# * Copy the configuration settings you want in:"
@echo "# $(confdir)/sympa.conf"
@echo "#"
@echo "# UPGRADING"
@echo "# * Run this script to upgrade your data structures:"
@echo "# $(sbindir)/sympa upgrade"
......@@ -218,7 +205,6 @@ nextstep:
uninstall-hook:
cd $(DESTDIR)$(confdir) && rm -f sympa.conf
cd $(DESTDIR)$(confdir) && rm -f sympa.conf-dist
cd $(DESTDIR)$(confdir) && rm -f wwsympa.conf
cd $(DESTDIR)$(sysconfdir) && rm -f data_structure.version
cd $(DESTDIR)$(sysconfdir) && rm -f README
......@@ -241,8 +227,3 @@ tidyall:
echo ')->process_paths(qw(src xt t))' \
) | $(PERL) -MCode::TidyAll
all-local: sympa.conf-dist
sympa.conf-dist:
@PERL5LIB=$(srcdir)/src/lib; export PERL5LIB; \
$(PERL) mk-sympa-dist.pl
......@@ -658,7 +658,6 @@ AM_CONDITIONAL(SETUID_QUEUE, [test "x$enable_setuid_queue" = "xyes"])
AC_CONFIG_FILES([
Makefile
sympa.conf
mk-sympa-dist.pl
default/Makefile
doc/Makefile
po/Makefile
......
......@@ -87,10 +87,6 @@ Command line utility to manage Sympa
Alias database maintenance
=item L<sympa_wizard(1)>
Help Performing Sympa Initial Setup
=back
=head3 Maintenance tools
......
# -*- 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) {
next if $param->{obsolete};
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";
......@@ -6,7 +6,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2021 The Sympa Community. See the
# Copyright 2017, 2018, 2019, 2021, 2022 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>.
#
......@@ -36,6 +36,9 @@ CLI_modules = \
Sympa/CLI/check.pm \
Sympa/CLI/close.pm \
Sympa/CLI/conf_2_db.pm \
Sympa/CLI/config.pm \
Sympa/CLI/config/create.pm \
Sympa/CLI/config/show.pm \
Sympa/CLI/copy.pm \
Sympa/CLI/create.pm \
Sympa/CLI/del.pm \
......
......@@ -27,6 +27,7 @@ use warnings;
use English qw(-no_match_vars);
use Getopt::Long qw(:config no_ignore_case);
use POSIX qw();
BEGIN { eval 'use Encode::Locale'; }
use Conf;
use Sympa::Constants;
......@@ -47,7 +48,31 @@ sub run {
my @argv = @_;
if ($class eq 'Sympa::CLI') {
# Deal with some POSIX locales (LL.encoding)
$class->istty;
# Detect console encoding.
if ($Encode::Locale::VERSION) {
unless ('ascii' eq
Encode::resolve_alias($Encode::Locale::ENCODING_CONSOLE_IN)) {
if ($class->istty(0)) {
binmode(STDIN, ':encoding(console_in):bytes');
foreach my $arg (@argv) {
Encode::from_to($arg,
$Encode::Locale::ENCODING_CONSOLE_IN, 'utf-8');
}
}
}
unless ('ascii' eq
Encode::resolve_alias($Encode::Locale::ENCODING_CONSOLE_OUT))
{
binmode(STDOUT, ':encoding(console_out):bytes')
if $class->istty(1);
binmode(STDERR, ':encoding(console_out):bytes')
if $class->istty(2);
}
}
# Deal with some POSIX locales (LL_cc.encoding)
my @langs =
map {s/[.].*\z//r} grep {defined} @ENV{qw(LANGUAGE LC_ALL LANG)};
$language->set_lang(@langs, 'en-US', 'en');
......@@ -160,6 +185,10 @@ sub run {
if ($arg eq '*') {
$val = $arg;
}
} elsif ($def eq 'keyvalue') {
if ($arg =~ /\A(\w+)=(.*)\z/) {
$val = [$1 => $2];
}
} else {
$val = $arg;
}
......@@ -299,6 +328,18 @@ sub arrange {
$is_arranged = 1;
}
my @istty;
sub istty {
my $class = shift;
unless (@_) { # Get tty-nesses.
@istty = (-t STDIN, -t STDOUT, -t STDERR);
} else {
return $istty[$_[0]];
}
}
# Moved from: _report() in sympa.pl.
sub _report {
my $class = shift;
......@@ -374,6 +415,7 @@ my $arg_labels = {
command => {gettext_id => 'command'},
string => {gettext_id => 'string'},
email => {gettext_id => 'email address'},
keyvalue => {gettext_id => '"key=value"'},
};
sub _arg_expected {
......
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2022 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/>.
package Sympa::CLI::config;
use strict;
use warnings;
use English qw(-no_match_vars);
use POSIX qw();
use Conf;
use Sympa::ConfDef;
use Sympa::Constants;
use Sympa::Language;
use Sympa::Tools::Data;
use parent qw(Sympa::CLI);
use constant _options => qw(output|o=s@);
use constant _args => qw(keyvalue*);
use constant _need_priv => 0;
my $language = Sympa::Language->instance;
sub _run {
my $class = shift;
my $options = shift;
my @argv = @_;
my %newConf;
foreach my $arg (@argv) {
# Check for key/values settings.
last unless ref $arg eq 'ARRAY';
my ($key, $val) = @$arg;
# FIXME: Resolve parameter aliase names.
$newConf{$key} = $val;
}
if (%newConf) {
my $curConf = _load();
return undef unless $curConf;
my $out = Sympa::Tools::Data::format_config(
[@Sympa::ConfDef::params],
$curConf, \%newConf,
only_changed => 1,
filter => ([@{$options->{output} // []}, qw(explicit mandatory)])
);
die "Not changed.\n" unless defined $out;
my $sympa_conf = Sympa::Constants::CONFIG();
my $date = POSIX::strftime('%Y%m%d%H%M%S', localtime time);
## Keep old config file
unless (rename $sympa_conf, $sympa_conf . '.' . $date) {
warn $language->gettext_sprintf('Unable to rename %s : %s',
$sympa_conf, $ERRNO);
}
# Write new config file.
my $umask = umask 037;
my $ofh;
unless (open $ofh, '>', $sympa_conf) {
umask $umask;
die "$0: "
. $language->gettext_sprintf('Unable to open %s : %s',
$sympa_conf, $ERRNO)
. "\n";
}
umask $umask;
chown [getpwnam(Sympa::Constants::USER)]->[2],
[getgrnam(Sympa::Constants::GROUP)]->[2], $sympa_conf
if $UID == 0;
print $ofh $out;
close $ofh;
print $language->gettext_sprintf(
"%s have been updated.\nPrevious versions have been saved as %s.\n",
$sympa_conf, "$sympa_conf.$date"
);
return 1;
}
Sympa::CLI->run(qw(help config));
}
# Old name: edit_configuragion() in sympa_wizard.pl.
# Obsoleted: Use Sympa::Tools::Data::format_config().
#sub _edit_configuration;
sub _load {
my $sympa_conf = shift || Sympa::Constants::CONFIG();
#FIXME: Refactor Conf.
my $res = Conf::_load_config_file_to_hash($sympa_conf);
return undef unless $res;
return $res->{config};
}
1;
__END__
=encoding utf-8
=head1 NAME
sympa-config - Manipulate configuration of Sympa
=head1 SYNOPSIS
C<sympa config> I<name>=I<value> ...
C<sympa config> I<sub-command> [ I<options> ... ]
=head1 DESCRIPTION
=over
=item C<sympa> C<config> I<name>C<=>I<value> ...
Edit configuration file in batch mode.
Arguments would include pairs of parameter name and value.
If no explicit changes given, configuration file won't be rewritten.
Options:
=over
=item C<-o>, C<--output=>I<set> ...
Specify set(s) of parameters to be output.
I<set> may be either C<omittable>, C<optional>, C<mandatory>,
C<full> (synonym for the former three), C<explicit> or C<minimal>.
This option can be specified more than once.
With this command, C<explicit> and C<mandatory> sets,
i.e. those defined in the configuration file explicitly,
specified in command line arguments or defined as mandatory,
are always included.
=back
=back
=head2 SUB-COMMANDS
Currently following sub-commands are available.
To see detail of each sub-command,
run 'C<sympa help config> I<sub-command>'.
=over
=item L<C<sympa config create> ...|sympa-config-create(1)>
Create configuration file.
=item L<C<sympa config show> ...|sympa-config-show(1)>
Show the content of configuration file.
=back
=head1 HISTORY
L<sympa_wizard.pl> appeared on Sympa 3.3.4b.9.
It was originally written by:
=over 4
=item Serge Aumont <sa@cru.fr>
=item Olivier SalaE<252>n <os@cru.fr>
=back
C<--batch> and C<--display> options are added on Sympa 6.1.25 and 6.2.15.
On Sympa 6.2.69b, the most of functions provided by this program was
reorganized and was integrated into C<sympa config> command line,
therefore sympa_wizard.pl was deprecated.
=cut
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2022 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/>.
package Sympa::CLI::config::create;
use strict;
use warnings;
use English qw(-no_match_vars);
use Sympa::ConfDef;
use Sympa::Constants;
use Sympa::Language;
use Sympa::Tools::Data;
use parent qw(Sympa::CLI::config);
use constant _options => qw(output|o=s@);
use constant _args => qw();
use constant _need_priv => 0;
my $language = Sympa::Language->instance;
# Old name: create_configuration() in sympa_wizard.pl.
sub _run {
my $class = shift;
my $options = shift;
my @argv = @_;
my $conf = $options->{config} // Sympa::Constants::CONFIG();
if (-f $conf) {
die $language->gettext_sprintf('The file %s already exists', $conf)
. "\n";
}
my $umask = umask 037;
my $ofh;
unless (open $ofh, '>', $conf) {
umask $umask;
die "$PROGRAM_NAME: "
. $language->gettext_sprintf('Unable to open %s : %s',
$conf, $ERRNO)
. "\n";
}
umask $umask;
chown [getpwnam(Sympa::Constants::USER)]->[2],
[getgrnam(Sympa::Constants::GROUP)]->[2], $conf
if $UID == 0;
print $ofh Sympa::Tools::Data::format_config([@Sympa::ConfDef::params],
filter => ($options->{output} // [qw(minimal)]));
close $ofh;
print $language->gettext_sprintf('The file %s has been created', $conf)
. "\n";
return 1;
}
1;
__END__
=encoding utf-8
=head1 NAME
sympa-config-create - Create configuration file
=head1 SYNOPSIS
C<sympa config create> S<[ C<--config=>I</path/to/new/sympa.conf> ]>
S<[ C<-o>, C<--output=>I<set> ... ]>
=head1 DESCRIPTION
Creates a new F<sympa.conf> configuration file.
Options:
=over
=item C<--config>, C<-f=>I</path/to/new/sympa.conf>
Use an alternative configuration file.
=item C<-o>, C<--output=>I<set> ...
Specify set(s) of parameters to be output.
I<set> may be either C<omittable>, C<optional>, C<mandatory>,
C<full> (synonym of the former three) or C<minimal>.
This option can be specified more than once.
By default only C<minimal> set of parameters, i.e. those described in the
installation manual, are written in the configuration file.
=back