summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2008-10-29 00:57:28 +0000
committerOlivier Blin <oblin@mandriva.com>2008-10-29 00:57:28 +0000
commitae9e730f7d5046243aeb87d0eb42efd18f541287 (patch)
treef1eb27c5a9260c05f724714a5d75daf518e71fe2
parent14da6683acda76b094c886508c79dc78fbb5be11 (diff)
downloaddraklive-ae9e730f7d5046243aeb87d0eb42efd18f541287.tar
draklive-ae9e730f7d5046243aeb87d0eb42efd18f541287.tar.gz
draklive-ae9e730f7d5046243aeb87d0eb42efd18f541287.tar.bz2
draklive-ae9e730f7d5046243aeb87d0eb42efd18f541287.tar.xz
draklive-ae9e730f7d5046243aeb87d0eb42efd18f541287.zip
move config code in MDV::Draklive::Config
-rwxr-xr-xdraklive92
-rw-r--r--lib/MDV/Draklive/Config.pm87
2 files changed, 95 insertions, 84 deletions
diff --git a/draklive b/draklive
index 59cbacb..7c33ca8 100755
--- a/draklive
+++ b/draklive
@@ -28,7 +28,6 @@ use fs;
use modules;
use detect_devices;
use run_program;
-use Cwd 'getcwd';
use Getopt::Long;
use Pod::Usage;
use File::Temp;
@@ -41,6 +40,7 @@ use MDV::Draklive::Loopback;
use MDV::Draklive::Initrd;
use MDV::Draklive::Mounts;
use MDV::Draklive::CustomMedia;
+use MDV::Draklive::Config;
my %storage = (
cdrom => {
@@ -1211,82 +1211,6 @@ sub copy_wizard {
$in->exit;
}
-sub read_config {
- my ($live, $config_root, $config_path, $settings_path) = @_;
-
- if ($config_path && -e getcwd() . '/' . $config_path) {
- $config_root = getcwd();
- }
- print "using $config_root as directory root\n";
-
- add2hash($live->{settings} ||= {}, { getVarsFromSh($config_root . '/' . $settings_path) }) if $settings_path;
- if ($config_path) {
- #- don't use do(), since it can't see lexicals in the enclosing scope
- my $cfg = eval(cat_($config_root . '/' . $config_path)) or die "unable to load $config_path: $@\n";
- put_in_hash($live, $cfg);
- print "loaded $config_path as config file\n";
- }
- $live->{settings}{config_root} = $config_root;
-}
-
-sub check_config {
- my ($live) = @_;
- unless (keys(%$live)) {
- warn "no live definition\n";
- Pod::Usage::pod2usage();
- }
- #- check for minimum requirements
- ref $live->{media} && $live->{media}{storage} or die "no media storage definition\n";
- ref $live->{system} or die "no system definition\n";
-}
-
-sub complete_config {
- my ($live) = @_;
-
- my $default_prefix = {
- build => {
- boot => '/boot',
- files => '/files',
- dist => '/dist',
- initrd => '/initrd',
- loopbacks => '/loopbacks',
- modules => '/modules',
- scripts => '/scripts',
- },
- media => {
- boot => '/boot',
- hidden_boot => '/.boot',
- loopbacks => '/loopbacks',
- hidden_loopbacks => '/.loopbacks',
- mnt => '/media',
- },
- live => {
- mnt => '/live',
- },
- };
-
- #- set unsupplied config dirs
- add2hash($live->{prefix}{$_} ||= {}, $default_prefix->{$_}) foreach keys %$default_prefix;
-
- $live->{settings}{builddir} ||= '/var/lib/draklive/build';
- $live->{settings}{chroot} ||= '/var/lib/draklive/chroot';
-
- $live->{settings}{arch} ||= chomp_(`rpm --eval '%{_target_cpu}'`);
- $live->{media}{title} ||= "live";
-
- bless $live->{media}, 'MDV::Draklive::Media';
-
- mkdir_p($live->get_builddir);
- mkdir_p($live->get_system_root);
- $live->{mnt} ||= $live->get_builddir . "/mnt";
-}
-
-sub dump_config {
- my ($live) = @_;
- use Data::Dumper;
- print Data::Dumper->Dump([ $live ], [ "live" ]);
-}
-
sub clean {
my ($live) = @_;
# umount filesystem in the live before cleaning
@@ -1295,7 +1219,7 @@ sub clean {
}
my @actions = (
- { name => 'dump-config', do => \&dump_config },
+ { name => 'dump-config', do => \&MDV::Draklive::Config::dump_config },
{ name => 'clean', do => \&clean },
{ name => 'install', do => \&install_system },
{ name => 'post-install', do => \&post_install_system },
@@ -1315,9 +1239,9 @@ die "you must be root to run this program\n" if $>;
my $live_object = 'MDV::Draklive::Live'->new;
my %opts;
-my $config_root = '/etc/draklive';
-my $config_path = 'config/live.cfg';
-my $settings_path = 'config/settings.cfg';
+my $config_root = $MDV::Draklive::Config::default_config_root;
+my $config_path = $MDV::Draklive::Config::default_config_path;
+my $settings_path = $MDV::Draklive::Config::default_settings_path;
GetOptions(
"help" => sub { Pod::Usage::pod2usage('-verbose' => 1) },
"copy-wizard" => \$live_object->{copy_wizard},
@@ -1338,9 +1262,9 @@ if ($live_object->{copy_wizard}) {
copy_wizard($live_object);
} else {
every { !$_->{to_run} } @actions and Pod::Usage::pod2usage();
- read_config($live_object, $config_root, $config_path, $settings_path);
- check_config($live_object);
- complete_config($live_object);
+ MDV::Draklive::Config::read_config($live_object, $config_root, $config_path, $settings_path);
+ MDV::Draklive::Config::check_config($live_object);
+ MDV::Draklive::Config::complete_config($live_object);
foreach my $region ($live_object->{all_regions} ? sort(keys %{$live_object->{regions}}) : $live_object->{settings}{region}) {
$region and print qq(=== proceeding with region "$region"\n);
$live_object->{settings}{region} = $region;
diff --git a/lib/MDV/Draklive/Config.pm b/lib/MDV/Draklive/Config.pm
new file mode 100644
index 0000000..3172d80
--- /dev/null
+++ b/lib/MDV/Draklive/Config.pm
@@ -0,0 +1,87 @@
+package MDV::Draklive::Config;
+
+use MDK::Common;
+use Pod::Usage;
+use Cwd 'getcwd';
+
+our $default_config_root = '/etc/draklive';
+our $default_config_path = 'config/live.cfg';
+our $default_settings_path = 'config/settings.cfg';
+
+sub read_config {
+ my ($live, $config_root, $config_path, $settings_path) = @_;
+
+ if ($config_path && -e getcwd() . '/' . $config_path) {
+ $config_root = getcwd();
+ }
+ print "using $config_root as directory root\n";
+
+ add2hash($live->{settings} ||= {}, { getVarsFromSh($config_root . '/' . $settings_path) }) if $settings_path;
+ if ($config_path) {
+ #- don't use do(), since it can't see lexicals in the enclosing scope
+ my $cfg = eval(cat_($config_root . '/' . $config_path)) or die "unable to load $config_path: $@\n";
+ put_in_hash($live, $cfg);
+ print "loaded $config_path as config file\n";
+ }
+ $live->{settings}{config_root} = $config_root;
+}
+
+sub check_config {
+ my ($live) = @_;
+ unless (keys(%$live)) {
+ warn "no live definition\n";
+ Pod::Usage::pod2usage();
+ }
+ #- check for minimum requirements
+ ref $live->{media} && $live->{media}{storage} or die "no media storage definition\n";
+ ref $live->{system} or die "no system definition\n";
+}
+
+sub complete_config {
+ my ($live) = @_;
+
+ my $default_prefix = {
+ build => {
+ boot => '/boot',
+ files => '/files',
+ dist => '/dist',
+ initrd => '/initrd',
+ loopbacks => '/loopbacks',
+ modules => '/modules',
+ scripts => '/scripts',
+ },
+ media => {
+ boot => '/boot',
+ hidden_boot => '/.boot',
+ loopbacks => '/loopbacks',
+ hidden_loopbacks => '/.loopbacks',
+ mnt => '/media',
+ },
+ live => {
+ mnt => '/live',
+ },
+ };
+
+ #- set unsupplied config dirs
+ add2hash($live->{prefix}{$_} ||= {}, $default_prefix->{$_}) foreach keys %$default_prefix;
+
+ $live->{settings}{builddir} ||= '/var/lib/draklive/build';
+ $live->{settings}{chroot} ||= '/var/lib/draklive/chroot';
+
+ $live->{settings}{arch} ||= chomp_(`rpm --eval '%{_target_cpu}'`);
+ $live->{media}{title} ||= "live";
+
+ bless $live->{media}, 'MDV::Draklive::Media';
+
+ mkdir_p($live->get_builddir);
+ mkdir_p($live->get_system_root);
+ $live->{mnt} ||= $live->get_builddir . "/mnt";
+}
+
+sub dump_config {
+ my ($live) = @_;
+ use Data::Dumper;
+ print Data::Dumper->Dump([ $live ], [ "live" ]);
+}
+
+1;