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

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

Backup of local dev. cms2pkg compiles but doesn't work and even remove the SVN :-(
pb_log added

  • Property svn:executable set to *
File size: 34.5 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);
[315]25use ProjectBuilder::Base qw (pb_conf_read pb_conf_get pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init);
[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
[315]38my @date=pb_get_date();
[16]39my $pbdate = strftime("%Y-%m-%d", @date);
[108]40my $debug = 0;
[152]41my $pbaccount; # Login to use to connect to the VM
[162]42my $pbport; # Port to use to connect to the VM
[199]43my $newver; # New version to create
[262]44my $iso; # ISO iage for the VM to create
[108]45my $LOG = \*STDOUT;
[5]46
[262]47getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts);
[5]48
[75]49my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[21]50if (defined $opts{'h'}) {
[74]51 pb_syntax();
[21]52 exit(0);
53}
54if (defined $opts{'v'}) {
55 $debug++;
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'};
[315]191 pb_log(2,"\n");
192 pb_log(2,"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
208 $dir = "$uri/$dir" if ($ENV{'PBREVISION'} ne "flat");
209 pb_cms_export($scheme,"$dir",$dest);
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#
860# Return the list of packages we are working on
861#
[77]862sub pb_get_pkg {
[16]863
[22]864my @pkgs;
[108]865my $defpkgdir = shift;
866my $extpkgdir = shift;
[22]867
868# Get packages list
869if (not defined $ARGV[0]) {
[112]870 @pkgs = keys %$defpkgdir;
[22]871} elsif ($ARGV[0] =~ /^all$/) {
[112]872 @pkgs = keys %$defpkgdir;
873 push(@pkgs, keys %$extpkgdir);
[22]874} else {
875 @pkgs = @ARGV;
876}
[315]877pb_log(2,"Packages: ".join(',',@pkgs)."\n");
[22]878return(\@pkgs);
879}
880
[105]881#
882# Return the list of VMs we are working on
883# $all is a flag to know if we return all of them
884# or only some (if all we publish also tar files in addition to pkgs
885#
[91]886sub pb_get_vm {
887
888my @vm;
[105]889my $all = 0;
[91]890
891# Get VM list
[105]892if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
[108]893 my ($ptr) = pb_conf_get("vmlist");
[274]894 my $ptr2 = $ptr->{$ENV{'PBPROJ'}};
895 $ptr2 =~ s/,/_64,/g;
896 $ptr2 =~ s/$/_64/g;
897 $ENV{'PBVM'} = "$ptr->{$ENV{'PBPROJ'}},$ptr2";
[105]898 $all = 1;
[91]899}
[315]900pb_log(2,"VMs: $ENV{'PBVM'}\n");
[105]901@vm = split(/,/,$ENV{'PBVM'});
902return(\@vm,$all);
[91]903}
904
[145]905# Returns the pid of a running VM command using a specific VM file
[142]906sub pb_check_ps {
907 my $vmcmd = shift;
908 my $vmm = shift;
909 my $vmexist = 0; # FALSE by default
910
911 open(PS, "ps auxhww|") || die "Unable to call ps";
912 while (<PS>) {
913 next if (! /$vmcmd/);
914 next if (! /$vmm/);
915 my ($void1, $void2);
916 ($void1, $vmexist, $void2) = split(/ +/);
917 last;
918 }
919 return($vmexist);
920}
921
922
[77]923sub pb_extract_build_files {
[25]924
925my $src=shift;
926my $dir=shift;
[26]927my $ddir=shift;
[28]928my @files;
[25]929
[188]930if ($src =~ /tar\.gz$/) {
931 pb_system("tar xfpz $src $dir","Extracting build files");
932} elsif ($src =~ /tar\.bz2$/) {
933 pb_system("tar xfpj $src $dir","Extracting build files");
934} else {
935 die "Unknown compression algorithm for $src";
936}
[25]937opendir(DIR,"$dir") || die "Unable to open directory $dir";
938foreach my $f (readdir(DIR)) {
939 next if ($f =~ /^\./);
[26]940 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[315]941 pb_log(2,"mv $dir/$f $ddir\n");
[28]942 push @files,"$ddir/$f";
[25]943}
944closedir(DIR);
[26]945# Not enough but still a first cleanup
[74]946pb_rm_rf("$dir");
[28]947return(@files);
[25]948}
949
[315]950sub pb_list_bfiles {
951
952my $dir = shift;
953my $pbpkg = shift;
954my $bfiles = shift;
955my $pkgfiles = shift;
956my $supfiles = shift;
957
958opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
959foreach my $f (readdir(BDIR)) {
960 next if ($f =~ /^\./);
961 $bfiles->{$f} = "$dir/$f";
962 $bfiles->{$f} =~ s~$ENV{'PBROOT'}~~;
963 if (defined $supfiles->{$pbpkg}) {
964 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
965 }
966}
967closedir(BDIR);
968}
969
[74]970sub pb_syntax {
[21]971
[53]972 print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
973 print "\n";
[313]974 print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"][-i iso] <action> [<pkg1> ...]\n";
[21]975 print "\n";
[310]976 print "-h: This help file\n";
977 print "-q: Quiet mode\n";
978 print "-t: Test mode (not done yet)\n";
979 print "-v: Verbose mode\n";
[21]980 print "\n";
[310]981 print "-m machine: Name of the Virtual Machines (VM) you want\n";
982 print " to build on (coma separated). All if none precised\n";
983 print " (or use the env variable PBVM) \n";
[69]984 print "\n";
[310]985 print "-s script: Name of the script you want\n";
986 print " to execute on the related VMs.\n";
[141]987 print "\n";
[310]988 print "-i iso: Name of the ISO image of the distribution you want\n";
989 print " to install on the related VMs.\n";
[288]990 print "\n";
[310]991 print "-a account: Name of the account to use\n";
992 print " to connect on the related VMs.\n";
[152]993 print "\n";
[313]994 print "-P port: Port number to use\n";
[310]995 print " to connect on the related VMs.\n";
[199]996 print "\n";
[310]997 print "-p project: Name of the project you're working on\n";
998 print " (or use the env variable PBPROJ) \n";
[21]999 print "\n";
[310]1000 print "-r pbroot: Path Name of project under the CMS \n";
1001 print " (or use the env variable PBROOT) \n";
[91]1002 print "\n";
[310]1003 print "-V newver: New version of the project to create\n";
1004 print " from the current one. \n";
[199]1005 print "\n";
[21]1006 print "<action> can be:\n";
1007 print "\n";
[310]1008 print "\tcms2build: Create tar files for the project under your CMS\n";
1009 print "\t CMS supported are SVN and CVS\n";
1010 print "\t parameters are packages to build\n";
1011 print "\t if not using default list\n";
[21]1012 print "\n";
[310]1013 print "\tbuild2pkg: Create packages for your running distribution \n";
[21]1014 print "\n";
[310]1015 print "\tcms2pkg: cms2build + build2pkg\n";
[169]1016 print "\n";
[310]1017 print "\tbuild2ssh: Send the tar files to a SSH host \n";
[105]1018 print "\n";
[310]1019 print "\tcms2ssh: cms2build + build2ssh\n";
[220]1020 print "\n";
[310]1021 print "\tpkg2ssh: Send the packages built to a SSH host \n";
[105]1022 print "\n";
[310]1023 print "\tbuild2vm: Create packages in VMs, launching them if needed\n";
1024 print "\t and send those packages to a SSH host once built\n";
1025 print "\t VM type supported are QEMU \n";
[136]1026 print "\n";
[310]1027 print "\tbuild2chroot: Create packages in a chroot, creating it if needed\n";
1028 print "\t and send those packages to a SSH host once built\n";
[169]1029 print "\n";
[310]1030 print "\tcms2vm: cms2build + build2vm\n";
[141]1031 print "\n";
[310]1032 print "\tlaunchvm: Launch one virtual machine\n";
[142]1033 print "\n";
[310]1034 print "\tscript2vm: Launch one virtual machine if needed \n";
1035 print "\t and executes a script on it \n";
[199]1036 print "\n";
[310]1037 print "\tnewvm: Create a new virtual machine\n";
[262]1038 print "\n";
[310]1039 print "\tnewchroot: Create a new chroot environment\n";
[273]1040 print "\n";
[310]1041 print "\tnewver: Create a new version of the project derived \n";
1042 print "\t from the current one \n";
1043 print "\n";
1044 print "\tnewproj: Create a new project and a template set of \n";
1045 print "\t configuration files under pbconf \n";
1046 print "\n";
[21]1047}
Note: See TracBrowser for help on using the repository browser.