lemonldap-ng/lemonldap-ng-common/scripts/convertConfig

91 lines
2.0 KiB
Plaintext
Raw Normal View History

2009-12-15 17:31:13 +01:00
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Lemonldap::NG::Common::Conf;
my %opts;
2009-12-30 21:00:54 +01:00
my $result = GetOptions( \%opts, 'help|h', 'current|c=s', 'new|n=s', 'latest|l',
'force|f' );
2009-12-15 17:31:13 +01:00
if ( $opts{help} or not( $opts{current} and $opts{new} ) ) {
2009-12-30 21:00:54 +01:00
print STDERR "
## Lemonldap::NG configuration converter ##
Usage: $0 --current=/current/lemonldap-ng.ini --new=/new/lemonldap-ng.ini
other parameters:
2009-12-15 17:31:13 +01:00
--latest -l
convert only last configuration
2009-12-30 21:00:54 +01:00
--force -f
continue even if an error occurs
2009-12-15 17:31:13 +01:00
";
exit 1;
}
foreach ( $opts{current}, $opts{new} ) {
unless ( -e $_ ) {
2009-12-15 17:31:13 +01:00
print STDERR "$_ does not exist\n";
exit 2;
}
unless ( -r $_ ) {
2009-12-15 17:31:13 +01:00
print STDERR "$_ is not readable\n";
exit 3;
}
}
my $old = Lemonldap::NG::Common::Conf->new(
{
2009-12-30 21:00:54 +01:00
confFile => $opts{current},
noCache => 1,
}
);
unless ($old) {
print STDERR
"Failed to get current conf : $Lemonldap::NG::Common::Conf::msg\n";
2009-12-15 17:31:13 +01:00
exit 4;
}
my $new = Lemonldap::NG::Common::Conf->new(
{
2009-12-30 21:00:54 +01:00
confFile => $opts{new},
force => 1,
noCache => 1,
cfgNumFixed => 1,
}
);
unless ($new) {
print STDERR
"Failed to create new conf object : $Lemonldap::NG::Common::Conf::msg\n";
2009-12-15 17:31:13 +01:00
exit 5;
}
my @available;
if ( $opts{lastest} ) {
2009-12-15 17:31:13 +01:00
@available = $old->lastCfg();
}
else {
2009-12-15 17:31:13 +01:00
@available = $old->available();
}
foreach (@available) {
my $conf = $old->getConf( { cfgNum => $_ } );
eval {
delete $conf->{reVHosts};
2009-12-30 21:00:54 +01:00
delete $conf->{cipher};
2009-12-15 17:31:13 +01:00
};
unless ($conf) {
print STDERR
"\nFailed to get conf $_ : $Lemonldap::NG::Common::Conf::msg\n";
2009-12-30 21:00:54 +01:00
next if ( $opts{force} );
2009-12-15 17:31:13 +01:00
exit 6;
}
2009-12-30 21:00:54 +01:00
if ( my $r = $new->saveConf($conf) ) {
print "Conf $conf->{cfgNum} stored\n";
next;
}
print STDERR
"Unable to store configuration $conf->{cfgNum}: $Lemonldap::NG::Common::Conf::msg";
next if ( $opts{force} );
exit 7;
2009-12-15 17:31:13 +01:00
}
2009-12-30 21:00:54 +01:00
exit 0;