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

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

Adds debian macro for Group

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