# Copyright (C) 2005 Mandriva # Olivier Blin # Copyright (C) 2017 Mageia # Martin Whitaker # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 'getcwd'; #- we bless Media objects here use MGA::DrakISO::Media; #- these modules can be used from config files use MGA::DrakISO::Mounts; use MGA::DrakISO::CustomMedia; sub read_config { my ($build, $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($build->{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($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"; ref $build->{media} && $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} ||= '/var/lib/drakiso'; $build->{settings}{arch} ||= chomp_(`rpm --eval '%{_target_cpu}'`); $_ = MGA::DrakISO::Media::new($_) foreach ( $build->{media}, ($build->{replicator} ? $build->{replicator}{media} : ()), ($build->{oem_rescue} ? $build->{oem_rescue}{media} : ()), ); mkdir_p($build->get_builddir); mkdir_p($build->get_system_root); $build->{mnt} ||= $build->get_builddir . "/mnt"; } sub dump_config { my ($build) = @_; use Data::Dumper; print Data::Dumper->Dump([ $build ], [ "build" ]); } 1;