1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# Copyright (C) 2005 Mandriva
# Olivier Blin <oblin@mandriva.com>
# Copyright (C) 2017-2018 Mageia
# Martin Whitaker <mageia@martin-whitaker.me.uk>
#
# 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, 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA.
# SYNOPSIS
# --------
# This package provides routines to read in and check the user-supplied
# settings and configuration files.
package MGA::DrakISO::Config;
use strict;
use MDK::Common;
use Pod::Usage;
use Cwd qw(abs_path);
#- these modules can be used from config files
use MGA::DrakISO::Mounts;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(read_config check_config complete_config dump_config);
sub read_config {
my ($build, $config_root, $config_path, $settings_path) = @_;
$config_root = abs_path($config_root);
print "Using $config_root as directory root\n";
if (substr($config_path, 0, 1) ne '/') {
$config_path = $config_root . '/' . $config_path;
}
-e $config_path or die "ERROR: $config_path does not exist\n";
if (substr($settings_path, 0, 1) ne '/') {
$settings_path = $config_root . '/' . $settings_path;
}
-e $settings_path or die "ERROR: $settings_path does not exist\n";
add2hash($build->{settings} ||= {}, { getVarsFromSh($settings_path) });
#- don't use do(), since it can't see lexicals in the enclosing scope
my $cfg = eval(cat_($config_path)) or die "ERROR: unable to load $config_path: $@\n";
put_in_hash($build, $cfg);
print "Loaded $config_path as config file\n";
$build->{settings}{config_root} = $config_root;
}
sub check_config {
my ($build) = @_;
unless (keys(%$build)) {
warn "no build definition\n";
Pod::Usage::pod2usage();
}
#- check for minimum requirements
$build->{settings}{arch}
or die "ERROR: you must specify an architecture\n";
$build->{media}{storage}
or die "ERROR: you must specify the media storage type\n";
$build->{media}{label}
or die "ERROR: you must supply a media label\n";
}
sub complete_config {
my ($build) = @_;
$build->{settings}{workdir} = abs_path($build->{settings}{workdir} || '.');
$build->{mount} ||= volatile_squash_union();
mkdir_p($build->get_build_dir);
mkdir_p($build->get_chroot_dir);
}
sub dump_config {
my ($build) = @_;
use Data::Dumper;
print Data::Dumper->Dump([ $build ], [ "build" ]);
}
1;
|