source: ProjectBuilder/devel/pb/bin/pb@ 319

Last change on this file since 319 was 319, checked in by Bruno Cornec, 16 years ago

pb_cms_export ready to host the real stuff for file.

  • Property svn:executable set to *
File size: 33.9 KB
RevLine 
[5]1#!/usr/bin/perl -w
2#
3# Project Builder main application
4#
5# $Id$
6#
7# Copyright B. Cornec 2007
8# Provided under the GPL v2
9
[22]10# Syntax: see at end
[9]11
[18]12use strict 'vars';
[5]13use Getopt::Std;
[9]14use Data::Dumper;
15use English;
[16]16use File::Basename;
[26]17use File::Copy;
[13]18use Time::localtime qw(localtime);
19use POSIX qw(strftime);
[5]20
[73]21# Global variables
[17]22use lib qw (lib);
[74]23use ProjectBuilder::Distribution qw (pb_distro_init);
24use ProjectBuilder::Version qw (pb_version_init);
[318]25use ProjectBuilder::Base;
[5]26
27my %opts; # CLI Options
[9]28my $action; # action to realize
29my $test = "FALSE";
30my $option = "";
31my @pkgs;
[95]32my $pbtag; # Global Tag variable
33my $pbver; # Global Version variable
[141]34my $pbscript; # Name of the script
[77]35my %pbver; # per package
36my %pbtag; # per package
[53]37my $pbrev; # Global REVISION variable
[318]38my @date = pb_get_date();
[16]39my $pbdate = strftime("%Y-%m-%d", @date);
[152]40my $pbaccount; # Login to use to connect to the VM
[162]41my $pbport; # Port to use to connect to the VM
[199]42my $newver; # New version to create
[262]43my $iso; # ISO iage for the VM to create
[5]44
[262]45getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts);
[5]46
[75]47my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[21]48if (defined $opts{'h'}) {
[74]49 pb_syntax();
[21]50 exit(0);
51}
52if (defined $opts{'v'}) {
[318]53 $debug = 2;
54 #$debug = $opts{'v'};
55 pb_log(0,"Debug value: $debug\n");
[21]56}
57if (defined $opts{'q'}) {
58 $debug=-1;
59}
[22]60if (defined $opts{'l'}) {
61 open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
62 $LOG = *LOG;
63 $debug = 0 if ($debug == -1);
64 }
[315]65pb_log_init($debug, $LOG);
66
[9]67# Handles test option
68if (defined $opts{'t'}) {
69 $test = "TRUE";
70 # Works only for SVN
71 $option = "-r BASE";
72}
[5]73
[67]74# Handle root of the project if defined
75if (defined $opts{'r'}) {
76 $ENV{'PBROOT'} = $opts{'r'};
77}
[91]78# Handle virtual machines if any
79if (defined $opts{'m'}) {
80 $ENV{'PBVM'} = $opts{'m'};
81}
[141]82if (defined $opts{'s'}) {
83 $pbscript = $opts{'s'};
84}
[152]85if (defined $opts{'a'}) {
86 $pbaccount = $opts{'a'};
87}
[162]88if (defined $opts{'P'}) {
89 $pbport = $opts{'P'};
90}
[199]91if (defined $opts{'V'}) {
92 $newver = $opts{'V'};
93}
[262]94if (defined $opts{'i'}) {
95 $iso = $opts{'i'};
96}
[108]97
98# Get Action
99$action = shift @ARGV;
100die pb_syntax() if (not defined $action);
101
[314]102my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
[273]103my $pbinit = undef;
104$pbinit = 1 if ($action =~ /^newproj$/);
[108]105
[59]106# Handles project name if any
[108]107# And get global params
[59]108if (defined $opts{'p'}) {
[315]109 ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
[273]110 = pb_env_init($opts{'p'},$pbinit);
[59]111} else {
[315]112 ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
[273]113 = pb_env_init(undef,$pbinit);
[59]114}
115
[315]116pb_log(0,"Project: $ENV{'PBPROJ'}\n");
117pb_log(0,"Action: $action\n");
[9]118
[91]119# Keep those project values to store them at the end each time
[83]120my $pbprojtag = $ENV{'PBTAG'};
121my $pbprojver = $ENV{'PBVER'};
122
[9]123# Act depending on action
124if ($action =~ /^cms2build$/) {
[77]125 pb_cms2build();
126} elsif ($action =~ /^build2pkg$/) {
127 pb_build2pkg();
128} elsif ($action =~ /^cms2pkg$/) {
129 pb_cms2build();
130 pb_build2pkg();
[88]131} elsif ($action =~ /^build2ssh$/) {
132 pb_build2ssh();
[220]133} elsif ($action =~ /^cms2ssh$/) {
134 pb_cms2build();
135 pb_build2ssh();
[88]136} elsif ($action =~ /^pkg2ssh$/) {
137 pb_pkg2ssh();
[91]138} elsif ($action =~ /^build2vm$/) {
139 pb_build2vm();
140} elsif ($action =~ /^cms2vm$/) {
141 pb_cms2build();
142 pb_build2vm();
[141]143} elsif ($action =~ /^launchvm$/) {
[262]144 pb_launchvm($ENV{'PBVM'},0);
[142]145} elsif ($action =~ /^script2vm$/) {
146 pb_script2vm($pbscript);
[199]147} elsif ($action =~ /^newver$/) {
148 pb_newver();
[310]149} elsif ($action =~ /^newchroot$/) {
150 pb_launchchroot($ENV{'PBCHROOT'},1);
[262]151} elsif ($action =~ /^newvm$/) {
152 pb_launchvm($ENV{'PBVM'},1);
[273]153} elsif ($action =~ /^newproj$/) {
154 # Nothing to do - already done in pb_env_init
[106]155} elsif ($action =~ /^clean$/) {
[77]156} else {
[315]157 pb_log(0,"\'$action\' is not available\n");
[77]158 pb_syntax();
159}
160
161sub pb_cms2build {
162
[112]163 my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
[22]164 @pkgs = @$ptr;
[315]165 my ($scheme,$uri)=pb_cms_init($ENV{'PBPROJ'});
[9]166
[313]167 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
[174]168
169 # declare packager for filtering
170 my ($tmp) = pb_conf_get("packager");
171 my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
172
[27]173 foreach my $pbpkg (@pkgs) {
[115]174 $ENV{'PBPKG'} = $pbpkg;
[274]175 $ENV{'PBVER'} = $pbprojver;
176 $ENV{'PBTAG'} = $pbprojtag;
[98]177 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
178 $pbver = $pkgv->{$pbpkg};
[115]179 $ENV{'PBVER'} = $pbver;
[9]180 } else {
[16]181 $pbver = $ENV{'PBVER'};
[9]182 }
[98]183 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
184 $pbtag = $pkgt->{$pbpkg};
[115]185 $ENV{'PBTAG'} = $pbtag;
[9]186 } else {
[16]187 $pbtag = $ENV{'PBTAG'};
[9]188 }
[95]189
[16]190 $pbrev = $ENV{'PBREVISION'};
[319]191 pb_log(0,"\n");
192 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
[9]193 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
[16]194 # Clean up dest if necessary. The export will recreate it
[27]195 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
[74]196 pb_rm_rf($dest) if (-d $dest);
[9]197
198 # Export CMS tree for the concerned package to dest
199 # And generate some additional files
200 $OUTPUT_AUTOFLUSH=1;
[29]201
[9]202 # computes in which dir we have to work
[113]203 my $dir = $defpkgdir->{$pbpkg};
204 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
[315]205 pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
[9]206
[315]207 # If it isn't a flat CMS, then we have the choice to export subdir
[319]208 #$dir = "$uri/$dir" if ($ENV{'PBREVISION'} ne "flat");
209 pb_cms_export($uri,"$dir",$dest);
[315]210
[285]211 # Get project info on authors and log file
212 my $chglog = "$ENV{'PBCONF'}/$pbpkg/pbcl";
213 $chglog = "$ENV{'PBCONF'}/pbcl" if (! -f $chglog);
214 $chglog = undef if (! -f $chglog);
215
216 my $authors = "$ENV{'PBCONF'}/$pbpkg/pbauthors";
217 $authors = "$ENV{'PBCONF'}/pbauthors" if (! -f $authors);
218 $authors = "/dev/null" if (! -f $authors);
219
[9]220 # Extract cms log history and store it
[285]221 if ((defined $chglog) && (! -f "$dest/NEWS")) {
[315]222 pb_log(2,"Generating NEWS file from $chglog\n");
[285]223 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
224 }
[315]225 pb_cms_log($scheme,$dir,$dest,$chglog,$authors);
[29]226
[21]227 my %build;
[91]228
[315]229 my ($ptr) = pb_conf_get_if("vmlist","chrootlist");
[91]230 foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
[315]231 my ($name,$ver,$arch) = split(/-/,$d);
232 chomp($arch);
[99]233 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
[315]234 pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n");
235 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
[13]236
[16]237 # Filter build files from the less precise up to the most with overloading
[13]238 # Filter all files found, keeping the name, and generating in dest
[16]239
240 # Find all build files first relatively to PBROOT
[300]241 # Find also all specific files referenced in the .pb conf file
[315]242 my %bfiles = {};
243 my %pkgfiles = {};
244 pb_log(2,"DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n");
[21]245 $build{"$ddir-$dver"} = "yes";
[315]246
247 if (-d "$ENV{'PBROOT'}/$pbpkg/$dtype") {
248 pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$dtype",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
249 } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$dfam") {
250 pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
251 } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$ddir") {
252 pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
253 } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$ddir-$dver") {
254 pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
[13]255 } else {
[21]256 $build{"$ddir-$dver"} = "no";
[13]257 next;
258 }
[315]259 pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
[13]260
[15]261 # Get all filters to apply
[77]262 my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
[15]263
[19]264 # Apply now all the filters on all the files concerned
265 # destination dir depends on the type of file
266 if (defined $ptr) {
[300]267 foreach my $f (values %bfiles,values %pkgfiles) {
[297]268 pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$pbpackager,$chglog);
[16]269 }
[15]270 }
[18]271 }
[315]272 my @found;
273 my @notfound;
274 foreach my $b (keys %build) {
275 push @found,$b if ($build{$b} =~ /yes/);
276 push @notfound,$b if ($build{$b} =~ /no/);
[21]277 }
[315]278 pb_log(0,"Build files generated for ".join(',',@found)."\n");
279 pb_log(0,"No Build files found for ".join(',',@notfound)."\n") if (@notfound);
[236]280 # Get the generic filter (all.pbf) and
281 # apply those to the non-build files including those
282 # generated by pbinit if applicable
283
284 # Get only all.pbf filter
[237]285 $ptr = pb_get_filters($pbpkg);
[236]286
287 my $liste ="";
288 if (defined $filteredfiles->{$pbpkg}) {
289 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
[315]290 pb_filter_file_inplace($ptr,"$dest/$f",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
[238]291 $liste = "$f $liste";
[236]292 }
293 }
[315]294 pb_log(2,"Files ".$liste."have been filtered\n");
[236]295
[265]296 # Prepare the dest directory for archive
[315]297 if (-x "$ENV{'PBROOT'}/$pbpkg/pbinit") {
298 pb_filter_file("$ENV{'PBROOT'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
[266]299 chmod 0755,"$ENV{'PBTMP'}/pbinit";
[315]300 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOT'}/$pbpkg/pbinit");
[265]301 }
302
[18]303 # Archive dest dir
[69]304 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
[25]305 # Possibility to look at PBSRC to guess more the filename
[94]306 pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
[315]307 pb_log(2,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
[83]308
[314]309 # Keep track of what is generated by default
310 open(LAST,"> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
311 #print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n";
312 # Why not use pbproj ?
313 print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOT'}\n";
[83]314 close(LAST);
315
316 # Keep track of per package version
[314]317 my ($pkg) = pb_conf_read_if("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[83]318 $pkg = { } if (not defined $pkg);
[88]319 if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) {
320 $pkg->{$pbpkg} = "$pbver-$pbtag";
[83]321 }
322
[315]323 pb_log(2,"DEBUG pkg: ".Dumper($pkg)."\n");
[83]324 open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
[88]325 foreach my $p (keys %$pkg) {
326 print PKG "pbpkg $p = $pkg->{$p}\n";
[83]327 }
328 close(PKG);
[288]329
330 # Final cleanup
331 pb_rm_rf($dest) if (-d $dest);
[9]332 }
[77]333}
[22]334
[77]335sub pb_build2pkg {
336
[22]337 # Get list of packages to build
[112]338 my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
[22]339 @pkgs = @$ptr;
340
341 # Get the running distro to build on
[99]342 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
[315]343 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
[22]344
[83]345 # Get content saved in cms2build
[89]346 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[83]347 $pkg = { } if (not defined $pkg);
348
[174]349 # declare packager
350 my ($tmp) = pb_conf_get("packager");
351 my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
352
[25]353 chdir "$ENV{'PBBUILDDIR'}";
[126]354 my $made = ""; # pkgs made during build
[27]355 foreach my $pbpkg (@pkgs) {
[88]356 my $vertag = $pkg->{$pbpkg};
[77]357 # get the version of the current package - maybe different
358 ($pbver,$pbtag) = split(/-/,$vertag);
359
[27]360 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[315]361 pb_log(2,"Source file: $src\n");
[25]362
[315]363 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
[25]364 if ($dtype eq "rpm") {
365 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
[28]366 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
[96]367 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d") || die "Please ensure that you can write into $ENV{'PBBUILDDIR'} to create $d\nchown the $ENV{'PBBUILDDIR'} directory to your uid";
[28]368 }
[25]369 }
370
[315]371 # Remove in case a previous link/file was there
[301]372 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
[188]373 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
[25]374 # We need to first extract the spec file
[28]375 my @specfile;
[77]376 @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
[25]377
[315]378 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
[25]379 # set LANGUAGE to check for correct log messages
380 $ENV{'LANGUAGE'}="C";
[28]381 foreach my $f (@specfile) {
382 if ($f =~ /\.spec$/) {
[291]383 pb_system("rpmbuild --define \'packager $pbpackager\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
[28]384 last;
385 }
386 }
[136]387 $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
[149]388 if (-f "/usr/bin/rpmlint") {
389 pb_system("rpmlint $made","Checking validity of rpms with rpmlint");
[150]390 }
[118]391 } elsif ($dtype eq "deb") {
[149]392 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
[274]393 pb_system("tar xfz $src","Extracting sources");
[149]394
395 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[310]396 pb_rm_rf("debian");
[149]397 symlink "pbconf/$ddir-$dver","debian" || die "Unable to symlink to pbconf/$ddir-$dver";
[199]398 chmod 0755,"debian/rules";
[149]399 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
[136]400 $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
[315]401 if (-f "/usr/bin/lintian") {
402 pb_system("lintian $made","Checking validity of debs with lintian");
403 }
[87]404 } elsif ($dtype eq "ebuild") {
[149]405 my @ebuildfile;
406 # For gentoo we need to take pb as subsystem name
[295]407 # We put every apps here under sys-apps. hope it's correct
408 # We use pb's home dir in order o have a single OVERLAY line
409 my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
410 pb_mkdir_p($tmpd) if (! -d "$tmpd");
411 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
[149]412
[295]413 # We need to first extract the ebuild file
414 @ebuildfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$tmpd");
[149]415
416 # Prepare the build env for gentoo
417 my $found = 0;
[295]418 my $pbbd = $ENV{'HOME'};
[150]419 $pbbd =~ s|/|\\/|g;
[295]420 if (-r "/etc/make.conf") {
421 open(MAKE,"/etc/make.conf");
422 while (<MAKE>) {
423 $found = 1 if (/$pbbd\/portage/);
424 }
425 close(MAKE);
[149]426 }
427 if ($found == 0) {
[295]428 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
[149]429 }
[295]430 #$found = 0;
431 #if (-r "/etc/portage/package.keywords") {
432 #open(KEYW,"/etc/portage/package.keywords");
433 #while (<KEYW>) {
434 #$found = 1 if (/portage\/pb/);
435 #}
436 #close(KEYW);
437 #}
438 #if ($found == 0) {
439 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
440 #}
[149]441
442 # Build
443 foreach my $f (@ebuildfile) {
444 if ($f =~ /\.ebuild$/) {
[295]445 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
446 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package");
447 # Now move it where pb expects it
448 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
449 move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
[149]450 }
451 }
452
[295]453 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
[118]454 } elsif ($dtype eq "slackware") {
[136]455 $made="$made build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
[118]456 pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
[87]457 } else {
[118]458 die "Unknown dtype format $dtype";
[87]459 }
460 }
[118]461 # Keep track of what is generated so that we can get them back from VMs
[129]462 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[118]463 print KEEP "$made\n";
464 close(KEEP);
[87]465}
466
[88]467sub pb_build2ssh {
[90]468 pb_send2ssh("Sources");
469}
[87]470
[90]471sub pb_pkg2ssh {
472 pb_send2ssh("Packages");
473}
474
[108]475# By default deliver to the the public site hosting the
476# ftp structure (or whatever) or a VM
[90]477sub pb_send2ssh {
478
479 my $cmt = shift;
[118]480 my $vm = shift || undef;
[142]481 my $vmexist = shift || 0; # 0 is FALSE
[200]482 my $vmpid = shift || 0; # 0 is FALSE
[108]483 my $host = shift || "sshhost";
484 my $login = shift || "sshlogin";
485 my $dir = shift || "sshdir";
486 my $port = shift || "sshport";
[203]487 my $tmout = shift || "vmtmout";
[158]488 my $cmd = "";
[90]489
[87]490 # Get list of packages to build
[112]491 my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
[87]492 @pkgs = @$ptr;
493
[136]494 # Get the running distro to consider
[118]495 my ($odir,$over) = (undef, undef);
496 if (defined $vm) {
497 ($odir,$over) = split(/_/,$vm);
498 }
499 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
[315]500 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
[87]501
502 # Get content saved in cms2build
[89]503 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
[87]504 $pkg = { } if (not defined $pkg);
505
[118]506 my $src = "";
[87]507 chdir "$ENV{'PBBUILDDIR'}";
508 foreach my $pbpkg (@pkgs) {
[88]509 my $vertag = $pkg->{$pbpkg};
[87]510 # get the version of the current package - maybe different
511 ($pbver,$pbtag) = split(/-/,$vertag);
512
[118]513 if (($cmt eq "Sources") || ($cmt eq "VMs")) {
[158]514 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[166]515 if ($cmd eq "") {
516 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
517 } else {
518 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
519 }
[118]520 }
521 }
522 if ($cmt eq "VMs") {
[132]523 $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}";
[142]524 } elsif ($cmt eq "Script") {
525 $src="$src $ENV{'PBDESTDIR'}/pbscript";
[118]526 } elsif ($cmt eq "Packages") {
527 # Get package list from file made during build2pkg
[129]528 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[126]529 $src = <KEEP>;
[118]530 chomp($src);
531 close(KEEP);
532 if ($dtype eq "rpm") {
533 # Also make a pbscript to generate yum/urpmi bases
[108]534 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[118]535 } elsif ($dtype eq "deb") {
536 # Also make a pbscript to generate apt bases
537 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[90]538 }
[87]539 }
[132]540 # Remove potential leading spaces (cause pb with basename)
541 $src =~ s/^ *//;
[129]542 my $basesrc = "";
[131]543 foreach my $i (split(/ +/,$src)) {
544 $basesrc .= " ".basename($i);
[130]545 }
[118]546
[315]547 pb_log(2,"Sources handled ($cmt): $src\n");
[290]548 my ($sshhost,$sshlogin,$sshdir,$sshport,$vmtmout,$testver) = pb_conf_get($host,$login,$dir,$port,$tmout,"testver");
[88]549 my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
[152]550 # Overwrite account value if passed as parameter
551 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
[108]552 my $tdir;
[136]553 my $bdir;
[142]554 if (($cmt eq "Sources") || ($cmt eq "Script")) {
[108]555 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
556 } elsif ($cmt eq "VMs") {
[136]557 $tdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/delivery";
558 $bdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/build";
559 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
560 $bdir =~ s|\$ENV.+\}/||;
[90]561 } elsif ($cmt eq "Packages") {
[108]562 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
[309]563 if ((defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} eq "true")) {
[289]564 # This is a test pkg => target dir is under test
565 $tdir .= "/test";
[291]566 }
[90]567 } else {
568 return;
[22]569 }
[239]570 my $nport = $sshport->{$ENV{'PBPROJ'}};
571 $nport = "$pbport" if (defined $pbport);
572
[136]573 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
[132]574 $tdir =~ s|\$ENV.+\}/||;
575
[203]576 my $tm = $vmtmout->{$ENV{'PBPROJ'}};
[239]577 pb_system("ssh -q -p $nport $mac \"mkdir -p $tdir ; cd $tdir ; echo \'for i in $basesrc; do if [ -f \$i ]; then rm -f \$i; fi; done\ ; $cmd' | bash\"","Preparing $tdir on $mac");
578 pb_system("cd $ENV{'PBBUILDDIR'} ; scp -p -P $nport $src $mac:$tdir 2> /dev/null","$cmt delivery in $tdir on $mac");
579 pb_system("ssh -q -p $nport $mac \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $mac if needed");
[108]580 if ($cmt eq "VMs") {
[128]581 # Get back info on pkg produced, compute their name and get them from the VM
[239]582 pb_system("scp -p -P $nport $mac:$bdir/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $bdir on $mac");
[129]583 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[118]584 my $src = <KEEP>;
585 chomp($src);
586 close(KEEP);
[131]587 $src =~ s/^ *//;
[136]588 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
[139]589 # Change pgben to make the next send2ssh happy
[143]590 my $made = "";
[139]591 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
[136]592 foreach my $p (split(/ +/,$src)) {
[139]593 my $j = basename($p);
[239]594 pb_system("scp -p -P $nport $mac:\'$bdir/$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $bdir from $mac");
[144]595 $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
[136]596 }
[143]597 print KEEP "$made\n";
[139]598 close(KEEP);
[239]599 pb_system("ssh -q -p $nport $mac \"rm -rf $tdir $bdir\"","VM cleanup on $mac");
[288]600 pb_send2ssh("Packages","$odir"."_"."$over");
[142]601 if (! $vmexist) {
[239]602 pb_system("ssh -q -p $nport $mac \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $vm halt (pid $vmpid)");
[142]603 }
[141]604 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
[108]605 }
[9]606}
[16]607
[142]608sub pb_script2vm {
609 my $pbscript=shift;
[141]610
611 # Prepare the script to be executed on the VM
612 # in $ENV{'PBDESTDIR'}/pbscript
[142]613 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
614 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
615 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
616 }
[141]617
[142]618 my ($vm,$all) = pb_get_vm();
619
[141]620 foreach my $v (@$vm) {
[142]621 # Launch the VM
[262]622 my ($vmexist,$vmpid) = pb_launchvm($v,0);
[141]623
[274]624 # Skip that VM if it something went wrong
625 next if (($vmpid == 0) && ($vmexist ==0));
626
[142]627 # Gather all required files to send them to the VM
628 # and launch the build thourgh pbscript
[314]629 pb_send2ssh("Script","$v",$vmexist,$vmpid,"vmhost","vmlogin","$ENV{'PBDESTDIR'}/pbrc","vmport","vmtmout");
[169]630
[142]631 }
632}
633
[310]634sub pb_launchchroot {
635 # Virtual env.
636 my $ve = shift;
637 my $create = shift || 0; # By default do not create a chroot
638
639 #die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
640 #die "No VM defined, unable to launch" if (not defined $ve);
641
642 # Keep only the first chroot in case many were given
643 $ve =~ s/,.*//;
644
645 # Launch the chroot
646 my ($ptr,$veopt,$veport,$vepath,$vetmout,$vesize) = pb_conf_get("vetype","veopt","veport","vepath","vetmout","vesize");
647 my $vetype = $ptr->{$ENV{'PBPROJ'}};
648 if (not defined $ENV{'PBCHROOTOPT'}) {
649 $ENV{'PBCHROOTOPT'} = "";
650 }
651 if (defined $veopt->{$ENV{'PBPROJ'}}) {
652 $ENV{'PBVMOPT'} .= " $veopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $veopt->{$ENV{'PBPROJ'}}/);
653 }
654 my $nport = $veport->{$ENV{'PBPROJ'}};
655 $nport = "$pbport" if (defined $pbport);
656
657 my $cmd;
658 my $vecmd; # has to be used for pb_check_ps
659 my $vem; # has to be used for pb_check_ps
660 if ($vetype eq "qemu") {
661 my $arch = `uname -m`;
662 chomp($arch);
663 my $qemucmd32;
664 my $qemucmd64;
665 if ($arch eq "x86_64") {
666 $qemucmd32 = "/usr/bin/qemu-system-i386";
667 $qemucmd64 = "/usr/bin/qemu";
668 } else {
669 $qemucmd32 = "/usr/bin/qemu";
670 $qemucmd64 = "/usr/bin/qemu-system-x86_64";
671 }
672 if ($ve =~ /_64/) {
673 $vecmd = "$qemucmd64 -no-kqemu";
674 } else {
675 $vecmd = "$qemucmd32";
676 }
677 $vem = "$vepath->{$ENV{'PBPROJ'}}/$ve.qemu";
678 if ($create != 0) {
679 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
680 }
681 $cmd = "$vecmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vem"
682 } elsif ($vetype eq "xen") {
683 } elsif ($vetype eq "vmware") {
684 } else {
685 die "VM of type $vetype not supported. Report to the dev team";
686 }
687 my ($tmpcmd,$void) = split(/ +/,$cmd);
688 my $veexist = pb_check_ps($tmpcmd,$vem);
689 my $vepid = 0;
690 if (! $veexist) {
691 if ($create != 0) {
692 pb_system("/usr/bin/qemu-img create -f qcow2 $vem $vesize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
693 }
694 if (! -f "$vem") {
[315]695 pb_log(0,"Unable to find VM $vem\n");
[310]696 } else {
697 pb_system("$cmd &","Launching the VM $vem");
698 pb_system("sleep $vetmout->{$ENV{'PBPROJ'}}","Waiting for VM $ve to come up");
699 $vepid = pb_check_ps($tmpcmd,$vem);
700 }
701 } else {
[315]702 pb_log(0,"Found an existing VM $vem (pid $veexist)\n");
[310]703 }
704 return($veexist,$vepid);
705}
706
[142]707sub pb_launchvm {
708 my $vm = shift;
[262]709 my $create = shift || 0; # By default do not create a VM
[142]710
[262]711 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
[142]712 die "No VM defined, unable to launch" if (not defined $vm);
713 # Keep only the first VM in case many were given
714 $vm =~ s/,.*//;
715
716 # Launch the VMs
[262]717 my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
[142]718 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
[262]719 if (not defined $ENV{'PBVMOPT'}) {
[142]720 $ENV{'PBVMOPT'} = "";
721 }
[262]722 if (defined $vmopt->{$ENV{'PBPROJ'}}) {
[296]723 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
[262]724 }
[239]725 my $nport = $vmport->{$ENV{'PBPROJ'}};
726 $nport = "$pbport" if (defined $pbport);
[142]727
728 my $cmd;
729 my $vmcmd; # has to be used for pb_check_ps
730 my $vmm; # has to be used for pb_check_ps
731 if ($vmtype eq "qemu") {
732 my $arch = `uname -m`;
733 chomp($arch);
734 my $qemucmd32;
735 my $qemucmd64;
736 if ($arch eq "x86_64") {
737 $qemucmd32 = "/usr/bin/qemu-system-i386";
738 $qemucmd64 = "/usr/bin/qemu";
[141]739 } else {
[142]740 $qemucmd32 = "/usr/bin/qemu";
741 $qemucmd64 = "/usr/bin/qemu-system-x86_64";
[141]742 }
[142]743 if ($vm =~ /_64/) {
744 $vmcmd = "$qemucmd64 -no-kqemu";
745 } else {
746 $vmcmd = "$qemucmd32";
747 }
748 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$vm.qemu";
[262]749 if ($create != 0) {
750 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
[142]751 }
[239]752 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
[142]753 } elsif ($vmtype eq "xen") {
754 } elsif ($vmtype eq "vmware") {
755 } else {
756 die "VM of type $vmtype not supported. Report to the dev team";
757 }
[199]758 my ($tmpcmd,$void) = split(/ +/,$cmd);
759 my $vmexist = pb_check_ps($tmpcmd,$vmm);
[200]760 my $vmpid = 0;
[142]761 if (! $vmexist) {
[262]762 if ($create != 0) {
[310]763 if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
764 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
765 } elsif ($vmtype eq "vmware") {
766 } else {
767 }
[262]768 }
769 if (! -f "$vmm") {
[315]770 pb_log(0,"Unable to find VM $vmm\n");
[274]771 } else {
772 pb_system("$cmd &","Launching the VM $vmm");
773 pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $vm to come up");
774 $vmpid = pb_check_ps($tmpcmd,$vmm);
[262]775 }
[200]776 } else {
[315]777 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
[141]778 }
[200]779 return($vmexist,$vmpid);
[141]780}
[142]781
[105]782sub pb_build2vm {
[108]783 # Prepare the script to be executed on the VM
784 # in $ENV{'PBDESTDIR'}/pbscript
[220]785 my ($ntp) = pb_conf_get("vmntp");
786 my $vmntp = $ntp->{$ENV{'PBPROJ'}};
[118]787 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
788 print SCRIPT "#!/bin/bash\n";
[126]789 print SCRIPT "echo ... Execution needed\n";
[132]790 print SCRIPT "# This is in directory delivery\n";
[118]791 print SCRIPT "# Setup the variables required for building\n";
792 print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
[132]793 print SCRIPT "# Preparation for pb\n";
794 print SCRIPT "mkdir -p ../pbconf\n";
795 print SCRIPT "mv $ENV{'PBPROJ'}.pb ../pbconf\n";
796 print SCRIPT "mv .pbrc \$HOME\n";
797 print SCRIPT "cd ..\n";
[268]798 # Force new date to be in the future compared to the date of the tar file by adding 1 minute
[226]799 my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
[268]800 $date[1]++;
[220]801 my $upddate = strftime("%m%d%H%M%Y", @date);
802 print SCRIPT "echo Setting up date on $vmntp...\n";
[268]803 # Or use ntpdate if available
[220]804 print SCRIPT "sudo date $upddate\n";
[118]805 print SCRIPT "export PBROOT=\`pwd\`\n";
806 print SCRIPT "# Build\n";
[127]807 my $p = "";
[272]808 $p = join(' ',@ARGV) if (defined $ARGV[0]);
[132]809 print SCRIPT "echo Building packages on VM...\n";
[166]810 print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
[118]811 close(SCRIPT);
812 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
813
[142]814 my ($vm,$all) = pb_get_vm();
815
[106]816 # Send tar files when we do a global generation
817 pb_build2ssh() if ($all == 1);
[118]818
819 foreach my $v (@$vm) {
[142]820 # Launch the VM
[262]821 my ($vmexist,$vmpid) = pb_launchvm($v,0);
[118]822
[274]823 # Skip that VM if it something went wrong
824 next if (($vmpid == 0) && ($vmexist == 0));
825
[142]826 # Gather all required files to send them to the VM
827 # and launch the build thourgh pbscript
[314]828 pb_send2ssh("VMs","$v",$vmexist,$vmpid,"vmhost","vmlogin","$ENV{'PBDESTDIR'}/pbrc","vmport","vmtmout");
[118]829 }
[105]830}
831
[262]832
[199]833sub pb_newver {
834
[204]835 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
[315]836 my $scheme=pb_cms_init($ENV{'PBPROJ'});
837 if ($scheme ne "svn") {
[199]838 die "Only SVN is supported at the moment";
839 }
[315]840 my $res = pb_cms_isdiff($scheme);
[199]841 die "You need to have no differences before creating a new version" if ($res != 0);
[315]842 my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBROOT'},"URL:");
[204]843 my $newurl = dirname($cmsurl)."/$newver";
[315]844 pb_cms_copy($scheme,$cmsurl,$newurl);
845 pb_cms_checkout($scheme,$newurl,"$ENV{'PBROOT'}/../$newver");
[208]846 my $oldver=basename($cmsurl);
[211]847 open(FILE,"$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb";
848 open(OUT,"> $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new";
[208]849 while(<FILE>) {
[209]850 s/projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
[211]851 print OUT $_;
[208]852 }
853 close(FILE);
[211]854 close(OUT);
855 rename("$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb");
[315]856 pb_cms_checkin($scheme,"$ENV{'PBROOT'}/../$newver");
[199]857}
858
[293]859#
[105]860# Return the list of VMs we are working on
861# $all is a flag to know if we return all of them
862# or only some (if all we publish also tar files in addition to pkgs
863#
[91]864sub pb_get_vm {
865
866my @vm;
[105]867my $all = 0;
[91]868
869# Get VM list
[105]870if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
[108]871 my ($ptr) = pb_conf_get("vmlist");
[274]872 my $ptr2 = $ptr->{$ENV{'PBPROJ'}};
873 $ptr2 =~ s/,/_64,/g;
874 $ptr2 =~ s/$/_64/g;
875 $ENV{'PBVM'} = "$ptr->{$ENV{'PBPROJ'}},$ptr2";
[105]876 $all = 1;
[91]877}
[315]878pb_log(2,"VMs: $ENV{'PBVM'}\n");
[105]879@vm = split(/,/,$ENV{'PBVM'});
880return(\@vm,$all);
[91]881}
882
[145]883# Returns the pid of a running VM command using a specific VM file
[142]884sub pb_check_ps {
885 my $vmcmd = shift;
886 my $vmm = shift;
887 my $vmexist = 0; # FALSE by default
888
889 open(PS, "ps auxhww|") || die "Unable to call ps";
890 while (<PS>) {
891 next if (! /$vmcmd/);
892 next if (! /$vmm/);
893 my ($void1, $void2);
894 ($void1, $vmexist, $void2) = split(/ +/);
895 last;
896 }
897 return($vmexist);
898}
899
900
[77]901sub pb_extract_build_files {
[25]902
903my $src=shift;
904my $dir=shift;
[26]905my $ddir=shift;
[28]906my @files;
[25]907
[188]908if ($src =~ /tar\.gz$/) {
909 pb_system("tar xfpz $src $dir","Extracting build files");
910} elsif ($src =~ /tar\.bz2$/) {
911 pb_system("tar xfpj $src $dir","Extracting build files");
912} else {
913 die "Unknown compression algorithm for $src";
914}
[25]915opendir(DIR,"$dir") || die "Unable to open directory $dir";
916foreach my $f (readdir(DIR)) {
917 next if ($f =~ /^\./);
[26]918 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[315]919 pb_log(2,"mv $dir/$f $ddir\n");
[28]920 push @files,"$ddir/$f";
[25]921}
922closedir(DIR);
[26]923# Not enough but still a first cleanup
[74]924pb_rm_rf("$dir");
[28]925return(@files);
[25]926}
927
[315]928sub pb_list_bfiles {
929
930my $dir = shift;
931my $pbpkg = shift;
932my $bfiles = shift;
933my $pkgfiles = shift;
934my $supfiles = shift;
935
936opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
937foreach my $f (readdir(BDIR)) {
938 next if ($f =~ /^\./);
939 $bfiles->{$f} = "$dir/$f";
940 $bfiles->{$f} =~ s~$ENV{'PBROOT'}~~;
941 if (defined $supfiles->{$pbpkg}) {
942 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
943 }
944}
945closedir(BDIR);
946}
947
[74]948sub pb_syntax {
[21]949
[53]950 print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
951 print "\n";
[313]952 print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"][-i iso] <action> [<pkg1> ...]\n";
[21]953 print "\n";
[310]954 print "-h: This help file\n";
955 print "-q: Quiet mode\n";
956 print "-t: Test mode (not done yet)\n";
957 print "-v: Verbose mode\n";
[21]958 print "\n";
[310]959 print "-m machine: Name of the Virtual Machines (VM) you want\n";
960 print " to build on (coma separated). All if none precised\n";
961 print " (or use the env variable PBVM) \n";
[69]962 print "\n";
[310]963 print "-s script: Name of the script you want\n";
964 print " to execute on the related VMs.\n";
[141]965 print "\n";
[310]966 print "-i iso: Name of the ISO image of the distribution you want\n";
967 print " to install on the related VMs.\n";
[288]968 print "\n";
[310]969 print "-a account: Name of the account to use\n";
970 print " to connect on the related VMs.\n";
[152]971 print "\n";
[313]972 print "-P port: Port number to use\n";
[310]973 print " to connect on the related VMs.\n";
[199]974 print "\n";
[310]975 print "-p project: Name of the project you're working on\n";
976 print " (or use the env variable PBPROJ) \n";
[21]977 print "\n";
[310]978 print "-r pbroot: Path Name of project under the CMS \n";
979 print " (or use the env variable PBROOT) \n";
[91]980 print "\n";
[310]981 print "-V newver: New version of the project to create\n";
982 print " from the current one. \n";
[199]983 print "\n";
[21]984 print "<action> can be:\n";
985 print "\n";
[310]986 print "\tcms2build: Create tar files for the project under your CMS\n";
987 print "\t CMS supported are SVN and CVS\n";
988 print "\t parameters are packages to build\n";
989 print "\t if not using default list\n";
[21]990 print "\n";
[310]991 print "\tbuild2pkg: Create packages for your running distribution \n";
[21]992 print "\n";
[310]993 print "\tcms2pkg: cms2build + build2pkg\n";
[169]994 print "\n";
[310]995 print "\tbuild2ssh: Send the tar files to a SSH host \n";
[105]996 print "\n";
[310]997 print "\tcms2ssh: cms2build + build2ssh\n";
[220]998 print "\n";
[310]999 print "\tpkg2ssh: Send the packages built to a SSH host \n";
[105]1000 print "\n";
[310]1001 print "\tbuild2vm: Create packages in VMs, launching them if needed\n";
1002 print "\t and send those packages to a SSH host once built\n";
1003 print "\t VM type supported are QEMU \n";
[136]1004 print "\n";
[310]1005 print "\tbuild2chroot: Create packages in a chroot, creating it if needed\n";
1006 print "\t and send those packages to a SSH host once built\n";
[169]1007 print "\n";
[310]1008 print "\tcms2vm: cms2build + build2vm\n";
[141]1009 print "\n";
[310]1010 print "\tlaunchvm: Launch one virtual machine\n";
[142]1011 print "\n";
[310]1012 print "\tscript2vm: Launch one virtual machine if needed \n";
1013 print "\t and executes a script on it \n";
[199]1014 print "\n";
[310]1015 print "\tnewvm: Create a new virtual machine\n";
[262]1016 print "\n";
[310]1017 print "\tnewchroot: Create a new chroot environment\n";
[273]1018 print "\n";
[310]1019 print "\tnewver: Create a new version of the project derived \n";
1020 print "\t from the current one \n";
1021 print "\n";
1022 print "\tnewproj: Create a new project and a template set of \n";
1023 print "\t configuration files under pbconf \n";
1024 print "\n";
[21]1025}
Note: See TracBrowser for help on using the repository browser.