Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Xavier Bachelot
lemonldap-ng
Commits
08eb1f86
Commit
08eb1f86
authored
Dec 16, 2009
by
Yadd
Browse files
lmMigrateConfFiles2ini now can be used to upgrade
parent
0e65a2bf
Changes
2
Show whitespace changes
Inline
Side-by-side
modules/lemonldap-ng-common/scripts/convertConfig
View file @
08eb1f86
...
...
@@ -5,10 +5,12 @@ use Getopt::Long;
use
Lemonldap::NG::Common::
Conf
;
my
%opts
;
my
$result
=
GetOptions
(
\
%opts
,
'
help|h
',
'
current|c=s
',
'
new|n=s
',
'
latest|l
'
);
my
$result
=
GetOptions
(
\
%opts
,
'
help|h
',
'
current|c=s
',
'
new|n=s
',
'
latest|l
'
);
if
(
$opts
{
help
}
or
not
(
$opts
{
current
}
and
$opts
{
new
}
)
)
{
print
STDERR
"
Usage: $0 --current=/current/lemonldap-ng.ini --new=/new/lemonldap-ng.ini
\n
";
if
(
$opts
{
help
}
or
not
(
$opts
{
current
}
and
$opts
{
new
}
)
)
{
print
STDERR
"
Usage: $0 --current=/current/lemonldap-ng.ini --new=/new/lemonldap-ng.ini
\n
";
print
STDERR
"
# other parameters:
--latest -l
convert only last configuration
...
...
@@ -16,51 +18,60 @@ if( $opts{help} or not ( $opts{current} and $opts{new} ) ) {
exit
1
;
}
foreach
(
$opts
{
current
},
$opts
{
new
}
)
{
unless
(
-
e
$_
)
{
foreach
(
$opts
{
current
},
$opts
{
new
}
)
{
unless
(
-
e
$_
)
{
print
STDERR
"
$_
does not exist
\n
";
exit
2
;
}
unless
(
-
r
$_
)
{
unless
(
-
r
$_
)
{
print
STDERR
"
$_
is not readable
\n
";
exit
3
;
}
}
my
$old
=
Lemonldap::NG::Common::
Conf
->
new
({
my
$old
=
Lemonldap::NG::Common::
Conf
->
new
(
{
confFile
=>
$opts
{
current
},
noCache
=>
1
,
});
unless
(
$old
)
{
print
STDERR
"
Failed to get current conf :
$Lemonldap
::NG::Common::Conf::msg
\n
";
noCache
=>
1
,
}
);
unless
(
$old
)
{
print
STDERR
"
Failed to get current conf :
$Lemonldap
::NG::Common::Conf::msg
\n
";
exit
4
;
}
my
$new
=
Lemonldap::NG::Common::
Conf
->
new
({
my
$new
=
Lemonldap::NG::Common::
Conf
->
new
(
{
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
";
force
=>
1
,
noCache
=>
1
,
cfgNumFixed
=>
1
,
}
);
unless
(
$new
)
{
print
STDERR
"
Failed to create new conf object :
$Lemonldap
::NG::Common::Conf::msg
\n
";
exit
5
;
}
my
@available
;
if
(
$opts
{
lastest
}
)
{
if
(
$opts
{
lastest
}
)
{
@available
=
$old
->
lastCfg
();
}
else
{
}
else
{
@available
=
$old
->
available
();
}
foreach
(
@available
)
{
my
$conf
=
$old
->
getConf
({
cfgNum
=>
$_
});
eval
{
delete
$conf
->
{
reVHosts
};
}
foreach
(
@available
)
{
my
$conf
=
$old
->
getConf
(
{
cfgNum
=>
$_
}
);
eval
{
delete
$conf
->
{
reVHosts
};
delete
$conf
->
{
cipher
};
};
unless
(
$conf
){
print
STDERR
"
\n
Failed to get conf
$_
:
$Lemonldap
::NG::Common::Conf::msg
\n
";
unless
(
$conf
)
{
print
STDERR
"
\n
Failed to get conf
$_
:
$Lemonldap
::NG::Common::Conf::msg
\n
";
exit
6
;
}
print
"
Conf
$conf
->{cfgNum}:
";
my
$r
=
$new
->
saveConf
(
$conf
);
print
(
$r
?
"
stored
"
:
"
failed:
$Lemonldap
::NG::Common::Conf::msg
");
print
(
$r
?
"
stored
"
:
"
failed:
$Lemonldap
::NG::Common::Conf::msg
"
);
print
"
\n
";
}
modules/lemonldap-ng-common/scripts/lmMigrateConfFiles2ini
View file @
08eb1f86
...
...
@@ -4,40 +4,77 @@ use strict;
use
Getopt::
Long
;
use
Config::
IniFiles
;
our
%opts
;
my
%opts
;
my
$result
=
GetOptions
(
\
%opts
,
'
storage|s=s
',
'
apply|a=s
',
'
dir|d=s
',
'
ini|i=s
',
'
preserve|p
'
);
use
Lemonldap::NG::Common::Conf::
Constants
;
$opts
{
dir
}
||=
'
/etc/lemonldap-ng
';
my
$old
=
{
storage
=>
$opts
{
storage
}
||
"
$opts
{dir}/storage.conf
",
my
$old
=
{
storage
=>
$opts
{
storage
}
||
"
$opts
{dir}/storage.conf
",
apply
=>
$opts
{
apply
}
||
"
$opts
{dir}/apply.conf
",
};
};
my
$new
=
$opts
{
ini
}
||
"
$opts
{dir}/lemonldap-ng.ini
";
my
$datas
;
-
r
$old
->
{
storage
}
or
quit
(
2
,"
$old
->{storage} is not readeable
");
-
r
$old
->
{
storage
}
or
quit
(
2
,
"
$old
->{storage} is not readeable
"
);
open
F
,
$old
->
{
storage
};
while
(
<
F
>
){
next
if
(
/^\s*(?:#.*)?$/
);
my
(
$k
,
$v
)
=
(
/^(\w+)\s*=\s*(.*)$/
)
or
quit
(
3
,"
bad line in
$old
->{storage}:
$_
");
$datas
->
{
configuration
}
->
{
$k
}
=
$v
;
while
(
<
F
>
)
{
next
if
(
/^\s*(?:#.*)?$/
);
my
(
$k
,
$v
)
=
(
/^(\w+)\s*=\s*(.*)$/
)
or
quit
(
3
,
"
bad line in
$old
->{storage}:
$_
"
);
$datas
->
{
configuration
}
->
{
$k
}
=
$v
;
}
close
F
;
if
(
-
e
$old
->
{
apply
}){
open
F
,
$old
->
{
apply
};
while
(
<
F
>
){
next
if
(
/^\s*(?:#.*)?$/
);
my
(
$k
,
$v
)
=
(
/^([\w\.\-]+)\s+(.*)$/
)
or
quit
(
3
,"
bad line in
$old
->{apply}:
$_
");
$datas
->
{
apply
}
->
{
$k
}
=
$v
;
if
(
-
e
$old
->
{
apply
}
)
{
open
F
,
$old
->
{
apply
};
while
(
<
F
>
)
{
next
if
(
/^\s*(?:#.*)?$/
);
my
(
$k
,
$v
)
=
(
/^([\w\.\-]+)\s+(.*)$/
)
or
quit
(
3
,
"
bad line in
$old
->{apply}:
$_
"
);
$datas
->
{
apply
}
->
{
$k
}
=
$v
;
}
close
F
;
}
if
(
-
e
$new
){
-
w
$new
or
quit
(
4
,"
$new
is not writeable
");
my
$conf
=
Config::
IniFiles
->
new
(
-
file
=>
$new
);
my
$conf
;
if
(
-
e
$new
)
{
-
w
$new
or
quit
(
4
,
"
$new
is not writeable
"
);
$conf
=
Config::
IniFiles
->
new
(
-
file
=>
$new
)
or
quit
(
4
,
"
Unable to open
$new
:
\n\t
"
.
join
(
"
\n\t
",
@
Config::IniFiles::
errors
)
);
}
else
{
$conf
=
Config::
IniFiles
->
new
();
}
my
@sections
=
$conf
->
Sections
();
foreach
(
qw(configuration apply)
)
{
next
unless
(
ref
$datas
->
{
$_
}
);
$conf
->
AddSection
(
$_
)
unless
(
$conf
->
SectionExists
(
$_
)
);
while
(
my
(
$k
,
$v
)
=
each
%
{
$datas
->
{
$_
}
}
)
{
if
(
$conf
->
exists
(
$_
,
$k
)
)
{
$conf
->
setval
(
$_
,
$k
,
$v
);
}
else
{
$conf
->
newval
(
$_
,
$k
,
$v
);
}
}
}
if
(
-
e
$new
)
{
$conf
->
RewriteConfig
();
}
else
{
$conf
->
WriteConfig
(
$new
)
or
quit
(
5
,
"
Unable to create
$new
:
\n\t
"
.
join
(
"
\n\t
",
@
Config::IniFiles::
errors
)
);
unless
(
$opts
{
preserve
}
)
{
unlink
$old
->
{
storage
},
$old
->
{
apply
};
}
}
sub
quit
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment