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

Last change on this file since 1097 was 1097, checked in by Bruno Cornec, 14 years ago
  • Fix #36 by adding new targets to pb with sbx2 suffix. They replace in feature the previous cms2 targets which now becomes really an extract from the Configuration Management System, where the former are from the exported content aka sandbox.
  • Property svn:executable set to *
File size: 99.4 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::Long qw(:config auto_abbrev no_ignore_case);
14use Data::Dumper;
15use English;
16use File::Basename;
17use File::Copy;
18use File::stat;
19use File::Temp qw(tempdir);
20use File::Find;
21use Time::localtime qw(localtime);
22use POSIX qw(strftime);
23use lib qw (lib);
24use ProjectBuilder::Version;
25use ProjectBuilder::Base;
26use ProjectBuilder::Display;
27use ProjectBuilder::Conf;
28use ProjectBuilder::Distribution;
29use ProjectBuilder::CMS;
30use ProjectBuilder::Env;
31use ProjectBuilder::Filter;
32use ProjectBuilder::Changelog;
33use Mail::Sendmail;
34
35# Global variables
36my %opts; # CLI Options
37my $action; # action to realize
38my $test = "FALSE"; # Not used
39my $pbforce = 0; # Force VE/VM rebuild
40my $pbsnap = 0; # Do not use snapshot mode for VM/VE by default
41my $option = ""; # Not used
42my @pkgs; # list of packages
43my $pbtag; # Global Tag variable
44my $pbver; # Global Version variable
45my $pbscript; # Name of the script
46my %pbver; # per package
47my %pbtag; # per package
48my $pbrev; # Global REVISION variable
49my $pbaccount; # Login to use to connect to the VM
50my $pbport; # Port to use to connect to the VM
51my $newver; # New version to create
52my $iso = undef; # ISO image for the VM to create
53
54my @date = pb_get_date();
55my $pbdate = strftime("%Y-%m-%d", @date);
56
57=pod
58
59=head1 NAME
60
61pb, aka project-builder.org - builds packages for your projects
62
63=head1 DESCRIPTION
64
65pb helps you build various packages directly from your project sources.
66Those sources could be handled by a CMS (Configuration Management System)
67such as Subversion, CVS, Git, Mercurial... or being a simple reference to a compressed tar file.
68It's based on a set of configuration files, a set of provided macros to help
69you keeping build files as generic as possible. For example, a single .spec
70file should be required to generate for all rpm based distributions, even
71if you could also have multiple .spec files if required.
72
73=head1 SYNOPSIS
74
75pb [-vhSq][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...]
76
77pb [--verbose][--help][--man][--quiet][--snapshot][--revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...]
78
79=head1 OPTIONS
80
81=over 4
82
83=item B<-v|--verbose>
84
85Print a brief help message and exits.
86
87=item B<-q|--quiet>
88
89Do not print any output.
90
91=item B<-h|--help>
92
93Print a brief help message and exits.
94
95=item B<-S|--snapshot>
96
97Use the snapshot mode of VMs or VEs
98
99=item B<--man>
100
101Prints the manual page and exits.
102
103=item B<-m|--machine machine1[,machine2,...]>
104
105Name of the Virtual Machines (VM) or Virtual Environments (VE) you want to build on (coma separated).
106All if none precised (or use the env variable PBV).
107
108=item B<-s|--script script>
109
110Name of the script you want to execute on the related VMs or VEs.
111
112=item B<-i|--iso iso_image>
113
114Name of the ISO image of the distribution you want to install on the related VMs.
115
116=item B<-a|--account account>
117
118Name of the account to use to connect on the related VMs.
119
120=item B<-P|--port port_number>
121
122Port number to use to connect on the related VMs.\n";
123
124=item B<-p|--project project_name>
125
126Name of the project you're working on (or use the env variable PBPROJ)
127
128=item B<-r|--revision revision>
129
130Path Name of the project revision under the CMS (or use the env variable PBROOT)
131
132=item B<-V|--version new_version>
133
134New version of the project to create based on the current one.
135
136=back
137
138=head1 ARGUMENTS
139
140<action> can be:
141
142=over 4
143
144=item B<sbx2build>
145
146Create tar files for the project under your CMS.
147Current state of the exported content is taken.
148CMS supported are SVN, SVK, CVS, Git and Mercurial
149parameters are packages to build
150if not using default list
151
152=item B<cms2build>
153
154Create tar files for the project under your CMS.
155Current state of the CMS is taken.
156CMS supported are SVN, SVK, CVS, Git and Mercurial
157parameters are packages to build
158if not using default list
159
160=item B<build2pkg>
161
162Create packages for your running distribution
163
164=item B<cms2pkg>
165
166cms2build + build2pkg
167
168=item B<sbx2pkg>
169
170sbx2build + build2pkg
171
172=item B<build2ssh>
173
174Send the tar files to a SSH host
175
176=item B<sbx2ssh>
177
178sbx2build + build2ssh
179
180=item B<cms2ssh>
181
182cms2build + build2ssh
183
184=item B<pkg2ssh>
185
186Send the packages built to a SSH host
187
188=item B<build2vm>
189
190Create packages in VMs, launching them if needed
191and send those packages to a SSH host once built
192VM type supported are QEMU
193
194=item B<build2ve>
195
196Create packages in VEs, creating it if needed
197and send those packages to a SSH host once built
198
199=item B<sbx2vm>
200
201sbx2build + build2vm
202
203=item B<sbx2ve>
204
205sbx2build + build2ve
206
207=item B<cms2vm>
208
209cms2build + build2vm
210
211=item B<cms2ve>
212
213cms2build + build2ve
214
215=item B<launchvm>
216
217Launch one virtual machine
218
219=item B<launchve>
220
221Launch one virtual environment
222
223=item B<script2vm>
224
225Launch one virtual machine if needed
226and executes a script on it
227
228=item B<script2ve>
229
230Execute a script in a virtual environment
231
232=item B<newvm>
233
234Create a new virtual machine
235
236=item B<newve>
237
238Create a new virtual environment
239
240=item B<setupvm>
241
242Setup a virtual machine for pb usage
243
244=item B<setupve>
245
246Setup a virtual environment for pb usage
247
248=item B<snapvm>
249
250Snapshot a virtual machine for pb usage
251
252=item B<snapve>
253
254Snapshot a virtual environment for pb usage
255
256=item B<test2pkg>
257
258Test a package locally
259
260=item B<test2vm>
261
262Test a package in a virtual machine
263
264=item B<test2ve>
265
266Test a package in a virtual environment
267
268=item B<newver>
269
270Create a new version of the project derived
271from the current one
272
273=item B<newproj>
274
275Create a new project and a template set of
276configuration files under pbconf
277
278=item B<announce>
279
280Announce the availability of the project through various means
281
282=item B<web2ssh>
283
284Deliver the Web site content to the target server using ssh.
285
286=item B<clean>
287
288Purge the build and delivery directories related to the current project
289
290=back
291
292<pkgs> can be a list of packages, the keyword 'all' or nothing, in which case the default list of packages is taken (corresponding to the defpkgdir list of arguments in the configuration file).
293
294=head1 WEB SITES
295
296The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
297
298=head1 USER MAILING LIST
299
300None exists for the moment.
301
302=head1 CONFIGURATION FILES
303
304Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
305
306Here is an example of such a configuration file:
307
308 #
309 # Define for each project the URL of its pbconf repository
310 # No default option allowed here as they need to be all different
311 #
312 # URL of the pbconf content
313 # This is the format of a classical URL with the extension of additional schema such as
314 # svn+ssh, cvs+ssh, ...
315 #
316 pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
317
318 # This is normaly defined in the project's configuration file
319 # Url of the project
320 #
321 pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
322
323 # All these URLs needs to be defined here as the are the entry point
324 # for how to build packages for the project
325 #
326 pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
327 pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
328 pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
329 pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
330
331 # Under that dir will take place everything related to pb
332 # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
333 # to your VMs/chroot/...
334 # if not defined then /var/cache
335 pbdefdir default = $ENV{'HOME'}/project-builder
336 pbdefdir pb = $ENV{'HOME'}
337 pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
338 pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
339
340 # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
341 # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
342 pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
343 pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
344
345 # pbdir points to the directory where the CMS content of the pburl is checked out
346 # If not defined, pbdir is under pbdefdir/pbproj
347 # Only defined if we have access to the dev of the project
348 pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
349 pbdir mondorescue = $ENV{'HOME'}/mondo/svn
350
351 # -daemonize doesn't work with qemu 0.8.2
352 vmopt default = -m 384
353
354=head1 AUTHORS
355
356The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
357
358=head1 COPYRIGHT
359
360Project-Builder.org is distributed under the GPL v2.0 license
361described in the file C<COPYING> included with the distribution.
362
363=cut
364
365# ---------------------------------------------------------------------------
366
367my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
368my $appname = "pb";
369
370# Initialize the syntax string
371
372pb_syntax_init("$appname (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
373
374GetOptions("help|?|h" => \$opts{'h'},
375 "man" => \$opts{'man'},
376 "verbose|v+" => \$opts{'v'},
377 "snapshot|S" => \$opts{'S'},
378 "quiet|q" => \$opts{'q'},
379 "log-files|l=s" => \$opts{'l'},
380 "force|f" => \$opts{'f'},
381 "account|a=s" => \$opts{'a'},
382 "revision|r=s" => \$opts{'r'},
383 "script|s=s" => \$opts{'s'},
384 "machines|mock|m=s" => \$opts{'m'},
385 "port|P=i" => \$opts{'P'},
386 "project|p=s" => \$opts{'p'},
387 "iso|i=s" => \$opts{'i'},
388 "version|V=s" => \$opts{'V'},
389) || pb_syntax(-1,0);
390
391if (defined $opts{'h'}) {
392 pb_syntax(0,1);
393}
394if (defined $opts{'man'}) {
395 pb_syntax(0,2);
396}
397if (defined $opts{'v'}) {
398 $pbdebug = $opts{'v'};
399}
400if (defined $opts{'f'}) {
401 $pbforce=1;
402}
403if (defined $opts{'q'}) {
404 $pbdebug=-1;
405}
406if (defined $opts{'S'}) {
407 $pbsnap=1;
408}
409if (defined $opts{'l'}) {
410 open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
411 $pbLOG = \*pbLOG;
412 $pbdebug = 0 if ($pbdebug == -1);
413 }
414pb_log_init($pbdebug, $pbLOG);
415pb_display_init("text","");
416
417# Handle root of the project if defined
418if (defined $opts{'r'}) {
419 $ENV{'PBROOTDIR'} = $opts{'r'};
420}
421# Handle virtual machines if any
422if (defined $opts{'m'}) {
423 $ENV{'PBV'} = $opts{'m'};
424}
425if (defined $opts{'s'}) {
426 $pbscript = $opts{'s'};
427}
428if (defined $opts{'a'}) {
429 $pbaccount = $opts{'a'};
430 die "option -a requires a -s script option" if (not defined $pbscript);
431}
432if (defined $opts{'P'}) {
433 $pbport = $opts{'P'};
434}
435if (defined $opts{'V'}) {
436 $newver = $opts{'V'};
437}
438if (defined $opts{'i'}) {
439 $iso = $opts{'i'};
440}
441
442# Get Action
443$action = shift @ARGV;
444die pb_syntax(-1,1) if (not defined $action);
445
446my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
447my $pbinit = undef;
448$pbinit = 1 if ($action =~ /^newproj$/);
449
450# Handles project name if any
451# And get global params
452($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action);
453
454#
455# Check for command requirements
456#
457my ($req,$opt) = pb_conf_get_if("oscmd","oscmdopt");
458my ($req2,$opt2) = (undef,undef);
459$req2 = $req->{$appname} if (defined $req);
460$opt2 = $opt->{$appname} if (defined $opt);
461pb_check_requirements($req2,$opt2);
462
463pb_log(0,"Project: $ENV{'PBPROJ'}\n");
464pb_log(0,"Action: $action\n");
465
466# Act depending on action
467if ($action =~ /^cms2build$/) {
468 pb_cms2build("CMS");
469} elsif ($action =~ /^sbx2build$/) {
470 pb_cms2build("SandBox");
471} elsif ($action =~ /^build2pkg$/) {
472 pb_build2pkg();
473} elsif ($action =~ /^cms2pkg$/) {
474 pb_cms2build("CMS");
475 pb_build2pkg();
476} elsif ($action =~ /^sbx2pkg$/) {
477 pb_cms2build("SandBox");
478 pb_build2pkg();
479} elsif ($action =~ /^build2ssh$/) {
480 pb_build2ssh();
481} elsif ($action =~ /^cms2ssh$/) {
482 pb_cms2build("CMS");
483 pb_build2ssh();
484} elsif ($action =~ /^sbxs2ssh$/) {
485 pb_cms2build("SandBox");
486 pb_build2ssh();
487} elsif ($action =~ /^pkg2ssh$/) {
488 pb_pkg2ssh();
489} elsif ($action =~ /^build2ve$/) {
490 pb_build2v("ve","build");
491} elsif ($action =~ /^build2vm$/) {
492 pb_build2v("vm","build");
493} elsif ($action =~ /^cms2ve$/) {
494 pb_cms2build("CMS");
495 pb_build2v("ve","build");
496} elsif ($action =~ /^sbx2ve$/) {
497 pb_cms2build("SandBox");
498 pb_build2v("ve","build");
499} elsif ($action =~ /^cms2vm$/) {
500 pb_cms2build("CMS");
501 pb_build2v("vm","build");
502} elsif ($action =~ /^sbx2vm$/) {
503 pb_cms2build("SandBox");
504 pb_build2v("vm","build");
505} elsif ($action =~ /^launchvm$/) {
506 pb_launchv("vm",$ENV{'PBV'},0);
507} elsif ($action =~ /^launchve$/) {
508 pb_launchv("ve",$ENV{'PBV'},0);
509} elsif ($action =~ /^script2vm$/) {
510 pb_script2v($pbscript,"vm");
511} elsif ($action =~ /^script2ve$/) {
512 pb_script2v($pbscript,"ve");
513} elsif ($action =~ /^newver$/) {
514 pb_newver();
515} elsif ($action =~ /^newve$/) {
516 pb_launchv("ve",$ENV{'PBV'},1);
517} elsif ($action =~ /^newvm$/) {
518 pb_launchv("vm",$ENV{'PBV'},1);
519 pb_log(0, "Please ensure that sshd is running in your VM by default\n");
520 pb_log(0, "and that it allows remote root login (PermitRootLogin yes in /etc/ssh/sshd_config)\n");
521 pb_log(0, "Also ensure that network is up, firewalling correctly configured, and perl and scp/ssh installed\n");
522 pb_log(0, "You should then be able to login with ssh -p VMPORT root\@localhost (if VM started with pb)\n");
523} elsif ($action =~ /^setupve$/) {
524 pb_setup2v("ve");
525} elsif ($action =~ /^setupvm$/) {
526 pb_setup2v("vm");
527} elsif ($action =~ /^snapve$/) {
528 pb_snap2v("ve");
529} elsif ($action =~ /^snapvm$/) {
530 pb_snap2v("vm");
531} elsif ($action =~ /^test2pkg$/) {
532 pb_test2pkg();
533} elsif ($action =~ /^test2ve$/) {
534 pb_build2v("ve","test");
535} elsif ($action =~ /^test2vm$/) {
536 pb_build2v("vm","test");
537} elsif ($action =~ /^newproj$/) {
538 # Nothing to do - already done in pb_env_init
539} elsif ($action =~ /^clean$/) {
540 pb_clean();
541} elsif ($action =~ /^announce$/) {
542 # For announce only. Require avoids the systematic load of these modules
543 require DBI;
544 require DBD::SQLite;
545
546 pb_announce();
547} elsif ($action =~ /^web2ssh$/) {
548 require DBI;
549 require DBD::SQLite;
550
551 pb_cms2build("Web");
552 pb_send2target("Web");
553} else {
554 pb_log(0,"\'$action\' is not available\n");
555 pb_syntax(-2,1);
556}
557
558sub pb_cms2build {
559
560 my $param = shift || undef;
561
562 my $pkg;
563 my @pkgs;
564 my $webdir;
565
566 my %pkgs;
567 my %pb; # Structure to store conf info
568
569 die "pb_cms2build requires a parameter: Web, SandBox or CMS" if (not defined $param);
570
571 # If Website, then pkg is only the website
572 if ($param eq "Web") {
573 ($webdir) = pb_conf_get("webdir");
574 pb_log(2,"webdir: ".Dumper($webdir)."\n");
575 $pkgs[0] = $webdir->{$ENV{'PBPROJ'}};
576 $extpkgdir = $webdir;
577 pb_log(0,"Package: $pkgs[0]\n");
578 } else {
579 $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
580 @pkgs = @$pkg;
581 }
582
583 my ($scheme, $uri) = pb_cms_init($pbinit,$param);
584
585 # We need 2 lines here
586 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
587 my @pt = pb_conf_get_if("vmlist","velist");
588
589 # declare packager and repo for filtering
590 # TODO: Is pbrepo needed so early in the process ?
591 my ($tmp1, $tmp2) = pb_conf_get("pbpackager","pbrepo");
592 $ENV{'PBPACKAGER'} = $tmp1->{$ENV{'PBPROJ'}};
593 $ENV{'PBREPO'} = $tmp2->{$ENV{'PBPROJ'}};
594
595 foreach my $pbpkg (@pkgs) {
596 $ENV{'PBPKG'} = $pbpkg;
597
598 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
599 $pbver = $pkgv->{$pbpkg};
600 } else {
601 $pbver = $ENV{'PBPROJVER'};
602 }
603 # If it's a test version, then tag == 0.date
604 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
605 $pbtag = "0.".strftime("%Y%m%d%H%M%S", @date);
606 $ENV{'PBPROJTAG'} = $pbtag;
607 } elsif ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
608 $pbtag = $pkgt->{$pbpkg};
609 } else {
610 $pbtag = $ENV{'PBPROJTAG'};
611 }
612
613 $pbrev = $ENV{'PBREVISION'};
614 pb_log(0,"\n");
615 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
616 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
617
618 # Clean up dest if necessary. The export will recreate it
619 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
620 pb_rm_rf($dest) if (-d $dest);
621
622 # Export CMS tree for the concerned package to dest
623 # And generate some additional files
624 $OUTPUT_AUTOFLUSH=1;
625
626 # computes in which dir we have to work
627 my $dir = $defpkgdir->{$pbpkg};
628 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
629 $dir = $webdir->{$ENV{'PBPROJ'}} if ($param eq "Web");
630 pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
631
632 # Exporting content from CMS
633 my $sourcedir = undef;
634 my $sourceuri = $uri;
635 if ($param eq "SandBox") {
636 # Point to the local instance
637 $sourcedir = "$ENV{'PBDIR'}/$dir";
638 } else {
639 # Get it from a subdir of the URI with same version as localy but different root
640 $sourceuri = "$ENV{'PBDIR'}/$dir";
641 $sourceuri =~ s|^$ENV{'PBPROJDIR'}/|$uri|;
642 }
643 my $preserve = pb_cms_export($sourceuri,$sourcedir,$dest);
644
645 # Generated fake content for test versions to speed up stuff
646 my $chglog;
647
648 # Get project info on authors and log file
649 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
650 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
651 $chglog = undef if (! -f $chglog);
652
653 my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
654 $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
655 $authors = "/dev/null" if (! -f $authors);
656
657 # Extract cms log history and store it
658 if ((defined $chglog) && (! -f "$dest/NEWS")) {
659 pb_log(2,"Generating NEWS file from $chglog\n");
660 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
661 }
662 pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
663
664 my %build;
665 # We want to at least build for the underlying distro
666 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $arch) = pb_distro_init();
667 my $tmpl = "$ddir-$dver-$arch,";
668 my %patches;
669
670 # Get list of distributions for which we need to generate build files
671 if (defined $pt[0]->{$ENV{'PBPROJ'}}) {
672 $tmpl .= $pt[0]->{$ENV{'PBPROJ'}};
673 }
674 if (defined $pt[1]->{$ENV{'PBPROJ'}}) {
675 # The 2 lists needs to be grouped with a ',' separating them
676 if ($tmpl ne "") {
677 $tmpl .= ",";
678 }
679 $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
680 }
681
682 # Setup %pb structure to allow filtering later on, on files using that structure
683 $pb{'tag'} = $pbtag;
684 $pb{'rev'} = $pbrev;
685 $pb{'ver'} = $pbver;
686 $pb{'pkg'} = $pbpkg;
687 $pb{'date'} = $pbdate;
688 $pb{'defpkgdir'} = $defpkgdir;
689 $pb{'extpkgdir'} = $extpkgdir;
690 $pb{'chglog'} = $chglog;
691 $pb{'packager'} = $ENV{'PBPACKAGER'};
692 $pb{'proj'} = $ENV{'PBPROJ'};
693 $pb{'repo'} = $ENV{'PBREPO'};
694 $pb{'patches'} = \%patches;
695 pb_log(2,"DEBUG: pb: ".Dumper(%pb)."\n");
696
697 # Do not do that for website
698 if ($param ne "Web") {
699 pb_log(0,"Build files are being generated for ...\n");
700 my %virt;
701 # De-duplicate similar VM and VE
702 foreach my $d (split(/,/,$tmpl)) {
703 # skip ill-formatted vms (name-ver-arch)
704 next if ($d !~ /-/);
705 $virt{$d} = $d;
706 }
707
708 foreach my $d (keys %virt) {
709 my ($name,$ver,$arch) = split(/-/,$d);
710 pb_log(0,"Bad format for $d") if ((not defined $name) || (not defined $ver) || (not defined $arch)) ;
711 chomp($arch);
712 my ($ddir, $dver, $dfam);
713 ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'os'}, $pb{'suf'}, $pb{'upd'}, $pb{'arch'}) = pb_distro_init($name,$ver,$arch);
714 pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
715 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
716
717 # We need to compute the real name of the package
718 my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pb{'dtype'});
719 $pb{'realpkg'} = $pbrealpkg;
720 pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $ddir-$dver\n") if ($pbrealpkg ne $pbpkg);
721
722 # Filter build files from the less precise up to the most with overloading
723 # Filter all files found, keeping the name, and generating in dest
724
725 # Find all build files first relatively to PBROOTDIR
726 # Find also all specific files referenced in the .pb conf file
727 my %bfiles = ();
728 my %pkgfiles = ();
729 $build{"$ddir-$dver-$arch"} = "yes";
730
731 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
732 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
733 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
734 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
735 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
736 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
737 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
738 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
739 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
740 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
741 } else {
742 $build{"$ddir-$dver-$arch"} = "no";
743 next;
744 }
745 pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
746
747 # Get all filters to apply
748 my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
749
750 # Prepare local patches for this distro - They are always applied first - May be a problem one day
751 foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
752 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
753 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
754 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$pb{'dtype'}$/));
755 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$pb{'dtype'}$/);
756 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
757 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
758 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
759 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
760 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
761 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
762 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
763 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
764 }
765
766 # Prepare also remote patches to be included - Applied after the local ones
767 foreach my $p ("all","$pb{'dtype'}","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
768 my $f = "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch.$p";
769 next if (not -f $f);
770 if (not open(PATCH,$f)) {
771 pb_display("Unable to open existing external patch file content $f\n");
772 next;
773 }
774 while (<PATCH>) {
775 chomp();
776 $patches{"$ddir-$dver-$arch"} .= "," if (defined $patches{"$ddir-$dver-$arch"});
777 $patches{"$ddir-$dver-$arch"} .= "$_";
778 }
779 close(PATCH);
780 }
781 pb_log(2,"DEBUG: pb->patches: ".Dumper($pb{'patches'})."\n");
782
783 # Apply now all the filters on all the files concerned
784 # destination dir depends on the type of file
785 if (defined $ptr) {
786 # For patch support
787 $pb{'tuple'} = "$ddir-$dver-$arch";
788 foreach my $f (values %bfiles,values %pkgfiles) {
789 pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
790 }
791 }
792 }
793 my @found;
794 my @notfound;
795 foreach my $b (keys %build) {
796 push @found,$b if ($build{$b} =~ /yes/);
797 push @notfound,$b if ($build{$b} =~ /no/);
798 }
799 pb_log(0," ... ".join(',',sort(@found))."\n");
800 pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
801 pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
802 }
803
804 # Get the generic filter (all.pbf) and
805 # apply those to the non-build files including those
806 # generated by pbinit if applicable
807
808 # Get only all.pbf filter
809 my $ptr = pb_get_filters($pbpkg);
810
811 my $liste ="";
812 if (defined $filteredfiles->{$pbpkg}) {
813 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
814 pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
815 $liste = "$f $liste";
816 }
817 }
818 pb_log(2,"Files ".$liste."have been filtered\n");
819
820 # Do not do that for website
821 if ($param ne "Web") {
822 my %tmp;
823 my $warnflag = 0;
824 # Filter potential patches (local + remote)
825 pb_log(0,"Delivering and compressing patches ");
826 foreach my $v (keys %patches) {
827 pb_mkdir_p("$dest/pbconf/$v/pbpatch");
828 foreach my $pf (split(/,/,$patches{$v})) {
829 my $pp = basename($pf);
830 if ($param eq "SandBox") {
831 $warnflag = 1;
832 }
833 pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
834 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
835 pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
836 $tmp{$pf} = "";
837 }
838 }
839 foreach my $v (keys %tmp) {
840 pb_log(0,"$v ");
841 }
842 pb_log(0,"\n");
843 pb_log(0,"WARNING: Patches are always taken from repository not local export\n") if ($warnflag == 1);
844 } else {
845 # Instead call News generation
846 pb_web_news2html($dest);
847 # And create an empty pbconf
848 pb_mkdir_p("$dest/pbconf");
849 # And prepare the pbscript to execute remotely
850 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
851 print SCRIPT "#!/bin/bash\n";
852 print SCRIPT "#set -x\n";
853 print SCRIPT "echo ... Extracting Website content\n";
854 print SCRIPT "find . -type f | grep -Ev '^./$pbpkg-$pbver.tar.gz|^./pbscript' | xargs rm -f non-existent\n";
855 print SCRIPT "find * -type d -depth | xargs rmdir 2> /dev/null \n";
856 print SCRIPT "tar xfz $pbpkg-$pbver.tar.gz\n";
857 print SCRIPT "mv $pbpkg-$pbver/* .\n";
858 print SCRIPT "rm -f $pbpkg-$pbver.tar.gz\n";
859 print SCRIPT "rmdir $pbpkg-$pbver\n";
860 close(SCRIPT);
861 }
862
863 # Prepare the dest directory for archive
864 if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
865 pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
866 chmod 0755,"$ENV{'PBTMP'}/pbinit";
867 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
868 }
869
870 # Do we have additional script to run to prepare the environement for the project ?
871 # Then include it in the pbconf delivery
872 foreach my $pbvf (<$ENV{'PBROOTDIR'}/pbv*.pre>,<$ENV{'PBROOTDIR'}/pbv*.post>, <$ENV{'PBROOTDIR'}/pbtest*>) {
873 if (-x "$pbvf") {
874 my $target = "$ENV{'PBDESTDIR'}/".basename($pbvf);
875 pb_filter_file("$pbvf",$ptr,$target,\%pb);
876 chmod 0755,"$target";
877 }
878 }
879
880 # Archive dest dir
881 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
882 if (defined $preserve) {
883 # In that case we want to preserve the original tar file for checksum purposes
884 # The one created is btw equivalent in that case to this one
885 # Maybe check basename of both to be sure they are the same ?
886 pb_log(0,"Preserving original tar file ");
887 move("$preserve","$pbpkg-$pbver.tar.gz");
888 } else {
889 # Possibility to look at PBSRC to guess more the filename
890 pb_system("tar cfz $pbpkg-$pbver.tar.gz --exclude=$pbpkg-$pbver/pbconf $pbpkg-$pbver","Creating $pbpkg tar files compressed");
891 }
892 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
893 pb_system("tar cfz $pbpkg-$pbver.pbconf.tar.gz $pbpkg-$pbver/pbconf","Creating pbconf tar files compressed");
894 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz\n");
895
896 # Keep track of version-tag per pkg
897 $pkgs{$pbpkg} = "$pbver-$pbtag";
898
899 # Final cleanup
900 pb_rm_rf($dest) if (-d $dest);
901 }
902
903 # Keep track of per package version
904 pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
905 open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
906 foreach my $pbpkg (keys %pkgs) {
907 print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
908 }
909 close(PKG);
910
911 # Keep track of what is generated by default
912 # We need to store the dir and info on version-tag
913 # Base our content on the existing .pb file
914 copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
915 open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
916 print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
917 print LAST "projver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
918 print LAST "projtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
919 print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
920 close(LAST);
921}
922
923sub pb_test2pkg {
924 # Get the running distro to test on
925 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $arch) = pb_distro_init();
926 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch))."\n");
927
928 # Get list of packages to test
929 # Get content saved in cms2build
930 my $ptr = pb_get_pkg();
931 @pkgs = @$ptr;
932
933 # Additional potential repo
934 pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
935 foreach my $pbpkg (@pkgs) {
936 # We need to install the package to test, and deps brought with it
937 pb_distro_installdeps(undef,$dtype,$pbupd,$pbpkg);
938 pb_system("$ENV{'PBDESTDIR'}/pbtest","Launching test for $pbpkg","verbose");
939 }
940}
941
942sub pb_build2pkg {
943
944 # Get the running distro to build on
945 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $arch) = pb_distro_init();
946 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch))."\n");
947
948 # Get list of packages to build
949 my $ptr = pb_get_pkg();
950 @pkgs = @$ptr;
951
952 # Get content saved in cms2build
953 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
954 $pkg = { } if (not defined $pkg);
955
956 chdir "$ENV{'PBBUILDDIR'}";
957 my $made = ""; # pkgs made during build
958 foreach my $pbpkg (@pkgs) {
959 my $vertag = $pkg->{$pbpkg};
960 # get the version of the current package - maybe different
961 ($pbver,$pbtag) = split(/-/,$vertag);
962
963 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
964 my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
965 pb_log(2,"Source file: $src\n");
966 pb_log(2,"Pbconf file: $src2\n");
967
968 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
969 if ($dtype eq "rpm") {
970 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
971 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
972 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";
973 }
974 }
975
976 # Remove in case a previous link/file was there
977 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
978 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
979 # We need to first extract the spec file
980 my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$ENV{'PBBUILDDIR'}/SPECS","spec");
981
982 # We need to handle potential patches to upstream sources
983 pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
984
985 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
986 # set LANGUAGE to check for correct log messages
987 $ENV{'LANGUAGE'}="C";
988 # Older Redhat use _target_platform in %configure incorrectly
989 my $specialdef = "";
990 if (($ddir eq "redhat") || (($ddir eq "rhel") && ($dver eq "2.1"))) {
991 $specialdef = "--define \'_target_platform \"\"\'";
992 }
993
994 # If needed we may add repository to the build env
995 pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
996 foreach my $f (@specfile) {
997 if ($f =~ /\.spec$/) {
998 pb_distro_installdeps($f,$dtype,$pbupd);
999 pb_system("rpmbuild $specialdef --define \"packager $ENV{'PBPACKAGER'}\" --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
1000 last;
1001 }
1002 }
1003 # Get the name of the generated packages
1004 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
1005 while (<LOG>) {
1006 chomp($_);
1007 next if ($_ !~ /^Wrote:/);
1008 s|.*/([S]*RPMS.*)|$1|;
1009 $made .=" $_";
1010 }
1011 close(LOG);
1012
1013 } elsif ($dtype eq "deb") {
1014 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1015 pb_system("tar xfz $src","Extracting sources");
1016 pb_system("tar xfz $src2","Extracting pbconf");
1017
1018 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
1019 pb_rm_rf("debian");
1020 symlink "pbconf/$ddir-$dver-$arch","debian" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
1021 chmod 0755,"debian/rules";
1022
1023 pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
1024 pb_distro_installdeps("debian/control",$dtype,$pbupd);
1025 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
1026 # Get the name of the generated packages
1027 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
1028 while (<LOG>) {
1029 chomp();
1030 my $tmp = $_;
1031 next if ($tmp !~ /^dpkg-deb.*:/);
1032 $tmp =~ s|.*../(.*)_(.*).deb.*|$1|;
1033 $made="$made $tmp.dsc $tmp.tar.gz $tmp"."_*.deb $tmp"."_*.changes";
1034 }
1035 close(LOG);
1036 } elsif ($dtype eq "ebuild") {
1037 my @ebuildfile;
1038 # For gentoo we need to take pb as subsystem name
1039 # We put every apps here under sys-apps. hope it's correct
1040 # We use pb's home dir in order to have a single OVERLAY line
1041 my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
1042 pb_mkdir_p($tmpd) if (! -d "$tmpd");
1043 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
1044
1045 # We need to first extract the ebuild file
1046 @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$tmpd","ebuild");
1047
1048 # Prepare the build env for gentoo
1049 my $found = 0;
1050 my $pbbd = $ENV{'HOME'};
1051 $pbbd =~ s|/|\\/|g;
1052 if (-r "/etc/make.conf") {
1053 open(MAKE,"/etc/make.conf");
1054 while (<MAKE>) {
1055 $found = 1 if (/$pbbd\/portage/);
1056 }
1057 close(MAKE);
1058 }
1059 if ($found == 0) {
1060 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
1061 }
1062 #$found = 0;
1063 #if (-r "/etc/portage/package.keywords") {
1064 #open(KEYW,"/etc/portage/package.keywords");
1065 #while (<KEYW>) {
1066 #$found = 1 if (/portage\/pb/);
1067 #}
1068 #close(KEYW);
1069 #}
1070 #if ($found == 0) {
1071 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
1072 #}
1073
1074 # Build
1075 foreach my $f (@ebuildfile) {
1076 if ($f =~ /\.ebuild$/) {
1077 pb_distro_installdeps($f,$dtype,$pbupd);
1078 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
1079 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
1080 # Now move it where pb expects it
1081 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
1082 move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-r$pbtag.ebuild");
1083 }
1084 }
1085
1086 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-r$pbtag.ebuild";
1087 } elsif ($dtype eq "tgz") {
1088 # Slackware family
1089 $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
1090
1091 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1092 pb_system("tar xfz $src","Extracting sources");
1093 pb_system("tar xfz $src2","Extracting pbconf");
1094 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
1095 symlink "pbconf/$ddir-$dver-$arch","install" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
1096 if (-x "install/pbslack") {
1097 pb_distro_installdeps("./install/pbslack",$dtype,$pbupd);
1098 pb_system("./install/pbslack","Building software");
1099 pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
1100 }
1101 } elsif ($dtype eq "pkg") {
1102 # Solaris
1103 $made="$made $pbpkg-$pbver-$pbtag.pkg.gz";
1104 my $pkgdestdir="$ENV{'PBBUILDDIR'}/install";
1105
1106 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1107 # Will host resulting packages
1108 pb_mkdir_p("$dtype");
1109 pb_mkdir_p("$pkgdestdir/delivery");
1110 pb_system("tar xfz $src","Extracting sources under $ENV{'PBBUILDDIR'}");
1111 pb_system("tar xfz $src2","Extracting pbconf under $ENV{'PBBUILDDIR'}");
1112 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
1113 if (-f "pbconf/$ddir-$dver-$arch/pbbuild") {
1114 chmod 0755,"pbconf/$ddir-$dver-$arch/pbbuild";
1115 # pkginfo file is mandatory
1116 die "Unable to find pkginfo file in pbconf/$ddir-$dver-$arch" if (! -f "pbconf/$ddir-$dver-$arch/pkginfo");
1117 # Build
1118 pb_system("pbconf/$ddir-$dver-$arch/pbbuild $pkgdestdir/delivery","Building software and installing under $pkgdestdir/delivery");
1119 # Copy complementary files
1120 if (-f "pbconf/$ddir-$dver-$arch/prototype") {
1121 copy("pbconf/$ddir-$dver-$arch/prototype", $pkgdestdir)
1122 } else {
1123 # No prototype provided, calculating it
1124 open(PROTO,"> $pkgdestdir/prototype") || die "Unable to create prototype file";
1125 print PROTO "i pkginfo\n";
1126 print PROTO "i depend\n" if (-f "pbconf/$ddir-$dver-$arch/depend");
1127 $ENV{'PBSOLDESTDIR'} = "$pkgdestdir/delivery";
1128 find(\&create_solaris_prototype, "$pkgdestdir/delivery");
1129 }
1130 copy("pbconf/$ddir-$dver-$arch/depend", $pkgdestdir) if (-f "pbconf/$ddir-$dver-$arch/depend");
1131 copy("pbconf/$ddir-$dver-$arch/pkginfo", $pkgdestdir);
1132 pb_system("cd $pkgdestdir/delivery ; pkgmk -o -f ../prototype -r $pkgdestdir/delivery -d $ENV{'PBBUILDDIR'}/$dtype","Packaging $pbpkg","verbose");
1133 pb_system("cd $ENV{'PBBUILDDIR'}/$dtype ; echo \"\" | pkgtrans -o -n -s $ENV{'PBBUILDDIR'}/$dtype $ENV{'PBBUILDDIR'}/$pbpkg-$pbver-$pbtag.pkg all","Transforming $pbpkg","verbose");
1134 pb_system("cd $ENV{'PBBUILDDIR'} ; gzip -9f $pbpkg-$pbver-$pbtag.pkg","Compressing $pbpkg-$pbver-$pbtag.pkg","verbose");
1135 } else {
1136 pb_log(0,"No pbconf/$ddir-$dver-$arch/pbbuild file found for $pbpkg-$pbver in \n");
1137 }
1138 chdir ".." || die "Unable to chdir to parent dir";
1139 pb_system("rm -rf $pbpkg-$pbver $ENV{'PBBUILDDIR'}/$dtype $pkgdestdir", "Cleanup");
1140 } else {
1141 die "Unknown dtype format $dtype";
1142 }
1143 }
1144 # Packages check if needed
1145 if ($dtype eq "rpm") {
1146 if (-f "/usr/bin/rpmlint") {
1147 pb_system("rpmlint $made","Checking validity of rpms with rpmlint","verbose");
1148 } else {
1149 pb_log(0,"rpm packages generated: $made\n");
1150 }
1151 } elsif ($dtype eq "deb") {
1152 my $made2 = "";
1153 foreach my $f (split(/ /,$made)) {
1154 $made2 .= "../$f " if ($f =~ /\.changes$/);
1155 }
1156 if (-f "/usr/bin/lintian") {
1157 pb_system("lintian $made2","Checking validity of debs with lintian","verbose");
1158 } else {
1159 pb_log(0,"deb packages generated: $made2\n");
1160 }
1161 } else {
1162 pb_log(0,"No check done for $dtype yet\n");
1163 pb_log(0,"Packages generated: $made\n");
1164 }
1165
1166 # Keep track of what is generated so that we can get them back from VMs
1167 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
1168 print KEEP "$made\n";
1169 close(KEEP);
1170}
1171
1172sub create_solaris_prototype {
1173
1174 my $uidgid = "bin bin";
1175 my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
1176
1177 return if ($_ =~ /^$pkgdestdir$/);
1178 if (-d $_) {
1179 my $n = $File::Find::name;
1180 $n =~ s~$pkgdestdir/~~;
1181 print PROTO "d none $n 0755 $uidgid\n";
1182 } elsif (-x $_) {
1183 my $n = $File::Find::name;
1184 $n =~ s~$pkgdestdir/~~;
1185 print PROTO "f none $n 0755 $uidgid\n";
1186 } elsif (-f $_) {
1187 my $n = $File::Find::name;
1188 $n =~ s~$pkgdestdir/~~;
1189 print PROTO "f none $n 0644 $uidgid\n";
1190 }
1191}
1192
1193sub pb_build2ssh {
1194 pb_send2target("Sources");
1195}
1196
1197sub pb_pkg2ssh {
1198 pb_send2target("Packages");
1199}
1200
1201# By default deliver to the the public site hosting the
1202# ftp structure (or whatever) or a VM/VE
1203sub pb_send2target {
1204
1205 my $cmt = shift;
1206 my $v = shift || undef;
1207 my $vmexist = shift || 0; # 0 is FALSE
1208 my $vmpid = shift || 0; # 0 is FALSE
1209 my $snapme = shift || 0; # 0 is FALSE
1210
1211 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
1212 my $host = "sshhost";
1213 my $login = "sshlogin";
1214 my $dir = "sshdir";
1215 my $port = "sshport";
1216 my $conf = "sshconf";
1217 my $tmout = undef;
1218 my $path = undef;
1219 if ($cmt =~ /^VM/) {
1220 $login = "vmlogin";
1221 $dir = "pbdefdir";
1222 # Specific VM
1223 $tmout = "vmtmout";
1224 $path = "vmpath";
1225 $host = "vmhost";
1226 $port = "vmport";
1227 } elsif ($cmt =~ /^VE/) {
1228 $login = "velogin";
1229 $dir = "pbdefdir";
1230 # Specific VE
1231 $path = "vepath";
1232 $conf = "rbsconf";
1233 } elsif ($cmt eq "Web") {
1234 $host = "websshhost";
1235 $login = "websshlogin";
1236 $dir = "websshdir";
1237 $port = "websshport";
1238 }
1239 my $cmd = "";
1240 my $src = "";
1241 my ($odir,$over,$oarch) = (undef, undef, undef);
1242 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch);
1243
1244 if ($cmt ne "Announce") {
1245 # Get list of packages to build
1246 my $ptr = pb_get_pkg();
1247 @pkgs = @$ptr;
1248
1249 # Get the running distro to consider
1250 if (defined $v) {
1251 ($odir,$over,$oarch) = split(/-/,$v);
1252 }
1253 ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch) = pb_distro_init($odir,$over,$oarch);
1254 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $darch))."\n");
1255
1256 # Get list of packages to build
1257 # Get content saved in cms2build
1258 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
1259 $pkg = { } if (not defined $pkg);
1260
1261 chdir "$ENV{'PBBUILDDIR'}";
1262 foreach my $pbpkg (@pkgs) {
1263 my $vertag = $pkg->{$pbpkg};
1264 # get the version of the current package - maybe different
1265 ($pbver,$pbtag) = split(/-/,$vertag);
1266
1267 if (($cmt eq "Sources") || ($cmt =~ /V[EM]build/)) {
1268 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
1269 if ($cmd eq "") {
1270 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
1271 } else {
1272 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
1273 }
1274 } elsif ($cmt eq "Web") {
1275 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"
1276 }
1277 }
1278 # Adds conf file for availability of conf elements
1279 pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
1280 }
1281
1282 if ($cmt =~ /V[EM]build/) {
1283 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
1284 } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) {
1285 $src="$src $ENV{'PBDESTDIR'}/pbscript";
1286 } elsif ($cmt =~ /V[EM]test/) {
1287 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript $ENV{'PBDESTDIR'}/pbtest";
1288 } elsif ($cmt eq "Announce") {
1289 $src="$src $ENV{'PBTMP'}/pbscript";
1290 } elsif ($cmt eq "Packages") {
1291 # Get package list from file made during build2pkg
1292 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
1293 $src = <KEEP>;
1294 chomp($src);
1295 close(KEEP);
1296 $src="$src $ENV{'PBBUILDDIR'}/pbscript";
1297 }
1298 # Remove potential leading spaces (cause problem with basename)
1299 $src =~ s/^ *//;
1300 my $basesrc = "";
1301 foreach my $i (split(/ +/,$src)) {
1302 $basesrc .= " ".basename($i);
1303 }
1304
1305 pb_log(0,"Sources handled ($cmt): $src\n");
1306 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$path,$conf))."\n");
1307 my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
1308 # Not mandatory...
1309 my ($rbsconf,$testver,$delivery) = pb_conf_get_if($conf,"testver","delivery");
1310 my ($vtmout,$vepath);
1311 # ...Except those in virtual context
1312 if ($cmt =~ /^VE/) {
1313 ($vepath) = pb_conf_get($path);
1314 }
1315 if ($cmt =~ /^VM/) {
1316 ($vtmout) = pb_conf_get($tmout);
1317 }
1318 pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vepath,$rbsconf))."\n");
1319
1320 my $mac;
1321 if ($cmt !~ /^VE/) {
1322 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
1323 # Overwrite account value if passed as parameter
1324 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
1325 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
1326 } else {
1327 # VE
1328 # Overwrite account value if passed as parameter (typically for setup2ve)
1329 $mac = $sshlogin->{$ENV{'PBPROJ'}};
1330 $mac = $pbaccount if (defined $pbaccount);
1331 }
1332
1333 my $tdir;
1334 my $bdir;
1335 if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/)) {
1336 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}/src";
1337 } elsif (($cmt =~ /V[EM]build/) || ($cmt =~ /V[EM]test/)) {
1338 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
1339 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
1340 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
1341 $bdir =~ s|\$ENV.+\}/||;
1342 } elsif ($cmt eq "Announce") {
1343 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}";
1344 } elsif ($cmt eq "Web") {
1345 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}";
1346 } elsif ($cmt eq "Packages") {
1347 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch";
1348
1349 my $repodir = $tdir;
1350 $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
1351
1352 my ($pbrepo) = pb_conf_get("pbrepo");
1353
1354 # Repository management
1355 open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
1356 if ($dtype eq "rpm") {
1357 # Also make a pbscript to generate yum/urpmi bases
1358 print PBS << "EOF";
1359#!/bin/bash
1360# Prepare a script to ease yum setup
1361cat > $ENV{'PBPROJ'}.repo << EOT
1362[$ENV{'PBPROJ'}]
1363name=$ddir $dver $darch - $ENV{'PBPROJ'} Vanilla Packages
1364baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
1365enabled=1
1366gpgcheck=0
1367EOT
1368chmod 644 $ENV{'PBPROJ'}.repo
1369
1370# Clean up old repo content
1371rm -rf headers/ repodata/
1372# Create yum repo
1373yum-arch .
1374# Create repodata
1375createrepo .
1376EOF
1377 if ($dfam eq "md") {
1378 # For Mandriva add urpmi management
1379 print PBS << "EOF";
1380# Prepare a script to ease urpmi setup
1381cat > $ENV{'PBPROJ'}.addmedia << EOT
1382urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with media_info/hdlist.cz
1383EOT
1384chmod 755 $ENV{'PBPROJ'}.addmedia
1385
1386# Clean up old repo content
1387rm -f hdlist.cz synthesis.hdlist.cz
1388# Create urpmi repo
1389genhdlist2 --clean .
1390if [ \$\? -ne 0 ]; then
1391 genhdlist .
1392fi
1393EOF
1394 }
1395 if ($ddir eq "fedora") {
1396 # Extract the spec file to please Fedora maintainers :-(
1397 print PBS << "EOF";
1398for p in $basesrc; do
1399 echo \$p | grep -q 'src.rpm'
1400 if [ \$\? -eq 0 ]; then
1401 rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
1402 fi
1403done
1404EOF
1405 }
1406 if ($dfam eq "novell") {
1407 # Add ymp scripts for one-click install on SuSE
1408 print PBS << "EOF";
1409# Prepare a script to ease SuSE one-click install
1410# Cf: http://de.opensuse.org/1-Klick-Installation/ISV
1411#
1412cat > $ENV{'PBPROJ'}.ymp << EOT
1413<?xml version="1.0" encoding="utf-8"?>
1414<!-- vim: set sw=2 ts=2 ai et: -->
1415<metapackage xmlns:os="http://opensuse.org/Standards/One_Click_Install" xmlns="http://opensuse.org/Standards/One_Click_Install">
1416 <group><!-- The group of software, typically one for project-builder.org -->
1417 <name>$ENV{'PBPROJ'} Bundle</name> <!-- Name of the software group -->
1418 <summary>Software bundle for the $ENV{'PBPROJ'} project</summary> <!--This message is shown to the user and should describe the whole bundle -->
1419 <description>This is the summary of the $ENV{'PBPROJ'} Project
1420
1421 Details are available on a per package basis below
1422
1423 </description><!--This is also shown to the user -->
1424 <remainSubscribed>false</remainSubscribed> <!-- Don't know what it mean -->
1425 <repositories><!-- List of needed repositories -->
1426 <repository>
1427 <name>$ENV{'PBPROJ'} Repository</name> <!-- Name of the repository -->
1428 <summary>This repository contains the $ENV{'PBPROJ'} project packages.</summary> <!-- Summary of the repository -->
1429 <description>This repository contains the $ENV{'PBPROJ'} project packages.</description><!-- This description is shown to the user -->
1430 <url>$pbrepo->{$ENV{'PBPROJ'}}/$repodir</url><!--URL of repository, which is added -->
1431 </repository>
1432 </repositories>
1433 <software><!-- A List of packages, which should be added through the one-click-installation -->
1434EOT
1435for p in $basesrc; do
1436 sum=`rpm -q --qf '%{SUMMARY}' \$p`
1437 name=`rpm -q --qf '%{NAME}' \$p`
1438 desc=`rpm -q --qf '%{description}' \$p`
1439 cat >> $ENV{'PBPROJ'}.ymp << EOT
1440 <item>
1441 <name>\$name</name><!-- Name of the package, is shown to the user and used to identify the package at the repository -->
1442 <summary>\$sum</summary> <!-- Summary of the package -->
1443 <description>\$desc</description> <!-- Description, is shown to the user -->
1444 </item>
1445EOT
1446done
1447cat >> $ENV{'PBPROJ'}.ymp << EOT
1448 </software>
1449 </group>
1450</metapackage>
1451EOT
1452chmod 644 $ENV{'PBPROJ'}.ymp
1453EOF
1454 }
1455 } elsif ($dtype eq "deb") {
1456 # Also make a pbscript to generate apt bases
1457 # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
1458 my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
1459 print PBS << "EOF";
1460#!/bin/bash
1461# Prepare a script to ease apt setup
1462cat > $ENV{'PBPROJ'}.sources.list << EOT
1463deb $rpd $dver contrib
1464deb-src $rpd $dver contrib
1465EOT
1466chmod 644 $ENV{'PBPROJ'}.sources.list
1467
1468# Prepare a script to create apt info file
1469(cd .. ; for a in i386 amd64 ia64; do mkdir -p dists/$dver/contrib/binary-\$a; dpkg-scanpackages -a\$a $dver/$darch /dev/null | gzip -c9 > dists/$dver/contrib/binary-\$a/Packages.gz; done; mkdir -p dists/$dver/contrib/source; dpkg-scansources $dver/$darch /dev/null | gzip -c9 > dists/$dver/contrib/source/Sources.gz)
1470#(cd .. ; rm -f dists/$dver/Release ; apt-ftparchive release dists/$dver > dists/$dver/Release; gpg --sign -ba -o dists/$dver/Release.gpg dists/$dver/Release)
1471EOF
1472 } elsif ($dtype eq "ebuild") {
1473 # make a pbscript to generate links to latest version
1474 print PBS << "EOF";
1475#!/bin/bash
1476# Prepare a script to create correct links
1477for p in $src; do
1478 echo \$p | grep -q '.ebuild'
1479 if [ \$\? -eq 0 ]; then
1480 j=`basename \$p`
1481 pp=`echo \$j | cut -d'-' -f1`
1482 ln -sf \$j \$pp.ebuild
1483 fi
1484done
1485EOF
1486 }
1487 close(PBS);
1488 chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
1489 } else {
1490 return;
1491 }
1492
1493 # Useless for VE
1494 my $nport;
1495 if ($cmt !~ /^VE/) {
1496 $nport = $sshport->{$ENV{'PBPROJ'}};
1497 $nport = "$pbport" if (defined $pbport);
1498 }
1499
1500 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
1501 $tdir =~ s|\$ENV.+\}/||;
1502
1503 my $tm = undef;
1504 if ($cmt =~ /^VM/) {
1505 $tm = $vtmout->{$ENV{'PBPROJ'}};
1506 }
1507
1508 # ssh communication if not VE
1509 # should use a hash instead...
1510 my ($shcmd,$cpcmd,$cptarget,$cp2target);
1511 if ($cmt !~ /^VE/) {
1512 my $keyfile = pb_ssh_get(0);
1513 $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
1514 $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
1515 $cptarget = "$mac:$tdir";
1516 if ($cmt =~ /^VMbuild/) {
1517 $cp2target = "$mac:$bdir";
1518 }
1519 } else {
1520 my $tp = $vepath->{$ENV{'PBPROJ'}};
1521 ($odir,$over,$oarch) = split(/-/,$v);
1522 my $tpdir = "$tp/$odir/$over/$oarch";
1523 my ($ptr) = pb_conf_get("vetype");
1524 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1525 if ($vetype eq "chroot") {
1526 $shcmd = "sudo chroot $tpdir /bin/su - $mac -c ";
1527 } elsif ($vetype eq "schroot") {
1528 $shcmd = "schroot $tp -u $mac -- ";
1529 }
1530 $cpcmd = "sudo cp -r ";
1531 # We need to get the home dir of the target account to deliver in the right place
1532 open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd";
1533 my $homedir = "";
1534 while (<PASS>) {
1535 my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
1536 $homedir = $c6 if ($c1 =~ /^$mac$/);
1537 pb_log(3,"Homedir: $homedir - account: $c6\n");
1538 }
1539 close(PASS);
1540 $cptarget = "$tpdir/$homedir/$tdir";
1541 if ($cmt eq "VEbuild") {
1542 $cp2target = "$tpdir/$homedir/$bdir";
1543 }
1544 pb_log(2,"On VE using $cptarget as target dir to copy to\n");
1545 }
1546
1547 my $logres = "";
1548 # Do not touch when just announcing
1549 if ($cmt ne "Announce") {
1550 pb_system("$shcmd \"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 $cptarget");
1551 } else {
1552 $logres = "> ";
1553 }
1554 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
1555
1556 # For VE we need to change the owner manually
1557 if ($cmt =~ /^VE/) {
1558 pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
1559 }
1560
1561 pb_system("$shcmd \"echo \'cd $tdir ; if [ -x pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
1562 if ($cmt =~ /^V[EM]build/) {
1563 # Get back info on pkg produced, compute their name and get them from the VM
1564 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
1565 # For VE we need to change the owner manually
1566 if ($cmt eq "VEbuild") {
1567 pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID");
1568 }
1569 # return here to avoid breaking the load on VMs/VEs in case of a bad one
1570 if (not -f "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") {
1571 pb_log(0,"Problem with VM $v on $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}");
1572 return;
1573 }
1574 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
1575 my $src = <KEEP>;
1576 chomp($src);
1577 close(KEEP);
1578 $src =~ s/^ *//;
1579 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
1580 # Change pgben to make the next send2target happy
1581 my $made = "";
1582 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
1583 foreach my $p (split(/ +/,$src)) {
1584 my $j = basename($p);
1585 # For VM we don't want shell expansion to hapen locally but remotely
1586 my $delim = '\'';
1587 if ($cmt =~ /^VEbuild/) {
1588 # For VE we need to support shell expansion locally
1589 $delim = "";
1590 }
1591 pb_system("$cpcmd $cp2target/$delim$p$delim $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Recovery of package $j in $ENV{'PBBUILDDIR'}/$odir/$over");
1592 $made="$made $odir/$over/$j"; # if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
1593 }
1594 print KEEP "$made\n";
1595 close(KEEP);
1596 pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
1597
1598 # Sign packages locally
1599 if ($dtype eq "rpm") {
1600 #pb_system("rpm --addsign --define \'_signature gpg\' --define \'_gpg_name \"$ENV{'PBPACKAGER'}\"\' --define \'__gpg_sign_cmd /usr/bin/gpg --batch --no-verbose --no-armor --no-tty --no-secmem-warning -sbo %{__signature_filename} %{__plaintext_filename} --use-agent\' $made","Signing RPM packages packages");
1601 } elsif ($dtype eq "deb") {
1602 #pb_system("debsign $made","Signing DEB packages");
1603 } else {
1604 pb_log(0,"I don't know yet how to sign packages for type $dtype.\nPlease give feedback to dev team\n");
1605 }
1606
1607 # We want to send them to the ssh account so overwrite what has been done before
1608 undef $pbaccount;
1609 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
1610 pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
1611 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
1612 }
1613 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
1614 if ((! $vmexist) && ($cmt =~ /^VM/)) {
1615 # If in setupvm then takes a snapshot just before halting
1616 if ($snapme != 0) {
1617 my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype");
1618 # For monitoring control
1619 if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) {
1620 require Net::Telnet;
1621 my $t = new Net::Telnet (Timeout => 120, Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor";
1622 # move to monitor mode
1623 my @lines = $t->cmd("c");
1624 # Create a snapshot named pb
1625 @lines = $t->cmd("savevm pb");
1626 # Write the new status in the VM
1627 @lines = $t->cmd("commit all");
1628 # End
1629 @lines = $t->cmd("quit");
1630 }
1631 }
1632 my $hoption = "-p";
1633 my $hpath = "/sbin";
1634 # Solaris doesn't support -h and has halt elsewhere
1635 if ($dtype eq "pkg") {
1636 $hoption = "" ;
1637 $hpath = "/usr/sbin";
1638 }
1639 pb_system("$shcmd \"sudo $hpath/halt $hoption \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
1640 }
1641 if (($cmt =~ /^VE/) && ($snapme != 0)) {
1642 ($odir,$over,$oarch) = split(/-/,$v);
1643 my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$odir/$over/$oarch";
1644 pb_system("sudo tar cz -f $vepath->{$ENV{'PBPROJ'}}/$odir-$over-$oarch.tar.gz -C $tpdir .","Creating a snapshot of $tpdir");
1645 }
1646}
1647
1648sub pb_script2v {
1649 my $pbscript=shift;
1650 my $vtype=shift;
1651 my $pbforce=shift || 0; # Force stop of VM. Default not
1652 my $vm1=shift || undef; # Only that VM to treat
1653 my $snapme=shift || 0; # Do we have to create a snapshot
1654 my $vm;
1655 my $all;
1656
1657 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce,".Dumper($vm1).",$snapme)\n");
1658 # Prepare the script to be executed on the VM
1659 # in $ENV{'PBDESTDIR'}/pbscript
1660 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
1661 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
1662 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
1663 }
1664
1665 if (not defined $vm1) {
1666 ($vm,$all) = pb_get2v($vtype);
1667 } else {
1668 @$vm = ($vm1);
1669 }
1670 my ($vmexist,$vmpid) = (undef,undef);
1671
1672 foreach my $v (@$vm) {
1673 # Launch VM/VE
1674 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme,$pbsnap);
1675
1676 if ($vtype eq "vm") {
1677 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
1678
1679 # Skip that VM if something went wrong
1680 next if (($vmpid == 0) && ($vmexist == 0));
1681
1682 # If force stopping the VM then reset vmexist
1683 if ($pbforce == 1) {
1684 $vmpid = $vmexist;
1685 $vmexist = 0;
1686 }
1687 } else {
1688 #VE
1689 $vmexist = 0;
1690 $vmpid = 0;
1691 }
1692
1693 # Gather all required files to send them to the VM
1694 # and launch the build through pbscript
1695 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
1696 pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme);
1697
1698 }
1699}
1700
1701sub pb_launchv {
1702 my $vtype = shift;
1703 my $v = shift;
1704 my $create = shift || 0; # By default do not create a VM/VE
1705 my $snapme = shift || 0; # By default do not snap a VM/VE
1706 my $usesnap = shift || 1; # By default study the usage of the snapshot feature of VM/VE
1707
1708 # If creation or snapshot creation mode, no snapshot usable
1709 if (($create == 1) || ($snapme == 1)) {
1710 $usesnap = 0;
1711 }
1712
1713 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create,$snapme,$usesnap)\n");
1714 die "No VM/VE defined, unable to launch" if (not defined $v);
1715 # Keep only the first VM in case many were given
1716 $v =~ s/,.*//;
1717
1718 my $arch = pb_get_arch();
1719
1720 # Launch the VMs/VEs
1721 if ($vtype eq "vm") {
1722 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
1723
1724 # TODO: vmmonport should be optional
1725 my ($ptr,$ptr2,$vmpath,$vmport,$vmsize,$vmmonport) = pb_conf_get("vmtype","vmcmd","vmpath","vmport","vmsize","vmmonport");
1726 my ($vmopt,$vmtmout,$vmsnap) = pb_conf_get_if("vmopt","vmtmout","vmsnap");
1727
1728 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
1729 my $vmcmd = $ptr2->{$ENV{'PBPROJ'}};
1730 if (not defined $ENV{'PBVMOPT'}) {
1731 $ENV{'PBVMOPT'} = "";
1732 }
1733 # Save the current status for later restoration
1734 $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
1735 # Set a default timeout of 2 minutes
1736 if (not defined $ENV{'PBVMTMOUT'}) {
1737 $ENV{'PBVMTMOUT'} = "120";
1738 }
1739 if (defined $vmopt->{$v}) {
1740 $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
1741 } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
1742 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
1743 }
1744
1745 # Are we allowed to use snapshot feature
1746 if ($usesnap == 1) {
1747 if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) {
1748 $ENV{'PBVMOPT'} .= " -snapshot";
1749 } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) {
1750 $ENV{'PBVMOPT'} .= " -snapshot";
1751 } elsif ($pbsnap eq 1) {
1752 $ENV{'PBVMOPT'} .= " -snapshot";
1753 }
1754 }
1755 if ($snapme != 0) {
1756 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
1757 # Configure the monitoring to automize the creation of the 'pb' snapshot
1758 $ENV{'PBVMOPT'} .= " -serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait";
1759 # In that case no snapshot call needed
1760 $ENV{'PBVMOPT'} =~ s/ -snapshot//;
1761 }
1762 }
1763 if (defined $vmtmout->{$v}) {
1764 $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
1765 } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
1766 $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
1767 }
1768 my $nport = $vmport->{$ENV{'PBPROJ'}};
1769 $nport = "$pbport" if (defined $pbport);
1770
1771 my $cmd;
1772 my $vmm; # has to be used for pb_check_ps
1773 if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
1774 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
1775 if (($create != 0) || (defined $iso)) {
1776 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
1777 }
1778 # Always redirect the network and always try to use a 'pb' snapshot
1779 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 -loadvm pb $vmm"
1780 } elsif ($vmtype eq "xen") {
1781 } elsif ($vmtype eq "vmware") {
1782 } else {
1783 die "VM of type $vmtype not supported. Report to the dev team";
1784 }
1785 # Restore the ENV VAR Value
1786 $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
1787
1788 my ($tmpcmd,$void) = split(/ +/,$cmd);
1789 my $vmexist = pb_check_ps($tmpcmd,$vmm);
1790 my $vmpid = 0;
1791 if (! $vmexist) {
1792 if ($create != 0) {
1793 die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
1794 if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
1795 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
1796 } elsif ($vmtype eq "vmware") {
1797 } else {
1798 }
1799 }
1800 if (! -f "$vmm") {
1801 pb_log(0,"Unable to find VM $vmm\n");
1802 } else {
1803 pb_system("$cmd &","Launching the VM $vmm");
1804 pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
1805 $vmpid = pb_check_ps($tmpcmd,$vmm);
1806 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
1807 }
1808 } else {
1809 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
1810 }
1811 pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
1812 return($vmexist,$vmpid);
1813 # VE here
1814 } else {
1815 # Get distro context
1816 my ($name,$ver,$darch) = split(/-/,$v);
1817 chomp($darch);
1818 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
1819
1820 # Get VE context
1821 my ($ptr,$vepath) = pb_conf_get("vetype","vepath");
1822 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1823
1824 # We can probably only get those params now we have the distro context
1825 my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv");
1826
1827 # We need to avoid umask propagation to the VE
1828 umask 0022;
1829
1830 if (($vetype eq "chroot") || ($vetype eq "schroot")) {
1831 # Architecture consistency
1832 if ($arch ne $darch) {
1833 die "Unable to launch a VE of architecture $darch on a $arch platform" if (($darch eq "x86_64") && ($arch =~ /i?86/));
1834 }
1835
1836 my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
1837 if (($create != 0) || ((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) {
1838 my ($rbsopt1) = pb_conf_get_if("rbsopt");
1839
1840 # We have to rebuild the chroot
1841 if ($dtype eq "rpm") {
1842
1843 # Which tool is used
1844 my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}};
1845
1846 # Get potential rbs option
1847 my $rbsopt = "";
1848 if (defined $rbsopt1) {
1849 if (defined $rbsopt1->{$verpmstyle}) {
1850 $rbsopt = $rbsopt1->{$verpmstyle};
1851 } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
1852 $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
1853 } else {
1854 $rbsopt = "";
1855 }
1856 }
1857
1858 my $postinstall = pb_get_postinstall($ddir,$dver,$darch,$rbspi,$verpmstyle);
1859 if ($verpmstyle eq "rinse") {
1860 # Need to reshape the mirrors generated with local before-post-install script
1861 my $b4post = "--before-post-install ";
1862 my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbsb4pi);
1863 if ($postparam eq "") {
1864 $b4post = "";
1865 } else {
1866 $b4post .= $postparam;
1867 }
1868
1869 # Need to reshape the package list for pb
1870 my $addpkgs;
1871 $postparam = "";
1872 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
1873 if ($postparam eq "") {
1874 $addpkgs = "";
1875 } else {
1876 my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
1877 open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
1878 foreach my $p (split(/,/,$postparam)) {
1879 print PKG "$p\n";
1880 }
1881 close(PKG);
1882 $addpkgs = "--add-pkg-list $pkgfile";
1883 }
1884
1885 my $rinseverb = "";
1886 $rinseverb = "--verbose" if ($pbdebug gt 0);
1887 my ($rbsconf) = pb_conf_get("rbsconf");
1888
1889 pb_system("sudo /usr/sbin/rinse --directory \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" --arch \"$darch\" --distribution \"$ddir-$dver\" --config \"$rbsconf->{$ENV{'PBPROJ'}}\" $b4post $postinstall $rbsopt $addpkgs $rinseverb","Creating the rinse VE for $ddir-$dver ($darch)", "verbose");
1890 } elsif ($verpmstyle eq "rpmbootstrap") {
1891 my $rbsverb = "";
1892 foreach my $i (1..$pbdebug) {
1893 $rbsverb .= " -v";
1894 }
1895 my $addpkgs = "";
1896 my $postparam = "";
1897 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
1898 if ($postparam eq "") {
1899 $addpkgs = "";
1900 } else {
1901 $addpkgs = "-a $postparam";
1902 }
1903 pb_system("sudo /usr/bin/rpmbootstrap $rbsopt $postinstall $addpkgs $ddir-$dver-$darch $rbsverb","Creating the rpmbootstrap VE for $ddir-$dver ($darch)", "verbose");
1904 } elsif ($verpmstyle eq "mock") {
1905 my ($rbsconf) = pb_conf_get("rbsconf");
1906 pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v $rbsopt","Creating the mock VE for $ddir-$dver ($darch)");
1907 # Once setup we need to install some packages, the pb account, ...
1908 pb_system("sudo /usr/sbin/mock --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
1909 } else {
1910 die "Unknown verpmtype type $verpmstyle. Report to dev team";
1911 }
1912 } elsif ($dtype eq "deb") {
1913 my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
1914
1915 my $codename = pb_distro_get_param($ddir,$dver,$darch,$oscodename);
1916 my $postparam = "";
1917 my $addpkgs;
1918 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
1919 if ($postparam eq "") {
1920 $addpkgs = "";
1921 } else {
1922 $addpkgs = "--include $postparam";
1923 }
1924 my $debmir = "";
1925 $debmir .= pb_distro_get_param($ddir,$dver,$darch,$rbsmirrorsrv);
1926
1927 # Get potential rbs option
1928 my $rbsopt = "";
1929 if (defined $rbsopt1) {
1930 if (defined $rbsopt1->{$vedebstyle}) {
1931 $rbsopt = $rbsopt1->{$vedebstyle};
1932 } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
1933 $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
1934 } else {
1935 $rbsopt = "";
1936 }
1937 }
1938
1939 # debootstrap works with amd64 not x86_64
1940 my $debarch = $darch;
1941 $debarch = "amd64" if ($darch eq "x86_64");
1942 if ($vedebstyle eq "debootstrap") {
1943 my $dbsverb = "";
1944 $dbsverb = "--verbose" if ($pbdebug gt 0);
1945
1946 # Some perl modules are in Universe on Ubuntu
1947 $rbsopt .= " --components=main,universe" if ($ddir eq "ubuntu");
1948
1949 pb_system("sudo /usr/sbin/debootstrap $dbsverb $rbsopt --arch=$debarch $addpkgs $codename \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" $debmir","Creating the debootstrap VE for $ddir-$dver ($darch)", "verbose");
1950 # debootstrap doesn't create an /etc/hosts file
1951 if (! -f "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts" ) {
1952 pb_system("sudo cp /etc/hosts $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts");
1953 }
1954 } else {
1955 die "Unknown vedebtype type $vedebstyle. Report to dev team";
1956 }
1957 } elsif ($dtype eq "ebuild") {
1958 die "Please teach the dev team how to build gentoo chroot";
1959 } else {
1960 die "Unknown distribution type $dtype. Report to dev team";
1961 }
1962 }
1963 # Fix modes to allow access to the VE for pb user
1964 pb_system("sudo chmod 755 $vepath->{$ENV{'PBPROJ'}}/$ddir $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch","Fixing permissions");
1965
1966 # Test if an existing snapshot exists and use it if appropriate
1967 # And also use it of no local extracted VE is present
1968 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
1969 (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) ||
1970 ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i)) ||
1971 ($pbsnap eq 1) ||
1972 (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch"))) {
1973 pb_system("sudo rm -rf $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch ; sudo mkdir -p $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch ; sudo tar xz -C $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Extracting snapshot of $ddir-$dver-$darch.tar.gz under $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch");
1974 }
1975 # Nothing more to do for VE. No real launch
1976 } else {
1977 die "VE of type $vetype not supported. Report to the dev team";
1978 }
1979 }
1980}
1981
1982# Return string for date synchro
1983sub pb_date2v {
1984
1985my $vtype = shift;
1986my $v = shift;
1987
1988my ($ntp) = pb_conf_get_if($vtype."ntp");
1989my $vntp = $ntp->{$ENV{'PBPROJ'}} if (defined $ntp);
1990my $ntpline;
1991
1992if (defined $vntp) {
1993 my ($ntpcmd) = pb_conf_get($vtype."ntpcmd");
1994 my $vntpcmd;
1995 if (defined $ntpcmd->{$v}) {
1996 $vntpcmd = $ntpcmd->{$v};
1997 } elsif (defined $ntpcmd->{$ENV{'PBPROJ'}}) {
1998 $vntpcmd = $ntpcmd->{$ENV{'PBPROJ'}};
1999 } else {
2000 $vntpcmd = "/bin/true";
2001 }
2002 $ntpline = "sudo $vntpcmd $vntp";
2003} else {
2004 $ntpline = undef;
2005}
2006# Force new date to be in the future compared to the date
2007# of the host by adding 1 minute
2008my @date=pb_get_date();
2009$date[1]++;
2010my $upddate = strftime("%m%d%H%M%Y", @date);
2011my $dateline = "sudo date $upddate";
2012return($ntpline,$dateline);
2013}
2014
2015sub pb_build2v {
2016
2017my $vtype = shift;
2018my $action = shift || "build";
2019
2020my ($v,$all) = pb_get2v($vtype);
2021
2022# Send tar files when we do a global generation
2023pb_build2ssh() if (($all == 1) && ($action eq "build"));
2024
2025my ($vmexist,$vmpid) = (undef,undef);
2026
2027foreach my $v (@$v) {
2028 # Prepare the script to be executed on the VM/VE
2029 # in $ENV{'PBDESTDIR'}/pbscript
2030 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
2031 print SCRIPT "#!/bin/bash\n";
2032
2033 # Transmit the verbosity level to the virtual env/mach.
2034 my $verbose = "";
2035 my $i = 0; # minimal debug level
2036 while ($i lt $pbdebug) {
2037 $verbose .= "-v ";
2038 $i++;
2039 }
2040 # Activate script verbosity if at least 2 for pbdebug
2041 print SCRIPT "set -x\n" if ($i gt 1);
2042 # Quiet if asked to be so on the original system
2043 $verbose = "-q" if ($pbdebug eq -1);
2044
2045 print SCRIPT "echo ... Execution needed\n";
2046 print SCRIPT "# This is in directory delivery\n";
2047 print SCRIPT "# Setup the variables required for building\n";
2048 print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
2049
2050 if ($action eq "build") {
2051 print SCRIPT "# Preparation for pb\n";
2052 print SCRIPT "mv .pbrc \$HOME\n";
2053 print SCRIPT "cd ..\n";
2054 }
2055
2056 # VE needs a good /proc
2057 if ($vtype eq "ve") {
2058 print SCRIPT "sudo mount -t proc /proc /proc\n";
2059 }
2060
2061 my ($ntpline,$dateline) = pb_date2v($vtype,$v);
2062 print SCRIPT "# Time sync\n";
2063 print SCRIPT "echo 'setting up date with '";
2064 if (defined $ntpline) {
2065 print SCRIPT "echo $ntpline\n";
2066 print SCRIPT "$ntpline\n";
2067 } else {
2068 print SCRIPT "echo $dateline\n";
2069 print SCRIPT "$dateline\n";
2070 }
2071 # Use potential local proxy declaration in case we need it to download repo, pkgs, ...
2072 if (defined $ENV{'http_proxy'}) {
2073 print SCRIPT "export http_proxy=\"$ENV{'http_proxy'}\"\n";
2074 }
2075
2076 if (defined $ENV{'ftp_proxy'}) {
2077 print SCRIPT "export ftp_proxy=\"$ENV{'ftp_proxy'}\"\n";
2078 }
2079
2080 # Get list of packages to build/test and get some ENV vars as well
2081 my $ptr = pb_get_pkg();
2082 @pkgs = @$ptr;
2083 my $p = join(' ',@pkgs) if (@pkgs);
2084 print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
2085 print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
2086 print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
2087
2088 # We may need to do some other tasks before building. Read a script here to finish setup
2089 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
2090 print SCRIPT "# Special pre-instructions to be launched\n";
2091 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
2092 }
2093
2094 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
2095 print SCRIPT "# Special pre-$action instructions to be launched\n";
2096 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
2097 }
2098
2099 print SCRIPT "# $action\n";
2100 print SCRIPT "echo $action"."ing packages on $vtype...\n";
2101
2102 if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
2103 die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
2104 }
2105 print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
2106
2107 if ($vtype eq "ve") {
2108 print SCRIPT "sudo umount /proc\n";
2109 }
2110
2111 # We may need to do some other tasks after building. Read a script here to exit properly
2112 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
2113 print SCRIPT "# Special post-$action instructions to be launched\n";
2114 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
2115 }
2116
2117 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
2118 print SCRIPT "# Special post-instructions to be launched\n";
2119 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
2120 }
2121
2122 close(SCRIPT);
2123 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
2124
2125 # Launch the VM/VE
2126 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
2127
2128 if ($vtype eq "vm") {
2129 # Skip that VM if it something went wrong
2130 next if (($vmpid == 0) && ($vmexist == 0));
2131 } else {
2132 # VE
2133 $vmexist = 0;
2134 $vmpid = 0;
2135 }
2136 # Gather all required files to send them to the VM/VE
2137 # and launch the build through pbscript
2138 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
2139 pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
2140}
2141}
2142
2143
2144sub pb_clean {
2145
2146 my $sleep=10;
2147 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
2148 die "Unable to get env var PBBUILDDIR" if (not defined $ENV{'PBBUILDDIR'});
2149 pb_log(0,"We will now wait $sleep s before removing both directories\n$ENV{'PBDESTDIR'} and $ENV{'PBBUILDDIR'}.\nPlease break me if this is wrong\n");
2150 sleep $sleep;
2151 pb_rm_rf($ENV{'PBDESTDIR'});
2152 pb_rm_rf($ENV{'PBBUILDDIR'});
2153}
2154
2155sub pb_newver {
2156
2157 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
2158
2159 # Need this call for PBDIR
2160 my ($scheme2,$uri) = pb_cms_init($pbinit);
2161
2162 my ($pbconf,$pburl) = pb_conf_get("pbconfurl","pburl");
2163 $uri = $pbconf->{$ENV{'PBPROJ'}};
2164 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
2165
2166 # Checking CMS repositories status
2167 ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
2168
2169 if ($scheme !~ /^svn/) {
2170 die "Only SVN is supported at the moment";
2171 }
2172
2173 my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
2174 die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
2175
2176 $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
2177 die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
2178
2179 # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
2180 # we want to get for the root of the new URL
2181
2182 my $tmp = $ENV{'PBROOTDIR'};
2183 $tmp =~ s|^$ENV{'PBCONFDIR'}||;
2184
2185 my $newurl = "$uri/".dirname($tmp)."/$newver";
2186 # Should probably use projver in the old file
2187 my $oldver= basename($tmp);
2188
2189 # Duplicate and extract project-builder part
2190 pb_log(2,"Copying $uri/$tmp to $newurl\n");
2191 pb_cms_copy($scheme,"$uri/$tmp",$newurl);
2192 pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
2193 pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
2194
2195 # Duplicate and extract project
2196 my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/".dirname($tmp)."/$newver";
2197
2198 pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$tmp to $newurl2\n");
2199 pb_cms_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$tmp",$newurl2);
2200 pb_log(2,"Checkout $newurl2 to $ENV{'PBDIR'}/../$newver\n");
2201 pb_cms_up($scheme2,"$ENV{'PBDIR'}/..");
2202
2203 # Update the .pb file
2204 open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
2205 open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
2206 while(<FILE>) {
2207 s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
2208 pb_log(0,"Changing projver from $oldver to $newver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/);
2209 pb_log(0,"Commenting testver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
2210 s/^testver/#testver/;
2211 print OUT $_;
2212 pb_log(0,"Please check delivery ($_) in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^delivery/);
2213 }
2214 close(FILE);
2215 close(OUT);
2216 rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
2217
2218 # Checking pbcl files
2219 foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
2220 # Compute new pbcl file
2221 my $f2 = $f;
2222 $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBROOTDIR'}/../$newver/|;
2223 open(PBCL,$f) || die "Unable to open $f";
2224 my $foundnew = 0;
2225 while (<PBCL>) {
2226 $foundnew = 1 if (/^$newver \(/);
2227 }
2228 close(PBCL);
2229 open(OUT,"> $f2") || die "Unable to write to $f2: $!";
2230 open(PBCL,$f) || die "Unable to open $f";
2231 while (<PBCL>) {
2232 print OUT "$_" if (not /^$oldver \(/);
2233 if ((/^$oldver \(/) && ($foundnew == 0)) {
2234 print OUT "$newver ($pbdate)\n";
2235 print OUT "- TBD\n";
2236 print OUT "\n";
2237 pb_log(0,"WARNING: version $newver not found in $f so added to $f2...\n") if ($foundnew == 0);
2238 }
2239 }
2240 close(OUT);
2241 close(PBCL);
2242 }
2243
2244 pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
2245 pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
2246}
2247
2248#
2249# Return the list of VMs/VEs we are working on
2250# $all is a flag to know if we return all of them
2251# or only some (if all we publish also tar files in addition to pkgs
2252#
2253sub pb_get2v {
2254
2255my $vtype = shift;
2256my @v;
2257my $all = 0;
2258my $vlist;
2259my $pbv = 'PBV';
2260
2261if ($vtype eq "vm") {
2262 $vlist = "vmlist";
2263} elsif ($vtype eq "ve") {
2264 $vlist = "velist";
2265}
2266# Get VM/VE list
2267if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
2268 my ($ptr) = pb_conf_get($vlist);
2269 $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
2270 $all = 1;
2271}
2272pb_log(2,"$vtype: $ENV{$pbv}\n");
2273@v = split(/,/,$ENV{$pbv});
2274return(\@v,$all);
2275}
2276
2277# Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
2278# Needs to use root account to connect to the VM/VE
2279# pb will take your local public SSH key to access
2280# the pb account in the VM later on if needed
2281sub pb_setup2v {
2282
2283my $vtype = shift;
2284
2285my ($vm,$all) = pb_get2v($vtype);
2286
2287# Script generated
2288my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
2289
2290foreach my $v (@$vm) {
2291 # Deal with date sync.
2292 my ($ntpline,$dateline) = pb_date2v($vtype,$v);
2293
2294 # Get distro context
2295 my ($name,$ver,$darch) = split(/-/,$v);
2296 chomp($darch);
2297 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd) = pb_distro_init($name,$ver,$darch);
2298
2299 # Name of the account to deal with for VM/VE
2300 # Do not use the one passed potentially with -a
2301 my ($pbac) = pb_conf_get($vtype."login");
2302 my ($key,$zero0,$zero1,$zero2);
2303 my ($vmexist,$vmpid);
2304
2305 # Prepare the script to be executed on the VM/VE
2306 # in $ENV{'PBDESTDIR'}/setupv
2307 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2308
2309 print SCRIPT << 'EOF';
2310#!/usr/bin/perl -w
2311
2312use strict;
2313use File::Copy;
2314
2315# We should not need in this script more functions than what is provided
2316# by Base and Distribution to avoid problems at exec time.
2317# They are appended at the end.
2318
2319our $pbdebug;
2320our $pbLOG;
2321our $pbsynmsg = "pbscript";
2322our $pbdisplaytype = "text";
2323our $pblocale = "";
2324pb_log_init($pbdebug, $pbLOG);
2325pb_temp_init();
2326
2327EOF
2328
2329 # Launch the VM/VE - Usage of snapshot disabled
2330 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,0,0);
2331
2332 if ($vtype eq "vm") {
2333 # Prepare the key to be used and transfered remotely
2334 my $keyfile = pb_ssh_get(1);
2335
2336 my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
2337 my $nport = $vmport->{$ENV{'PBPROJ'}};
2338 $nport = "$pbport" if (defined $pbport);
2339
2340 # Skip that VM if something went wrong
2341 next if (($vmpid == 0) && ($vmexist == 0));
2342
2343 # Store the pub key part in a variable
2344 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
2345 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
2346 close(FILE);
2347
2348 $key = "\Q$zero1";
2349
2350 pb_system("cat $keyfile.pub | ssh -q -o UserKnownHostsFile=/dev/null -p $nport -i $keyfile root\@$vmhost->{$ENV{'PBPROJ'}} \"mkdir -p .ssh ; chmod 700 .ssh ; cat >> .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys ; if [ -x /usr/bin/chcon ]; then /usr/bin/chcon -Rt home_ssh_t .ssh 2> /dev/null; fi\"","Copying local keys to $vtype. This may require the root password");
2351 # once this is done, we can do what we want on the VM remotely
2352 } elsif ($vtype eq "ve") {
2353 print SCRIPT << "EOF";
2354# For VE we need a good null dev
2355pb_system("rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null");
2356EOF
2357 print SCRIPT << "EOF";
2358# For VE we first need to mount some FS
2359pb_system("mount -t proc /proc /proc");
2360
2361EOF
2362 }
2363
2364if ($vtype eq "vm") {
2365 print SCRIPT << 'EOF';
2366# Removes duplicate in .ssh/authorized_keys of our key if needed
2367#
2368my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
2369open(PBFILE,$file1) || die "Unable to open $file1";
2370open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
2371my $count = 0;
2372while (<PBFILE>) {
2373
2374EOF
2375 print SCRIPT << "EOF";
2376 if (/ $key /) {
2377 \$count++;
2378 }
2379print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
2380}
2381close(PBFILE);
2382close(PBOUT);
2383rename("\$file1.new",\$file1);
2384chmod 0600,\$file1;
2385
2386# Sync date
2387EOF
2388 if (defined $ntpline) {
2389 print SCRIPT "pb_system(\"$ntpline\");\n";
2390 } else {
2391 print SCRIPT "pb_system(\"$dateline\");\n";
2392 }
2393 }
2394 print SCRIPT << 'EOF';
2395
2396# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
2397#
2398my $file="/etc/passwd";
2399open(PBFILE,$file) || die "Unable to open $file";
2400my $found = 0;
2401while (<PBFILE>) {
2402EOF
2403 print SCRIPT << "EOF";
2404 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
2405EOF
2406
2407my $home = "/home";
2408# Solaris doesn't like that we use /home
2409$home = "/export/home" if ($dtype eq "pkg");
2410
2411 print SCRIPT << "EOF";
2412}
2413close(PBFILE);
2414
2415if ( \$found == 0 ) {
2416 if ( ! -d "$home" ) {
2417 pb_mkdir_p("$home");
2418 }
2419EOF
2420 print SCRIPT << "EOF";
2421pb_system("/usr/sbin/groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
2422pb_system("/usr/sbin/useradd -g $pbac->{$ENV{'PBPROJ'}} -m -d $home/$pbac->{$ENV{'PBPROJ'}} $pbac->{$ENV{'PBPROJ'}}","Adding user $pbac->{$ENV{'PBPROJ'}} (group $pbac->{$ENV{'PBPROJ'}} - home $home/$pbac->{$ENV{'PBPROJ'}})");
2423}
2424EOF
2425
2426 # Copy the content of our local conf file to the VM/VE
2427 my $content = pb_get_content(pb_distro_conffile());
2428 print SCRIPT << "EOF";
2429 #
2430 # Create a temporary local conf file for distribution support
2431 # This is created here before its use later. Its place is hardcoded, so no choice for the path
2432 #
2433 my \$tempconf = pb_distro_conffile();
2434 pb_mkdir_p(dirname(\$tempconf));
2435 open(CONF,"> \$tempconf") || die "Unable to create \$tempconf";
2436 print CONF q{$content};
2437 close(CONF);
2438EOF
2439
2440 if ($vtype eq "vm") {
2441 print SCRIPT << "EOF";
2442# allow ssh entry to build
2443#
2444mkdir "$home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
2445# Allow those accessing root to access the build account
2446copy("\$ENV{'HOME'}/.ssh/authorized_keys","$home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
2447chmod 0600,".ssh/authorized_keys";
2448pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} $home/$pbac->{$ENV{'PBPROJ'}}","Finish setting up the account env for $pbac->{$ENV{'PBPROJ'}}");
2449
2450EOF
2451}
2452 print SCRIPT << 'EOF';
2453# No passwd for build account only keys
2454$file="/etc/shadow";
2455if (-f $file) {
2456 open(PBFILE,$file) || die "Unable to open $file";
2457 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2458 while (<PBFILE>) {
2459EOF
2460 print SCRIPT << "EOF";
2461 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
2462 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
2463 s/^$pbac->{$ENV{'PBPROJ'}}:\\*LK\\*:/$pbac->{$ENV{'PBPROJ'}}:NP:/; #Solaris e.g.
2464EOF
2465 print SCRIPT << 'EOF';
2466 print PBOUT $_;
2467 }
2468 close(PBFILE);
2469 close(PBOUT);
2470 rename("$file.new",$file);
2471 chmod 0640,$file;
2472 }
2473
2474# Keep the VM in text mode
2475$file="/etc/inittab";
2476if (-f $file) {
2477 open(PBFILE,$file) || die "Unable to open $file";
2478 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2479 while (<PBFILE>) {
2480 s/^(..):5:initdefault:$/$1:3:initdefault:/;
2481 print PBOUT $_;
2482 }
2483 close(PBFILE);
2484 close(PBOUT);
2485 rename("$file.new",$file);
2486 chmod 0640,$file;
2487}
2488
2489# pb has to be added to portage group on gentoo
2490
2491# We need to have that pb_distro_init function
2492# Get it from Project-Builder::Distribution
2493# And we now need the conf file required for this to work created above
2494
2495my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch) = pb_distro_init();
2496print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $darch))."\n";
2497
2498# Adapt sudoers
2499# sudo is not default on Solaris and needs to be installed first
2500# from http://www.sunfreeware.com/programlistsparc10.html#sudo
2501if ($dtype eq "pkg") {
2502 $file="/usr/local/etc/sudoers";
2503} else {
2504 $file="/etc/sudoers";
2505}
2506open(PBFILE,$file) || die "Unable to open $file";
2507open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2508while (<PBFILE>) {
2509EOF
2510 print SCRIPT << "EOF";
2511 next if (/^$pbac->{$ENV{'PBPROJ'}} /);
2512EOF
2513 print SCRIPT << 'EOF';
2514 s/Defaults[ \t]+requiretty//;
2515 print PBOUT $_;
2516}
2517close(PBFILE);
2518EOF
2519 print SCRIPT << "EOF";
2520# Some distro force requiretty at compile time, so disable here
2521print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} !requiretty\n";
2522print PBOUT "Defaults:root !requiretty\n";
2523# This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
2524print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} env_keep += \\\"http_proxy ftp_proxy\\\"\n";
2525print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
2526EOF
2527 print SCRIPT << 'EOF';
2528close(PBOUT);
2529rename("$file.new",$file);
2530chmod 0440,$file;
2531
2532EOF
2533
2534 # We may need a proxy configuration. Get it from the local env
2535
2536 if (defined $ENV{'http_proxy'}) {
2537 print SCRIPT "\$ENV\{'http_proxy'\}=\"$ENV{'http_proxy'}\";\n";
2538 }
2539
2540 if (defined $ENV{'ftp_proxy'}) {
2541 print SCRIPT "\$ENV\{'ftp_proxy'\}=\"$ENV{'ftp_proxy'}\";\n";
2542 }
2543
2544 print SCRIPT << 'EOF';
2545
2546 my ($ospkgdep,$osperldep,$osperlver) = pb_conf_get_if("ospkgdep","osperldep","osperlver");
2547
2548 # First install all required packages
2549 pb_system("yum clean all","Cleaning yum env") if (($ddir eq "fedora") || ($ddir eq "asianux") || ($ddir eq "rhel"));
2550 my $pkgdep = pb_distro_get_param($ddir,$dver,$darch,$ospkgdep,$dfam,$dtype,$dos);
2551 pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,join(' ',split(/,/,$pkgdep))));
2552
2553 # Then install manually the missing perl modules
2554 my $perldep = pb_distro_get_param($ddir,$dver,$darch,$osperldep,$dfam,$dtype,$dos);
2555 foreach my $m (split(/,/,$perldep)) {
2556 # Skip empty deps
2557 next if ($m =~ /^\s*$/);
2558 my $dir = $m;
2559 $dir =~ s/-.*//;
2560 pb_system("echo \"rm -rf $m* ; wget http://search.cpan.org/CPAN/modules/by-module/$dir/$m-$osperlver->{$m}.tar.gz ; gzip -cd $m-$osperlver->{$m}.tar.gz | tar xf - ; cd $m* ; if [ -f Build.PL ]; then perl Build.PL; ./Build ; ./Build install ; else perl Makefile.PL; make ; make install ; fi; cd .. ; rm -rf $m*\" | bash" ,"Installing perl module $m-$osperlver->{$m}");
2561 }
2562
2563# Suse wants sudoers as 640
2564if ((($ddir eq "sles") && (($dver =~ /10/) || ($dver =~ /9/))) || (($ddir eq "opensuse") && ($dver =~ /10.[012]/))) {
2565 chmod 0640,$file;
2566}
2567
2568pb_system("rm -rf ProjectBuilder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/ProjectBuilder-latest.tar.gz ; gzip -cd ProjectBuilder-latest.tar.gz | tar xf - ; cd ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf ProjectBuilder-* ; rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; gzip -cd project-builder-latest.tar.gz | tar xf - ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf project-builder-* ;","Building Project-Builder");
2569pb_system("pb 2>&1 | head -5",undef,"verbose");
2570EOF
2571 if ($vtype eq "ve") {
2572 print SCRIPT << 'EOF';
2573# For VE we need to umount some FS at the end
2574
2575pb_system("umount /proc");
2576
2577# Create a basic network file if not already there
2578
2579my $nf="/etc/sysconfig/network";
2580if ((! -f $nf) && ($dtype eq "rpm")) {
2581 open(NF,"> $nf") || die "Unable to create $nf";
2582 print NF "NETWORKING=yes\n";
2583 print NF "HOSTNAME=localhost\n";
2584 close(NF);
2585}
2586chmod 0755,$nf;
2587EOF
2588 }
2589
2590 # Adds pb_distro_init and all functions needed from ProjectBuilder::Distribution and Base
2591 foreach my $d (@INC) {
2592 my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm","$d/ProjectBuilder/Conf.pm");
2593 foreach my $f (@f) {
2594 if (-f "$f") {
2595 open(PBD,"$f") || die "Unable to open $f";
2596 while (<PBD>) {
2597 next if (/^package/);
2598 next if (/^use Exporter/);
2599 next if (/^use ProjectBuilder::/);
2600 next if (/^our /);
2601 print SCRIPT $_;
2602 }
2603 close(PBD);
2604 }
2605 }
2606 }
2607 close(SCRIPT);
2608 chmod 0755,"$pbscript";
2609
2610 # That build script needs to be run as root and force stop of VM at end
2611 $pbaccount = "root";
2612
2613 # Force shutdown of VM exept if it was already launched
2614 my $pbforce = 0;
2615 if ((! $vmexist) && ($vtype eq "vm")) {
2616 $pbforce = 1;
2617 }
2618
2619 pb_script2v($pbscript,$vtype,$pbforce,$v);
2620}
2621return;
2622}
2623
2624# Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
2625sub pb_snap2v {
2626
2627my $vtype = shift;
2628
2629my ($vm,$all) = pb_get2v($vtype);
2630
2631# Script generated
2632my $pbscript = "$ENV{'PBDESTDIR'}/snapv";
2633
2634my ($pbac) = pb_conf_get($vtype."login");
2635
2636foreach my $v (@$vm) {
2637 # Get distro context
2638 my ($name,$ver,$darch) = split(/-/,$v);
2639 chomp($darch);
2640 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
2641 my ($vepath) = pb_conf_get("vepath");
2642
2643 # Test if an existing snapshot exists and remove it if there is a VE
2644 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
2645 (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch")) {
2646 pb_system("sudo rm -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Removing previous snapshot $ddir-$dver-$darch.tar.gz");
2647 }
2648
2649 # Name of the account to deal with for VM/VE
2650 # Do not use the one passed potentially with -a
2651 my ($vmexist,$vmpid);
2652
2653 # Prepare the script to be executed on the VM/VE
2654 # in $ENV{'PBDESTDIR'}/setupv
2655 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2656
2657 print SCRIPT << 'EOF';
2658 #!/bin/bash
2659 sleep 2
2660EOF
2661 close(SCRIPT);
2662 chmod 0755,"$pbscript";
2663
2664 # Force shutdown of VM/VE
2665 # Force snapshot of VM/VE
2666 pb_script2v($pbscript,$vtype,1,$v,1);
2667}
2668return;
2669}
2670
2671sub pb_announce {
2672
2673 # Get all required parameters
2674 my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
2675 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
2676 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
2677 my @pkgs = @$pkg;
2678 my %pkgs;
2679 my $first = 0;
2680
2681 # Command to find packages on repo
2682 my $findstr = "find . ";
2683 # Generated announce files
2684 my @files;
2685
2686 foreach my $pbpkg (@pkgs) {
2687 if ($first != 0) {
2688 $findstr .= "-o ";
2689 }
2690 $first++;
2691 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
2692 $pbver = $pkgv->{$pbpkg};
2693 } else {
2694 $pbver = $ENV{'PBPROJVER'};
2695 }
2696 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
2697 $pbtag = $pkgt->{$pbpkg};
2698 } else {
2699 $pbtag = $ENV{'PBPROJTAG'};
2700 }
2701
2702 # TODO: use virtual/real names here now
2703 $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver*\.ebuild\' ";
2704
2705 my $chglog;
2706
2707 # Get project info on log file and generate tmp files used later on
2708 pb_cms_init($pbinit);
2709 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
2710 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
2711 $chglog = undef if (! -f $chglog);
2712
2713 open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
2714 my %pb;
2715 $pb{'dtype'} = "announce";
2716 $pb{'realpkg'} = $pbpkg;
2717 $pb{'ver'} = $pbver;
2718 $pb{'tag'} = $pbtag;
2719 $pb{'suf'} = "N/A"; # Should not be empty even if unused
2720 $pb{'date'} = $pbdate;
2721 $pb{'chglog'} = $chglog;
2722 $pb{'packager'} = $pbpackager;
2723 $pb{'proj'} = $ENV{'PBPROJ'};
2724 $pb{'repo'} = $pbrepo;
2725 pb_changelog(\%pb,\*OUT,"yes");
2726 close(OUT);
2727 push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
2728 }
2729 $findstr .= " | grep -Ev \'src.rpm\'";
2730
2731 # Prepare the command to run and execute it
2732 open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
2733 print PBS "$findstr\n";
2734 close(PBS);
2735 chmod 0755,"$ENV{'PBTMP'}/pbscript";
2736 pb_send2target("Announce");
2737
2738 # Get subject line
2739 my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
2740 pb_log(0,"Please enter the title of your announce\n");
2741 pb_log(0,"(By default: $sl)\n");
2742 my $sl2 = <STDIN>;
2743 $sl = $sl2 if ($sl2 !~ /^$/);
2744
2745 # Prepare a template of announce
2746 open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
2747 print ANN << "EOF";
2748$sl</p>
2749
2750<p>The project team is happy to announce the availability of a newest version of $ENV{'PBPROJ'} $ENV{'PBPROJVER'}. Enjoy it as usual!</p>
2751<p>
2752Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
2753</p>
2754<p>
2755EOF
2756 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
2757 my $col = 2;
2758 my $i = 1;
2759 print ANN << 'EOF';
2760<TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
2761<TR>
2762EOF
2763 while (<LOG>) {
2764 print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
2765 $i++;
2766 if ($i > $col) {
2767 print ANN "</TR>\n<TR>";
2768 $i = 1;
2769 }
2770 }
2771 close(LOG);
2772 print ANN << "EOF";
2773</TR>
2774</TABLE>
2775</p>
2776
2777<p>As usual source packages are also available in the same directory.</p>
2778
2779<p>
2780Changes are :
2781</p>
2782<p>
2783EOF
2784 # Get each package changelog content
2785 foreach my $f (sort(@files)) {
2786 open(IN,"$f") || die "Unable to read $f:$!";
2787 while (<IN>) {
2788 print ANN $_;
2789 }
2790 close(IN);
2791 print ANN "</p><p>\n";
2792 }
2793 print ANN "</p>\n";
2794 close(ANN);
2795
2796 # Allow for modification
2797 my $editor = "vi";
2798 $editor = $ENV{'EDITOR'} if (defined $ENV{'EDITOR'});
2799 pb_system("$editor $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
2800
2801 # Store it in DB for external usage (Web pages generation)
2802 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
2803
2804 my $precmd = "";
2805 if (! -f $db) {
2806 $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
2807 }
2808
2809 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
2810 { RaiseError => 1, AutoCommit => 1 })
2811 || die "Unable to connect to $db";
2812
2813 if ($precmd ne "") {
2814 my $sth = $dbh->prepare(qq{$precmd})
2815 || die "Unable to create table into $db";
2816 $sth->execute();
2817 }
2818
2819 # To read whole file
2820 local $/;
2821 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2822 my $announce = <ANN>;
2823 close(ANN);
2824
2825 pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
2826 my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
2827 || die "Unable to insert into $db";
2828 $sth->execute($pbdate, $announce);
2829 $sth->finish();
2830 $dbh->disconnect;
2831
2832 # Then deliver it on the Web
2833 # $TOOLHOME/livwww www
2834
2835 # Mail it to project's ML
2836 open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
2837 print ML << 'EOF';
2838<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
2839
2840<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
2841 <head>
2842 </head>
2843 <body>
2844 <p>
2845EOF
2846 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2847 while(<ANN>) {
2848 print ML $_;
2849 }
2850 print ML << 'EOF';
2851</body>
2852</html>
2853EOF
2854 close(ML);
2855
2856 # To read whole file
2857 local $/;
2858 open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
2859 my $msg = <ANN>;
2860 close(ANN);
2861
2862 # Preparation of headers
2863
2864 my %mail = (
2865 To => $pbml->{$ENV{'PBPROJ'}},
2866 From => $pbpackager->{$ENV{'PBPROJ'}},
2867 Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
2868 Body => $msg,
2869 Subject => "[ANNOUNCE] $sl",
2870 );
2871
2872 # Send mail
2873 sendmail(%mail) or die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
2874}
2875
2876#
2877# Creates a set of HTML file containing the news for the project
2878# based on what has been generated by the pb_announce function
2879#
2880sub pb_web_news2html {
2881
2882 my $dest = shift || $ENV{'PBTMP'};
2883
2884 # Get all required parameters
2885 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
2886
2887 # DB of announces for external usage (Web pages generation)
2888 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
2889
2890 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
2891 { RaiseError => 1, AutoCommit => 1 })
2892 || die "Unable to connect to $db";
2893 # For date handling
2894 $ENV{LANGUAGE}="C";
2895 my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
2896 my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
2897 pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
2898 my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
2899 my %news;
2900 $news{"cy"} = ""; # current year's news
2901 $news{"ly"} = ""; # last year news
2902 $news{"py"} = ""; # previous years news
2903 $news{"fp"} = ""; # first page news
2904 my $cpt = 4; # how many news for first page
2905 # Extract info from DB
2906 foreach my $row (@$all) {
2907 my ($id, $date, $announce) = @$row;
2908 $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
2909 $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
2910 $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
2911 $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
2912 $cpt--;
2913 }
2914 pb_log(1,"news{fp}: ".$news{"fp"}."\n");
2915 $dbh->disconnect;
2916
2917 # Generate the HTML content
2918 foreach my $pref (keys %news) {
2919 open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
2920 print NEWS "$news{$pref}";
2921 close(NEWS);
2922 }
2923}
2924
2925
2926# Return the SSH key file to use
2927# Potentially create it if needed
2928
2929sub pb_ssh_get {
2930
2931my $create = shift || 0; # Do not create keys by default
2932
2933# Check the SSH environment
2934my $keyfile = undef;
2935
2936# We have specific keys by default
2937$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
2938if (!(-e $keyfile) && ($create eq 1)) {
2939 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
2940}
2941
2942$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
2943$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
2944$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
2945die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
2946return($keyfile);
2947}
2948
2949
2950# Returns the pid of a running VM command using a specific VM file
2951sub pb_check_ps {
2952 my $vmcmd = shift;
2953 my $vmm = shift;
2954 my $vmexist = 0; # FALSE by default
2955
2956 open(PS, "ps auxhww|") || die "Unable to call ps";
2957 while (<PS>) {
2958 next if (! /$vmcmd/);
2959 next if (! /$vmm/);
2960 my ($void1, $void2);
2961 ($void1, $vmexist, $void2) = split(/ +/);
2962 last;
2963 }
2964 return($vmexist);
2965}
2966
2967
2968sub pb_extract_build_files {
2969
2970my $src=shift;
2971my $dir=shift;
2972my $ddir=shift;
2973my $mandatory=shift || "spec";
2974my @files;
2975
2976my $flag = "mayfail" if ($mandatory eq "patch");
2977my $res;
2978
2979if ($src =~ /tar\.gz$/) {
2980 $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
2981} elsif ($src =~ /tar\.bz2$/) {
2982 $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
2983} else {
2984 die "Unknown compression algorithm for $src";
2985}
2986# If not mandatory return now
2987return() if (($res != 0) and ($mandatory eq "patch"));
2988opendir(DIR,"$dir") || die "Unable to open directory $dir";
2989foreach my $f (readdir(DIR)) {
2990 next if ($f =~ /^\./);
2991 # Skip potential patch dir
2992 next if ($f =~ /^pbpatch/);
2993 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
2994 pb_log(2,"mv $dir/$f $ddir\n");
2995 push @files,"$ddir/$f";
2996}
2997closedir(DIR);
2998# Not enough but still a first cleanup
2999pb_rm_rf("$dir");
3000return(@files);
3001}
3002
3003sub pb_list_bfiles {
3004
3005my $dir = shift;
3006my $pbpkg = shift;
3007my $bfiles = shift;
3008my $pkgfiles = shift;
3009my $supfiles = shift;
3010
3011opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
3012foreach my $f (readdir(BDIR)) {
3013 next if ($f =~ /^\./);
3014 $bfiles->{$f} = "$dir/$f";
3015 $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
3016 if (defined $supfiles->{$pbpkg}) {
3017 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
3018 }
3019}
3020closedir(BDIR);
3021}
3022
3023
3024#
3025# Return the list of packages we are working on in a non CMS action
3026#
3027sub pb_get_pkg {
3028
3029my @pkgs = ();
3030
3031my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
3032@pkgs = keys %$var;
3033
3034pb_log(0,"Packages: ".join(',',@pkgs)."\n");
3035return(\@pkgs);
3036}
3037
3038#
3039# Return the postinstall line if needed
3040#
3041
3042sub pb_get_postinstall {
3043
3044my $ddir = shift;
3045my $dver = shift;
3046my $darch = shift;
3047my $rbspi = shift;
3048my $vestyle = shift;
3049my $post = "";
3050
3051# Do we have a local post-install script
3052if ($vestyle eq "rinse") {
3053 $post = "--post-install ";
3054} elsif ($vestyle eq "rpmbootstrap") {
3055 $post = "-s ";
3056}
3057
3058my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbspi);
3059if ($postparam eq "") {
3060 $post = "";
3061} else {
3062 $post .= $postparam;
3063}
3064return($post);
3065}
3066
30671;
Note: See TracBrowser for help on using the repository browser.