summaryrefslogtreecommitdiffstats
path: root/drakclassic
blob: 096459ca3cae87253bebd88afb5240c6a2eaa2cb (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/perl

# 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.

use lib qw(/usr/lib/libDrakX);

use strict;

use MDK::Common;

use Getopt::Long;
use Pod::Usage;

use MGA::DrakISO::Config;
use MGA::DrakISO::ClassicBuild;
use MGA::DrakISO::Utils;

use MGA::DrakISO::BuildMedia;
use MGA::DrakISO::BuildBoot;
use MGA::DrakISO::BuildISO;

###############################################################################
# Globals
###############################################################################

$::verbose = 1;

$::force = 0;

###############################################################################
# Actions
###############################################################################

sub clean {
    my ($build) = @_;

    my $build_dir = $build->get_build_dir;
    if (-e $build_dir) {
        run_as_root('rm', '-rf', $build_dir);
    }
}

###############################################################################
# Main Program
###############################################################################

my @actions = (
    { name => 'dump-config',    do => \&dump_config },
    { name => 'clean',          do => \&clean },
    { name => 'media',          do => \&prepare_media },
    { name => 'boot',           do => \&prepare_iso_bootloader },
    { name => 'master',         do => \&build_iso },
);
my @all = qw(media boot master);

my $build_object  = 'MGA::DrakISO::ClassicBuild'->new;
my $config_root   = '.';
my $config_path   = 'config/build.cfg';
my $settings_path = 'config/settings.cfg';

GetOptions(
    "help"              => sub { Pod::Usage::pod2usage('-verbose' => 1) },
    "all"               => sub { $_->{to_run} = 1 foreach grep { member($_->{name}, @all) } @actions },
    (map { $_->{name}   => \$_->{to_run} } @actions),
    "config-root=s"     => \$config_root,
    "config=s"          => \$config_path,
    "settings=s"        => \$settings_path,
    "define=s"          => \%{$build_object->{settings}},
    "verbose=i"         => \$::verbose,
    "force"             => \$::force,
) or Pod::Usage::pod2usage();

require standalone;
    every { !$_->{to_run} } @actions and Pod::Usage::pod2usage();

    read_config($build_object, $config_root, $config_path, $settings_path);
    check_config($build_object);
    complete_config($build_object);

    foreach (grep { $_->{to_run} } @actions) {
        print qq(* entering step "$_->{name}"\n);
        $_->{do}->($build_object);
        print qq(* step "$_->{name}" done\n);
    }

__END__

###############################################################################
# Documentation
###############################################################################

=head1 NAME

drakclassic - A classic installer ISO mastering tool

=head1 SYNOPSIS

drakclassic [options]

 Options:
   --help            long help message

   --media           prepare the installation media to be included on the ISO
   --boot            prepare installer boot and ISO bootloader files
   --master          build master image

   --all             run all the above steps

   --clean           clean out the working directories

   --config-root <dir>
                     root directory containing config and additional files
                     defaults to current directory

   --config <file>   use this configuration file to control the build
                     defaults to "config/build.cfg"

   --settings <file> use this file as build settings (name=value format)
                     defaults to "config/settings.cfg"

   --define name=value
                     set setting "name" to "value"
                     takes precedence over values from a settings file

   --verbose <level>
                     set verbosity level to <level>
                     defaults to 1

   --force           forces the build to continue even if some package
                     conflicts or inconsistencies cannot be resolved

Examples:

 drakclassic --clean

 drakclassic --all

 drakclassic --config config/classic.cfg --media

=head1 OPTIONS

=over 8

=item B<--config>

Makes B<drakclassic> use the next argument as a configuration file. This file
should contain an associative array specifying the ISO composition. See
L<https://wiki.mageia.org/en/drakclassic> for details.

=item B<--settings>

Makes B<drakclassic> load the next argument as a file in name=value format into
the $build->{settings} associative array ($build being the global configuration
associative array). See L<https://wiki.mageia.org/en/drakclassic> for details.

=back

=head1 DESCRIPTION

B<drakclassic> builds a classic installer ISO according to a configuration
file.

See L<https://wiki.mageia.org/en/drakclassic>

=head1 AUTHORS

Martin Whitaker <mageia@martin-whitaker.me.uk>

=cut