#!/usr/bin/perl # # to prepare, create and burn iso images # my $VERSION = "3.4.7"; use strict; use File::NCopy qw(copy); use Mkcd::Commandline qw(parseCommandLine usage); use Mkcd::Tools qw(printTable getTracks du cpal checkcds cleanrpmsrate config compute_md5 include_md5 convert_size); use Mkcd::Group; use Mkcd::Package qw(packageOutOfRpmsrate getLeaves list_hdlist mkcd_build_hdlist %ARCH); use packdrake; use RPM::Header; # # FIXME not up to date # # config structure # # $config{name} = name for the product # # $config{list} = list data # $config{list}[list number]{name} = list name # {filelist} = ( file list location 1, file list location 2, ..., file list location n ) # # $config{list}[list number]{packages}[location i] = (RPMS location i, SRPMS location i) # # $config{list}[list number]{done} # {empty} # {auto} # {cd} # {sources} # # $config{list}[list number]{disc} = { cd => { rep => { options }} } # # $config{disc} = disc data # $config{disc}[disc number]{size} = size in bytes # $config{disc}[disc number]{serial} = serial number # $config{disc}[disc number]{name} = disc number irl # $config{disc}[disc number]{longname} = disc long name # $config{disc}[disc number]{fastgeneric} = [ generic data 1, generic data 2, ..., generic data n] # # $config{disc}[disc number]{function}{list}[function number] = (function name, { data }) # # $config{disc}[disc number]{function}{data}{dir}{repository identifier} = $config[2][cd number][1][function number] # # $config{disc}[disc number]{function}{data}{'installation'} = $config[2][cd number][1][function number] it should have only one installation by disc, anyway # # $config{disc}[disc number]{function}{data}[2]{'advertising'} = $config[2][cd number][1][function number] # # $config{disc}[disc number]{steps} = function to execute to build the disc # # # $config other values: # # discMax = higher real disc number # configfile = config file use for this session # lists # fast # nodeps # verbose # print # printscript # nolive # noiso # deps # nosrcfit # product # bugzilla # builddir # topdir # discsize # isodir # filetag # log # mkisoopt # tmp # # # Availaible functions # # see Functions.pm # # old -> new schema # # config structure # # $config[0][0] -> $config{name} # # $config[1] -> $config{list} # $config[1][list number][0] -> $config{list}[list number]{filelist} # # $config[1][list number][1][location i] -> $config{list}[list number]{packages}[location i] # # $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} # # $config[1][list number][3] -> $config{list}[list number]{disc} # # $config[2] -> $config{disc} # $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} # # $config[2][cd number][1][function number] -> $config{disc}[disc number]{function}{list}[function number] # # $config[2][cd number][2]{dir}{repository identifier} -> $config{disc}[disc number]{function}{data}{dir}{repository identifier} # # $config[2][cd number][2]{'installation'} -> $config{disc}[disc number]{function}{data}{'installation'} # # $config[2][cd number][2]{'advertising'} -> $config{disc}[disc number]{function}{data}[2]{'advertising'} # # $config[2][cd number][3] -> $config{disc}[disc number]{steps} # # # $config[3] -> $config{discMax}, $config{configfile} # # our %FUNCTIONS; our $functions; our $optimize; our $LOG; our $topdir = `pwd`; chop $topdir; our %config = ( lists => [], fast => 0, nodeps => 0, verbose => 0, print => 0, printscript => 0, nolive => 0, noiso => 0, deps => 0, nosrcfit => 0, nosrc => 0, product => 0, bugzilla => 0, builddir => 0, topdir => $topdir, discsize => 681000000, isodir => 0, filetag => 0, log => 0, mkisoopt => "-r -J -hide-rr-moved -nobak -cache-inodes", tmp => $ENV{TMPDIR} || "$topdir/tmp", disc_building_tries => 3, rejected_options => { no_disc => "Could not add more disc for this package", no_space => "Not enough space", deps => "Missing dependencies", old_version => "More recent version found", deps_rejected => "Some needed dependencies rejected", excluded => "Explicitely excluded", order_pb => "Needed dependency could not be put before", sequential => "Could not add interlist dependencies in sequential mode", autodeps => "not selected in rpm lists" }, optimize_space => 1, ARCH => \%ARCH ); $config{group} = new Mkcd::Group(\%config); $functions = $config{group}{disc}{functions}{functions}; my $arg = @ARGV; our @params; @params = ( # [ "one letter option", "long name option", "number of args (-X means ´at least X´)", "help text", "function to call", "log info"] [ "", "mkcd", 0, "", "mkcd Mandrake Linux Disc maker", sub { $arg or usage('mkcd', \@params) }, "" ], [ "a", "auto", [ ["", "auto", -1, " ... ", "Auto mode configuration", sub { my ($tmp, @arg) = @_; $tmp->[0] ||= {}; push @$tmp, @arg; 1 }, "Setting auto mode arguments"], ["c", "cd", 1, "", "Max number of discs", sub { my ($tmp, $cd) = @_; if ($cd =~ /\d+/) { $tmp->[0]{cd} = $cd } else { return 0 }; 1 }, "Setting max number of discs"], ["s", "sources", [ [ "", "sources", 0, "", "Sources mode options", sub { my ($tmp) = @_; $tmp->[0] ||= {}; 1 }, "Setting source mode options" ], [ "s", "separate", 0, "", "Separate binaries discs from sources discs", sub { my ($tmp) = @_; $tmp->[0]{separate} = 1 }, "Setting source mode separate option" ] ], "", "Create SRPMS discs too", sub { my ($tmp, $opt) = @_; $tmp->[0]{sources} = $opt }, "Setting source mode"], ["", "noisolinux", 0, "", "Do not use a isolinux boot", sub { my ($tmp) = @_; $tmp->[0]{noisolinux} = 1 }, "Setting noisolinux option"] ], "[options] ... ", "Automated mode, build discs from a repository.", \&auto_mode, "Auto mode" ], [ "", "addmd5", 1, "", "Add md5sum to iso header.", sub { my $err = include_md5(pop, 1, 1); print $err }, "Adding md5 to ISO header" ], [ "k", "checkmd5", 1, "", "Checking md5sum of iso header.", sub { my $err = include_md5(pop, 0, 1); print $err }, "Checking md5 of ISO header" ], [ "", "bugzilla", 0, "", "Use bugzilla as information source.", sub { $config{bugzilla} = 1 }, "Using Bugzilla" ], [ "b", "builddir", 1, "", "Where live iso image are created (default current dir).", sub { $config{builddir} = pop @_ }, "Setting the build directory" ], [ "", "buildhdlist", -1, " ... ", "Build hdlist.cz files for given directories.", sub { my $i; mkcd_build_hdlist(1 + @_, [ 0, map { $i++; { rpms => [ glob "$_/*.rpm" ], hdlist => "./hdlist$i.cz", synthesis => "./synthesis.hdlist$i.cz" } } @_ ], "$config{tmp}/.build_hdlist") }, "building hdlist files" ], [ "", "batch", 2, " ", "batch mode to rebuilt discs from a previous session.", \&batchMode, "Batch mode" ], [ "c", "catto", 1, "", "Log file.", sub { $config{log} = pop @_; open $LOG, ">$config{log}" or die "unable to open $config{log}\n" }, "Log file" ], [ "", "listrpmsrate", 1, "", "List the package in the rpmsrate file", \&packageOutOfRpmsrate, "Listing rpmsrate file" ], [ "d", "depslist-creation", 0 , "", "rebuild the desplist.ordered file before checking the list.", sub { $config{deps}=1 }, "Depslist creation switch" ], [ "", "discsize", 1 , "", "Select a custom disc size (default $config{discsize}).", sub { $config{discsize} = convert_size(pop, $config{discsize}, $config{LOG}) }, "Custom disc size selection" ], [ "f", "fast", 0 , "", "fast mode.", sub { $config{fast} = 1; $config{disc_building_tries} = 1; $optimize = 0; $config{optimize_space} = 0 }, "Fast mode" ], [ "", "getleaves", 1, "", "Getting leaves from a depslist.ordered file", \&getLeaves, "Getting leaves from a depslist.ordered" ], # FIXME function help should take 0 or one argument, but this is not possible with this structure [ "h", "help", -1, " ", "Display help, eg. mkcd -h installation fixed. Type mkcd -h config for configuration files options.", sub { my (@function) = @_; if (@function) { my $key = join '/', @function; if (ref $FUNCTIONS{$key}) { usage($key, $FUNCTIONS{$key}) } } usage("mkcd", \@params); }, "" ], [ "", "check", -1, " ... ", "Check the hdlists, depslist and RPMS consistency.", sub { checkcds(@_) }, "Checking the hdlists, depslist and RPMs consistency" ], [ "K", "checkdisc", 2, " ", "Check the disc.", sub { check_discs(@_) }, "Checking the disc" ], [ "i", "isodir", 1, "", "Where ISOs are built (default ./iso/product_name/).", sub { $config{isodir} = pop @_ }, "Setting the iso directory" ], [ "l", "lists", 1 , "", "lists of discs taken into account.", sub { $config{lists} = getTracks(pop @_) }, "Using given disc list" ], [ "m", "make", 1, "", "Build the discs.", \&make , "Building the discs" ], [ "", "nodeps", 0, "", "Do not include automatically dependencies of packages", sub { $config{nodeps} = 1 }, "Setting nodeps flag" ], [ "", "nolive", 0, "", "Do not create live image of the discs.", sub { $config{nolive} = 1 }, "Setting nolive option" ], [ "", "noiso", 0, "", "Do not create iso images of the discs.", sub { $config{noiso} = 1 }, "Setting noiso option" ], [ "", "nosrcfit", 0, "", "Do not stop if sources discs are full", sub { $config{nosrcfit} = 1 }, "Setting nosrcfit option" ], [ "", "nosrc", 0, "", "Do not include sources", sub { $config{nosrc} = 1 }, "Setting nosrc option" ], [ "", "oem", -1, " ... ", "Build a OEM installation CD based on the given disc", \&oem, "Building oem disc" ], [ "p", "printscript", 1, "