source: soft/build_system/build_system/mkcd/tags/V3_3_4_1mdk/mkcd @ 1

Last change on this file since 1 was 1, checked in by fasma, 12 years ago

Initial Import from Mandriva's soft revision 224062 and package revision 45733

File size: 18.8 KB
Line 
1#!/usr/bin/perl
2#
3# to prepare, create and burn iso images
4#
5
6my $VERSION = "3.3.4";
7
8use strict;
9use File::NCopy qw(copy);       
10use Mkcd::Commandline qw(parseCommandLine usage);
11use Mkcd::Tools qw(printTable getTracks du cpal checkcds cleanrpmsrate config compute_md5 include_md5);
12use Mkcd::Group;
13use Mkcd::Package qw(packageOutOfRpmsrate getLeaves list_hdlist mkcd_build_hdlist);
14use packdrake;
15use RPM::Header;
16
17#
18# FIXME not up to date
19#
20# config structure
21#
22# $config{name} = name for the product
23#
24# $config{list} = list data
25#   $config{list}[list number]{name} = list name
26#                             {filelist} = ( file list location 1, file list location 2, ..., file list location n )
27#
28#   $config{list}[list number]{packages}[location i] = (RPMS location i, SRPMS location i)
29#
30#   $config{list}[list number]{done}
31#                             {empty}
32#                             {auto}
33#                             {cd}
34#                             {sources}
35#
36#   $config{list}[list number]{disc} = { cd => { rep => { options }}  }
37#
38# $config{disc} = disc data
39#   $config{disc}[disc number]{size} = size in bytes
40#   $config{disc}[disc number]{serial} = serial number
41#   $config{disc}[disc number]{name} = disc number irl
42#   $config{disc}[disc number]{longname} = disc long name
43#   $config{disc}[disc number]{fastgeneric} = [ generic data 1, generic data 2, ..., generic data n]
44#
45#   $config{disc}[disc number]{function}{list}[function number] = (function name, { data })
46#
47#   $config{disc}[disc number]{function}{data}{dir}{repository identifier} = $config[2][cd number][1][function number]
48#
49#   $config{disc}[disc number]{function}{data}{'installation'} = $config[2][cd number][1][function number]  it should have only one installation by disc, anyway
50#
51#   $config{disc}[disc number]{function}{data}[2]{'advertising'} = $config[2][cd number][1][function number]
52#
53#   $config{disc}[disc number]{steps} = function to execute to build the disc
54#
55#
56# $config other values:
57#
58#    discMax = higher real disc number
59#    configfile = config file use for this session
60#    lists
61#    fast
62#    nodeps
63#    verbose
64#    print
65#    printscript
66#    nolive
67#    noiso
68#    deps
69#    nosrcfit
70#    product
71#    bugzilla
72#    builddir
73#    topdir
74#    discsize
75#    isodir
76#    filetag
77#    log
78#    mkisoopt
79#    tmp
80#
81
82#
83# Availaible functions
84#
85#   see Functions.pm
86#
87
88# old -> new schema
89#
90# config structure
91#
92# $config[0][0] -> $config{name}
93#
94# $config[1] -> $config{list}
95#   $config[1][list number][0] ->  $config{list}[list number]{filelist}
96#
97#   $config[1][list number][1][location i] -> $config{list}[list number]{packages}[location i]
98#
99#   $config[1][list number][2] -> $config{list}[list number]{done}, $config{list}[list number]{empty} $config{list}[list number]{cd}$config{list}[list number]{auto}
100#
101#   $config[1][list number][3] -> $config{list}[list number]{disc}
102#
103# $config[2] -> $config{disc}
104#   $config[2][cd number][0] -> $config{disc}[disc number]{size}, $config{disc}[disc number]{serial}, $config{disc}[disc number]{name}, $config{disc}[disc number]{longname}, $config{disc}[disc number]{fastgeneric}
105#
106#   $config[2][cd number][1][function number] -> $config{disc}[disc number]{function}{list}[function number]
107#
108#   $config[2][cd number][2]{dir}{repository identifier} -> $config{disc}[disc number]{function}{data}{dir}{repository identifier}
109#
110#   $config[2][cd number][2]{'installation'} -> $config{disc}[disc number]{function}{data}{'installation'}
111#
112#   $config[2][cd number][2]{'advertising'} -> $config{disc}[disc number]{function}{data}[2]{'advertising'}
113#
114#   $config[2][cd number][3] -> $config{disc}[disc number]{steps}
115#
116#
117# $config[3] -> $config{discMax}, $config{configfile}
118#
119#
120use vars qw($topdir %config @params %FUNCTIONS $functions $optimize);
121
122$topdir = `pwd`;
123chop $topdir;
124%config = (
125    lists => [],
126    fast => 0,
127    nodeps => 0,
128    verbose => 0,
129    print => 0,
130    printscript => 0,
131    nolive => 0,
132    noiso => 0,
133    deps => 0,
134    nosrcfit => 0,
135    product => 0,
136    bugzilla => 0,
137    builddir => 0,
138    topdir => $topdir,
139    discsize => 681000000,
140    isodir => 0,
141    filetag => 0,
142    log => 0,
143    mkisoopt => "-r -J -hide-rr-moved -nobak -cache-inodes",
144    tmp => $ENV{TMPDIR} || "$topdir/tmp",
145    disc_building_tries => 3,
146    rejected_options => { 
147        no_disc => "Could not add more disc for this package",
148        no_space => "Not enough space",
149        deps => "Missing dependencies",
150        old_version => "More recent version found",
151        deps_rejected => "Some needed dependencies rejected",
152        excluded => "Explicitely excluded",
153        order_pb => "Needed dependency could not be put before",
154        sequential => "Could not add interlist dependencies in sequential mode",
155        autodeps => "not selected in rpm lists"
156    },
157    optimize_space => 1,
158    ARCH => { 
159        i586 => 1,
160        noarch => 1,
161        k7 => 1,
162        ppc => 1,
163        ia64 => 1,
164        i686 => 2,
165        i486 => 2,
166        i386 => 3
167    }
168);
169
170$config{group} = new Mkcd::Group(\%config);
171$functions = $config{group}{disc}{functions}{functions};
172@params = ( 
173    #    [ "one letter option", "long name option", "number of args (-X means Žat least XŽ)", "help text", "function to call", "log info"]
174    [ "","mkcd", 0, "<options>","mkcd Mandrake Linux Disc maker", sub { 1 }, ""],
175    [ "a", "auto", [
176        ["", "auto", -1, "<repository> <extra RPMS directory 1> <extra RPMS directory 2> ... <extra RPMS directory n>","Auto mode configuration", 
177        sub {   my ($tmp,@arg) = @_;
178            $tmp->[0] ||= {};
179            push @$tmp, @arg;
180            1
181        },"Setting auto mode arguments"],
182        ["c", "cd", 1, "<number of discs>","Max number of discs", sub { my ($tmp, $cd) = @_; if ($cd =~ /\d+/) { $tmp->[0]{cd} = $cd } else { return 0 }; 1 },"Setting max number of discs"],
183        ["s", "sources", [
184          [ "", "sources", 0, "<options>", "Sources mode options", 
185            sub {   my ($tmp) = @_;
186                $tmp->[0] ||= {};
187                1
188            },"Setting source mode options"],
189          [ "s", "separate", 0, "","Separate binaries discs from sources discs",sub { my ($tmp) = @_; $tmp->[0]{separate} = 1 },"Setting source mode separate option"]
190        ], "","Create SRPMS discs too", sub { my ($tmp, $opt) = @_; $tmp->[0]{sources} = $opt },"Setting source mode"],
191        ["", "noisolinux", 0, "","Do not use a isolinux boot", sub { my ($tmp) = @_; $tmp->[0]{noisolinux} = 1 },"Setting noisolinux option"]
192], "[options] <repository> <extra RPMS directory 1> <extra RPMS directory 2> ... <extra RPMS directory n>", "Automated mode, build discs from a repository.", \&auto_mode, "Auto mode"],
193    [ "", "addmd5", 1, "<iso file>","Add md5sum to iso header.", sub { include_md5(pop,1,1) }, "Adding md5 to ISO header"],
194    [ "k", "checkmd5", 1, "<iso file>","Checking md5sum of iso header.", sub { my $err = include_md5(pop,0,1); print $err }, "Checking md5 of ISO header"],
195    [ "", "bugzilla", 0, "","Use bugzilla as information source.", sub { $config{bugzilla} = 1 }, "Using Bugzilla"],
196    [ "b", "builddir", 1, "<build dir>", "Where live iso image are created (default current dir).",  sub { $config{builddir} = pop @_ }, "Setting the build directory"],
197    [ "", "buildhdlist", -1, "<rpms dir 1> <rpms dir 2> ... <rpms dir n>", "Build hdlist.cz files for given directories.", 
198    sub {
199        my $i;
200        mkcd_build_hdlist(1 + @_, [ 0, map { $i++; { rpms => [ glob "$_/*.rpm" ], hdlist => "./hdlist$i.cz", synthesis => "./synthesis.hdlist$i.cz" } } @_ ], "$config{tmp}/.build_hdlist")
201    }, "building hdlist files"],
202    [ "", "batch", 2, "<discs list> <batch file>", "batch mode to rebuilt discs from a previous session.",  \&batchMode, "Batch mode"],
203    [ "c", "catto", 1, "<log file>", "Log file.", sub { $config{log} = pop @_; open LOG,">$config{log}" or die "unable to open $config{log}\n"}, "Log file"],
204    [ "", "listrpmsrate", 1,"<rpmsrate file>", "List the package in the rpmsrate file", \&packageOutOfRpmsrate, "Listing rpmsrate file"],
205    [ "d", "depslist-creation", 0 , "", "rebuild the desplist.ordered file before checking the list.", sub { $config{deps}=1 }, "Depslist creation switch"],
206    [ "", "discsize", 1 , "<disc size in bytes>", "Select a custom disc size (default $config{discsize}).", sub { $config{discsize} = pop}, "Custom disc size selection"],
207    [ "f", "fast", 0 , "", "fast mode.", sub { 
208        $config{fast} = 1;
209        $config{disc_building_tries} = 1;
210        $optimize = 1;
211        $config{optimize_space} = 0
212    }, "Fast mode"],
213    [ "", "getleaves", 1, "<depslist file>", "Getting leaves from a depslist.ordered file",\&getLeaves,"Getting leaves from a depslist.ordered"],
214# FIXME function help should take 0 or one argument, but this is not possible with this structure
215    [ "h", "help", -1, "<path> <to> <the> <function>", "Display help, eg. mkcd -h installation fixed. Type mkcd -h config for configuration files options.", sub { my (@function) = @_; if (@function) { my $key = join '/', @function; usage($key,$FUNCTIONS{$key}) } else { usage("mkcd",\@params) } 1}, ""],
216    [ "", "check", -1, "<dir 1> <dir 2> ... <dir n>", "Check the hdlists, depslist and RPMS consistency.", sub { checkcds(@_) }, "Checking the hdlists, depslist and RPMs consistency"],
217    [ "K", "checkdisc", 2, "<ISO mount point> <md5 file>", "Check the disc.", sub { check_discs(@_) }, "Checking the disc"],
218    [ "i", "isodir", 1, "<iso dir>", "Where ISOs are built (default ./iso/product_name/).",  sub { $config{isodir} = pop @_ }, "Setting the iso directory"],
219    [ "l", "lists", 1 , "","lists of discs taken into account.", sub { $config{lists} = getTracks(pop @_) }, "Using given disc list"],
220    [ "m", "make", 1, "<cds number>", "Build the discs.", \&make , "Building the discs"],
221    [ "", "nodeps", 0, "", "Do not include automatically dependencies of packages", sub { $config{nodeps} = 1 }, "Setting nodeps flag"],
222    [ "", "nolive", 0, "", "Do not create live image of the discs.", sub { $config{nolive} = 1}, "Setting nolive option"],
223    [ "", "noiso", 0, "", "Do not create iso images of the discs.", sub { $config{noiso} = 1}, "Setting noiso option"],
224    [ "", "nosrcfit", 0, "", "Do not stop if sources discs are full", sub { $config{nosrcfit} = 1}, "Setting nosrcfit option"],
225    [ "", "oem", -1, "<root of disc 1> <root of disc 2> ... <root of disc n>", "Build a OEM installation CD based on the given disc", \&oem, "Building oem disc" ],
226    [ "p", "printscript", 1, "<script file>", "Print the script that can be use to rebuild the discs", sub { $config{printscript} = shift}, "Printing script"],
227    [ "", "printdiscsfiles", 1, "<file>", "Print the contains of each disc", sub { $config{print} = shift}, "Printing disc contains"],
228    [ "", "pl", -1, "<hdlist 1> <hdlist 2> ... <hdlist n>", "Do a packdrake -l on the hdlists", sub { list_hdlist(@_) }, "Printing hdlist contents"],
229    [ "s","spec", 1, "<config file>","Configuration file", sub { config(shift,\%config,$functions) } , "Loading configuration file"],
230    [ "t", "topdir", 1, "<top dir>", "Where files are created (default current dir).",  sub { $config{topdir} = pop @_; $config{tmp} = $ENV{TMPDIR} || "$config{$topdir}/tmp" }, "Setting the top directory"],
231    [ "", "update-rpmsrate", -2, "<rpmsrate> <rpms directory 1> <rpms directory 2> ... <rpms directory n>", "Add major to libraries in rpmsrate", 
232        sub { 
233            my %rpm;
234            foreach (@_) { $rpm{$_} = [ map { s/\.rpm$//; $_ } glob "$_/*.rpm" ] };
235            cleanrpmsrate(shift,0,0, \%rpm) 
236        }, "Adding major to libraries in rpmsrate"],
237    [ "", "verbose", 0 , "", "Print more messages", sub { $config{verbose} = 1}, "Setting the verbose flag"],
238    [ "v", "version", 0, "", "Print program version",  sub { print {$config{LOG} } "\nmkcd version $VERSION\n"; 1}, ""],
239    [ "", "disc_building_tries", 1 , "<maximum number of iteration to build correct ISO size>", "Set the number of iterations when trying to adjust ISO size", sub { $config{disc_building_tries} = shift ; $optimize = 1 }, "Setting the disc_building_tries value"],
240    [ "", "use_optimize_space", 1 , "<number of disc building tries>", "Use optimize_space algorythm", 
241    sub { 
242        my $t = shift; 
243        $config{disc_building_tries} = $t; 
244        $optimize = 1;
245        $config{optimize_space} = $t
246        }, "Setting the disc_building_tries value"],
247    [ "P", "Publisher", 1 , "<publisher name>", "Set the publisher name for ISO header publisher_id (128 char max)", sub { $config{Publisher} = substr shift, 0, 128 }, "Setting the publisher ID flag"],
248);
249
250# FIXME this permit to have specific help
251foreach (@params){
252    $FUNCTIONS{"$_->[1]"} = [ $_ ]
253}
254
255$FUNCTIONS{mkcd} = \@params;
256foreach my $k (keys %{$functions}){
257    $FUNCTIONS{$k} = $functions->{$k};
258    foreach (@{$functions->{$k}}){
259        $FUNCTIONS{"$k/$_->[1]"} = ref $_->[2] ? $_->[2] : [ $_ ]
260    }
261    push @{$FUNCTIONS{"config"}} , $functions->{$k}->[0]
262}
263
264local *LOG;
265open LOG,">&STDERR";   
266$config{LOG} = *LOG;
267
268my $todo = parseCommandLine("mkcd",\@ARGV,\@params);
269@ARGV and usage("mkcd",\@params,"@ARGV, too many arguments");
270foreach my $t (@$todo){
271    print LOG "mkcd: $t->[2]\n";
272    &{$t->[0]}(@{$t->[1]}) or print LOG "ERROR: $t->[2]\n";
273}
274
275sub batchMode{
276    my ($cds,$file) = @_;
277    config($file,\%config,$functions);
278    my ($discsFiles,$cd) = readBatchFile($file);
279    (my $lists,$cds) = getDiscsList($cds);
280    my @mkisos;
281    my @size;
282    Mkcd::Disc::makeDiscs(0,$lists,$cds,\@size,\@mkisos,$discsFiles);
283    Mkcd::Disc::makeDiscs(1,$lists,$cds,\@size,\@mkisos,$discsFiles,$cd);
284}
285
286sub getDiscsList {
287    my ($cds) = @_;
288    $cds = getTracks($cds);
289    print LOG "getDiscList: discs @$cds\n";
290    my %list;
291    $cds = [grep { ref $config{disc}[$_] and do { $list{$_} = 2; push @{$config{lists}}, $_} or print LOG "WARNING: disc $_ not defined\n" and 0} @$cds];
292    $config{lists} ||= $cds;
293    $config{lists} = [grep { $list{$_} or ref $config{disc}[$_] and $list{$_} = 1 or print LOG "WARNING: disc $_ not defined\n" and 0} @{$config{lists}}];
294    return (\%list,$cds)
295}
296
297sub auto_mode{
298    my ($opt,$repository, @rpms) = @_;
299    $config{nolive} = 1;
300    $config{nosrcfit} = 1;
301    $config{deps} = 1;
302    if (!$optimize){
303        $config{disc_building_tries} = 1;
304        $config{use_optimize_space} = 0;
305    }
306    -d "$repository/Mandrake" or print "ERROR: $repository/Mandrake does not exist\n" and return 0;
307    my $dir = "$repository/Mandrake";
308    local *DIR; opendir DIR, $dir;
309    my $size;
310    foreach (readdir DIR){
311        -d "$dir/$_" or next;
312        m/RPMS(\d*)$/ or next;
313        print LOG "auto_mode: adding $dir/$_\n";
314        unshift @rpms, "$dir/$_"
315    }
316    my ($name,$tag);
317    if (-f "$repository/VERSION"){
318        local *A; open A, "$repository/VERSION";
319        <A>;
320        /^Mandrake Linux (.*) \d{8} \d{2}:\d{2}$/;
321        ($name,$tag) = split ' ', $1
322    }
323    $name ||= "Cooker";
324    $config{name} = $name;
325    foreach (keys %$opt) { $config{list}[1]{$_} = $opt->{$_} }
326    $config{list}[1]{auto} = 1;
327    foreach (keys %{$config{list}[1]}) { print LOG "auto_mode: list options $_ -> $config{list}[1]{$_}\n"}
328    foreach (@rpms){
329        #       $size += du($_);
330        push @{$config{list}[1]{packages}}, [$_ , @rpms]
331    }
332    my %cd = (1 => 2);
333    my @cd = (1);
334    #print LOG "Total RPMS $size\n";
335    $config{disc}[1]{size} = $config{discsize};
336    $config{disc}[1]{serial} = "${name}-disc1";
337    $config{disc}[1]{name} = 1;
338    $config{disc}[1]{longname} = "MandrakeLinux $name";
339    $config{disc}[1]{appname} = "MandrakeLinux $name disc 1";
340    $config{disc}[1]{label} = substr "MandrakeLinux-$name-1.i586", 0, 32;
341    my $idx = 1;
342    my %idx;
343    &{$functions->{dir}[0][5]}(1,$idx,"rpms","Mandrake/RPMS");
344    $idx++;
345    &{$functions->{generic}[0][5]}(1,$idx,"rpms",1);
346    $idx++;
347    $idx{installation} = $idx;
348    &{$functions->{installation}[0][5]}(1,$idx);
349    &{$functions->{installation}[5][5]}(1,$idx,"$repository");
350    &{$functions->{installation}[10][5]}(1,$idx,"$tag");
351    &{$functions->{installation}[18][5]}(1,$idx,"1/rpms");
352    $idx++;
353    &{$functions->{boot}[0][5]}(1,$idx);
354    if (-w "$repository/isolinux/isolinux.bin" && !$opt->{noisolinux}){
355        &{$functions->{boot}[1][5]}(1,$idx,{ isolinux => 1 },"isolinux");
356        &{$functions->{boot}[2][5]}(1,$idx,{ bootimg => 1 },"isolinux/isolinux.bin");
357        &{$functions->{boot}[5][5]}(1,$idx,"$repository/isolinux");
358        $idx++;
359        &{$functions->{cp}[0][5]}(1,$idx,"$repository/images","images/");
360    }else{
361        &{$functions->{boot}[2][5]}(1,$idx,{ bootimg => 1, dir => "Boot" },"images/cdrom.img");
362        &{$functions->{boot}[4][5]}(1,$idx,"$repository/images");
363    }
364    if ($opt->{sources}){
365        $config{nosrcfit} = 0;
366        if ($opt->{sources}{separate}){
367            $config{disc}[2]{size} = $config{discsize};
368            $config{disc}[2]{serial} = "${name}-disc2-sources";
369            $config{disc}[2]{name} = 2;
370            $config{disc}[2]{longname} = "MandrakeLinux $name sources";
371            $config{disc}[1]{appname} = "MandrakeLinux $name sources disc 2";
372            push @cd,2;
373            $cd{2} = 2;
374            &{$functions->{dir}[0][5]}(2,1,"srpms","Mandrake/SRPMS");
375            &{$functions->{generic}[0][5]}(2,2,"srpms",1);
376            &{$functions->{generic}[1][5]}(2,2, { source => 1 });
377            &{$functions->{installation}[17][5]}(1,$idx{installation},"2/srpms")
378        }else{
379            $idx++;
380            &{$functions->{dir}[0][5]}(1,$idx,"srpms","Mandrake/SRPMS");
381            $idx++;
382            &{$functions->{generic}[0][5]}(1,$idx,"srpms",1);
383            &{$functions->{generic}[1][5]}(1,$idx, { source => 1 });
384            &{$functions->{installation}[17][5]}(1,$idx{installation},"1/srpms")
385        }
386    }else {
387        &{$functions->{installation}[6][5]}(1,$idx)
388    }
389    printTable(\%config);
390    $config{group}->makeWithGroups(\%cd, \@cd);
391    1   
392}
393
394sub make {
395    my ($cds) = @_;
396    $config{group}->makeWithGroups(getDiscsList($cds));
397    1
398}               
399
400sub oem {
401    my (@cds) = @_;
402}
403
404sub check_discs {
405    my ($mntpt,$mdfile) = @_;
406    local *A; open A, "$mdfile";
407    my %ignore;
408    my $sum;
409    while (<A>){
410        chomp;
411        last if ($sum) = /^(.*) - .*$/;
412        my $t = "/$_";
413        $t =~ s/\/\/+/\//g;
414        $ignore{$t} = 1
415    }
416    close A;
417    my $hexdigest = compute_md5([[ "/", $mntpt ]],\%ignore);
418    if ($hexdigest eq $sum){
419        print "\nOK ($hexdigest)\n"
420    }else{
421        print "\nFAILED (computed $hexdigest <> expected $sum)\n";
422        return 0
423    }
424    1
425}
426
427#
428# Changeloh
429#
430# 2002 03 15
431# new sources handling
432#
433# 2002 03 19
434# cdcom are now handled as normal list, so that deps are not forced.
435
436# 2002 03 23
437# change Group.pm getAlone to work with alone group.
438#
439# 2002 03 29
440# fix a bug in Functions.pm for nolive mode and rpmsrate
441#
442# 2002 04 12
443# oem mode
444#
445# 2002 05 02
446# add separate mode for auto sources mode
447#
448# 2002 05 07
449# add check_discs
450#
451# 2002 05 09
452# check_discs, compute_md5, md5_add_tree
453#
454# 2002 05 13
455# fix fentry problem in List.pm that create the "needed spreading" problem
456#
457# 2002 06 01
458# first draft for new needed code
459# new perl-URPM
460#
461# 2002 06 01
462# fix perl-URPM integration
463#
464# 2002 06 15
465# begin new diff mode.
466#
467# 2002 08 12
468# change clean_rpmsrate
469#
470# 2002 08 19
471# start optimize_space for sources moving
472# change diff structure
473# change process_diff
474#
475# 2002 08 20
476# some interlist and intergroup binaries moving in optimize_space
477#
478# 2002 08 25
479# various update of optimize_space
480# new needed and deps handling in optimize_space
481#
482# 2002 08 29
483# prepare_cloned_disc enhanced
484# add disc_prereq data in groups for cloned discs
485#
486# 20020918
487# fixes in optimize_space
Note: See TracBrowser for help on using the repository browser.