aboutsummaryrefslogtreecommitdiffstats
path: root/BCD
diff options
context:
space:
mode:
authorAntoine Ginies <aginies@mandriva.com>2010-10-06 07:58:18 +0000
committerAntoine Ginies <aginies@mandriva.com>2010-10-06 07:58:18 +0000
commitb364785ea90e60806aaaec56d15bcc70a74daf6d (patch)
treeda257e1277bd0218929f12fde2e318657067eb16 /BCD
parent46324a3fd9b86040b16dc3070b3a22438f7a616d (diff)
downloadbcd-b364785ea90e60806aaaec56d15bcc70a74daf6d.tar
bcd-b364785ea90e60806aaaec56d15bcc70a74daf6d.tar.gz
bcd-b364785ea90e60806aaaec56d15bcc70a74daf6d.tar.bz2
bcd-b364785ea90e60806aaaec56d15bcc70a74daf6d.tar.xz
bcd-b364785ea90e60806aaaec56d15bcc70a74daf6d.zip
end of the move
Diffstat (limited to 'BCD')
-rw-r--r--BCD/Bcd.pm101
-rw-r--r--BCD/Common.pm126
-rw-r--r--BCD/Genisoimage.pm123
-rw-r--r--BCD/Isolinux.pm118
-rw-r--r--BCD/Media.pm1132
-rw-r--r--BCD/Resign.pm63
-rw-r--r--BCD/Stagex.pm88
-rw-r--r--BCD/Web.pm222
8 files changed, 1973 insertions, 0 deletions
diff --git a/BCD/Bcd.pm b/BCD/Bcd.pm
new file mode 100644
index 0000000..98a68e1
--- /dev/null
+++ b/BCD/Bcd.pm
@@ -0,0 +1,101 @@
+package BCD::Bcd;
+
+use strict;
+use XML::Simple;
+use Data::Dumper;
+use Pod::Usage;
+use MDK::Common;
+
+use BCD::Resign;
+use BCD::Common qw(:DEFAULT $wd $isoconf $name $arch $version $isodir $builddir $error_color $dir_deps);
+use BCD::Genisoimage;
+use BCD::Isolinux;
+use BCD::Stagex;
+use BCD::Media;
+use BCD::Web;
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(main_bcd);
+our $conf_file;
+my $color = "cyan";
+
+sub print_info() {
+ print Dumper($isoconf);
+}
+
+sub help_bcd {
+ pod2usage('-verbose' => 2, '-input' => "bcd.pod", '-pathlist' => @INC);
+}
+
+sub do_all {
+ my ($option) = @_;
+ clean_all;
+ check_dir;
+ main_isolinux;
+ main_stagex;
+ main_media($option);
+ main_iso($option);
+ main_html;
+ show_info();
+}
+
+sub show_info {
+ print "\n";
+ print "ISO dir: $isodir\n";
+ print "build dir: $builddir\n";
+ print "LOG of media: /tmp/$name-$version-$arch\n";
+ print "stored URPMQ result: /var/lib/bcd/$name-$version-$arch\n";
+ print "\n";
+}
+
+sub main_bcd() {
+ my %opts = (
+ '' => \&help_bcd,
+ info => \&print_info,
+ iso => \&main_iso,
+ md5 => \&create_md5,
+ stagex => \&main_stagex,
+ isolinux => \&main_isolinux,
+ media => \&main_media,
+ gendistrib => \&use_gendistrib,
+ clean => \&clean_all,
+ list => \&list_media,
+ mediarepo => \&list_medias_available,
+ checkrepo => \&check_repo_hdlist,
+ rpmcheck => \&rpmcheck_launch,
+ doble => \&solve_doble_issue,
+ kernel => \&find_all_kernel,
+ resign => \&resign_media,
+ getsrpm => \&get_srpms_list,
+ clean => \&clean_urpmq_log,
+ html => \&main_html,
+ all => \&do_all,
+ );
+
+
+
+ if (! -d $dir_deps) {
+ print_color(" I will create $dir_deps to store all urpmq queries", $error_color);
+ print_color(" Please give full access RW to your current user to this directory", $color);
+ mkdir_p($dir_deps);
+ }
+ print_color("-- If you don't want to use previous urpmq query:\n ++ remove the directory $dir_deps\n ++ or remove the file wich contains the urpmq result for the package to redo an another one (ie: the file $dir_deps/tocopy_plop_todo_Main-drakconf)", $color);
+# $ARGV[0] or help_bcd;
+# -f $ARGV[0] or die "Cant acces to conf file $ARGV[0]\n";
+ if (my $f = $opts{$ARGV[1]}) {
+ if ($ARGV[2]) {
+ my $options;
+ foreach my $arg (2 .. $#ARGV) {
+ $arg and $options = $options . ' ' . $ARGV[$arg];
+ }
+ $f->($options);
+ } else {
+ $f->();
+ }
+ } else {
+ print_color(" ** Dont know what todo ** \n unknow option", $error_color);
+ }
+}
+
+
+1;
diff --git a/BCD/Common.pm b/BCD/Common.pm
new file mode 100644
index 0000000..df200b5
--- /dev/null
+++ b/BCD/Common.pm
@@ -0,0 +1,126 @@
+package BCD::Common;
+
+use strict;
+use XML::Simple;
+use MDK::Common;
+use Term::ANSIColor;
+use File::Copy::Recursive qw(dircopy pathrm);
+use File::Glob ':glob';
+
+use BCD::Bcd qw(:DEFAULT);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(create_needed_dir check_dir clean_all print_color);
+# export all needed var
+our @EXPORT_OK = qw($isoconf $wd $name $arch $file $based_on $version $repo $isodir $builddir $distrib_path $error_color $DISTRIB $THEME $tmp_rpmsrate $NB_FORK $dir_deps @list_of_removed $rpmrc $pwd_file $conf_file $date);
+
+my $LOG="COMMON -";
+my $color = "red";
+
+our @list_of_removed;
+
+my ($sec,$min,$hour,$mday,$mon,$year,undef,undef,undef)= localtime(time);
+$year = $year + 1900; $mon = $mon + 1;
+our $date = $year . '_' . $mon . '_' . $mday . '-' . $hour . 'h' . $min . '-' . $sec;
+
+sub whereisthedoc {
+ print_color(" 'man bcd' and man 'conf.xml'\nREAD the full documentation in pdf format available in the /usr/share/doc/bcd dir",$color) and exit 1;
+}
+if (!$ARGV[0]) {
+ print_color(" First arg must be the XML file to use!", $color);
+ whereisthedoc;
+} elsif (!$ARGV[1]) {
+ print_color(" You must do an action ! actions are:", $color);
+ print_color("###\nstagex isolinux clean media gendistrib rpmcheck list mediarepo checkrepo all\nmd5 resign clean doble nodoble kernel info iso verbose\n###", $color);
+ whereisthedoc;
+}
+our $conf_file = $ARGV[0];
+our $isoconf = XMLin($conf_file, keyattr => ['']);
+
+our $DISTRIB = $isoconf->{theme}{name};
+our $THEME = $isoconf->{theme}{theme};
+our $name = $isoconf->{nameid};
+our $NB_FORK = $isoconf->{nb_fork};
+our $wd = $isoconf->{workdir}{path};
+our $arch = $isoconf->{arch};
+our $version = $isoconf->{mediainfo}{version};
+our $repo = $isoconf->{repo}{path};
+our $based_on = $isoconf->{based_on};
+
+$DISTRIB or print_color("You must define the <theme><name> tag",$color) and exit 1;
+$THEME or print_color("You must define the <theme><theme> tag",$color) and exit 1;
+$name or print_color("You must define the <namedid> tag",$color) and exit 1;
+$wd or print_color("You must define the <workdir><path> tag",$color) and exit 1;
+$arch or print_color("You must define the <arch> tag",$color) and exit 1;
+$NB_FORK or print_color("You must define the <nb_fork> tag",$color) and exit 1;
+$version or print_color("You must define the <mediainfo><version>", $color) and exit 1;
+$repo or print_color("You must define the <repo><path> tag",$color) and exit 1;
+$based_on or print_color("You must define the <based_on> tag",$color) and exit 1;
+
+# password file
+#"/home/plop/.signature.gpg";
+our $pwd_file = $isoconf->{signature};
+#"/home/plop/.rpmrc";
+our $rpmrc = $isoconf->{rpmrc};
+
+# where to store urpmq queries results
+our $dir_deps = "/var/lib/bcd/$name-$version-$arch";
+our $builddir = "$wd/$isoconf->{iso}{genisoimage}{builddir}/$name-$version-$arch/$arch";
+our $isodir = "$wd/$isoconf->{iso}{genisoimage}{isodir}/$name-$version-$arch";
+# distrib path in chroot (mounted loop)
+our $distrib_path = "/tmp/distrib";
+our $tmp_rpmsrate = "/tmp/rpmsrate_$name-$version-$arch";
+our $error_color = "blue on_magenta";
+
+sub print_color {
+ my ($text, $color) = @_;
+ print color $color;
+ print "$text\n";
+ print color 'reset';
+
+}
+
+sub create_needed_dir {
+ my ($dir) = @_;
+ # create needed dir to create the build tree, and to store the ISO
+ if (! -d $dir) {
+ #mkdir $dir, 0755;
+ print_color("$LOG creation of $dir", $color);
+ mkdir_p($dir);
+ } else {
+ print_color("$LOG $dir already exist", $color);
+ }
+}
+
+sub check_dir {
+ create_needed_dir($builddir);
+ create_needed_dir("$builddir/$isoconf->{mediainfo}{mediainfo_dir}");
+ create_needed_dir($isodir);
+ create_needed_dir("/tmp/$isoconf->{nameid}-$version-$isoconf->{arch}");
+}
+
+sub clean_all {
+ my @l = glob("/tmp/$isoconf->{nameid}-$version-$isoconf->{arch}/$distrib_path/*");
+ foreach (@l) {
+ $_ or next;
+ if (-f "$_" || -d "$_") {
+ print_color("Distribution repositery already mounted exiting !\n Check /tmp/$isoconf->{nameid}-$version-$isoconf->{arch}/$distrib_path directory", $color);
+ print_color("sudo umount /tmp/$isoconf->{nameid}-$version-$isoconf->{arch}$distrib_path", $error_color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{external}{name} and print_color("You should check also umount the external media /tmp/$isoconf->{nameid}-$version-$isoconf->{arch}/tmp/$media->{external}{name}\nsudo umount /tmp/$isoconf->{nameid}-$version-$isoconf->{arch}/tmp/$media->{external}{name}", $error_color);
+ }
+ print_color("WARNING: if you didnt umount repositery or external media you can erase them unless they are mounted bind in RO mode.", $color);
+ exit 1;
+ }
+ }
+ print_color("$LOG rmdir /tmp/$isoconf->{nameid}-$version-$isoconf->{arch}", $color);
+ system("sudo rm -rf /tmp/$isoconf->{nameid}-$version-$isoconf->{arch}");
+ print_color("$LOG rmdir $builddir", $color);
+ #pathrm("$wd/$isoconf->{iso}{genisoimage}{builddir}/$name/$arch") or die $!;
+ -d $builddir and system("rm -rf $builddir");
+ print_color("$LOG rmdir $isodir", $color);
+ #pathrm("$wd/$isoconf->{iso}{genisoimage}{isodir}/$name/$arch") or die $!;
+ -d $isodir and system("rm -rf $isodir");
+}
+1;
diff --git a/BCD/Genisoimage.pm b/BCD/Genisoimage.pm
new file mode 100644
index 0000000..7dba9b1
--- /dev/null
+++ b/BCD/Genisoimage.pm
@@ -0,0 +1,123 @@
+package BCD::Genisoimage;
+
+use strict;
+use XML::Simple;
+use BCD::Common qw(:DEFAULT $isoconf $wd $name $arch $version $builddir $isodir $error_color $repo $based_on);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(main_iso);
+our @EXPORT_OK = qw($isoname);
+
+my $LOG="GENISOIMAGE -";
+my $color = "green";
+
+# mandriva-linux-free-2009.1-i586
+our $isoname = $isoconf->{nameid} . '-' . $isoconf->{mediainfo}{version} . '-' . $isoconf->{arch};
+
+# genisoimage -f -sort /home/plop/tmp/build/2009.1/11.sort -r -J -hide-rr-moved -nobak -cache-inodes -A "Mandriva Linux - 2009 Spring (Free64)" -publisher "Mandriva" -sysid "Mandriva Linux" -p "Mandriva-Linux" -volset "Mandriva Linux - 2009 Spring (Free64) - DVD x86_64 [1/1]" -V "Free-20091-x86_64" -o /home/plop/iso/2009.1/11-2009.1.iso -b x86_64/isolinux/isolinux.bin -c x86_64/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table "/home/plop/build/2009.1/first/11" /home/plop/build/2009.1/11
+
+
+sub create_version {
+ # create the VERSION file available on the base of the ISO
+ my $version_file = "$builddir/VERSION";
+ print_color("$LOG create the $version_file file", $color);
+ open my $VERSION, ">$version_file";
+ my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime(time());
+ $year += 1900;
+ my $tag = $isoconf->{iso}{tag};
+ my $product = $isoconf->{iso}{product};
+ my $publisher = $isoconf->{iso}{header}{publisherid};
+ printf $VERSION "$publisher $name $tag %04d%02d%02d $hour:%02d\n", $year, $mon+1, $mday, $min;
+ close $VERSION;
+}
+
+sub create_productid {
+ # vendor=Mandriva,distribution=Mandriva Linux,type=basic,version=2009.1,branch=cooker,release=0.1,arch=i586,product=maratangua
+ print_color("$LOG create the $builddir/product.id", $color);
+ my $productid_file = "$builddir/product.id";
+ open my $product_id, ">$productid_file";
+ print $product_id "vendor=$isoconf->{iso}{header}{publisherid},";
+ print $product_id "distribution=$isoconf->{iso}{header}{systemid},";
+ print $product_id "type=$isoconf->{iso}{type},";
+ print $product_id "version=$isoconf->{based_on},";
+ print $product_id "branch=$isoconf->{iso}{branch},";
+ print $product_id "release=$isoconf->{iso}{minor}.$isoconf->{iso}{subversion},";
+ print $product_id "arch=$arch,";
+ print $product_id "product=$isoconf->{iso}{product}";
+ close $product_id;
+}
+
+sub create_idx {
+ print_color("$LOG create the IDX file from $builddir/pkg-$version-$isoconf->{iso}{tag}.idx", $color);
+ # pkg-2009.1-pauillac.idx
+ system("find $builddir -name \*.rpm | awk -F 'media/' {'print \"$isoconf->{iso}{header}{volumeid} \" \$2'} | sed -e 's/\.rpm\$//g' | sort > $builddir/pkg-$version-$isoconf->{iso}{tag}.idx");
+ system("cp -v $builddir/pkg-$version-$isoconf->{iso}{tag}.idx $isodir/$isoname.idx");
+}
+
+sub create_iso {
+ # build the ISO with all args
+ print_color("$LOG Building the ISO", $color);
+ my $cmd = "genisoimage $isoconf->{iso}{genisoimage}{options} \\
+-A '$isoconf->{iso}{header}{applicationid}' \\
+-publisher '$isoconf->{iso}{header}{publisherid}' \\
+-sysid '$isoconf->{iso}{header}{systemid}' \\
+-p '$isoconf->{iso}{header}{datapreparer}' \\
+-volset '$isoconf->{iso}{header}{volumesetid}' \\
+-V '$isoconf->{iso}{header}{volumeid}' \\
+-o '$isodir/$isoname.iso' \\
+-b $arch/isolinux/isolinux.bin \\
+-boot-info-table \\
+$builddir/../
+";
+#-quiet \\
+ print_color("\n------------\n $cmd", $color);
+ system($cmd);
+ system("du -h $isodir/$isoname.iso");
+ system("du -sh $builddir/install");
+
+}
+
+sub create_md5 {
+ # create the MD5 of the ISO
+ print_color("$LOG Create the MD5 and SHA1 of the ISO", $color);
+ my $ISOFILE = "$isodir/$isoname.iso";
+ if (! -f $ISOFILE) {
+ print_color("$LOG can't find $ISOFILE", $error_color);
+ exit 1;
+ } else {
+ print_color("$LOG do a: md5sum $ISOFILE > $ISOFILE.md5", $color);
+ system("cd $isodir && md5sum $isoname.iso > $ISOFILE.md5 &");
+ print_color("$LOG do a: sha1sum $ISOFILE > $ISOFILE.sha1", $color);
+ system("cd $isodir && sha1sum $isoname.iso > $ISOFILE.sha1 &");
+ }
+}
+
+sub isohybrid {
+ print_color("$LOG isohybrid the ISO", $color);
+ my $ISOFILE = "$isodir/$isoname.iso";
+ system("isohybrid -fatfirst $ISOFILE") == 0 or die "$LOG system isohybrid failed: $?\n";
+}
+
+sub copy_textfiles {
+ map { system("cp -vf $repo/$based_on/$arch/$_ $builddir/");
+ } qw(COPYING INSTALL.txt install.htm LICENSE.txt LICENSE-APPS.txt README.txt index.htm release-notes.html release-notes.txt);
+}
+
+sub main_iso {
+ my ($option) = @_;
+ create_version;
+ create_productid;
+ copy_textfiles;
+ create_idx;
+ if ($option =~ /noiso/) {
+ print_color("$LOG skipping ISO creation", $color);
+ } else {
+ create_iso;
+ isohybrid;
+ create_md5;
+ }
+
+}
+
+1;
+
diff --git a/BCD/Isolinux.pm b/BCD/Isolinux.pm
new file mode 100644
index 0000000..41c3d97
--- /dev/null
+++ b/BCD/Isolinux.pm
@@ -0,0 +1,118 @@
+package BCD::Isolinux;
+
+use File::Copy::Recursive qw(dircopy pathrm);
+use BCD::Common qw(:DEFAULT $isoconf $wd $name $arch $version $based_on $repo $builddir);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(main_isolinux);
+
+my $LOG="ISOLINUX -";
+my $color = "yellow";
+
+my $repo_isolinux;
+if (!defined($isoconf->{isolinux}{fullpath})) {
+ $repo_isolinux = "$repo/$based_on/$arch/$isoconf->{isolinux}{defaultpath}/";
+} else {
+ $repo_isolinux = $isoconf->{isolinux}{fullpath};
+}
+my $build_isolinux_dir = "$builddir/isolinux";
+
+sub switch_theme {
+ my $theme = $isoconf->{theme}{bootsplash};
+ print_color("$LOG switch to theme $theme", $color);
+ -d "$isoconf->{theme}{bootsplash_path}/themes/$theme" or die "$LOG cant find the gfxboot theme: $isoconf->{theme}{bootsplash_path}/themes/$theme";
+ opendir my $DIR, $build_isolinux_dir or die "$LOG FATAL switch_theme: unable to open $build_isolinux_dir\n";
+ foreach my $f (readdir $DIR) {
+ $f =~ /^\.{1,2}$/ and next;
+ -d "$build_isolinux_dir/$f" or next;
+ opendir my $ALT, "$build_isolinux_dir/$f" or die "LOG FATAL switch_theme: unable to open $dir/$f\n";
+ foreach my $all (readdir $ALT) {
+ $all =~ /all.rdz/ or next;
+ my $initrd = "$build_isolinux_dir/$f/$all";
+ my $binary = "/usr/share/bootsplash/scripts/make-boot-splash-raw";
+ -x $binary or die "$LOG you need $binary which is available in bootsplash >= 3.2.3\n";
+ my $cmd;
+ if ($isoconf->{based_on} gt "2009.1") {
+ $cmd = "$binary $initrd $theme";
+ } else {
+ # old script use a resolution parameter
+ $cmd = "$binary $initrd 800x600 $theme";
+ }
+ print_color("$LOG using $f", $color);
+ system($cmd) == 0 or die "$LOG FATAL switch_theme: config file for $theme may not exist\n";
+ }
+ closedir $ALT;
+ }
+ closedir $DIR;
+ # syslinux
+ my $lilo_sys = "$isoconf->{theme}{bootsplash_path}/themes/$theme/lilo/syslinux";
+ -f $lilo_sys and system("cp -vf $lilo_sys", "$build_isolinux_dir/boot.msg");
+ print_color("$LOG copy $isoconf->{theme}{gfxboot_path}/themes/*.jpg to $build_isolinux_dir/",, $color);
+ system("cp -vf $isoconf->{theme}{gfxboot_path}/themes/$theme/welcome.jpg $build_isolinux_dir/");
+ system("cp -vf $isoconf->{theme}{gfxboot_path}/themes/$theme/back.jpg $build_isolinux_dir/");
+}
+
+sub add_entry {
+ my $syslinuxcfg = "$build_isolinux_dir/isolinux.cfg";
+ -f $syslinuxcfg or die "$LOG can't path $syslinuxcfg";
+ foreach my $syslinux (@{$isoconf->{isolinux}{entry}}) {
+ $syslinux->{name} or next;
+ print_color("$LOG add $syslinux->{name} in $syslinuxcfg", $color);
+ open my $SYS, ">> $syslinuxcfg";
+ print $SYS "label $syslinux->{label}\n";
+ print $SYS " kernel $syslinux->{kernel}\n";
+ print $SYS " append $syslinux->{append}\n";
+ close $SYS;
+ if (-f $syslinux->{bin}) {
+ system("cp -vf $syslinux->{bin} $build_isolinux_dir/");
+ } else {
+ die "$LOG $syslinux->{bin} is not present on the system !\n";
+ }
+ }
+}
+
+sub use_firmware {
+ print_color("$LOG copy fw.gz to $build_isolinux_dir/alt0/", $color);
+ my $syslinuxcfg = "$build_isolinux_dir/isolinux.cfg";
+ open (IN, "+<$syslinuxcfg");
+ @file = <IN>;
+ seek IN,0,0;
+ foreach (@file){
+ $_ =~ s|alt0/all.rdz|alt0/all.rdz,alt0/fw.gz|g;
+ print IN $_;
+ }
+ close IN;
+ system("cp -v /usr/lib*/drakx-installer-images/isolinux/alt0/fw.gz $build_isolinux_dir/alt0/")
+}
+
+sub copy_files {
+ foreach my $file (@{$isoconf->{isolinux}{tocopy}}) {
+ $file->{name} or next;
+ if (-f $file->{file}) {
+ print_color("$LOG copy $file->{file} in $build_isolinux_dir", $color);
+ system("cp -avf $file->{file} $build_isolinux_dir/");
+ } else {
+ die "$LOG $file->{file} is not present on the system !\n";
+ }
+ }
+}
+
+sub main_isolinux {
+ if (! -d $repo_isolinux) {
+ print_color("$LOG I can't find the isolinux dir $repo_isolinux !", $color);
+ exit;
+ }
+ print_color("$LOG Remove old copy of isolinux", $color);
+ pathrm("$build_isolinux_dir/isolinux") or die $!;
+ print_color("$LOG copy $repo_isolinux to $build_isolinux_dir", $color);
+ dircopy($repo_isolinux, $build_isolinux_dir) or die $!;
+ add_entry;
+ if ($isoconf->{isolinux}{firmware} eq "yes") {
+ use_firmware;
+ }
+ copy_files;
+ switch_theme;
+}
+
+1;
+
diff --git a/BCD/Media.pm b/BCD/Media.pm
new file mode 100644
index 0000000..9499d44
--- /dev/null
+++ b/BCD/Media.pm
@@ -0,0 +1,1132 @@
+package BCD::Media;
+
+use File::Copy::Recursive qw(dircopy pathrm);
+use strict;
+use URPM;
+use File::Copy;
+use File::stat;
+use Data::Dumper;
+use MDK::Common;
+use File::Glob ':glob';
+use Parallel::ForkManager;
+
+use BCD::Common qw(:DEFAULT $isoconf $wd $name $arch $version $based_on $repo $builddir $distrib_path $error_color $DISTRIB $THEME $tmp_rpmsrate $NB_FORK $dir_deps @list_of_removed);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(main_media list_media use_gendistrib list_medias_available check_repo_hdlist rpmcheck_launch solve_doble_issue clean_urpmq_log get_srpms_list find_all_kernel);
+our @EXPORT_OK = qw($rpmcheck_list_pkg $file_rpmcheck_log);
+
+my $verbose;
+my $LOG="MEDIA -";
+my $color = "magenta";
+
+# all mounted loop dir to umount
+my @to_umount;
+my @add_media;
+
+my $mediainfo_sourcedir;
+if (defined($isoconf->{mediainfo}{fullpath})) {
+ $mediainfo_sourcedir = $isoconf->{mediainfo}{fullpath};
+} else {
+ $mediainfo_sourcedir = "$repo/$based_on/$arch/$isoconf->{mediainfo}{mediainfo_dir}";
+}
+
+my $chroot_path = "/tmp/$isoconf->{nameid}-$version-$isoconf->{arch}";
+our $rpmcheck_list_pkg = "/tmp/rpmcheck_list_pkg_to_add_$isoconf->{nameid}-$version-$isoconf->{arch}";
+our $file_rpmcheck_log = "/tmp/rpmcheck_failure_$isoconf->{nameid}-$version-$isoconf->{arch}";
+
+sub create_media {
+ print_color("$LOG Create the media dir in $builddir", $color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ create_needed_dir("$builddir/media/$media->{destmedia}");
+ }
+}
+
+sub show_size {
+ print_color("$LOG size of the builddir", $color);
+ system("du -sLh $builddir");
+}
+
+sub list_media {
+ print_color("$LOG all media are listed there:", $color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ print "
+name: $media->{name}
+ desc: $media->{desc}
+ mediadir: $media->{mediadir}
+ destmedia: $media->{destmedia}
+ pubkey: $media->{pubkey}\n";
+ foreach my $files (@{$media->{input}}) {
+ $files->{file} or next;
+ if (-f $files->{file}) {
+ print "list of wanted: $files->{file}\n";
+ } else { print_color("$files->{file} not present", $error_color); }
+ }
+ foreach my $files (@{$media->{exclude}}) {
+ $files->{file} or next;
+ if (-f $files->{file}) {
+ print "list of exclusion: $files->{file}\n";
+ } else { print_color("$files->{file} not present", $error_color); }
+ }
+ }
+}
+
+sub copy_pubkey {
+ my ($source_key, $destmedia) = @_;
+ print_color("$LOG copy $source_key to the $builddir/media/$destmedia/media_info directory", $color);
+ create_needed_dir("$builddir/media/$destmedia/media_info/");
+ if (! -f $source_key) {
+ print_color("$LOG can't find the $source_key", $error_color);
+ #exit;
+ }
+ system("cp -vf $source_key $builddir/media/$destmedia/media_info/");
+}
+
+sub use_gendistrib {
+ my $destmedia;
+ print_color("$LOG remove hdlists and synthesys from $builddir/media/$destmedia/media_info and $builddir/media/media_info", $color);
+ system("rm -vf $builddir/media/media_info/*.cz");
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{destmedia} or next;
+ if ($destmedia eq $media->{destmedia}) { next }
+ $destmedia = $media->{destmedia};
+ system("rm -vf $builddir/media/$destmedia/media_info/*.cz");
+ system("rm -vf $builddir/media/$destmedia/media_info/MD5SUM");
+ }
+ undef $destmedia;
+ print_color("$LOG gendistrib --mediacfg $builddir/$isoconf->{iso}{mediacfg} $builddir", $color);
+ my $cmd = "gendistrib --mediacfg $builddir/$isoconf->{iso}{mediacfg} $builddir";
+ system($cmd) == 0 or die "$LOG system $cmd failed: $?\n";
+ if ($isoconf->{based_on} lt "2009.1") {
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if ($destmedia eq $media->{destmedia}) { next }
+ $destmedia = $media->{destmedia};
+ print_color("$LOG move hdlists and synthesys from $builddir/media/$destmedia/media_info to $builddir/media/media_info/", $color);
+ system("rm -vf $builddir/media/media_info/*_$media->{name}.cz");
+ system("rm -vf $builddir/media/media_info/pubkey_$media->{name}");
+ system("cp -avf $builddir/media/$destmedia/media_info/hdlist.cz $builddir/media/media_info/hdlist_$media->{name}.cz");
+ system("cp -avf $builddir/media/$destmedia/media_info/pubkey $builddir/media/media_info/pubkey_$media->{name}");
+ system("cp -avf $builddir/media/$destmedia/media_info/synthesis.hdlist.cz $builddir/media/media_info/synthesis.hdlist_$media->{name}.cz");
+ system("rm -vf $builddir/media/$destmedia/media_info/*.cz");
+ system("rm -vf $builddir/media/$destmedia/media_info/MD5SUM");
+ }
+ }
+}
+
+sub copy_rpm {
+ my ($source_dir, $dest_dir) = @_;
+ system ("cp -a $source_dir/*.rpm $dest_dir");
+}
+
+sub create_mediacfg {
+ print_color("$LOG $builddir/$isoconf->{iso}{mediacfg}", $color);
+ system("rm -rf $builddir/$isoconf->{mediainfo}{mediainfo_dir}");
+ create_needed_dir("$builddir/$isoconf->{mediainfo}{mediainfo_dir}");
+ my $media_cfg = "$builddir/$isoconf->{iso}{mediacfg}";
+ open my $MEDIACFG, ">$media_cfg";
+ print $MEDIACFG "\n";
+ print $MEDIACFG "[media_info]\n";
+ print $MEDIACFG "version=$version\n";
+ if ($isoconf->{based_on} gt "2009.1") {
+ print $MEDIACFG "mediacfg_version=2\n";
+ }
+ print $MEDIACFG "branch=$isoconf->{iso}{branch}\n";
+ print $MEDIACFG "arch=$arch\n";
+ print $MEDIACFG "minor=$isoconf->{iso}{minor}\n";
+ print $MEDIACFG "subversion=$isoconf->{iso}{subversion}\n";
+ if ($isoconf->{mediainfo}{suppl}{todo} eq "yes") {
+ print $MEDIACFG "suppl=1\n";
+ }
+ if ($isoconf->{mediainfo}{askmedia}{todo} eq "yes") {
+ print $MEDIACFG "askmedia=1\n";
+ }
+ if ($isoconf->{mediainfo}{xmlinfo}{todo} eq "yes") {
+ print $MEDIACFG "xml-info=1\n";
+ }
+ my $destmedia;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if ($destmedia eq $media->{destmedia}) { next }
+ $destmedia = $media->{destmedia};
+ if ($isoconf->{based_on} lt "2009.1") {
+ print $MEDIACFG "
+
+[$media->{destmedia}]
+hdlist=hdlist_$media->{name}.cz
+pubkey=pubkey_$media->{name}
+name=$isoconf->{iso}{header}{volumesetid}
+desc=$isoconf->{iso}{header}{volumesetid}
+\n";
+} else {
+ print $MEDIACFG "
+[$media->{destmedia}]
+synthesis=$media->{destmedia}/media_info/synthesis.hdlist.cz
+hdlist=$media->{destmedia}/media_info/hdlist.cz
+pubkey=$media->{destmedia}/media_info/pubkey
+name=$media->{desc}
+\n";
+ }
+ }
+ close $MEDIACFG;
+}
+
+# based on a similar functions in pkgs.pm
+sub get_list_from_CAT {
+ #4 META_CLASS"desktop" mandriva-xfce-config-One
+ my ($file, $cat, $poids) = @_;
+ my (%rates, @need_to_copy);
+ my (@l);
+ local $_;
+ foreach (cat_($file)) {
+ s/#.*//; # comments
+ my ($indent, $data) = /(\s*)(.*)/;
+ next if !$data; # skip empty lines
+
+ @l = grep { $_->[0] < length $indent } @l;
+
+ my @m = @l ? @{$l[-1][1]} : ();
+ my ($t, $flag, @l2);
+ while ($data =~
+ /^((
+ [1-5]
+ |
+ (?: (?: !\s*)? [0-9A-Z_]+(?:".*?")?)
+ (?: \s*\|\|\s* (?: !\s*)? [0-9A-Z_]+(?:".*?")?)*
+ )
+ (?:\s+|$)
+ )(.*)/x) { #@")) {
+ ($t, $flag, $data) = ($1,$2,$3);
+ while ($flag =~ s,^\s*(("[^"]*"|[^"\s]*)*)\s+,$1,) {}
+ push @m, $flag;
+ push @l2, [ length $indent, [ @m ] ];
+ $indent .= $t;
+ }
+ if ($data) {
+ # has packages on same line
+ my ($rates, $flags) = partition { /^\d$/ } @m;
+ foreach my $name (split ' ', $data) {
+ if (member($cat, @$flags)) {
+ if ("@$rates" ge "$poids") {
+ push @need_to_copy, $name;
+ } else {
+ print "exclude $name of $cat (@$rates < $poids)\n";
+ }
+ next;
+ }
+ }
+ push @l, @l2;
+ } else {
+ push @l, [ $l2[0][0], $l2[-1][1] ];
+ }
+ }
+ \%rates, \@need_to_copy;
+}
+
+sub mini_chroot {
+ # it is usefull to use a mini chroot for add remove media, we have to keep the list of installed packages to copy them on ISO
+ print_color("$LOG create a mini chroot to run urpmi", $color);
+ # store all file needed to be installed on the system
+ my $cmd = "LC_ALL=C sudo urpmi --quiet --no-suggests --auto --no-verify-rpm --use-distrib $repo/$based_on/$arch --urpmi-root $chroot_path";
+ # sudo urpmi --no-verify-rpm --auto --urpmi-root /tmp/mk --use-distrib /mnt/BIG/dis/2009.0/i586/ basesystem-minimal urpmi --test
+ #
+ system("LC_ALL=C sudo urpmi --test --no-suggests --auto --no-verify-rpm --use-distrib $repo/$based_on/$arch --urpmi-root /tmp/$isoconf->{nameid}-$version-$isoconf->{arch} --media 'Main,Main Updates' --excludemedia 'Main Testing,Main Backports' urpmi basesystem-minimal bash basesystem > $chroot_path/$isoconf->{tocopy_file}_TODO_chroot");
+ # install all those file to be able to use urpmi.XXXXXX
+ system("LC_ALL=C $cmd --prefer $DISTRIB,$THEME urpmi bash");
+ system("sudo chroot $chroot_path mkdir -p $distrib_path");
+ system("sudo mount -o bind $repo/$based_on/$arch $chroot_path/$distrib_path -o ro");
+ push @to_umount, $distrib_path;
+ system("sudo chroot $chroot_path urpmi.removemedia -a");
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ chomp($media->{name});
+ system("LC_ALL=C sudo chroot $chroot_path urpmi.addmedia --probe-synthesis '$media->{name}' $distrib_path/media/$media->{mediadir}/release");
+ if ($media->{updates} eq "yes") {
+ system("LC_ALL=C sudo chroot $chroot_path urpmi.addmedia --update --probe-synthesis \"$media->{name} Updates\" $distrib_path/media/$media->{mediadir}/updates");
+ }
+ if ($media->{backports} eq "yes") {
+ system("sudo chroot $chroot_path urpmi.addmedia --probe-synthesis '$media->{name} Backports' $distrib_path/media/$media->{mediadir}/backport");
+ }
+ if ($media->{testing} eq "yes") {
+ system("sudo chroot $chroot_path urpmi.addmedia --probe-synthesis '$media->{name} Testing' $distrib_path/media/$media->{mediadir}/testing");
+ }
+ }
+# } else {
+# system("sudo chroot $chroot_path urpmi.addmedia --distrib $distrib_path --no-md5sum");
+# }
+}
+
+sub add_media {
+ my ($name, $path, $update) = @_;
+ print_color("$LOG add media $name from $path", $color);
+ system("sudo chroot $chroot_path mkdir -p /tmp/$name");
+ system("sudo mount -o bind $path $chroot_path/tmp/$name -o ro");
+ # check if path contain sub direcroty or not (media/release media/updates etc...)
+ if (-d "$path/release" and -d "$path/updates") {
+ print_color("$LOG This supp media contains release and updates sub-directory", $color);
+ system("LC_ALL=C sudo chroot $chroot_path urpmi.addmedia $name-release /tmp/$name/release");
+ if ($update =~ /yes/) {
+ system("LC_ALL=C sudo chroot $chroot_path urpmi.addmedia --update '$name Updates' /tmp/$name/updates");
+ }
+ } else {
+ system("LC_ALL=C sudo chroot $chroot_path urpmi.addmedia $name /tmp/$name");
+ }
+ push @to_umount, "/tmp/$name";
+ push @add_media, "$name";
+}
+
+sub drop_media {
+ my ($name) = @_;
+ print_color("$LOG remove media $name from urpmi config", $color);
+ system("LC_ALL=C sudo chroot $chroot_path urpmi.removemedia $name");
+}
+
+
+
+my $listcopy = "$chroot_path/$isoconf->{tocopy_file}";
+sub generate_list_of_rpm_2_copy {
+ my @toget;my @toexclude;my $extra;
+ mini_chroot;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{external}{name} and add_media($media->{external}{name}, $media->{external}{fullpath_mediadir}, $media->{updates});
+ foreach my $input (@{$media->{input}}) {
+ $input->{file} or next;
+ -f $input->{file} or print_color("$LOG i can not find the $input->{file}, remove this list or fix...", $error_color);
+ foreach my $tohave (cat_($input->{file})) {
+ if ($tohave =~ /^\s/ || $tohave =~ /^\#/) {
+ next;
+ } elsif ($tohave =~ /^\S*\s\d$/) {
+ my ($section, $poids) = $tohave =~ /^(\S*)\s(\d)/;
+ print "$LOG get packages from $section using weight of $poids\n";
+ # TOFIX remove META_CLASS to avoid theme pb
+ system("cat $builddir/$isoconf->{mediainfo}{mediainfo_dir}/rpmsrate | grep -v META_CLASS > $tmp_rpmsrate");
+# system("cat $tmp_rpmsrate | grep -v theme > $tmp_rpmsrate");
+ my ($rates, $need_to_copy) = get_list_from_CAT($tmp_rpmsrate, $section, $poids);
+ foreach my $data (@{$need_to_copy}) {
+ push @toget, $data;
+ }
+ next;
+ } else {
+ chomp($tohave);
+ $verbose and print "$LOG $tohave\n";
+ push @toget, $tohave;
+ next;
+ }
+ }
+ }
+ foreach my $exclude (@{$media->{exclude}}) {
+ $exclude->{file} or next;
+ -f $exclude->{file} or print_color("$LOG i can not find the $exclude->{file}, remove this list or fix...", $error_color);
+ foreach my $totest (cat_($exclude->{file})) {
+ if ($totest =~ /^\s/ || $totest =~ /^\#/) {
+ next;
+ } else {
+ chomp($totest);
+ push @toexclude, $totest;
+ next;
+ }
+ }
+ }
+# print "$LOG $media, $toget, $toexclude";
+ create_list($media, \@toget, \@toexclude, $media->{external}{name}, $media->{media_supp});
+ @toexclude = "";
+ @toget = "";
+ }
+}
+
+sub rpmcheck_list {
+ my @toget = cat_($rpmcheck_list_pkg);
+ my $todo = @toget;
+ if ($todo ne "0") {
+ print_color("$LOG calculate deps from the auto-generated rpmcheck list file", $error_color);
+ my $list_filename = "$isoconf->{tocopy_file}_todo_rpmcheck";
+ my $list = "$chroot_path/urpmq/$list_filename";
+ my $urpmq_options = "--requires-recursive -c --sources $isoconf->{mediainfo}{urpmi_option}";
+ my $pkgs;
+ foreach (@toget) { $_ or next ; chomp($_); $pkgs = "$_ " . $pkgs; }
+ my $cmd_do_it = "LC_ALL=C sudo -P chroot $chroot_path urpmq --prefer $DISTRIB,$THEME $urpmq_options --no-suggests";
+ do_fork($pkgs, $list_filename, $list, $cmd_do_it);
+ } else {
+ print_color("$LOG No rpmcheck error", $error_color);
+ }
+}
+
+sub remove_notpresent {
+ my ($urpmi_error, $wanted) = @_;
+ my @toremove;
+ foreach my $entry (cat_($urpmi_error)) {
+ my ($data, $tor) = $entry =~ /(.*)\s(.*)\n/;
+ $data =~ /-/ and next;
+ $data =~ /^\s/ and next;
+ $tor or next;
+ push @toremove, $tor;
+ }
+ # keep only one line per packages
+ my %already_seen; my @final_list;
+ @already_seen{@toremove} = ();
+ foreach my $object (@{$wanted}) {
+ if (exists $already_seen{$object} and $verbose) { print_color("$LOG i cant find this package: $object, remove it from list", $error_color); }
+ push(@final_list, $object) unless exists $already_seen{$object};
+ }
+ # prepare the final list
+ my $final_list;
+ foreach (@final_list) {
+ chomp($_);
+ $final_list = $final_list . " $_";
+ }
+ return $final_list;
+}
+
+sub create_list {
+ my ($media, $wanted, $exclude, $extra, $media_supp) = @_;
+ my $extra_media;
+ # Main media is mandatory for all other media !
+ # we will use only Main + updates and this media + updates to calculte the list of wanted pkg
+ if ($media->{name} eq "Main") {
+ if ($media->{updates} eq "yes") {
+ #$extra_media = "--media \"Main,Main Updates,$extra,$media_supp\" --sortmedia \"Main Updates,Main\"";
+ $extra_media = "--media \"Main,Main Updates,$extra,$media_supp\"";
+ } else {
+ $extra_media = "--media \"Main,$extra,$media_supp\"";
+ }
+ } else {
+ my $extra2;
+ foreach (@add_media) { chomp($_); $_ and $extra2 = $_ . ',' . $extra2; };
+ #$extra_media = "--media \"Main,Main Updates,$extra2,$media_supp,$media->{name},$media->{name} Updates\" --sortmedia \"Main Updates,Main,$media->{name} Updates,$media->{name}\"";
+ if ($media->{updates} eq "yes") {
+ $extra_media = "--media \"Main,Main Updates,$extra2,$media_supp,$media->{name},$media->{name} Updates\"";
+ } else {
+ $extra_media = "--media \"Main,$extra2,$media_supp,$media->{name}\"";
+ }
+ }
+
+ # check the suggests option in the XML configuration
+ my $opt_sug;
+ if ($media->{nosuggests} eq "yes") {
+ $opt_sug = "--no-suggests";
+ } else { $opt_sug = ""; }
+ # list of wanted RPM per media name
+ my $list_filename = "$isoconf->{tocopy_file}_todo_$media->{name}";
+# my $list_filename_update = "$isoconf->{tocopy_file}_todo_$media->{name}_update";
+ my $list = "$chroot_path/urpmq/$list_filename";
+ my $list_update = "$chroot_path/urpmq/$list_filename" . "_update";
+ system("sudo chroot $chroot_path mkdir -m 777 -p urpmq");
+ # urpmq error file
+ my $urpmq_error = "$chroot_path/$isoconf->{tocopy_file}_urpmi_error_$media->{name}";
+ my $urpmq_error_update = "$chroot_path/$isoconf->{tocopy_file}_urpmi_error_update_$media->{name}";
+
+ # create list of wanted and exlude
+ my $tested_exclude;
+ my $tested_wanted;
+ foreach (@{$wanted}) { $tested_wanted = $tested_wanted . " $_" }
+ foreach (@{$exclude}) {
+ $_ or next;
+ $tested_exclude = $tested_exclude . " --skip $_"
+ };
+ print_color("$LOG remove unwanted mandriva-release, use $DISTRIB", $color);
+ # urpmq options (with option in the xml file)
+ my $urpmq_options = "--requires-recursive -c --sources $isoconf->{mediainfo}{urpmi_option}";
+ my $urpmq_extra_opt = "$opt_sug $extra_media";
+
+ ###
+ # do the job with update, find missing package from list
+ # only if the media as udpate option enable
+ if ($media->{updates} eq "yes") {
+ my $cmd_find_missing_update = "LC_ALL=C sudo chroot $chroot_path urpmq --update --prefer $DISTRIB,$THEME $urpmq_options $urpmq_extra_opt $tested_wanted $tested_exclude 2> $urpmq_error_update";
+ print_color("$LOG first attempt to run urpmq --update on media $media->{name} (to find all packages not availables in update)", $color);
+ system($cmd_find_missing_update);
+ # urpmq error found, so we have to remove some entry in the list of wanted packages
+ my $final_list_update = remove_notpresent($urpmq_error_update, $wanted);
+ my $cmd_do_it_update = "LC_ALL=C sudo -P chroot $chroot_path urpmq --update -a --prefer $DISTRIB,$THEME $urpmq_options $urpmq_extra_opt $tested_exclude";
+ do_fork($final_list_update, "$list_filename" . "_update", $list_update, $cmd_do_it_update);
+ }
+
+ ###
+ # select rpm from all media, find missing from list
+ my $cmd_find_missing = "LC_ALL=C sudo chroot $chroot_path urpmq --prefer $DISTRIB,$THEME $urpmq_options $urpmq_extra_opt $tested_wanted $tested_exclude 2> $urpmq_error > $list";
+ print_color("$LOG first attempt to run urpmq on media $media->{name} (to find all packages not availables)", $color);
+ system($cmd_find_missing);
+ # urpmq error found, so we have to remove some entry in the list of wanted packages
+ my $final_list = remove_notpresent($urpmq_error, $wanted);
+ print_color("$LOG launch urpmq on media $media->{name} (to create $list)", $color);
+ my $cmd_do_it = "LC_ALL=C sudo -P chroot $chroot_path urpmq --prefer $DISTRIB,$THEME $urpmq_options $urpmq_extra_opt $tested_exclude";
+ do_fork($final_list, $list_filename, $list, $cmd_do_it);
+}
+
+
+sub do_fork {
+ my ($final_list, $list_filename, $list, $cmd) = @_;
+ my @list_alone = split(/ /, $final_list);
+ my $count = @list_alone;
+ my $status = "0";
+ my $pm = new Parallel::ForkManager($NB_FORK);
+ print_color("$LOG $count transactions to do ... be patient !!!!", $color);
+ $| = 1;
+ foreach my $pkg (@list_alone) {
+ $pkg or next;
+ $status++;
+ my $pid = $pm->start and next;
+ back_and_print($status, $count);
+ # check an urpmq has been done before in an other media
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if (-f "$dir_deps/$isoconf->{tocopy_file}_todo_$media->{name}-$pkg") {
+ $verbose and print_color("$LOG found the urpmq transaction for $pkg, i will use it $dir_deps/$isoconf->{tocopy_file}_todo_$media->{name}-$pkg", $color);
+ system("touch $dir_deps/bypass-$pkg");
+ system("cp -f $dir_deps/$isoconf->{tocopy_file}_todo_$media->{name}-$pkg $list-$pkg");
+ #system("cp -f $dir_deps/$isoconf->{tocopy_file}_todo_$media->{name}-$pkg $dir_deps/$list_filename-$pkg");
+ last;
+ } else {
+ $verbose and print_color("$LOG can't found the urpmq transaction", $color);
+ }
+ }
+ # check an urpmq has been done before in this media
+ if (-f "$dir_deps/bypass-$pkg") {
+ #my $pkg_found = `grep -P '\/$pkg-' $dir_deps/$list_filename-$pkg`;
+ #$pkg_found = basename($pkg_found);
+ $verbose and print_color("$LOG found the urpmq transaction for $pkg, i will the previous one found in $dir_deps directory", $color);
+ #system("cp -f $dir_deps/$list_filename-$pkg $list-$pkg");
+ } else {
+ # match the case using --update option
+ my $cmd_do_it = "$cmd $pkg > $list-$pkg";
+ if ($cmd =~ /\-\-update/) {
+ my @result = `urpmq --update $pkg`;
+ foreach (@result) {
+ # exact match with --update option
+ $_ or next;
+ if ($_ =~ /^$pkg/) {
+ system($cmd_do_it);
+ system("cp -f $list-$pkg $dir_deps/$list_filename-$pkg");
+ last;
+ } else { $verbose and print "$LOG $pkg is not in update, it's a package that contains the string $pkg!\n"; last }
+ }
+ } else {
+ system($cmd_do_it);
+ system("cp -f $list-$pkg $dir_deps/$list_filename-$pkg");
+ }
+ }
+ $pm->finish;
+ }
+ print_color("$LOG Waiting for the end of some urpmq command...", $color);
+ $pm->wait_all_children;
+ print_color("$LOG all urpmq command are done...", $color);
+}
+
+
+sub back_and_print {
+ my ($status, $total) = @_;
+ printf STDERR "%s / %2d \n", $status, $total;
+ print STDERR "\e[A";
+}
+
+
+sub concatenate_files {
+ # remove urpmq queries from excluded packages
+ print_color("$LOG remove urpmq queries from removed packages", $color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ foreach my $exclude (@{$media->{exclude}}) {
+ $exclude->{file} or next;
+ -f $exclude->{file} or print_color("$LOG i can not find the $exclude->{file}, remove this list or fix...", $error_color);
+ foreach my $totest (cat_($exclude->{file})) {
+ chomp($totest);
+ if (! $totest) { next };
+ system("rm -vf $chroot_path/urpmq/$isoconf->{tocopy_file}_todo_*$totest");
+ }
+ }
+ }
+ print_color("$LOG create the final list: $listcopy", $color);
+ system("cat $chroot_path/urpmq/$isoconf->{tocopy_file}_todo_* > $listcopy.tmp");
+ system("sed -e 's|^\\w*\\s/|/|' $listcopy.tmp > $listcopy");
+ system("grep '^/' $listcopy > $listcopy.tmp");
+ system("cat $listcopy.tmp | sort | uniq > $listcopy");
+}
+
+sub target_size {
+ print_color("$LOG calculate the size of all packages:", $color);
+ my $total;my $pkg_info;
+ foreach my $pkg (cat_($listcopy)) {
+ chomp($pkg);
+ if (-f "$pkg") {
+ # stat is not really good to get size file of linked packages over nfs
+ $pkg_info = stat($pkg);
+ $total = ($total+$pkg_info->size);
+ next;
+ } else { next; }
+ }
+ my $human_total = int(($total/1024)/1024);
+ print_color("$LOG Size of all RPMS: $human_total Mo", $color);
+ my $left = ($isoconf->{iso}{size} - $human_total);
+ # i need to add the install/ directory size
+ if ("$isoconf->{iso}{size}" ge "$human_total") {
+ print_color("$LOG all you data will fit on the CD/DVD, extra size: $left", $color);
+ } else {
+ print_color("$LOG all packages will not fit on $isoconf->{iso}{size}, i need $left Mo", $error_color);
+ }
+}
+
+sub count_nb_to_copy {
+ my ($file) = @_;
+ my $lines = 0;
+ open(FILE, $file) or die "Can't open `$file': $!";
+ while (sysread FILE, my $buffer, 4096) {
+ if ($buffer =~ /^install/ || $buffer =~ /^\-/ || $buffer =~ /^More/ || $buffer =~ /^Install/ ) {
+ next;
+ } else {
+ $lines += ($buffer =~ tr/\n//);
+ }
+ }
+ close FILE;
+ return $lines;
+}
+
+sub find_source_dest_media {
+ my ($todeal) = @_;
+ # distribution path
+ if ($todeal =~ m!^$distrib_path!) {
+ # find the source media name
+ # f_path will contrib/release, dir_f_path will be contrib
+ my ($f_path) = $todeal =~ /^$distrib_path\/media\/(.*)/;
+ my $dir_f_path = dirname($f_path);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ # find a mediadir or next one
+ $media->{mediadir} or next;
+ #print "DEBUG media->name: $media->{mediadir} f_path: $f_path\n";
+ # try to find the source media
+ if ($media->{mediadir} eq $dir_f_path) {
+ #print "DEBUG todeal: $todeal FROM $repo/$based_on/$arch/media/$f_path TO media/$media->{destmedia}\n";
+ return("$repo/$based_on/$arch/media/$f_path", "media/$media->{destmedia}");
+ }
+ }
+ next;
+ } else {
+ #external repository
+ #/tmp/u_xos or /tmp/u_xos/release and /tmp/u_xos/updates
+ my ($source_media) = $todeal =~ /\/tmp\/(.*)/;
+ # find the dest media from source media
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ # find a media or next one
+ $media->{name} or next;
+ if ($source_media eq $media->{name}) {
+ #print "DEBUG todeal: $todeal DEBUG media->name: $media->{name} source_media: $source_media\n";
+ # we have found the media so destmedia is $media->{destmedia}
+ # return the destmedia
+ return($media->{external}{fullpath_mediadir}, "media/$media->{destmedia}");
+ } elsif ($source_media eq "$media->{name}/release") {
+ return("$media->{external}{fullpath_mediadir}/release", "media/$media->{destmedia}");
+ } elsif ($source_media eq "$media->{name}/updates") {
+ return("$media->{external}{fullpath_mediadir}/updates", "media/$media->{destmedia}");
+ }
+ next;
+ }
+ }
+}
+
+sub parse_copy_link {
+ my ($wichaction) = @_;
+ my $count;my $action;
+ if ($wichaction =~ /link/) {
+ $action = "ln -sf";
+ } else {
+ $action = "cp -fa";
+ }
+ my $total = count_nb_to_copy($listcopy);
+ print_color("$LOG $wichaction all wanted packages to $builddir/XXXX ($total packages)", $color);
+ # chroot packages
+ if (!-f "$chroot_path/$isoconf->{tocopy_file}_TODO_chroot") { exit 1 }
+ foreach my $line (cat_("$chroot_path/$isoconf->{tocopy_file}_TODO_chroot")) {
+ chomp($line);
+ my @list = split(/ /, $line);
+ my $data = $list[$#list];
+ # if (! -d $data) { print "$data is not a directory !\n"; }
+ foreach my $pkg (@list) {
+ if (-f "$data/$pkg") {
+ #print "$LOG $action $data/$pkg TO1 $builddir/media/main/$pkg\n";
+ system("$action $data/$pkg $builddir/media/main/$pkg");
+ next;
+ } elsif (-f $data) {
+ my $package = basename($data);
+ chomp($package);
+ #print "$LOG $action $data TO2 $builddir/media/main/$package\n";
+ system("$action $data $builddir/media/main/$package");
+ next;
+ }
+ }
+ }
+ foreach my $tocopy (cat_($listcopy)) {
+ chomp($tocopy);
+ #print "info tocopy $tocopy\n";
+ my @list = split(/ /, $tocopy);
+ # path final
+ my $data2 = $list[$#list];
+ my ($path, $pkg) = $tocopy =~ m!^(/.*)/(.*)\.[rpm|]$!;
+ # une ligne avec un mot avant
+ # $pkg or ($path, $pkg) = $tocopy =~ m!^\w+\s(/.*)/(.*)\.rpm$!;
+
+ my $source_media; my $dest_media;
+ my $package = basename($data2);
+ my $dirn = dirname($data2);
+ if (-f "$chroot_path/$data2" || !-d "$chroot_path/$data2") {
+ chomp($package);
+ ($source_media, $dest_media) = find_source_dest_media($dirn);
+ $dest_media or print "$LOG $package is require/suggest but has no destination, removing it from list\n" and next;
+ #print "parse_copy_link package: $package, sourcemedia: $source_media, dest_media: $dest_media\n";
+ #print "parse_copy_link $LOG $action $source_media/$package TO3 $builddir/$dest_media/$package\n";
+ system("$action $source_media/$package $builddir/$dest_media/$package");
+ next;
+ } else {
+ #print "$chroot_path/$data2 data2 is a directory \n";
+ ($source_media, $dest_media) = find_source_dest_media($data2);
+ foreach my $pkg2 (@list) {
+ if (-f "$chroot_path/$data2/$pkg2") {
+ print "DATA2/pkg2 i found $chroot_path/$data2/$pkg2 \n";
+ #print "$LOG $action $source_media/$pkg2 TO4 $builddir/$dest_media/$pkg2\n";
+ system("$action $source_media/$pkg2 $builddir/$dest_media/$pkg2");
+ next;
+ }
+ }
+ }
+ $path or next;
+ if (!-d "$chroot_path/$path") {
+ print "";
+ #print "$chroot_path/$path isnt a directory\n";
+ } elsif (-f "$chroot_path/$path/$pkg") {
+ #print "$chroot_path/$path/$pkg is a package\n";
+ ($source_media, $dest_media) = find_source_dest_media($path);
+ $package = basename("chroot_path/$path/$pkg");
+ chomp($package);
+ #print "$LOG $action $source_media/$package TO5 $builddir/$dest_media/$pkg\n";
+ system("$action $source_media/$package $builddir/$dest_media/$pkg");
+ next;
+ } else { print "lost in space !!\n"; }
+ next;
+ }
+}
+
+sub rpmVersionCompare {
+ my ($pkg1, $pkg2) = @_;
+ my ($name_a, $av, $ar) = $pkg1 =~ /^(?:([^:]*):)?([^-]*)(?:-(.*))?$/;
+ my ($name_b, $bv, $br) = $pkg2 =~ /^(?:([^:]*):)?([^-]*)(?:-(.*))?$/;
+ my $rc = 0;
+ if(defined($name_a) && ! defined($name_b)) {
+ return 1;
+ } elsif(!defined($name_a) && defined($name_b)) {
+ return -1;
+ } else {
+ $rc = URPM::rpmvercmp($name_a, $name_b) if (defined($name_a) && defined($name_b));
+ if ($rc == 0) {
+ $rc = URPM::rpmvercmp($av, $bv);
+ if ($rc == 0) {
+ if(defined($ar) && !defined($br)) {
+ return 1;
+ } elsif(!defined($ar) && defined($br)) {
+ return -1;
+ } elsif (!defined($ar) && !defined($br)) {
+ return 0;
+ } else {
+ return URPM::rpmvercmp($ar, $br);
+ }
+ } else {
+ return $rc;
+ }
+ } else {
+ return $rc;
+ }
+ }
+}
+
+sub remove_all_excluded {
+ # this functions should be available if explicitely needed, it's really too dangerous to remove packages from a list...
+ print_color("$LOG remove all RPM from exclude list", $color);
+ print_color("$LOG WARNING remove needed packages can break dependencies, check rpmcheck messages", $error_color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if ($media->{remove_noarch} =~ /yes/) {
+ print_color("$LOG remove noarch from media $media->{name} $builddir/media/$media->{destmedia}/", $color);
+ system("rm -rf $builddir/media/$media->{destmedia}/*.noarch.rpm");
+ }
+ foreach my $exclude (@{$media->{exclude}}) {
+ $exclude->{file} or next;
+ -f $exclude->{file} or print_color("$LOG i can not find the $exclude->{file}, remove this list or fix...", $error_color);
+ foreach my $totest (cat_($exclude->{file})) {
+ chomp($totest);
+ if (! $totest) { next };
+ if ($totest =~ /^\s.*/ || $totest =~ /^\#/) {
+ next;
+ } else {
+ my @l = glob("$builddir/media/$media->{destmedia}/$totest*.rpm");
+ foreach my $file (@l) {
+ $file or next;
+ if (-f $file) {
+ $verbose and print "$LOG $file found, removing this file\n";
+ system("rm -f $file");
+ next;
+ }
+ }
+ }
+ next;
+ }
+ next;
+ }
+ }
+}
+
+sub copy_filedeps {
+ print_color("$LOG copy $mediainfo_sourcedir/$isoconf->{mediainfo}{filedeps} in $builddir/$isoconf->{mediainfo}{mediainfo_dir}", $color);
+ -f "$mediainfo_sourcedir/$isoconf->{mediainfo}{filedeps}" or print "$LOG missing filedeps\n";
+ system("cp -vf $mediainfo_sourcedir/$isoconf->{mediainfo}{filedeps} $builddir/$isoconf->{mediainfo}{mediainfo_dir}/file-deps") == 0 or die "$LOG copy of $mediainfo_sourcedir/$isoconf->{mediainfo}{filedeps} failed: $?\n";
+}
+
+sub copy_rpmsrate {
+ print_color("$LOG copy $mediainfo_sourcedir/$isoconf->{mediainfo}{rpmsrate} in $builddir/$isoconf->{mediainfo}{mediainfo_dir}", $color);
+ -f "$mediainfo_sourcedir/$isoconf->{mediainfo}{rpmsrate}" or print "$LOG missing rpmsrate\n";
+ system("cp -vf $mediainfo_sourcedir/$isoconf->{mediainfo}{rpmsrate} $builddir/$isoconf->{mediainfo}{mediainfo_dir}/rpmsrate") == 0 or die "$LOG copy of $mediainfo_sourcedir/$isoconf->{mediainfo}{rpmsrate} failed: $?\n";
+}
+
+sub copy_compssusers {
+ print_color("$LOG copy $mediainfo_sourcedir/$isoconf->{mediainfo}{compssusers} in $builddir/$isoconf->{mediainfo}{mediainfo_dir}", $color);
+ -f "$mediainfo_sourcedir/$isoconf->{mediainfo}{compssusers}" or print "$LOG missing compssusers\n";
+ system("cp -vf $mediainfo_sourcedir/$isoconf->{mediainfo}{compssusers} $builddir/$isoconf->{mediainfo}{mediainfo_dir}/compssUsers.pl") == 0 or die "$LOG copy of $mediainfo_sourcedir/$isoconf->{mediainfo}{compssusers} failed: $?\n";;
+}
+
+sub use_genhdlist2 {
+ my $destmedia;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if ($destmedia eq $media->{destmedia}) { next }
+ $destmedia = $media->{destmedia};
+ print_color("$LOG build hdlists and synthesys in $builddir/media/$media->{destmedia}", $color);
+ system("genhdlist2 -v --clean --file-deps $builddir/media/media_info/$isoconf->{medianfo}{filedeps} --media_info-dir $builddir/media/media_info/ $builddir/media/$media->{destmedia}");
+ system("mv $builddir/media/$destmedia/media_info/hdlist.cz $builddir/media/media_info/hdlist_$media->{name}.cz");
+ system("mv $builddir/media/$destmedia/media_info/synthesis.hdlist.cz $builddir/media/media_info/synthesis.hdlist_$media->{name}.cz");
+# system("genhdlist2 --quiet --clean --no-hdlist --file-deps $builddir/media/media_info/$isoconf->{medianfo}{filedeps} $builddir/media/$media->{destmedia}");
+ }
+ system("cd $builddir/media/media_info/ && md5sum *.cz > MD5SUM");
+}
+
+sub rpmcheck_launch {
+ my $options = "-explain -failures";
+ my $destmedia = "0";
+ print_color("$LOG launch rpmcheck to check hdlists", $color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{drop} =~ /yes/ and drop_media("$media->{name}-release");
+ if ($destmedia eq $media->{destmedia}) { next }
+ $destmedia = $media->{destmedia};
+ system("cp $builddir/media/$destmedia/media_info/hdlist.cz $builddir/media/media_info/hdlist_$media->{name}.cz");
+ }
+ my $cmd = "zcat $builddir/media/media_info/hdlist*.cz | rpmcheck $options";
+ print_color("$LOG $cmd", $color);
+ system("$cmd 2> /dev/null > $file_rpmcheck_log") == 0 or die "$LOG system $cmd failed: $?\n";
+ open my $LIST_FAILURE, ">$rpmcheck_list_pkg.tmp";
+ my @list_failure = cat_($file_rpmcheck_log);
+ foreach my $package (@list_failure) {
+ print "$package";
+ my ($package2) = $package =~ /^\s+(\S*)\s.*/;
+ $package2 and print $LIST_FAILURE "$package2\n";
+ }
+ close $LIST_FAILURE;
+ system("cat $rpmcheck_list_pkg.tmp | sort | uniq > $rpmcheck_list_pkg");
+ print_color("$LOG check this file $file_rpmcheck_log", $color);
+ print_color("$LOG check this file $rpmcheck_list_pkg", $color);
+}
+
+sub remove_hdlist {
+ my $destmedia;
+ if ($isoconf->{based_on} gt "2009.1") {
+ print_color("$LOG remove hdlists*.cz from $builddir/media/media_info", $color);
+ system("rm -vf $builddir/media/media_info/hdlist*.cz");
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if ($destmedia eq $media->{destmedia}) { next }
+ $destmedia = $media->{destmedia};
+ print_color("$LOG remove hdlists from $builddir/media/$destmedia/media_info", $color);
+ system("rm -vf $builddir/media/$destmedia/media_info/hdlist.cz");
+ system("cd $builddir/media/$destmedia/media_info ; md5sum *.cz > MD5SUM");
+ }
+ }
+}
+
+sub copy_all_pubkey {
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ if ($media->{pubkey} eq "") {
+ print_color("$LOG using $media->{file_pubkey}", $color);
+ copy_pubkey($media->{file_pubkey}, "$media->{destmedia}");
+ } else {
+ # media/ dir will be added in the copy_pubkey functions
+ print_color("$LOG $repo/$based_on/$arch/media/$media->{mediadir}/$media->{pubkey}, $media->{destmedia}", $color);
+ copy_pubkey("$repo/$based_on/$arch/media/$media->{mediadir}/$media->{pubkey}", "$media->{destmedia}");
+ }
+ next;
+ }
+}
+
+sub list_medias_available {
+ #my @mediacfg = cat_("$repo/$based_on/$arch/$isoconf->{mediainfo_dir}/media.cfg");
+ print_color("$LOG list all medias availables in $repo/$based_on/$arch repositery", $color);
+ my @mediacfg = cat_("$repo/$based_on/$arch/media/media_info/media.cfg");
+ my @medias = grep {/^name=/} @mediacfg;
+ foreach my $media (@medias) {
+ $media =~ s/name\=//;
+ $media and print("$media");
+ }
+}
+
+sub check_repo_hdlist {
+ my $options = "-explain -failures";
+ print_color("$LOG check media repositery hdlists in $repo/$version/$arch", $color);
+ system("zcat $repo/$version/$arch/media/media_info/hdlist*ain.cz | rpmcheck $options");
+}
+
+sub umount_all_mountloop {
+ print "$LOG umount all mounted loop dir\n";
+ foreach (@to_umount) {
+ system("sudo umount $chroot_path/$_");
+ }
+}
+
+sub get_srpms_list {
+ my $pm = new Parallel::ForkManager(20);
+ my $pkg_name; my @srpms; my @checked; my $already_done;
+ my $tmp_bs = "/tmp/list_BS-$isoconf->{nameid}-$version-$isoconf->{arch}";
+ system("mkdir $tmp_bs");
+ system("rm -f $tmp_bs/*");
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{destmedia} or next;
+ foreach (@checked) { $_ or next ; $media->{destmedia} =~ /^$_$/ and $already_done = 1; };
+ $already_done and next;
+ push @checked, $media->{destmedia};
+ my @list_pkg = glob("$builddir/media/$media->{destmedia}/*.rpm");
+ my $list_srpm = "$tmp_bs/list_SRPM-$isoconf->{nameid}-$version-$isoconf->{arch}-$media->{name}-$media->{destmedia}";
+ my $list_buildreq = "$tmp_bs/list_BUILDREQ-$isoconf->{nameid}-$version-$isoconf->{arch}-$media->{name}-$media->{destmedia}";
+ my $total = @list_pkg;
+ my $status = "0";
+ print_color("$LOG i have to find $total SRPMS name in the media media/$media->{destmedia} ... be patient !!!!", $color);
+ foreach my $pkg (@list_pkg) {
+ $status++;
+ my $pid = $pm->start and next;
+ $pkg_name = `rpm -qp --queryformat %{SOURCERPM} $pkg`;
+ # tostore somewhere
+ # $media->{name} $pkg_name
+ system("sudo chroot $chroot_path echo '$pkg_name' > $list_srpm-$pkg_name");
+ back_and_print($status, $total);
+ $pm->finish;
+ $pm->wait_all_children;
+ }
+ system("cat $tmp_bs/list_SRPM-* | sort | uniq > $list_srpm");
+ my @list_srpm = cat_($list_srpm);
+ $total = @list_srpm;
+ $status = "0";
+ print_color("$LOG get the buildrequires from SRPMS", $color);
+ foreach my $srpm (@list_srpm) {
+ $srpm or next;
+ $status++;
+ chomp($srpm);
+ my $pid = $pm->start and next;
+ my $pkg = `basename $srpm .src.rpm`;
+ my $SRPMS_PATH;
+ # find the package in an official sub dir
+ my @struct = qw(release updates backport testing);
+ back_and_print($status, $total);
+ my @data; my $q;
+ foreach (@struct) {
+ #print "$repo/$based_on/SRPMS/$media->{mediadir}/$_/$srpm";
+ if (-f "$repo/$based_on/SRPMS/$media->{mediadir}/$_/$srpm") {
+ $SRPMS_PATH="$repo/$based_on/SRPMS/$media->{mediadir}/$_/";
+ my $media="--sortmedia \"Main Updates,Main,Contrib Updates,Contrib\"";
+ system("LC_ALL=C urpmq --use-distrib $repo/$based_on/$arch $media --sources --requires-recursive --prefer $DISTRIB,$THEME,kernel-source-dekstop --no-suggests $SRPMS_PATH/$srpm > $list_buildreq-$srpm");
+ last;
+ } else {
+ #print "$repo/$based_on/SRPMS/$media->{mediadir}/$_/$srpm doesnt exist \n";
+ next;
+ }
+ }
+ $pm->finish;
+ $pm->wait_all_children;
+ }
+ system("cat $tmp_bs/list_BUILDREQ-* | sort | uniq > $list_buildreq");
+ system("cp $list_buildreq $chroot_path/list_ALL_BUILDREQ");
+ system("cp $list_srpm $chroot_path/list_ALL_SRPM");
+# system("rm -f $tmp_bs/list_BUILDREQ-* $tmp_bs/list_SRPM-*");
+ }
+}
+
+
+sub extra_filter {
+ my ($filter) = @_;
+ print_color("$LOG compare versions of $filter and keep the latest one", $color);
+ my @l; my $keeped;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{destmedia} or next;
+ @l = glob("$builddir/media/$media->{destmedia}/$filter-*.rpm");
+ my $l = @l; $l eq "0" and last;
+ foreach (@l) {
+ my $pkg = basename($_);
+ # check it will be a number after the filter name
+ $pkg =~ /$filter\-\d.*/ or next;
+ $keeped or $keeped = $pkg;
+ $pkg ne $keeped and print "$LOG COMPARE $pkg and $keeped:\n" or next;
+ my $r = rpmVersionCompare($pkg, $keeped);
+ if ($r eq "-1") {
+ $keeped = $keeped;
+ print "i will keep $keeped\n";
+ system("rm -vf $builddir/media/$media->{destmedia}/$pkg");
+ next;
+ } elsif ($r eq "1") {
+ system("rm -vf $builddir/media/$media->{destmedia}/$keeped");
+ $keeped = $pkg;
+ print "i will keep $keeped\n";
+ next;
+ };
+ }
+ }
+}
+
+sub solve_doble_issue {
+ my $pkg_name; my $pkg_version;
+ my @list_to_filter; my @todeal;
+ my %already_seen; my @final_list;
+ my $keeped;
+ # 50 should not cause any trouble... NB_FORK is too small...
+ my $pm = new Parallel::ForkManager(50);
+ my @checked; my $already_done;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{destmedia} or next;
+ foreach (@checked) { $_ or next; $_ =~ /^\#/ and next ; $media->{destmedia} =~ /^$_$/ and $already_done = 1; };
+ $already_done and next;
+ push @checked, $media->{destmedia};
+ # get all rpm from the media dir
+ my @list_pkg = glob("$builddir/media/$media->{destmedia}/*.rpm");
+ my $total = @list_pkg;
+ my $status = "0";
+ print_color("$LOG i have to check $total doble in the media media/$media->{destmedia} ... be patient !!!!", $color);
+ # parse all files in the media
+ foreach my $pkg (@list_pkg) {
+ $status++;
+ # get the rpm name
+ my $pid = $pm->start and next;
+ $pkg_name = `rpm -qp --queryformat %{name} $pkg`;
+ my @l = glob("$builddir/media/$media->{destmedia}/$pkg_name*.rpm");
+ my $l = @l; $l eq "0" and last;
+ foreach (@l) {
+ #print_color("$LOG compare versions of $filter and keep the latest one", $color);
+ $_ or next; my $found = 0;
+ my $pkg = basename($_);
+ foreach (cat_($isoconf->{mediainfo}{filter})) {
+ if ($_ =~ /^$pkg_name/) { print "- skipping $_\n (from $isoconf->{mediainfo}{filter} file)" and $found = 1; }
+ }
+ if ($_ =~ /kernel/) { print "- $pkg_name is a package relative to a kernel ! will be treated later\n"; }
+ $found eq "1" and next;
+ $pkg =~ /^$pkg_name\-\d.*/ or next;
+ # bypass special case like libwnck-1_22
+ $pkg =~ /^$pkg_name\-\d\_.*/ and print "- $pkg comparaison skipped... (bcd regexp)\n" and next;
+ # check it will be a number after the filter name
+ $keeped or $keeped = $pkg;
+ #print "$LOG COMPARE $pkg and $keeped: \n";
+ my $r = rpmVersionCompare($pkg, $keeped);
+ if ($r eq "-1") {
+ $keeped = $keeped;
+ $verbose and print "i will keep $keeped and erase $builddir/media/$media->{destmedia}/$pkg\n";
+ system("rm -f $builddir/media/$media->{destmedia}/$pkg");
+ push @list_of_removed, "$builddir/media/$media->{destmedia}/$pkg";
+ } elsif ($r eq "1") {
+ system("rm -f $builddir/media/$media->{destmedia}/$keeped");
+ $keeped = $pkg;
+ $verbose and print "i will keep $keeped and remove $builddir/media/$media->{destmedia}/$keeped\n";
+ push @list_of_removed, "$builddir/media/$media->{destmedia}/$keeped";
+ };
+ }
+ back_and_print($status, $total);
+ $pm->finish;
+ print_color("$LOG Waiting for the end of some system command...", $color);
+ $pm->wait_all_children;
+ }
+ }
+}
+
+sub find_all_kernel {
+ print_color("$LOG kernel comparaison", $color);
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ $media->{destmedia} or next;
+ my @l = glob("$builddir/media/$media->{destmedia}/kernel-*.rpm");
+ my $l = @l; $l eq "0" and last;
+ foreach my $k (@l) {
+ my ($kname, $kversion) = $k =~ m/kernel-([\w]+(?:\-[\w]+){0,3})-([0-9]+(?:\.[0-9]+){2,3})/;
+ $kname or next;
+ #print_color("$LOG i will compare all versions of kernel-$kname and keep the latest one", $color);
+ extra_filter("kernel-$kname");
+ next;
+ }
+ }
+}
+
+sub process_list_link {
+ my ($option) = @_;
+ concatenate_files;
+ # link or copy
+ if ($option =~ /copy/) {
+ parse_copy_link("copy");
+ } else {
+ parse_copy_link("link");
+ }
+ # remove packages listed in exclude list
+ remove_all_excluded;
+ if ($option =~ /nodoble/) { print_color("$LOG skipping doble\n", $color); } else { solve_doble_issue; }
+ find_all_kernel;
+ use_gendistrib;
+## use_genhdlist2;
+}
+
+sub clean_urpmq_log {
+ my ($option) = @_;
+ if ($option =~ /clean/) {
+ print_color("$LOG i will remove all previous urpmq log", $color);
+ system("rm -rf $dir_deps");
+ }
+}
+
+sub main_media {
+ my ($option) = @_;
+ if ($option =~ /verbose/) { $verbose = "1"; }
+ list_media;
+ create_media;
+ copy_all_pubkey;
+
+ create_mediacfg;
+
+ copy_filedeps;
+ copy_rpmsrate;
+ copy_compssusers;
+
+ create_needed_dir($chroot_path);
+ print_color("$LOG erase previous bypasss file", $color);
+ system("rm -f $dir_deps/bypass-*");
+ generate_list_of_rpm_2_copy;
+ process_list_link($option);
+ # target_size;
+ # first rpmcheck launch
+ rpmcheck_launch;
+ rpmcheck_list;
+ process_list_link($option);
+ # second laucn of rpmcheck (should have fix a lot of missing deps)
+ rpmcheck_launch;
+ umount_all_mountloop;
+ remove_hdlist;
+ show_size;
+ my $l = @list_of_removed;
+ if ($l ne "0") {
+ print_color("$LOG List of package removed, if you dont want to remove them, just add them in the file $isoconf->{mediainfo}{filter}:", $color);
+ foreach (@list_of_removed) { print "$_\n"; }
+ }
+}
+
+1;
+
diff --git a/BCD/Resign.pm b/BCD/Resign.pm
new file mode 100644
index 0000000..b6cc001
--- /dev/null
+++ b/BCD/Resign.pm
@@ -0,0 +1,63 @@
+package BCD::Resign;
+
+use strict;
+use Parallel::ForkManager;
+use File::Glob ':glob';
+use File::Basename;
+use Expect;
+
+use BCD::Common qw(:DEFAULT $isoconf $NB_FORK $rpmrc $pwd_file $builddir);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(resign_media);
+
+my $verbose;
+my $LOG="MEDIA -";
+my $color = "yellow";
+
+my $password;
+if (defined $pwd_file) {
+ -f $pwd_file and $password = `cat $pwd_file`;
+}
+
+sub print_info {
+ map { if (!-f $pwd_file) { print_color("$LOG I cant find $_ file, i cant sign packages...", $color); } } $rpmrc, $pwd_file;
+ print_color("$LOG i will resign using info in those files: $rpmrc $pwd_file", $color);
+}
+
+sub resign_media {
+ print_info();
+ my $pm = new Parallel::ForkManager($NB_FORK);
+ my @list_path; my @checked; my $already_done;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ foreach (@checked) { $_ or next ; $media->{destmedia} =~ /^$_$/ and $already_done = 1; };
+ $already_done and next;
+ push @checked, $media->{destmedia};
+ push @list_path, $media->{destmedia};
+ print_color("$LOG resigning packages from $media->{destmedia} media", $color);
+ }
+ foreach (@list_path) {
+ my @list_pkg = glob("$builddir/media/$_/*.rpm");
+ my $count = @list_pkg;
+ print_color("$count transactions to do ... be patient !!!!", $color);
+ my $status = "0";
+ foreach my $pkg (@list_pkg) {
+ $pkg or next;
+ my $basename_pkg = basename($pkg);
+ $status++;
+ my $pid = $pm->start and next;
+ print("$basename_pkg ($status/$count)\n");
+ my $command = Expect->spawn("LC_ALL=C rpm --rcfile=$rpmrc --resign $pkg") or die "Couldn't start rpm: $!\n";
+ $command->log_stdout($verbose);
+ $command->expect(20, -re, 'Enter pass phrase:' => sub { print $command $password; });
+ $command->expect(undef);
+ $command->soft_close();
+ $pm->finish;
+ }
+ print_color("Waiting for the end of some signature...", $color);
+ $pm->wait_all_children;
+ print_color("all signature are done...", $color);
+ }
+}
+
+1;
diff --git a/BCD/Stagex.pm b/BCD/Stagex.pm
new file mode 100644
index 0000000..ed9bd2d
--- /dev/null
+++ b/BCD/Stagex.pm
@@ -0,0 +1,88 @@
+package BCD::Stagex;
+
+
+use strict;
+use XML::Simple;
+use File::Copy::Recursive qw(dircopy pathrm);
+use BCD::Common qw(:DEFAULT $isoconf $wd $name $arch $based_on $repo $version $builddir $error_color);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(main_stagex);
+
+my $LOG="STAGEX -";
+my $color = "blue";
+my $installer_destdir = "$builddir/$isoconf->{installer}{defaultpath}";
+
+sub update_stage {
+-d $repo or print_color("$LOG $repo does not exists !", $color) and exit;
+
+my $installer_dir;
+if (!defined($isoconf->{installer}{fullpath})) {
+ $installer_dir = "$repo/$based_on/$arch/$isoconf->{installer}{defaultpath}";
+} else {
+ $installer_dir = "$isoconf->{installer}{fullpath}/install";
+}
+-d $installer_dir or print_color("$LOG $installer_dir does not exists !", $error_color) and exit;
+
+
+# print "$LOG remove old copy $builddir\n";
+# pathrm($builddir) or die $!;
+ print_color("$LOG copy $installer_dir to $installer_destdir", $color);
+ dircopy($installer_dir, $installer_destdir) or die $!;
+}
+
+sub update_advertising {
+if (defined($isoconf->{installer}{advertising}{fullpath})) {
+ print_color("$LOG copy $isoconf->{installer}{advertising}{fullpath} to $installer_destdir/extra/", $color);
+ system("rm -rf $installer_destdir/extra/advertising");
+ system("cp -a $isoconf->{installer}{advertising}{fullpath} $installer_destdir/extra/");
+ }
+}
+
+sub copy_dosutils {
+ print_color("$LOG copy of dosutils directory from $repo/$based_on/$arch to $builddir/../", $color);
+ if (-d "$repo/$based_on/$arch/dosutils") {
+ system("cp -a $repo/$based_on/$arch/dosutils $builddir/../");
+ system("cp -a $repo/$based_on/$arch/autorun.inf $builddir/../");
+ } else {
+ print_color("$LOG FAILED copy of dosutils directory from $repo/$based_on/$arch", $error_color);
+ }
+}
+
+sub copy_doc {
+ print_color("$LOG copy of doc directory from $repo/$based_on/$arch to $builddir/", $color);
+ if (-d "$repo/$based_on/$arch/doc") {
+ system("cp -a $repo/$based_on/$arch/doc $builddir/");
+ } else {
+ print_color("$LOG FAILED copy of doc directory from $repo/$based_on/$arch", $error_color);
+ }
+}
+
+sub copy_misc {
+ print_color("$LOG copy of misc directory from $repo/$based_on/$arch to $builddir/../", $color);
+ if (-d "$repo/$based_on/$arch/misc") {
+ system("rm -rf $builddir/misc && mkdir $builddir/misc");
+ system("cp -a $repo/$based_on/$arch/misc/drakx-in-chroot $builddir/misc/");
+ system("cp -a $repo/$based_on/$arch/misc/mdkinst_stage2_tooldosutils $builddir/misc/");
+ } else {
+ print_color("$LOG FAILED copy of misc directory from $repo/$based_on/$arch", $error_color);
+ }
+}
+
+sub patch_oem {
+ if (-f $isoconf->{installer}{patch}) {
+ print_color("$LOG copy $isoconf->{installer}{patch} to $installer_destdir/", $color);
+ system("cp -a $isoconf->{installer}{patch} $installer_destdir/");
+ }
+}
+
+sub main_stagex {
+ update_stage;
+ update_advertising;
+ copy_dosutils;
+ copy_doc;
+ copy_misc;
+ patch_oem;
+}
+
+1;
diff --git a/BCD/Web.pm b/BCD/Web.pm
new file mode 100644
index 0000000..235e375
--- /dev/null
+++ b/BCD/Web.pm
@@ -0,0 +1,222 @@
+package BCD::Web;
+
+use strict;
+use BCD::Media qw($rpmcheck_list_pkg $file_rpmcheck_log);
+use BCD::Genisoimage qw($isoname);
+use URPM;
+use File::Slurp;
+use MDK::Common;
+
+use BCD::Common qw(:DEFAULT $isoconf $isodir $wd $arch $version $based_on $repo $THEME $name $conf_file $date);
+
+our @ISA = qw(Exporter);
+our @EXPORT = qw(main_html);
+
+my $verbose;
+my $LOG="MEDIA -";
+my $color = "pink";
+
+my $index = $isoconf->{nameid} . '-' . $isoconf->{mediainfo}{version} . '-' . $isoconf->{arch} . ".html";
+my $public_html = "~/public_html";
+my $webdir = "$public_html/$isoname-$date";
+
+map { !-d "$webdir/$_" and system("mkdir -p $webdir/$_"); } qw(log rpmcheck input iso);
+
+sub main_html {
+ #next_build_info;
+ show_general_info();
+ copy_conf();
+ link_input();
+ prep_build_log();
+ show_rpmcheck();
+ rename_iso();
+ link_urpmq_log();
+ clean_previous_iso();
+ link_iso();
+ open my $B, ">>$index";
+ print $B "</html>";
+ close $B;
+ system("mv $index $webdir/");
+ system("ln -sf $webdir/$index $webdir/index.html");
+}
+
+sub show_general_info {
+ my $date_repo;
+ if (-f "$repo/$based_on/$arch/VERSION") {
+ $date_repo = read_file("$repo/$based_on/$arch/VERSION");
+ } else { $date_repo = "UNKNOW date"; print "You should check that a VERSION file is present"; }
+ open my $B, ">$index";
+ print $B "<HTML>
+ <HEAD>
+ <STYLE TYPE='text/css'>
+a:link {
+ color: #0073c7;
+ background-color: inherit;
+}
+
+a:visited {
+ color: #5A88B5;
+ background-color: inherit;
+}
+
+a:hover,
+a:active {
+ color: #0073c7;
+ background-color: #f0f0f0;
+}
+h2 {
+ padding: 0.2em;
+ margin: 0 0 0.5em 0;
+ border: 1px solid #405871;
+ background-color: inherit;
+ color: #036;
+ text-decoration: none;
+ font-size: 22px;
+ font-weight: bold;
+}
+
+h1 {
+ padding: 0.2em 0 0.2em 0.7em;
+ margin: 10px 0 0.5em 0;
+ text-decoration: none;
+ font-size: 18px;
+ font-weight: bold;
+ background: #FF7700;
+ color: white;
+}
+h3 {
+ background-color: inherit;
+ color: #ff7700;
+ text-decoration: none;
+ font-weight: bold;
+ font-size: 16px;
+ margin: 1.3em 0 0.4em 0;
+ padding: 0;
+}
+
+ </STYLE>
+ </HEAD>
+ <TITLE>$isoname</TITLE>
+ <h1 name='main h1'>$isoname build at $date</h1>
+ <BODY>
+ ";
+ print $B "<ul>\n";
+ print $B "<li>Date of the synchronisation to the cooker repository: <b>$date_repo</b></li>\n";
+ print $B "<li>Configuration file used: <a href='$conf_file'>$conf_file</a></li>\n";
+ print $B "<li>Architecture: <b>$arch</b></li>\n";
+ print $B "<li>Distribution based on: <b>$based_on</b></li>\n";
+ print $B "<li>Version: <b>$version</b></li>\n";
+ print $B "<li>Theme used: <b>$THEME</b></li>\n";
+ print $B "</ul>\n";
+ close $B;
+}
+
+sub copy_conf {
+ system("cp $conf_file $webdir/");
+}
+
+
+sub link_input {
+ open my $B, ">>$index";
+ print $B "<hr>\n";
+ print $B "<h1 name='Media list'>Media list</h1>\n";
+ close $B;
+ foreach my $media (@{$isoconf->{media}{list}}) {
+ $media->{name} or next;
+ open my $B, ">>$index";
+ print $B "<h2 name='Media $media->{name}'>Media $media->{name}</h1>";
+ print $B "<pre>
+Name of the media: $media->{name}
+Description: $media->{desc}
+From wich dir: $media->{mediadir}
+destination dir: $media->{destmedia}
+Pubkey: $media->{pubkey}
+</pre>
+";
+ print $B "<h3 name='list of input file'>list of input file</h3>\n";
+ print $B "<ul>\n";
+ foreach my $files (@{$media->{input}}) {
+ $files->{file} or next;
+ if (-f $files->{file}) {
+ my $short_name = basename($files->{file});
+ print $B "<li><a href='input/$short_name'>$short_name</a></li>\n";
+ system("cp -af $files->{file} $webdir/input/");
+ } else { print $B "<li><b>$files->{file} not present</b></li>"; }
+
+ }
+ print $B "</ul>\n";
+ print $B "<h3 name='list of exclude file'>list of exclude file</h3>\n";
+ print $B "<ul>\n";
+ foreach my $files (@{$media->{exclude}}) {
+ $files->{file} or next;
+ if (-f $files->{file}) {
+ my $short_name = basename($files->{file});
+ print $B "<li><a href='input/$short_name'>$short_name</a></li>\n";
+ system("cp -af $files->{file} $webdir/input/");
+ } else { print $B "</li><b>$files->{file} not present</b></li>"; }
+ }
+ print $B "</ul>\n";
+ close $B;
+ }
+}
+
+sub prep_build_log {
+ system("cp -af /var/lib/bcd/$name-$version-$arch/* $webdir/log/");
+}
+
+sub show_rpmcheck {
+ my $size;
+ system("cp -af $rpmcheck_list_pkg $file_rpmcheck_log $webdir/rpmcheck/");
+ open my $B, ">>$index";
+ print $B "<h1 name='RPMCHECK status'>RPMCHECK Status</h1>\n";
+ my @files = glob("$webdir/rpmcheck/*");
+ foreach (@files) {
+ $size = (stat($_))[7];
+ print $size;
+ if ($size ne 0) {
+ print $B "<fond color=red><b>ERROR in RPMCHECK !</b></font>\n";
+ }
+ }
+ print $B "<a href=rpmcheck/>rpmcheck directory</a> (rpmcheck --explain --failures)\n";
+ close $B;
+}
+
+sub clean_previous_iso {
+ system("find $public_html/$isoname* -name \.iso -exec rm -vf {} \;");
+}
+
+sub rename_iso {
+ #-f "$isodir/$isoname.iso" and system("cp -f $isodir/$isoname.iso $webdir/iso/$isoname-$date.iso");
+ -f "$isodir/$isoname.idx" and system("cp -f $isodir/$isoname.idx $webdir/iso/$isoname-$date.idx");
+ -f "$isodir/$isoname.iso.md5" and system("cp -f $isodir/$isoname.iso.md5 $webdir/iso/$isoname-$date.iso.md5");
+ -f "$isodir/$isoname.iso.sha1" and system("cp -f $isodir/$isoname.iso.sha1 $webdir/iso/$isoname-$date.iso.sha1");
+
+}
+
+sub link_urpmq_log {
+ open my $B, ">>$index";
+ print $B "<hr>\n";
+ print $B "<h1 name='Link to URPMQ logs'>Link to URPMQ logs</h1>\n";
+ print $B "<a href=log/>All log of URPMQ command per package/media</a> (based on: urpmq --requires-recursive -c --sources)\n";
+ close $B;
+}
+
+sub link_iso {
+ open my $B, ">>$index";
+ print $B "<hr>\n";
+ print $B "<h1 name='Link to ISO, IDX, SHA1 and MD5'>Link to ISO, IDX, SHA1 and MD5</h1>\n";
+ print $B "<ul>\n";
+ if (-f "$webdir/iso/$isoname-$date.iso") {
+ print $B "<li><a href=iso/$isoname-$date.iso>$isoname-$date.iso</a></li>\n";
+ print $B "<li><a href=iso/$isoname-$date.iso.md5>$isoname-$date.iso.md5</a></li>\n";
+ print $B "<li><a href=iso/$isoname-$date.iso.sha1>$isoname-$date.iso.sha1</a></li>\n";
+ } else {
+ print $B "<li><fond color=red><b>No ISO available</b></font></li>\n";
+ }
+ print $B "<li><a href=iso/$isoname-$date.idx>$isoname-$date.idx</a></li>\n";
+ print $B "</ul>\n";
+ close $B;
+}
+
+
+1;