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

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