#!/usr/bin/perl
# 
# Copyright (C) 2000,2001,2002,2003,2004,2005 Mandriva
# 
# Author: Florent Villard <warly@mandriva.com>
#
# 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.
#
# to prepare, create and burn iso images
#
# TODO
# - follow symlinks when copying rpms
#

my $VERSION = "4.2.5";

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(check_rpmsrate packageOutOfRpmsrate getLeaves list_hdlist mkcd_build_hdlist %ARCH genDeps);
use Mkcd::Config qw(%config);
use MDK::Common qw(all);
use packdrake;

our %FUNCTIONS;
our $functions;
our $optimize;
our $LOG;

our $topdir = `pwd`;
chop $topdir;

$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, "<options>", 
    "mkcd Mandriva Linux Disc maker", 
    sub { $arg or usage('mkcd', \@params) }, "" ],
    [ "a", "auto", [
	["", "auto", -1, "<repository> <extra RPMS directory 1> <extra RPMS directory 2> ... <extra RPMS directory n>", 
	"Auto mode configuration", 
	sub { 	
            my ($tmp, @arg) = @_;
	    $tmp->[0] ||= {};
	    push @$tmp, @arg;
	    1
	}, "Setting auto mode arguments"],
	["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"],
	["s", "sources", [
	  [ "", "sources", 0, "<options>", 
	  "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] <repository> <extra RPMS directory 1> <extra RPMS directory 2> ... <extra RPMS directory n>", 
"Automated mode, build discs from a repository.", \&auto_mode, "Auto mode" ],
    [ "", "addmd5", 1, "<iso file>", 
    "Add md5sum to iso header.", 
    sub { my $err = include_md5(pop, 1, 1); print $err }, "Adding md5 to ISO header" ],
    [ "", "arch", 1, "<architecture>", 
    "Specify a architecture (ia64, ppc), x86 is the default.", 
    sub { $config{arch} = pop }, "Specifying the achitecture" ],
    [ "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" ],
    [ "", "bugzilla", 0, "", 
    "Use bugzilla as information source.", 
    sub { $config{bugzilla} = 1 }, "Using Bugzilla" ],
    [ "b", "builddir", 1, "<build dir>", 
    "Where live iso image are created (default current dir).",  
    sub { $config{builddir} = pop @_ }, "Setting the build directory" ],
    [ "", "buildhdlist", -1, "<rpms dir 1> <rpms dir 2> ... <rpms dir n>", "Build hdlist.cz files for given directories.",  
    sub {
	my $i;
	mkcd_build_hdlist(int @_, 
		[ 0, 
		map { 
		    $i++;
		    if (/(.*)(hdlist.*\.cz)$/) {  
			{ done => 1, hdlist => $_, synthesis => "$1synthesis.$2" } 
		    } else {
			{ rpms => [ glob "$_/*.rpm" ], hdlist => "./hdlist$i.cz", synthesis => "./synthesis.hdlist$i.cz" } 
		    }
		} @_ ], "$config{tmp}/.build_hdlist", 'depslist.ordered', 'provides', 'compss')
    }, "building hdlist files" ],
    [ "", "batch", 2, "<discs list> <batch file>", 
    "batch mode to rebuilt discs from a previous session.",  \&batchMode, "Batch mode" ],
    [ "c", "catto", 1, "<log file>", 
    "Log file.", 
    sub { 
	$config{log} = pop @_; 
	open $LOG, ">$config{log}" or die "unable to open $config{log}\n";
	print $LOG, "command line: @ARGV\n"
    }, "Log file" ],
    [ "", "checkdeps", -1, "<RPMS dir 1> <RPMS dir 2> ... <RPMS dir n>", 
    "Check coherency of a set of directories.", \&check_deps, "Checking dependencies" ],
    [ "", "cpu", 1, "<cpu number>", 
    "Force cpu number", 
    sub { $config{cpu} = shift }, "Setting cpu number" ],
    [ "", "listrpmsrate", 1, "<rpmsrate file>", 
    "List the package in the rpmsrate file", \&packageOutOfRpmsrate, "Listing rpmsrate file" ],
    [ "", "checkrpmsrate", -2, "<rpmsrate file> <rpms dir 1> <rpms dir 2> ... <rpms dir n>", 
    "List the package in the rpmsrate file and not in the given repositories", \&check_rpmsrate, "Checking rpmsrate file" ],
    [ "d", "depslist-creation", 0 , "", 
    "rebuild the desplist.ordered file before checking the list.", 
    sub { $config{deps} = 1 }, "Depslist creation switch" ],
    [ "", "discsize", 1 , "<disc size in bytes>", 
    "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;
	1
    }, "Fast mode" ],
    [ "", "getleaves", 1, "<depslist file>", 
    "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, "<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; 
	    if (ref $FUNCTIONS{$key}) {
		usage($key, $FUNCTIONS{$key})
	    }
	}
	usage("mkcd", \@params);
	}, "" ],
    [ "", "check", -1, "<dir 1> <dir 2> ... <dir n>", 
    "Check the hdlists, depslist and RPMS consistency.", 
    sub { checkcds(@_) }, "Checking the hdlists, depslist and RPMs consistency" ],
    [ "K", "checkdisc", 2, "<ISO mount point> <md5 file>", 
    "Check the disc.", 
    sub { check_discs(@_) }, "Checking the disc" ],
    [ "i", "isodir", 1, "<iso dir>", 
    "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, "<cds number>", 
    "Build the discs.", \&make , "Building the discs" ],
    [ "", "missing-non-fatal", 0 , "", 
    "Missing packages tagged as needed non-fatal for the build.", 
    sub { $config{missing_non_fatal} = 1 }, "Missing needed packages non fatal switch" ],
    [ "", "no-check-disc", 0, "", 
    "Do not check the consistency between hdlist and disc RPMs", 
    sub { $config{no_check_disc} = 1 }, "Setting no-check-disc flag" ],
    [ "", "nodeps", 0, "", 
    "Do not include automatically dependencies of packages", 
    sub { $config{nodeps} = 1 }, "Setting nodeps flag" ],
    [ "", "nofork", 0, "", 
    "Do not fork", 
    sub { $config{nofork} = 1 }, "Setting nofork 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" ],
    [ "", "nosuggests", 0, "",
    "Do not use the suggests tag in package to build depencies tries",
    sub { $config{nosuggests} = 1 }, "Setting nosuggests option" ],
    [ "", "dualarch", 0, "",
    "Add the specific dual arch option linux64 for isolinux in i586/isolinux/isolinux.cfg",
    sub { $config{dualarch} = 1 }, "Setting dualarch option" ],
    [ "", "nohdlists", 0, "",
    "Do not create hdlists in media/media_info, since release 2009.1",
    sub { $config{nohdlists} = 1 }, "Don't create hdlists.cz" ],
    [ "", "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, "<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" ],
    [ "", "struct", 1 , "<struct>", 
    "Build ISO with a specific structure", 
    sub { $config{struct_version} = shift }, "Selecting the structure version" ],
    [ "p", "printscript", 1, "<script file>", 
    "Print the script that can be use to rebuild the discs", 
    sub { $config{printscript} = shift }, "Printing script" ],
    [ "", "printdiscsfiles", 1, "<file>", 
    "Print the contains of each disc", 
    sub { $config{print} = shift }, "Printing disc contains" ],
    [ "", "pl", -1, "<hdlist 1> <hdlist 2> ... <hdlist n>", 
    "Do a packdrake -l on the hdlists", 
    sub { list_hdlist(\@_,1) }, "Printing hdlist contents" ],
    [ "s", "spec", 1, "<config file>", 
    "Configuration file", 
    sub { config(shift, \%config, $functions, \%FUNCTIONS) } , "Loading configuration file" ],
    [ "", "shell", 0, "", 
    "Activate a mkcd shell to dynamically chose package to include", 
    sub { $config{shell} = 1 ; $config{disc_building_tries}++ }, "Preparing mkcd shell" ],
    [ "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" ],
    [ "", "testlist", 3, "<config file> <list number> <rpmsrate_file>", 
    "Perform a rapid resolution of the file list.", \&test_list, "Testing the file list" ],
    [ "", "update-rpmsrate", -2, "<rpmsrate> <rpms directory 1> <rpms directory 2> ... <rpms directory n>", 
    "Add major to libraries in rpmsrate",  
	sub { 
	    my %rpm;
	    my $rpmsrate = shift @_;
	    foreach my $d (@_) { $rpm{$d} = [ map { s,$d/?(.*)\.rpm$,$1,; $_ } glob "$d/*.rpm" ] };
	    cleanrpmsrate($rpmsrate, 0, 0, \%rpm) 
	}, "Adding major to libraries in rpmsrate" ],
    [ "", "verbose", 1 , "<log level>", 
    "Print more messages (the higher the more, 5 is the higher)", 
    sub { $config{verbose} = shift; 1 }, "Setting the verbose flag" ],
    [ "v", "version", 0, "", "Print program version",  
    	sub { 
	    print_fh($config{LOG}, "\nmkcd version $VERSION\n"); 
	    1 }, "" ],
    [ "", "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; 1 }, "Setting the disc_building_tries value" ],
    [ "", "use_optimize_space", 1 , "<number of disc building tries>", 
    "Use optimize_space algorythm", 
    sub { 
	my $t = shift; 
	$config{disc_building_tries} = $t; 
	$optimize = 1;
	$config{optimize_space} = $t
        }, "Setting the disc_building_tries value" ],
    [ "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" ],
#    [ "", "test", 0 , "", "Set the publisher name for ISO header publisher_id (128 char max)", sub { print "ARCH ", keys %{$config{ARCH}} , "\n\n" }, "Setting the publisher ID flag"],
);

# FIXME this permit to have specific help
foreach (@params) {
    $FUNCTIONS{$_->[1]} = ref($_->[2]) ? $_->[2] : [ $_ ]
}

$FUNCTIONS{mkcd} = \@params;
foreach my $k (keys %$functions) {
    $FUNCTIONS{$k} = $functions->{$k};
    foreach (@{$functions->{$k}}) {
	$FUNCTIONS{"$k/$_->[1]"} = ref($_->[2]) ? $_->[2] : [ $_ ]
    }
    push @{$FUNCTIONS{config}} , $functions->{$k}[0]
}

open($LOG, ">&STDERR");	
$config{LOG} = $LOG;

my $todo = parseCommandLine("mkcd", \@ARGV, \@params);
@ARGV and usage("mkcd", \@params, "@ARGV, too many arguments");
foreach my $t (@$todo)  {
    print $LOG "mkcd: $t->[2]\n";
    &{$t->[0]}(@{$t->[1]}) or print $LOG "ERROR: $t->[2]\n";
}

# FIXME only to make perl_checker happy
sub print_fh {
    my ($fh, $text) = @_;
    print $fh $text
}

sub batchMode {
    my ($cds, $file) = @_;
    config($file, \%config, $functions, \%FUNCTIONS);
    my ($discsFiles, $cd) = readBatchFile($file);
    (my $lists,$cds) = getDiscsList($cds);
    my @mkisos;
    my @size;
    Mkcd::Disc::makeDiscs(0,$lists,$cds, \@size, \@mkisos,$discsFiles);
    Mkcd::Disc::makeDiscs(1,$lists,$cds, \@size, \@mkisos,$discsFiles,$cd);
}

sub getDiscsList {
    my ($cds) = @_;
    $cds = getTracks($cds);
    print $LOG "getDiscList: discs @$cds\n";
    my %list;
    $cds = [grep { if (ref $config{disc}[$_]) { $list{$_} = 2; push @{$config{lists}}, $_; 1 } else { print $LOG "WARNING: disc $_ not defined\n"; 0 } } @$cds];
    $config{lists} ||= $cds;
    $config{lists} = [ grep { $list{$_} or ref $config{disc}[$_] and $list{$_} = 1 or print $LOG "WARNING: disc $_ not defined\n" and 0 } @{$config{lists}}];
    foreach my $c (@$cds) {
	foreach (@{$config{virtual_disc}{$c}}) {
	    $list{$_} = 1;
	    push @{$config{lists}}, $_
	}
    }
    return \%list, $cds
}

sub auto_mode {
    my ($opt, $repository, @rpms) = @_;
    $config{nolive} = 1;
    $config{nosrcfit} = 1;
    $config{deps} = 1;
    if (!$optimize) {
	$config{disc_building_tries} = 1;
	$config{optimize_space} = 0;
    }
    my $struct_v = $config{struct_version};
    my $install_dir = $config{struct}{$struct_v}{install};
    my $media_dir = $config{struct}{$struct_v}{media_base};
    -d "$repository/$media_dir" or print "ERROR: $repository/$media_dir does not exist\n" and return 0;
    my $dir = "$repository/$media_dir";
    opendir my $DIR, $dir;
    foreach (readdir $DIR) {
	-d "$dir/$_" or next;
	m/^(media_info|\..*)$/ and next;
	print $LOG "auto_mode: adding $dir/$_\n";
	unshift @rpms, "$dir/$_"
    }
    my ($name, $tag);
    if (-f "$repository/VERSION") {
	open my $A, "$repository/VERSION";
	local $_;
	<$A> and /^Mandriva Linux (.*) \d{8} \d{2}:\d{2}$/ and ($name,$tag) = split ' ', $1;
	close $A
    }
    $name ||= "Cooker-download";
    $config{name} = $name;
    foreach (keys %$opt) { $config{list}[1]{$_} = $opt->{$_} }
    $config{list}[1]{auto} = 1;
    my $media_info_dir = "$repository/$config{struct}{$struct_v}{media_info}";
    if (-d $media_info_dir) {
	opendir my $basedir, $media_info_dir;
	foreach my $file (readdir $basedir) {
	    $file =~ /^pubkey/ or next;
	    push @{$config{list}[1]{keyfiles}}, "$media_info_dir/$file"
	}
	closedir $basedir
    }
    foreach (keys %{$config{list}[1]}) { print $LOG "auto_mode: list options $_ -> $config{list}[1]{$_}\n" }
    foreach (@rpms) {
	#	$size += du($_);
	push @{$config{list}[1]{packages}}, { rpm => [ $_ ], srpm => \@rpms }
    }
    my %cd = (1 => 2);
    my @cd = 1;
    #print $LOG "Total RPMS $size\n";
    $config{disc}[1]{size} = $config{discsize};
    $config{disc}[1]{serial} = "${name}-disc1";
    $config{disc}[1]{name} = 1;
    $config{disc}[1]{longname} = "Mandriva Linux $name";
    $config{disc}[1]{appname} = "Mandriva Linux $name disc 1";
    $config{disc}[1]{label} = substr "$name-Disc1", 0, 32;
    my $idx = 1;
    my %idx;
    &{$functions->{dir}[0][5]}(1,$idx, "rpms", $config{struct}{$struct_v}{media});
    $idx++;
    &{$functions->{generic}[0][5]}(1,$idx, "rpms",1);
    &{$functions->{generic}[2][5]}(1,$idx);
    $idx++;
    $idx{installation} = $idx;
    &{$functions->{installation}[0][5]}(1,$idx);
    &{$functions->{installation}[5][5]}(1,$idx, $repository);
    &{$functions->{installation}[10][5]}(1,$idx, $tag);
    &{$functions->{installation}[14][5]}(1,$idx);
    &{$functions->{installation}[18][5]}(1,$idx, "1/rpms");
    $idx++;
    &{$functions->{boot}[0][5]}(1,$idx);
    my $isolinux_dir = $config{struct}{$struct_v}{isolinux};
    my $images_dir = $config{struct}{$struct_v}{images};
    if (-w "$repository/$isolinux_dir/isolinux.bin" && !$opt->{noisolinux}) {
	&{$functions->{boot}[1][5]}(1,$idx, { isolinux => 1 });
#	&{$functions->{boot}[2][5]}(1,$idx, { bootimg => 1 }, "$isolinux_dir/isolinux.bin");
	&{$functions->{boot}[3][5]}(1,$idx, { first => 1 }, "$repository/$isolinux_dir");
	&{$functions->{boot}[3][5]}(1,$idx, { first => 1, dest => "$install_dir"}, "$repository/$images_dir");
    } else {
	my $bootimg = $config{arch} eq 'ia64' ? 'all.img' : "cdrom.img";
	&{$functions->{boot}[2][5]}(1,$idx, { bootimg => 1, dir => "Boot" }, "$images_dir/$bootimg");
	&{$functions->{boot}[3][5]}(1,$idx, { first => 1, dest => "$install_dir"}, "$repository/$images_dir");
    }
    if ($opt->{sources}) {
	$config{nosrcfit} = 0;
	if ($opt->{sources}{separate}) {
	    $config{disc}[2]{size} = $config{discsize};
	    $config{disc}[2]{serial} = "${name}-2-src";
	    $config{disc}[2]{name} = 2;
	    $config{disc}[2]{longname} = "Mandriva Linux $name sources";
	    $config{disc}[1]{appname} = "Mandriva Linux $name sources disc 2";
	    push @cd,2;
	    $cd{2} = 2;
	    &{$functions->{dir}[0][5]}(2,1, "srpms", $config{struct}{$struct_v}{srpm_media});
	    &{$functions->{generic}[0][5]}(2,2, "srpms",1);
	    &{$functions->{generic}[1][5]}(2,2, { source => 1 });
	    &{$functions->{installation}[17][5]}(1, $idx{installation}, "2/srpms")
	} else {
	    $idx++;
	    &{$functions->{dir}[0][5]}(1,$idx, "srpms", $config{struct}{$struct_v}{srpm_media});
	    $idx++;
	    &{$functions->{generic}[0][5]}(1,$idx, "srpms",1);
	    &{$functions->{generic}[1][5]}(1,$idx, { source => 1 });
	    &{$functions->{installation}[17][5]}(1, $idx{installation}, "1/srpms")
	}
    } else {
     	&{$functions->{installation}[6][5]}(1,$idx)
    }
    printTable(\%config);
    $config{group}->makeWithGroups(\%cd, \@cd);
    1	
}

sub make {
    my ($cds) = @_;
    $config{group}->makeWithGroups(getDiscsList($cds));
    1
}		

sub oem {
    my (@cds) = @_;
}

sub check_discs {
    my ($mntpt, $mdfile) = @_;
    local *A; open A, $mdfile;
    my %ignore;
    my $sum;
    local $_;
    while (<A>) {
	chomp;
	last if ($sum) = /^(.*) - /;
	my $t = "/$_";
	$t =~ s,//+,/,g;
	$ignore{$t} = 1
    }
    close A;
    my $hexdigest = compute_md5([[ "/", $mntpt ]], \%ignore);
    if ($hexdigest eq $sum) {
	print "\nOK ($hexdigest)\n"
    } else {
    	print "\nFAILED (computed $hexdigest <> expected $sum)\n";
	return 0
    }
    1
}

sub check_deps {
    my (@rep) = @_;
    my %group;
    my $tmpdir = "$config{tmp}/mkcd_check_deps";
    -d $tmpdir or mkdir $tmpdir or die "FATAL: could not create $tmpdir";
    foreach (@rep) { push @{$group{rep_pkg}{$_}}, grep { s/\.rpm$// } all $_  }
    $group{urpm} = genDeps($tmpdir, $group{rep_pkg}, 0, $config{verbose}, $config{tmp});
    $group{option} = {};
    $group{rejected} = {};
    Mkcd::List::reverseDepslist({}, \%group, {}, 1);
    foreach my $rpm (sort keys %{$group{rejected}}) { 
	print "$rpm ", join (' ', map { map { $_->[1] } @$_ } values %{$group{rejected}{$rpm}}), "\n"
    }
}

sub test_list {
    my ($config_file, $list, $rpmsrate) = @_;
    config($config_file, \%config, $functions, \%FUNCTIONS);
    my $class = $config{group};
    my $discs_files;
    my $rpmlist;
    my %group = (
	list => { 
	    $list => { },
	},
	orderedlist => { rpm => [ $list ] },
    );
    Mkcd::Group::getGroupReps(\%config, \%group, $discs_files);
    # fake rpm list
    foreach my $dir (keys %{$group{rep_pkg}{rpm}}) {
	foreach my $rpm (@{$group{rep_pkg}{rpm}{$dir}}) {
	    $group{urpm}{rpm}{$rpm} = 1;
	    $group{size}{$rpm}{$list}[2] = 0;
	    push @{$group{listrpm}{$list}}, $rpm
	}
    }
    ($group{filelist}, my $norpmsrate) = $class->{list}->getList(\%group, $discs_files);
    $group{rpmsrate} = cleanrpmsrate($rpmsrate, "$config{tmp}/rpmsrate", $norpmsrate, $group{rep_pkg}{rpm}, $group{urpm});
    $class->{list}->build_list(\%group, 1);
    1
}

# 20060712
# The shell mode is just started, it should be continued to be able to have a working command line to build the CDs
#
