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

Last change on this file since 1712 was 1712, checked in by Bruno Cornec, 11 years ago
  • Adds target build2setup*
  • Improve date setup when ntp is failing (don't know yet why for some VMs)
  • pb now prints the name of the VM as a prefix for each command result, improving greatly debug in parallel mode
  • Property svn:executable set to *
File size: 153.1 KB
Line 
1#!/usr/bin/perl -w
2#
3# Project Builder main application
4#
5# $Id$
6#
7# Copyright B. Cornec 2007-2012
8# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
9# Provided under the GPL v2
10
11# Syntax: see at end
12
13use strict 'vars';
14
15# The modules mentioned here are required by pb when used both
16# locally or inside a VE/VM/RM
17# Additional required modules only used locally are called with a require
18# in their respective section
19use Getopt::Long qw(:config auto_abbrev no_ignore_case);
20use Carp qw/confess cluck/;
21use Data::Dumper;
22use English;
23use File::Basename;
24use File::Copy;
25use File::stat;
26use File::Find;
27use Time::localtime qw(localtime);
28use POSIX qw(strftime);
29use lib qw (lib);
30use ProjectBuilder::Version;
31use ProjectBuilder::Base;
32use ProjectBuilder::Display;
33use ProjectBuilder::Conf;
34use ProjectBuilder::Distribution;
35use ProjectBuilder::VCS;
36use ProjectBuilder::CMS;
37use ProjectBuilder::Env;
38use ProjectBuilder::Filter;
39use ProjectBuilder::Changelog;
40use ProjectBuilder::VE;
41
42# Global variables
43$Global::pb_stop_on_error = 0; # False by default
44$Global::pb_show_sudo = 0; # False by default
45
46my %opts; # CLI Options
47my $action; # action to realize
48my $test = "FALSE"; # Not used
49my $pbforce = 0; # Force VE/VM rebuild
50my $pbsnap = 0; # Do not use snapshot mode for VM/VE by default
51my $pbkeep = 0; # keep temporary directory at the end
52my $option = ""; # Not used
53my @pkgs; # list of packages
54my $pbtag; # Global Tag variable
55my $pbver; # Global Version variable
56my $pbscript; # Name of the script
57my %pbver; # per package
58my %pbtag; # per package
59my $pbrev; # Global REVISION variable
60my $pbaccount; # Login to use to connect to the VM/RM
61my $pbtarget = undef; # Target os-ver-arch you want to build for
62my $pbport; # Port to use to connect to the VM/RM
63my $newver; # New version to create
64my $iso = undef; # ISO image for the VM to create
65
66my @date = pb_get_date();
67my $pbdate = strftime("%Y-%m-%d", @date);
68
69=pod
70
71=head1 NAME
72
73pb, aka project-builder.org - builds packages for your projects
74
75=head1 DESCRIPTION
76
77pb helps you build various packages directly from your project sources.
78Those sources could be handled by a CMS (Configuration Management System)
79such as Subversion, CVS, Git, Mercurial... or being a simple reference to a compressed tar file.
80It's based on a set of configuration files, a set of provided macros to help
81you keeping build files as generic as possible. For example, a single .spec
82file should be required to generate for all rpm based distributions, even
83if you could also have multiple .spec files if required.
84
85=head1 SYNOPSIS
86
87pb [-vhSq][-r pbroot][-p project][[-s script -a account -P port][-t [os-ver-arch]][-m os-ver-arch[,...]]][-g][-i iso] <action> [<pkg1> ...]
88
89pb [--verbose][--help][--man][--quiet][--snapshot][--revision pbroot][--project project][[--script script --account account --port port][--target [os-ver-arch]][--machine os-ver-arch[,...]]][--nographic][--iso iso][--rebuild] <action> [<pkg1> ...]
90
91=head1 OPTIONS
92
93=over 4
94
95=item B<-v|--verbose>
96
97Print a brief help message and exits.
98
99=item B<-q|--quiet>
100
101Do not print any output.
102
103=item B<-h|--help>
104
105Print a brief help message and exits.
106
107=item B<-S|--snapshot>
108
109Use the snapshot mode of VMs or VEs
110
111=item B<--man>
112
113Prints the manual page and exits.
114
115=item B<-t|--target os-ver-arch>
116
117Name of the target system you want to build for.
118All if none precised.
119
120=item B<-m|--machine os-ver-arch[,os-ver-arch,...]>
121
122Name of the Virtual Machines (VM), Virtual Environments (VE) or Remote Machines (RM)
123you want to build on (comma separated).
124All if none precised (or use the env variable PBV).
125
126=item B<-s|--script script>
127
128Name of the script you want to execute on the related VMs/VEs/RMs.
129
130=item B<-g|--nographic>
131
132Do not launch VMs in graphical mode.
133
134=item B<-i|--iso iso_image>
135
136Name of the ISO image of the distribution you want to install on the related VMs.
137
138=item B<-a|--account account>
139
140Name of the account to use to connect on the related VMs/RMs.
141
142=item B<-P|--port port_number>
143
144Port number to use to connect on the related VMs/RMs.";
145
146=item B<-p|--project project_name>
147
148Name of the project you're working on (or use the env variable PBPROJ)
149
150=item B<-r|--revision revision>
151
152Path Name of the project revision under the CMS (or use the env variable PBROOT)
153
154=item B<-V|--version new_version>
155
156New version of the project to create based on the current one.
157
158=item B<-k|--keep>
159
160Keep the temporary dir where files have been created in or der to help debug
161
162=item B<--rebuild>
163
164Only valid with the checkssh action, it alllows to automatically relaunch the build of the failed packages
165
166=item B<--no-stop-on-error>
167
168Continue through errors with best effort.
169
170=back
171
172=head1 ARGUMENTS
173
174<action> can be:
175
176=over 4
177
178=item B<sbx2build>
179
180Create tar files for the project under your CMS.
181Current state of the exported content is taken.
182CMS supported are SVN, SVK, CVS, Git and Mercurial
183parameters are packages to build
184if not using default list
185
186=item B<cms2build>
187
188Create tar files for the project under your CMS.
189Current state of the CMS is taken.
190CMS supported are SVN, SVK, CVS, Git and Mercurial
191parameters are packages to build
192if not using default list
193
194=item B<build2pkg>
195
196Create packages for your running distribution
197
198=item B<cms2pkg>
199
200cms2build + build2pkg
201
202=item B<sbx2pkg>
203
204sbx2build + build2pkg
205
206=item B<sbx2pkg2ins>
207
208sbx2pkg + final install of packages
209
210=item B<build2ssh>
211
212Send the tar files to a SSH host
213
214=item B<sbx2ssh>
215
216sbx2build + build2ssh
217
218=item B<cms2ssh>
219
220cms2build + build2ssh
221
222=item B<pkg2ssh>
223
224Send the packages built to a SSH host
225
226=item B<build2vm>
227
228Create packages in VMs, launching them if needed
229and send those packages to a SSH host once built
230VM type supported are QEMU and KVM
231
232=item B<build2ve>
233
234Create packages in VEs, creating it if needed
235and send those packages to a SSH host once built
236
237=item B<build2rm>
238
239Create packages in RMs, which should pre-exist,
240and send those packages to a SSH host once built
241RM means Remote Machine, and could be a physical or Virtual one.
242This is one buildfarm integration for pb.
243
244=item B<sbx2vm>
245
246sbx2build + build2vm
247
248=item B<sbx2ve>
249
250sbx2build + build2ve
251
252=item B<sbx2rm>
253
254sbx2build + build2rm
255
256=item B<cms2vm>
257
258cms2build + build2vm
259
260=item B<cms2ve>
261
262cms2build + build2ve
263
264=item B<cms2rm>
265
266cms2build + build2rm
267
268=item B<launchvm>
269
270Launch one virtual machine
271
272=item B<launchve>
273
274Launch one virtual environment
275
276=item B<script2vm>
277
278Launch one virtual machine if needed
279and executes a script on it
280
281=item B<script2ve>
282
283Execute a script in a virtual environment
284
285=item B<script2rm>
286
287Execute a script on a remote machine
288
289=item B<newvm>
290
291Create a new virtual machine
292
293=item B<newve>
294
295Create a new virtual environment
296
297=item B<setupvm>
298
299Setup a virtual machine for pb usage
300
301=item B<setupve>
302
303Setup a virtual environment for pb usage
304
305=item B<setuprm>
306
307Setup a remote machine for pb usage
308
309=item B<sbx2setupvm>
310
311Setup a virtual machine for pb usage using the sandbox version of pb instead of the latest stable
312Reserved to dev team.
313
314=item B<sbx2setupve>
315
316Setup a virtual environment for pb usage using the sandbox version of pb instead of the latest stable
317Reserved to dev team.
318
319=item B<sbx2setuprm>
320
321Setup a remote machine for pb usage using the sandbox version of pb instead of the latest stable
322Reserved to dev team.
323
324=item B<build2setupvm>
325
326Setup a virtual machine for pb usage using the build available
327Reserved to dev team.
328
329=item B<build2setupve>
330
331Setup a virtual environment for pb usage using the build available
332Reserved to dev team.
333
334=item B<build2setuprm>
335
336Setup a remote machine for pb usage using the build available
337Reserved to dev team.
338
339=item B<snapvm>
340
341Snapshot a virtual machine for pb usage
342
343=item B<snapve>
344
345Snapshot a virtual environment for pb usage
346
347=item B<updatevm>
348
349Update the distribution in the virtual machine
350
351=item B<updateve>
352
353Update the distribution in the virtual environment
354
355=item B<updaterm>
356
357Update the distribution in the remote machine
358
359=item B<test2pkg>
360
361Test a package locally
362
363=item B<test2vm>
364
365Test a package in a virtual machine
366
367=item B<test2ve>
368
369Test a package in a virtual environment
370
371=item B<test2rm>
372
373Test a package in a remote machine
374
375=item B<checkssh>
376
377Check the delivery of the packages on the repository
378
379=item B<newver>
380
381Create a new version of the project derived
382from the current one
383
384=item B<newproj>
385
386Create a new project and a template set of
387configuration files under pbconf
388
389=item B<announce>
390
391Announce the availability of the project through various means
392
393=item B<sbx2webssh>
394
395Create tar files for the website under your CMS.
396Current state of the exported content is taken.
397Deliver the content to the target server using ssh from the exported dir.
398
399=item B<cms2webssh>
400
401Create tar files for the website from your CMS.
402Deliver the content to the target server using ssh from the DVCS.
403
404=item B<sbx2webpkg>
405
406Create tar files for the website under your CMS.
407Current state of the exported content is taken.
408
409=item B<cms2webpkg>
410
411Create tar files for the website under your CMS.
412
413=item B<getconf>
414
415Print the full configuration parameters as found in the various configuration files. help to debug conf issues.
416
417=item B<clean>
418
419Purge the build and delivery directories related to the current project
420
421=item B<cleanssh>
422
423Purge the ssh server of its packages (only for testver and test packages)
424
425=back
426
427<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).
428
429=head1 WEB SITES
430
431The 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/>.
432
433=head1 USER MAILING LIST
434
435None exists for the moment.
436
437=head1 CONFIGURATION FILES
438
439Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
440
441Here is an example of such a configuration file:
442
443 #
444 # Define for each project the URL of its pbconf repository
445 # No default option allowed here as they need to be all different
446 #
447 # URL of the pbconf content
448 # This is the format of a classical URL with the extension of additional schema such as
449 # svn+ssh, cvs+ssh, ...
450 #
451 pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
452
453 # This is normaly defined in the project's configuration file
454 # Url of the project
455 #
456 pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
457
458 # All these URLs needs to be defined here as the are the entry point
459 # for how to build packages for the project
460 #
461 pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
462 pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
463 pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
464 pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
465
466 # Under that dir will take place everything related to pb
467 # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
468 # to your VMs/chroot/...
469 # if not defined then /var/cache
470 pbdefdir default = $ENV{'HOME'}/project-builder
471 pbdefdir pb = $ENV{'HOME'}
472 pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
473 pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
474
475 # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
476 # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
477 pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
478 pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
479
480 # pbdir points to the directory where the CMS content of the pburl is checked out
481 # If not defined, pbdir is under pbdefdir/pbproj
482 # Only defined if we have access to the dev of the project
483 pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
484 pbdir mondorescue = $ENV{'HOME'}/mondo/svn
485
486 # -daemonize doesn't work with qemu 0.8.2
487 vmopt default = -m 384
488
489=head1 COMMAND DETAILS
490
491=head2 newproj
492
493The newproj command creates a new project-builder project. To run this command you first need to define two variables in your ~/.pbrc file:
494
495 pbconfurl I<project> = file:///home/anderse/.git/project-builder-config/I<project>
496 pbdefdir default = $ENV{HOME}/cache-project-builder
497
498The first line defines the version controlled configuration information and the second defines the root directory for project-builder to use.
499
500You can then run the command:
501
502 % pb -p I<$project> -r I<$version> newproj I<$pkg>
503
504to create the new project. Running the newproj command will then generate the file $pbdefdir/$project/pbconf/$version/$project.pb, and the directory $pbdefdir/$project/pbconf/$version/$pkg. You will need to edit those files to make the later commands work.
505
506=head2 cms2build
507
508The cms2build command takes your files from the content management system and makes the two tar files that are necessary for building files. You need to have run the newproj command first. Then there are several steps for running this command:
509
510=over 4
511
512=item Update your $project.pb configuration file.
513
514You need to set the pburl, pbrepo, pbwf, pbpackager, projver, projtag, testver, delivery, and defpkgdir lines as described in the configuration file. The pburl entry is used to find the source for your package. The pbrepo entry is used to build the .repo or .sources.list files for use by downloaders of the package. The pbwf entry indicates that the source tar file is named by I<package-name>-I<version>. The pbpackager entry will be stored in the packages and should be you or your team. The projver/projtag entries indicate the version of the software and the version of the packaging scripts. The testver entry when true indicates that the package is in a test version, so no log file is computed (can be long), and version is made up using a timstamp. The delivery entry gives the subdirectory under which the packages will be delivered on the repository, and the defpkgdir entry corresponds to the local subdirectory hosting the package content.
515
516For example:
517
518 pburl Lintel = file:///home/anderse/projects/Lintel-0.2012.02.28.tar.gz
519 pbrepo Lintel = http://tesla.hpl.hp.com/opensource
520 pbwf Lintel = 1
521 pbpackager Lintel = Eric Anderson <eric.anderson4@hp.com>
522 projver Lintel = 0.2012.02.28
523 projtag Lintel = 1
524 testver Lintel = false
525 delivery Lintel = production
526 defpkgdir Lintel = Lintel-0.2012.02.28
527
528=item Create the build .tar.gz files:
529
530Then you need to take those files and create the initial tar files. Run a command like:
531
532 % pb -p $project -r $version cms2build
533
534To create the $pbdefdir/$project/delivery/$project-$version.{,pbconf}.tar.gz files, the $version-$projtag.pb and pbrc files in the same directory.
535
536=back
537
538=head2 build2pkg
539
540The build2pkg command takes the tar files created in the cms2build step and attempts to build binary packages for your current operating system. There are two steps:
541
542=over 4
543
544=item Update your filters and build files.
545
546You probably need to edit the files describing the build steps in one of the $pbdefdir/$project/pbconf/$version/$project/{deb,rpm,pkg} directories and the filters in $pbdefdir/$project/pbconf/$version/pbfilter. Note that you can define additional filters and transforms in the *.pbf files. The build files will be filtered by the filters defined in the *.pbf files to generate the inputs to the build step. Therefore, if you change those files, you need to re-run the cms2build step.
547
548=item Build the package.
549
550Then you can run a command like:
551
552 % pb -p $project -r $version build2pkg
553
554To create the files in $project/build that comprise your binary package(s).
555
556=back
557
558=head2 newve
559
560The newve command creates a new virtual environment, i.e. a chrooted OS for building packages. Using a virtual environment is an efficient way to build packages on a related set of operating systems. The OS's have to be related because the kernel will be shared. Steps:
561
562=over 4
563
564=item Update ~/.pbrc
565
566Update your ~/.pbrc file to specify the vepath, velist, velogin, and vetype variables, e.g.:
567
568 vepath default = $ENV{HOME}/cache-project-builder/chroot
569 velist default = debian-6.0-i386
570 velogin default = pb
571 vetype default = chroot
572
573If you are building for rpm style OS's, update the verpmtype option, and install the appropriate tool.
574
575 verpmtype default = rpmbootstrap
576
577You may also choose to specify a mirror for the OS packages, and optionally http/ftp proxies. You can specify the proxies either through environment variables ($http_proxy/$ftp_proxy) or in the configuration file. The configuration file will be used if no corresponding environment variable has been set. For example, for debian and with a local squid proxy:
578
579 rbsmirrorsrv debian = http://mirrors1.kernel.org/debian/
580 http_proxy default = http://localhost:3128/
581 ftp_proxy default = http://localhost:3128/
582
583=item Run the cms2build command
584
585If you have deleted your $package/delivery directory, re-run the cms2build command as in the earlier step. This step is necessary to generate the I<package>/delivery/pbrc file.
586
587=item Create the new virtual environment
588
589Initialize the new operating system. This step will install the core OS packages for the virtual environment, e.g.:
590
591 % pb -v -p $project -m debian-6.0-i386 newve
592
593=back
594
595=head2 setupve
596
597The setupve command prepares a virtual environment for use by project builder. In particular it installs project-builder from the packages into the virtual environment. Two sub-steps are necessary:
598
599=over 4
600
601=item Update $project.pb
602
603You need to have a sshhost entry for setupve to work, so add one, even an invalid one, e.g.:
604
605 sshhost $project = foo.example.org
606
607=item Setup the virtual environment
608
609 % pb -v -p $project -m debian-6.0-i386 setupve
610
611If you prefer to install the current SVN version of project builder, you can substitute the setupve option by the sbx2setupv one.
612
613=back
614
615=head2 build2ve
616
617The build2ve command is similar to the build2pkg command in that it will take the sources created by cms2build and turn them into binary packages. The command has two differences. First, it creates the packages in a virtual environment, i.e. the one made by an earlier setupve setup. Second it copies the resulting packages to a repository and builds the repository meta-data needed.
618
619Three sub-steps are needed:
620
621=over 4
622
623=item Update $project.pb
624
625You need to have a valid sshdir and sshhost entry for build2ve to work, so add them. Note that you need to be able to ssh from the host you run the command on to the repository host, preferably without needing to type in a password, so using ssh-agent or having a special passwordless project-builder ssh key will make this step easier.
626
627 sshhost $project = localhost
628 sshdir $project = $home/cache-project-builder/repos
629
630You may also need to specify additional repository files to use or rpms to install. Note the URL for repositories is not the URL of the repository, but the URL of a file that can be put in the yum.repos.d or apt.sources.d directory.
631
632 addrepo centos-5-i386 = http://localhost/pb/centos-extras.repo,http://mirror.centos.org/centos/5/extras/i386/RPMS/chrpath-0.13-3.el5.centos.i386.rpm
633
634=item Update your filters and build files
635
636You may need to update your filter files (*.pbf) as in the build2pkg step if you are building for a new OS or architecture.
637
638=item Build the packages and copy them to the repository
639
640 % pb -v -p $project -m debian-6.0-i386 build2ve
641
642=back
643
644*Debugging:* If the build fails (and you did not specify the --no-stop-on-error) option, then the virtual environment and scripts should still be present and configured to build the package. You can run a command like 'sudo setarch i386 chroot $path bash' in order to get into the environment. In your log you should see a command like that. From there you can go into the /home/pb directory as the pb user and run the same style of pb commands as you did when doing build2pkg. This will help you figure out what has gone wrong in the build in the virtual environment.
645
646=head1 AUTHORS
647
648The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
649
650=head1 COPYRIGHT
651
652Project-Builder.org is distributed under the GPL v2.0 license
653described in the file C<COPYING> included with the distribution.
654
655=cut
656
657# ---------------------------------------------------------------------------
658
659my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
660my $appname = "pb";
661
662# Initialize the syntax string
663
664pb_syntax_init("$appname (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
665
666GetOptions("help|?|h+" => \$opts{'h'},
667 "man" => \$opts{'man'},
668 "verbose|v+" => \$opts{'v'},
669 "snapshot|S" => \$opts{'S'},
670 "quiet|q" => \$opts{'q'},
671 "log-files|l=s" => \$opts{'l'},
672 "force|f" => \$opts{'f'},
673 "account|a=s" => \$opts{'a'},
674 "revision|r=s" => \$opts{'r'},
675 "script|s=s" => \$opts{'s'},
676 "machines|mock|m=s" => \$opts{'m'},
677 "target|t:s" => \$opts{'t'},
678 "nographic|g" => \$opts{'g'},
679 "port|P=i" => \$opts{'P'},
680 "project|p=s" => \$opts{'p'},
681 "rebuild" => \$opts{'rebuild'},
682 "iso|i=s" => \$opts{'i'},
683 "version|V=s" => \$opts{'V'},
684 "keep|k" => \$opts{'k'},
685 "stop-on-error!" => \$Global::pb_stop_on_error,
686) || pb_syntax(-1,0);
687
688if (defined $opts{'l'}) {
689 open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
690 $pbLOG = \*pbLOG;
691 $pbdebug = 0 if ($pbdebug == -1);
692 }
693pb_log_init($pbdebug, $pbLOG);
694
695if (defined $opts{'h'}) {
696 pb_syntax(0,$opts{'h'}-1);
697}
698if (defined $opts{'man'}) {
699 pb_syntax(0,2);
700}
701if (defined $opts{'v'}) {
702 $pbdebug = $opts{'v'};
703}
704if (defined $opts{'f'}) {
705 $pbforce=1;
706}
707if (defined $opts{'q'}) {
708 $pbdebug=-1;
709}
710if (defined $opts{'S'}) {
711 $pbsnap=1;
712}
713if (defined $opts{'k'}) {
714 $pbkeep=1;
715}
716pb_display_init("text","");
717
718# Handle root of the project if defined
719if (defined $opts{'r'}) {
720 $ENV{'PBROOTDIR'} = $opts{'r'};
721}
722# Handle virtual machines if any
723if (defined $opts{'m'}) {
724 $ENV{'PBV'} = $opts{'m'};
725}
726if (defined $opts{'s'}) {
727 $pbscript = $opts{'s'};
728}
729if (defined $opts{'a'}) {
730 $pbaccount = $opts{'a'};
731 die "option -a requires a -s script option" if (not defined $pbscript);
732}
733if (defined $opts{'P'}) {
734 $pbport = $opts{'P'};
735}
736if (defined $opts{'V'}) {
737 $newver = $opts{'V'};
738}
739if (defined $opts{'i'}) {
740 $iso = $opts{'i'};
741}
742if (defined $opts{'t'}) {
743 $pbtarget = $opts{'t'};
744}
745
746# Get Action
747$action = shift @ARGV;
748die pb_syntax(-1,1) if (not defined $action);
749
750my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
751my $pbinit = undef;
752$pbinit = 1 if ($action =~ /^newproj$/);
753
754# Handles project name if any
755# And get global params
756($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action,$pbkeep);
757
758#
759# Check for command requirements
760#
761my ($req,$opt,$pbpara,$pbshowsudo,$pbstoponerr) = pb_conf_get_if("oscmd","oscmdopt","pbparallel","pbshowsudo","pbstoponerr");
762pb_check_requirements($req,$opt,$appname);
763
764$Global::pb_show_sudo = 1 if ((defined $pbshowsudo) && (defined $pbshowsudo->{$ENV{'PBPROJ'}}) && ($pbshowsudo->{$ENV{'PBPROJ'}} =~ /true/oi));
765$Global::pb_stop_on_error = 1 if ((defined $pbstoponerr) && (defined $pbstoponerr->{$ENV{'PBPROJ'}}) && ($pbstoponerr->{$ENV{'PBPROJ'}} =~ /true/oi));
766
767#
768# Check if we can launch some actions in // with Parallel::ForkManager
769#
770my $pbparallel = $pbpara->{$appname} if (defined $pbpara);
771if (not defined $pbparallel) {
772 eval
773 {
774 require Sys::CPU;
775 Sys::CPU->import();
776 };
777 if ($@) {
778 # Sys::CPU not found, defaulting to 1
779 pb_log(1,"ADVISE: Install Sys::CPU to benefit from automatic parallelism optimization.\nOr use pbparallel in your pb.conf file\nOnly 1 process at a time for the moment\n");
780 $pbparallel = 1;
781 } else {
782 # Using the number of cores
783 $pbparallel = Sys::CPU::cpu_count();
784 pb_log(1,"Using parallel mode with $pbparallel processes\n");
785 }
786}
787
788eval
789{
790 require Parallel::ForkManager;
791 Parallel::ForkManager->import();
792};
793# Parallel::ForkManager not found so no // actions
794if ($@) {
795 $pbparallel = undef;
796 pb_log(1,"ADVISE: Install Parallel::ForkManager to benefit from automatic parallelism optimization.\nOnly 1 process at a time for the moment\n");
797}
798
799pb_log(0,"Project: $ENV{'PBPROJ'}\n");
800pb_log(0,"Action: $action\n");
801
802my $do_install = undef;
803# Possibility to add a 2ins to some commands to launch automatic installation
804$do_install = 1 if ($action =~ /2ins$/);
805
806# Act depending on action
807if ($action =~ /^cms2build$/) {
808 pb_cms2build("CMS");
809} elsif ($action =~ /^sbx2build$/) {
810 pb_cms2build("SandBox");
811} elsif ($action =~ /^build2pkg/) {
812 pb_build2pkg($do_install);
813} elsif ($action =~ /^cms2pkg/) {
814 pb_cms2build("CMS");
815 pb_build2pkg($do_install);
816} elsif ($action =~ /^sbx2pkg/) {
817 pb_cms2build("SandBox");
818 pb_build2pkg($do_install);
819} elsif ($action =~ /^build2ssh$/) {
820 pb_build2ssh();
821} elsif ($action =~ /^cms2ssh$/) {
822 pb_cms2build("CMS");
823 pb_build2ssh();
824} elsif ($action =~ /^sbx2ssh$/) {
825 pb_cms2build("SandBox");
826 pb_build2ssh();
827} elsif ($action =~ /^pkg2ssh$/) {
828 pb_pkg2ssh();
829} elsif ($action =~ /^build2rm$/) {
830 pb_build2v("rm","build");
831} elsif ($action =~ /^build2ve$/) {
832 pb_build2v("ve","build");
833} elsif ($action =~ /^build2vm$/) {
834 pb_build2v("vm","build");
835} elsif ($action =~ /^cms2rm$/) {
836 pb_cms2build("CMS");
837 pb_build2v("rm","build");
838} elsif ($action =~ /^cms2ve$/) {
839 pb_cms2build("CMS");
840 pb_build2v("ve","build");
841} elsif ($action =~ /^sbx2rm$/) {
842 pb_cms2build("SandBox");
843 pb_build2v("rm","build");
844} elsif ($action =~ /^sbx2ve$/) {
845 pb_cms2build("SandBox");
846 pb_build2v("ve","build");
847} elsif ($action =~ /^cms2vm$/) {
848 pb_cms2build("CMS");
849 pb_build2v("vm","build");
850} elsif ($action =~ /^sbx2vm$/) {
851 pb_cms2build("SandBox");
852 pb_build2v("vm","build");
853} elsif ($action =~ /^launchvm$/) {
854 my $pm;
855 my $all_ok = 1;
856 if (defined $pbparallel) {
857 $pm = new Parallel::ForkManager($pbparallel);
858
859 # Set which port the VM/RM will use to communicate
860 $pm->run_on_start(\&pb_set_port);
861 $pm->run_on_finish(sub { my ($pid, $code, $id, $signal, $dump) = @_;
862 $all_ok = 0 unless (($code == 0) && ($signal == 0) && ($dump == 0));
863 });
864 }
865
866 my $counter = 0;
867 foreach my $v (split(/,/,$ENV{'PBV'})) {
868 $counter++;
869 # Modulo pbparallel
870 $counter = 1 if ((defined $pbparallel) && ($counter > $pbparallel));
871 $pm->start($counter) and next if (defined $pbparallel);
872
873 pb_launchv("vm",$v,0);
874 }
875 $pm->wait_all_children if (defined $pbparallel);
876 die "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error));
877} elsif ($action =~ /^launchve$/) {
878 pb_launchv("ve",$ENV{'PBV'},0);
879} elsif ($action =~ /^script2vm$/) {
880 pb_script2v($pbscript,"vm");
881} elsif ($action =~ /^script2ve$/) {
882 pb_script2v($pbscript,"ve");
883} elsif ($action =~ /^script2rm$/) {
884 pb_script2v($pbscript,"rm");
885} elsif ($action =~ /^newver$/) {
886 pb_newver();
887} elsif ($action =~ /^newve$/) {
888 pb_launchv("ve",$ENV{'PBV'},1);
889} elsif ($action =~ /^newvm$/) {
890 pb_launchv("vm",$ENV{'PBV'},1);
891 pb_log(0, "Please ensure that sshd is running in your VM by default\n");
892 pb_log(0, "and that it allows remote root login (PermitRootLogin yes in /etc/ssh/sshd_config)\n");
893 pb_log(0, "Also ensure that network is up, firewalling correctly configured\n");
894 pb_log(0, "and perl, tar, sudo, ntpdate and scp/ssh installed\n");
895 pb_log(0, "You should then be able to login with ssh -p VMPORT root\@localhost (if VM started with pb)\n");
896} elsif ($action =~ /^setuprm$/) {
897 pb_setup2v("rm");
898} elsif ($action =~ /^setupve$/) {
899 pb_setup2v("ve");
900} elsif ($action =~ /^setupvm$/) {
901 pb_setup2v("vm");
902} elsif ($action =~ /^sbx2setuprm$/) {
903 die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
904 pb_cms2build("SandBox");
905 pb_setup2v("rm","SandBox");
906} elsif ($action =~ /^sbx2setupve$/) {
907 die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
908 pb_cms2build("SandBox");
909 pb_setup2v("ve","SandBox");
910} elsif ($action =~ /^sbx2setupvm$/) {
911 die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
912 pb_cms2build("SandBox");
913 pb_setup2v("vm","SandBox");
914} elsif ($action =~ /^build2setuprm$/) {
915 die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
916 pb_setup2v("rm","SandBox");
917} elsif ($action =~ /^build2setupve$/) {
918 die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
919 pb_setup2v("ve","SandBox");
920} elsif ($action =~ /^build2setupvm$/) {
921 die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
922 pb_setup2v("vm","SandBox");
923} elsif ($action =~ /^updaterm$/) {
924 pb_update2v("rm");
925} elsif ($action =~ /^updateve$/) {
926 pb_update2v("ve");
927} elsif ($action =~ /^updatevm$/) {
928 pb_update2v("vm");
929} elsif ($action =~ /^snapve$/) {
930 pb_snap2v("ve");
931} elsif ($action =~ /^snapvm$/) {
932 pb_snap2v("vm");
933} elsif ($action =~ /^test2pkg$/) {
934 pb_test2pkg();
935} elsif ($action =~ /^test2rm$/) {
936 pb_build2v("rm","test");
937} elsif ($action =~ /^test2ve$/) {
938 pb_build2v("ve","test");
939} elsif ($action =~ /^test2vm$/) {
940 pb_build2v("vm","test");
941} elsif ($action =~ /^newproj$/) {
942 # Nothing to do - already done in pb_env_init
943} elsif ($action =~ /^getconf$/) {
944 my $pbos = pb_distro_get_context();
945 pb_conf_print();
946} elsif ($action =~ /^clean$/) {
947 pb_clean();
948} elsif ($action =~ /^announce$/) {
949 # For announce only. Require avoids the systematic load of these modules
950 require DBI;
951 require DBD::SQLite;
952
953 pb_announce("Announce");
954} elsif ($action =~ /^cleanssh$/) {
955 pb_announce("Clean");
956} elsif ($action =~ /^checkssh$/) {
957 pb_announce("Check");
958} elsif ($action =~ /^sbx2webpkg$/) {
959 require DBI;
960 require DBD::SQLite;
961
962 pb_cms2build("SandBox","Web");
963} elsif ($action =~ /^sbx2webssh$/) {
964 require DBI;
965 require DBD::SQLite;
966
967 pb_cms2build("SandBox","Web");
968 pb_send2target("Web");
969} elsif ($action =~ /^cms2webpkg$/) {
970 require DBI;
971 require DBD::SQLite;
972
973 pb_cms2build("CMS","Web");
974} elsif ($action =~ /^cms2webssh$/) {
975 require DBI;
976 require DBD::SQLite;
977
978 pb_cms2build("CMS","Web");
979 pb_send2target("Web");
980} else {
981 pb_log(0,"\'$action\' is not available\n");
982 pb_syntax(-2,1);
983}
984
985pb_exit();
986
987sub pb_cms2build {
988
989 my $param = shift || undef;
990 my $web = shift || undef;
991
992 my $pkg;
993 my @pkgs;
994 my $webdir;
995
996 my %pkgs;
997 my $pb; # Structure to store conf info
998
999 die "pb_cms2build requires a parameter: SandBox or CMS" if (not defined $param);
1000
1001 # If Website, then pkg is only the website
1002 if (defined $web) {
1003 ($webdir) = pb_conf_get("webdir");
1004 pb_log(2,"webdir: ".Dumper($webdir)."\n");
1005 $pkgs[0] = $webdir->{$ENV{'PBPROJ'}};
1006 $extpkgdir = $webdir;
1007 pb_log(0,"Package: $pkgs[0]\n");
1008 } else {
1009 $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
1010 @pkgs = @$pkg;
1011 }
1012
1013 my ($scheme, $uri) = pb_cms_init($pbinit,$param);
1014
1015 # We need 2 lines here
1016 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
1017
1018 # declare packager and repo for filtering
1019 my ($tmp1, $tmp2) = pb_conf_get("pbpackager","pbrepo");
1020 $ENV{'PBPACKAGER'} = $tmp1->{$ENV{'PBPROJ'}};
1021 $ENV{'PBREPO'} = $tmp2->{$ENV{'PBPROJ'}};
1022 my ($delivery) = pb_conf_get_if("delivery");
1023 $delivery->{$ENV{'PBPROJ'}} = "" if (not defined $delivery->{$ENV{'PBPROJ'}});
1024
1025 # If we deal with a test dir, we want to keep the date in tar file and dir name
1026 my $pbextdir = "";
1027 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
1028 $pbextdir = strftime("%Y%m%d%H%M%S", @date);
1029 }
1030
1031 foreach my $pbpkg (@pkgs) {
1032 $ENV{'PBPKG'} = $pbpkg;
1033
1034 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
1035 $pbver = $pkgv->{$pbpkg};
1036 } else {
1037 $pbver = $ENV{'PBPROJVER'};
1038 }
1039 # If it's a test version, then tag == 0
1040 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
1041 $pbtag = "0";
1042 $ENV{'PBPROJTAG'} = $pbtag;
1043 } elsif ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
1044 $pbtag = $pkgt->{$pbpkg};
1045 } else {
1046 $pbtag = $ENV{'PBPROJTAG'};
1047 }
1048
1049 $pbrev = $ENV{'PBREVISION'};
1050 pb_log(0,"\n");
1051 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
1052 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
1053
1054 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir";
1055 # Create the structure if needed
1056 pb_mkdir_p($dest);
1057 # Clean up dest if necessary. The export will recreate it
1058 pb_rm_rf($dest) if (-d $dest);
1059
1060 # Export CMS tree for the concerned package to dest
1061 # And generate some additional files
1062 $OUTPUT_AUTOFLUSH=1;
1063
1064 # computes in which dir we have to work
1065 my $dir = $defpkgdir->{$pbpkg};
1066 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
1067 $dir = $webdir->{$ENV{'PBPROJ'}} if (defined $web);
1068 die "Variable \$dir not defined. Please report to dev team with log of a verbose run and this info ".Dumper($defpkgdir,$extpkgdir,$webdir) if (not defined $dir);
1069 pb_log(2,"def:".Dumper($defpkgdir)."ext: ".Dumper($extpkgdir)."dir: $dir\n");
1070
1071 # Exporting content from CMS
1072 my $sourcedir = undef;
1073 my $sourceuri = $uri;
1074 if ($param eq "SandBox") {
1075 # Point to the local instance
1076 $sourcedir = "$ENV{'PBDIR'}/$dir";
1077 } else {
1078 # Get it from a subdir of the URI with same version as localy but different root
1079 # Only if using a real CMS
1080 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
1081 if (($scheme !~ /^file/) && ($scheme !~ /^(ht|f)tp/)) {
1082 $sourceuri = "$ENV{'PBDIR'}/$dir";
1083 $sourceuri =~ s|^$ENV{'PBPROJDIR'}/|$uri/|;
1084 }
1085 }
1086 my $preserve = pb_vcs_export($sourceuri,$sourcedir,$dest);
1087
1088 # Generated fake content for test versions to speed up stuff
1089 my $chglog;
1090
1091 # Get project info on authors and log file
1092 # TODO: Make it CMS aware
1093 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
1094 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
1095 $chglog = undef if (! -f $chglog);
1096
1097 # TODO: Make it CMS aware
1098 my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
1099 $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
1100 $authors = "/dev/null" if (! -f $authors);
1101
1102 # Extract cms log history and store it
1103 if ((defined $chglog) && (! -f "$dest/NEWS")) {
1104 pb_log(2,"Generating NEWS file from $chglog\n");
1105 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
1106 }
1107 pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
1108
1109 my %build;
1110 # We want to at least build for the underlying distro
1111 # except if a target was given, in which case we only build for it
1112 # if -t was passed without target then build for the native distro.
1113 my $pbos = pb_distro_get_context($pbtarget);
1114 my $tmpl = pb_get_distros($pbos,$pbtarget);
1115
1116 # Setup $pb structure to allow filtering later on, on files using that structure
1117 $pb->{'tag'} = $pbtag;
1118 $pb->{'rev'} = $pbrev;
1119 $pb->{'ver'} = $pbver;
1120 $pb->{'pkg'} = $pbpkg;
1121 $pb->{'suf'} = $pbos->{'suffix'};
1122 $pb->{'realpkg'} = $pbpkg;
1123 $pb->{'date'} = $pbdate;
1124 $pb->{'defpkgdir'} = $defpkgdir;
1125 $pb->{'extpkgdir'} = $extpkgdir;
1126 $pb->{'chglog'} = $chglog;
1127 $pb->{'extdir'} = $pbextdir;
1128 $pb->{'packager'} = $ENV{'PBPACKAGER'};
1129 $pb->{'proj'} = $ENV{'PBPROJ'};
1130 $pb->{'repo'} = "$ENV{'PBREPO'}/$delivery->{$ENV{'PBPROJ'}}";
1131 $pb->{'patches'} = ();
1132 $pb->{'sources'} = ();
1133
1134 my $tmpd = "$ENV{'PBTMP'}/cms.$$";
1135 pb_mkdir_p($tmpd) if (defined $pbparallel);
1136
1137 # Get only all.pbf filter at this stage for pbinit
1138 my $ptr = pb_get_filters($pbpkg);
1139
1140 # Do not do that for website
1141 if (not defined $web) {
1142 my %virt;
1143 # De-duplicate similar VM/VE/RM
1144 foreach my $d (split(/,/,$tmpl)) {
1145 # skip ill-formatted vms (name-ver-arch)
1146 next if ($d !~ /-/);
1147 $virt{$d} = $d;
1148 }
1149
1150 # Try to use // processing here
1151 my $all_ok = 1;
1152 my $pm = new Parallel::ForkManager($pbparallel) if (defined $pbparallel);
1153 $pm->run_on_finish(sub { my ($pid, $code, $id, $signal, $dump) = @_;
1154 $all_ok = 0 unless (($code == 0) && ($signal == 0) && ($dump == 0)); }) if (defined $pbparallel);
1155
1156 pb_log(0,"Preparing delivery ...\n");
1157 foreach my $v (keys %virt) {
1158 $pm->start and next if (defined $pbparallel);
1159
1160 # Distro context
1161 my $pbos = pb_distro_get_context($v);
1162
1163 $pb->{'pbos'} = $pbos;
1164 $pb->{'suf'} = $pbos->{'suffix'};
1165 pb_log(3,"DEBUG: pb: ".Dumper($pb)."\n");
1166
1167 # Get all filters to apply
1168 $ptr = pb_get_filters($pbpkg,$pbos);
1169
1170 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
1171
1172 # We need to compute the real name of the package
1173 my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pbos->{'type'});
1174 $pb->{'realpkg'} = $pbrealpkg;
1175 pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $pbos->{'name'}-$pbos->{'version'}\n") if ($pbrealpkg ne $pbpkg);
1176
1177 # Filter build files from the less precise up to the most with overloading
1178 # Filter all files found, keeping the name, and generating in dest
1179
1180 # Find all build files first relatively to PBROOTDIR
1181 # Find also all specific files referenced in the .pb conf file
1182 my %bfiles = ();
1183 my %pkgfiles = ();
1184 # Used in Filter.pm by pb_filter_file
1185
1186 $build{$v} = "no";
1187 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'os'}") {
1188 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'os'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
1189 $build{$v} = "yes";
1190 }
1191 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'type'}") {
1192 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'type'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
1193 $build{$v} = "yes";
1194 }
1195 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'family'}") {
1196 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'family'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
1197 $build{$v} = "yes";
1198 }
1199 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}") {
1200 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
1201 $build{$v} = "yes";
1202 }
1203 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}") {
1204 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
1205 $build{$v} = "yes";
1206 }
1207 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") {
1208 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
1209 $build{$v} = "yes";
1210 }
1211 pb_log(2,"DEBUG($v) bfiles: ".Dumper(\%bfiles)."\n");
1212
1213 if ($build{$v} ne "no") {
1214 # Apply now all the filters on all the files concerned
1215 # destination dir depends on the type of file
1216 # For patch support
1217 # TODO: Make it CMS aware
1218 $pb->{'patches'} = pb_list_sfiles("$ENV{'PBROOTDIR'}/$pbpkg/pbpatch", $pb->{'patches'}, $pbos, "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch");
1219 pb_log(2,"DEBUG($v) patches: ".Dumper($pb->{'patches'})."\n");
1220 # TODO: Make it CMS aware
1221 $pb->{'sources'} = pb_list_sfiles("$ENV{'PBROOTDIR'}/$pbpkg/pbsrc", $pb->{'sources'}, $pbos, "$ENV{'PBROOTDIR'}/$pbpkg/pbextsrc");
1222 pb_log(2,"DEBUG($v) sources: ".Dumper($pb->{'sources'})."\n");
1223
1224 if (defined $pb->{'patches'}->{$v}) {
1225 # Filter potential patches (local + remote)
1226 pb_mkdir_p("$dest/pbconf/$v/pbpatch");
1227 # If Debian based distribution, then prepare what will be done at build time
1228 my ($patchcmd,$patchopt);
1229 if ($pbos->{'type'} eq "deb") {
1230 ($patchcmd,$patchopt) = pb_distro_get_param($pbos,pb_conf_get_if("ospatchcmd","ospatchopt"));
1231 open(SCRIPT,"> $dest/pbconf/$v/pbpatch/pbapplypatch") || die "Unable to create $dest/pbconf/$v/pbpatch/pbapplypatch";
1232 print SCRIPT "#!/bin/bash\n";
1233 print SCRIPT "set -x\n" if ($pbdebug gt 1);
1234 }
1235 foreach my $pf (split(/,/,$pb->{'patches'}->{$v})) {
1236 my $pp = basename($pf);
1237 pb_vcs_export($pf,undef,"$dest/pbconf/$v/pbpatch");
1238 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",$pb);
1239 pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
1240 if ($pbos->{'type'} eq "deb") {
1241 # If Debian based distribution, then prepare what will be done at build time
1242 # by applying the patches that will be available under the debian/patches dir
1243 print SCRIPT "$patchcmd $patchopt \< debian/patches/$pp\n";
1244 }
1245 }
1246 if ($pbos->{'type'} eq "deb") {
1247 close(SCRIPT);
1248 chmod 0755,"$dest/pbconf/$v/pbpatch/pbapplypatch";
1249 }
1250 #pb_system("cat $dest/pbconf/$v/pbpatch/pbapplypatch","APPLY","verbose");
1251 }
1252 if (defined $pb->{'sources'}->{$v}) {
1253 pb_mkdir_p("$dest/pbconf/$v/pbsrc");
1254 foreach my $pf (split(/,/,$pb->{'sources'}->{$v})) {
1255 my $pp = basename($pf);
1256 pb_vcs_export($pf,undef,"$dest/pbconf/$v/pbsrc");
1257 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbsrc/$pp",$pb);
1258 }
1259 }
1260 # Filter build files at the end, as they depend on patches and sources
1261 foreach my $f (keys %bfiles) {
1262 pb_filter_file("$ENV{'PBROOTDIR'}/$bfiles{$f}",$ptr,"$dest/pbconf/$v/$f",$pb);
1263 }
1264 foreach my $f (keys %pkgfiles) {
1265 pb_filter_file("$ENV{'PBROOTDIR'}/$pkgfiles{$f}",$ptr,"$dest/pbconf/$v/$f",$pb);
1266 }
1267 }
1268
1269 if (defined $pbparallel) {
1270 # Communicate results back to parent
1271 my $str = "";
1272 $str .= "build $v = $build{$v}\n" if (defined $build{$v});
1273 $str .= "patches $v = $pb->{'patches'}->{$v}\n" if (defined $pb->{'patches'}->{$v});
1274 $str .= "sources $v = $pb->{'sources'}->{$v}\n" if (defined $pb->{'sources'}->{$v});
1275 pb_set_content("$tmpd/$$","$str");
1276 $pm->finish;
1277 }
1278 }
1279 # In the parent, we need to get the result from the children
1280 $pm->wait_all_children if (defined $pbparallel);
1281 die "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error));
1282 my $made = "";
1283 my %h = ();
1284 my %tmp;
1285 my %tmp2;
1286 my $pt;
1287 my $k;
1288
1289 foreach $k (<$tmpd/*>) {
1290 $made .= pb_get_content($k);
1291 }
1292 pb_rm_rf($tmpd);
1293 pb_log(3,"MADE:\n$made");
1294
1295 # Rebuild local hashes
1296 foreach $k (split(/\n/,$made)) {
1297 if ($k =~ /^\s*([A-z0-9-_]+)\s+([[A-z0-9-_.]+)\s*=\s*(.+)$/) {
1298 $h{$1}->{$2}=$3;
1299 }
1300 }
1301 pb_log(2,"HASH: ".Dumper(%h));
1302
1303 # Patches
1304 pb_log(0,"Delivered and compressed patches ");
1305 $pt = $h{'patches'};
1306 foreach $k (keys %$pt) {
1307 foreach my $v1 (split(/,/,$pt->{$k})) {
1308 $tmp{$v1} = "";
1309 }
1310 }
1311 if (keys %tmp) {
1312 foreach $k (keys %tmp) {
1313 pb_log(0,"$k ");
1314 }
1315 } else {
1316 pb_log(0,"N/A");
1317 }
1318 pb_log(0,"\n");
1319
1320 # Sources
1321 pb_log(0,"Delivered additional sources ");
1322 $pt = $h{'sources'};
1323 foreach $k (keys %$pt) {
1324 foreach my $v1 (split(/,/,$pt->{$k})) {
1325 $tmp2{$v1} = "";
1326 }
1327 }
1328 if (keys %tmp2) {
1329 foreach $k (keys %tmp2) {
1330 pb_log(0,"$k ");
1331 }
1332 } else {
1333 pb_log(0,"N/A");
1334 }
1335 pb_log(0,"\n");
1336
1337 # Build files
1338 my @found;
1339 my @notfound;
1340 $pt = $h{'build'};
1341 foreach my $b (keys %$pt) {
1342 push @found,$b if ($pt->{$b} =~ /yes/);
1343 push @notfound,$b if ($pt->{$b} =~ /no/);
1344 }
1345 pb_log(0,"Build files have been generated for ... ".join(',',sort(@found))."\n") if (@found);
1346 pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
1347
1348 } else {
1349 # Instead call News generation
1350 pb_web_news2html($dest);
1351 # And create an empty pbconf
1352 pb_mkdir_p("$dest/pbconf");
1353 # And prepare the pbscript to execute remotely
1354 open(SCRIPT,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
1355 print SCRIPT "#!/bin/bash\n";
1356 print SCRIPT "#set -x\n";
1357 print SCRIPT "echo ... Extracting Website content\n";
1358 print SCRIPT "find . -type f | grep -Ev '^./$pbpkg-$pbver$pbextdir.tar.gz|^./pbscript' | xargs rm -f non-existent\n";
1359 print SCRIPT "find * -type d -depth | xargs rmdir 2> /dev/null \n";
1360 print SCRIPT "tar xfz $pbpkg-$pbver$pbextdir.tar.gz\n";
1361 print SCRIPT "mv $pbpkg-$pbver$pbextdir/* .\n";
1362 print SCRIPT "rm -f $pbpkg-$pbver$pbextdir.tar.gz\n";
1363 print SCRIPT "rmdir $pbpkg-$pbver$pbextdir\n";
1364 print SCRIPT "find . -type f -print0 | xargs -0 chmod 644\n";
1365 print SCRIPT "find . -type d -print0 | xargs -0 chmod 755\n";
1366 close(SCRIPT);
1367 chmod 0755,"$ENV{'PBTMP'}/pbscript";
1368 }
1369
1370 # Apply filters to the non-build files
1371 my $liste ="";
1372 if (defined $filteredfiles->{$pbpkg}) {
1373 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
1374 pb_filter_file_inplace($ptr,"$dest/$f",$pb);
1375 $liste = "$f $liste";
1376 }
1377 }
1378 pb_log(2,"Files ".$liste."have been filtered\n");
1379
1380 # TODO: Make it CMS aware
1381 # Execute the pbinit script if any
1382 if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
1383 pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$pb);
1384 chmod 0755,"$ENV{'PBTMP'}/pbinit";
1385 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit under $dest","verbose");
1386 }
1387
1388 # Do we have additional script to run to prepare the environement for the project ?
1389 # Then include it in the pbconf delivery
1390 foreach my $pbvf (<$ENV{'PBROOTDIR'}/pbv*.pre>,<$ENV{'PBROOTDIR'}/pbv*.post>, <$ENV{'PBROOTDIR'}/pbtest*>) {
1391 if (-x "$pbvf") {
1392 my $target = "$ENV{'PBDESTDIR'}/".basename($pbvf);
1393 pb_filter_file("$pbvf",$ptr,$target,$pb);
1394 chmod 0755,"$target";
1395 }
1396 }
1397
1398 # Prepare the dest directory for archive
1399 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
1400 if (defined $preserve) {
1401 # In that case we want to preserve the original tar file for checksum purposes
1402 # The one created is btw equivalent in that case to this one
1403 # Maybe check basename of both to be sure they are the same ?
1404 pb_log(0,"Preserving original tar file ");
1405 move("$preserve","$pbpkg-$pbver$pbextdir.tar.gz");
1406 } else {
1407 # Possibility to look at PBSRC to guess more the filename
1408 pb_system("tar cfz $pbpkg-$pbver$pbextdir.tar.gz --exclude=$pbpkg-$pbver$pbextdir/pbconf $pbpkg-$pbver$pbextdir","Creating $pbpkg tar files compressed");
1409 }
1410 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz\n");
1411 pb_system("tar cfz $pbpkg-$pbver$pbextdir.pbconf.tar.gz $pbpkg-$pbver$pbextdir/pbconf","Creating pbconf tar files compressed");
1412 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.pbconf.tar.gz\n");
1413
1414 # Keep track of version-tag per pkg
1415 $pkgs{$pbpkg} = "$pbver-$pbtag";
1416
1417 # Final cleanup
1418 pb_rm_rf($dest) if (-d $dest);
1419 }
1420
1421 # Keep track of per package version
1422 pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
1423 open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
1424 foreach my $pbpkg (keys %pkgs) {
1425 print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
1426 }
1427 close(PKG);
1428
1429 # Keep track of what is generated by default
1430 # We need to store the dir and info on version-tag
1431 # Base our content on the existing .pb file
1432 copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
1433 open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
1434 print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
1435 print LAST "projver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
1436 print LAST "projtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
1437 print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
1438 print LAST "pbextdir $ENV{'PBPROJ'} = $pbextdir\n";
1439 close(LAST);
1440}
1441
1442sub pb_test2pkg {
1443 # Get the running distro to test on
1444 my $pbos = pb_distro_get_context();
1445
1446 # Get list of packages to test
1447 # Get content saved in cms2build
1448 my $ptr = pb_get_pkg();
1449 @pkgs = @$ptr;
1450
1451 # Additional potential repo
1452 pb_distro_setuprepo($pbos);
1453 foreach my $pbpkg (@pkgs) {
1454 # We need to install the package to test, and deps brought with it
1455 pb_distro_installdeps(undef,$pbos,$pbpkg);
1456 pb_system("$ENV{'PBDESTDIR'}/pbtest","Launching test for $pbpkg","verbose");
1457 }
1458}
1459
1460sub pb_build2pkg {
1461
1462 my $do_install = shift;
1463
1464 pb_log(0,"INFO: ------ Starting to build package ------\n");
1465 # Get the running distro to build on
1466 my $pbos = pb_distro_get_context();
1467
1468 # If needed we may add repository to the build env
1469 pb_distro_setuprepo($pbos);
1470
1471 # Get list of packages to build
1472 my $ptr = pb_get_pkg();
1473 @pkgs = @$ptr;
1474
1475 # Get content saved in cms2build
1476 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
1477 $pkg = { } if (not defined $pkg);
1478 my $pbextdir = pb_get_extdir();
1479
1480 pb_mkdir_p("$ENV{'PBBUILDDIR'}") if (! -d "$ENV{'PBBUILDDIR'}");
1481 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1482 my $made = ""; # pkgs made during build
1483 my $pm;
1484 my $all_ok = 1;
1485
1486 if (defined $pbparallel) {
1487 $pm = new Parallel::ForkManager($pbparallel);
1488 $pm->run_on_finish(sub { my ($pid, $code, $id, $signal, $dump) = @_;
1489 $all_ok = 0 unless (($code == 0) && ($signal == 0) && ($dump == 0)); });
1490 }
1491
1492 # We need to communicate info back from the children if parallel so prepare a dir for that
1493 my $tmpd = "$ENV{'PBTMP'}/build.$$";
1494 pb_mkdir_p($tmpd) if (defined $pbparallel);
1495
1496 # Do it here as this doesn't work in // mode as itdies if it fails
1497 if ($pbos->{'type'} eq "rpm") {
1498 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
1499 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
1500 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d");
1501 }
1502 }
1503 }
1504
1505 foreach my $pbpkg (@pkgs) {
1506 $pm->start and next if (defined $pbparallel);
1507
1508 my $vertag = $pkg->{$pbpkg};
1509 pb_log(2,"Vertag: $vertag\n");
1510 # get the version of the current package - maybe different
1511 ($pbver,$pbtag) = split(/-/,$vertag);
1512
1513 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz";
1514 my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.pbconf.tar.gz";
1515 pb_log(2,"Source file: $src\n");
1516 pb_log(2,"Pbconf file: $src2\n");
1517
1518 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
1519 if ($pbos->{'type'} eq "rpm") {
1520 # Remove in case a previous link/file was there
1521 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
1522 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
1523 # We need to first extract the spec file
1524 my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/","$ENV{'PBBUILDDIR'}/SPECS","spec");
1525
1526 # We need to handle potential patches to upstream sources
1527 pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
1528
1529 # We need to handle potential additional sources to upstream sources
1530 pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbsrc/","$ENV{'PBBUILDDIR'}/SOURCES","src");
1531
1532 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
1533 # set LANGUAGE to check for correct log messages
1534 $ENV{'LANGUAGE'}="C";
1535 # Older Redhat use _target_platform in %configure incorrectly
1536 my $specialdef = "";
1537 if (($pbos->{'name'} eq "rhel") && ($pbos->{'version'} eq "2.1")) {
1538 $specialdef = "--define \'_target_platform \"\"\'";
1539 }
1540 my $buildcmd = "rpmbuild";
1541 if (($pbos->{'name'} eq "redhat") && ($pbos->{'version'} =~ /^6/)){
1542 $buildcmd = "rpm" ;
1543 }
1544
1545 foreach my $f (@specfile) {
1546 if ($f =~ /\.spec$/) {
1547 # This could cause an issue in // mode
1548 pb_distro_installdeps($f,$pbos);
1549 pb_system("$buildcmd $specialdef --define \"packager $ENV{'PBPACKAGER'}\" --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
1550 last;
1551 }
1552 }
1553 # Get the name of the generated packages
1554 open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to open $ENV{'PBTMP'}/system.$$.log";
1555 while (<LOG>) {
1556 chomp($_);
1557 next if ($_ !~ /^Wrote:/);
1558 s|.*/([S]*RPMS.*)|$1|;
1559 $made .=" $_";
1560 }
1561 close(LOG);
1562
1563 } elsif ($pbos->{'type'} eq "deb") {
1564 pb_system("tar xfz $src","Extracting sources");
1565 pb_system("tar xfz $src2","Extracting pbconf");
1566
1567 chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
1568 pb_rm_rf("debian");
1569 my $confdir = "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
1570 die "Configuration directory $confdir is not a directory\nIs os description listed in your {ve,vm,rm}list values?" if (not -d $confdir);
1571 symlink "$confdir","debian" || die "Unable to symlink 'debian' to $confdir";
1572 chmod 0755,"debian/rules";
1573
1574 # We need to handle potential patches to upstream sources
1575 pb_mkdir_p("debian/patches");
1576 my @f = pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbpatch/","debian/patches","patch");
1577
1578 # By default we use format 1.0 - Cf man dpkg-source
1579 my $debsrcfmt = "1.0";
1580 my $debsrcfile = "debian/source/format";
1581 if (-f $debsrcfile) {
1582 $debsrcfmt = pb_get_content($debsrcfile);
1583 }
1584
1585 if ($debsrcfmt =~ /^3.*quilt/) {
1586 # If we use quilt to manage patches, we then setup the env correctly
1587 # as per http://pkg-perl.alioth.debian.org/howto/quilt.html
1588 # Generate Debian patch series for quilt
1589 open(SERIE,"> debian/patches/series") || die "Unable to write in debian/patches/series";
1590 $ENV{'QUILT_PATCHES'}="debian/patches";
1591 } else {
1592 # If we use dpatch to manage patches, we then setup the 00list file as well
1593 open(SERIE,"> debian/patches/00list") || die "Unable to write in debian/patches/00list";
1594 }
1595 foreach my $f (sort @f) {
1596 # Skip the script made to apply the patches to the Debian tree
1597 next if ($f =~ /pbapplypatch/);
1598 # We also need to uncompress them
1599 pb_system("gzip -d $f","","quiet");
1600 $f =~ s/\.gz$//;
1601 print SERIE "$f\n";
1602 }
1603 close(SERIE);
1604 if (@f) {
1605 # We have patches...
1606 my $patch_file = "debian/patches/pbapplypatch";
1607 if (($debsrcfmt =~ /^1.*/) && (-x $patch_file)) {
1608 # In that case we need to apply the patches ourselves locally
1609 pb_system("cat $patch_file","APPLY","verbose");
1610 pb_system("$patch_file","Applying patches to $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} tree");
1611 }
1612 # ...so modify the name of files to be Debian compliant
1613 move("../$src","../$pbpkg-$pbver$pbextdir.orig.tar.gz");
1614 }
1615
1616 # We need to handle potential additional sources to upstream sources
1617 #pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbsrc/","$ENV{'PBBUILDDIR'}/debian","src");
1618
1619 # This can create problems in // mode as well
1620 pb_distro_installdeps("debian/control",$pbos);
1621 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
1622
1623 # Get the name of the generated packages
1624 open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to open $ENV{'PBTMP'}/system.$$.log";
1625 while (<LOG>) {
1626 chomp();
1627 pb_log(3,"In loop: $_\n");
1628 next unless (/^dpkg-deb.*\.\.\/(.*_.*\.deb).*/);
1629 my $tmp = $1;
1630 #doesn't work in my case
1631 #die "Missing file $tmp" if (not -f "../$tmp");
1632 $made = "$made $tmp";
1633 }
1634 close(LOG);
1635 pb_log(2,"Now made is: $made\n");
1636
1637 open(CTRL,"debian/control") || die "Unable to open debian/control: $!";
1638 while (<CTRL>) {
1639 pb_log(3,"In loop: $_\n");
1640 next unless (/^Source: (\S+)/o);
1641 my $tmp = $1;
1642 $made = "$made $tmp"."_*.dsc $tmp"."_*.tar.gz $tmp"."_*.changes";
1643 #doesn't work in my case
1644 #foreach my $glob (("$1\_*.changes", "$1\_*.dsc", "$1\_*.tar.gz")) {
1645 #my @file = glob($glob);
1646 #die "Missing file for $glob" unless (@file > 0);
1647 #die "Too many files for $glob" if (@file > 1);
1648 #die "Missing file $file[0]" if (not -f $file[0]);
1649 #$made .= " $file[0]";
1650 #}
1651 }
1652 close(CTRL);
1653 #pb_display_file("$ENV{'PBTMP'}/system.$$.log");
1654 pb_log(2,"Finally made is: $made\n");
1655
1656 chdir ".." || die "Unable to chdir to parent dir";
1657 pb_rm_rf("$pbpkg-$pbver$pbextdir");
1658 } elsif ($pbos->{'type'} eq "ebuild") {
1659 my @ebuildfile;
1660 # For gentoo we need to take pb as subsystem name
1661 # We put every apps here under sys-apps. hope it's correct
1662 # We use pb's home dir in order to have a single OVERLAY line
1663 my $tmpe = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
1664 pb_mkdir_p($tmpe) if (! -d "$tmpe");
1665 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
1666
1667 # We need to first extract the ebuild file
1668 @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/","$tmpe","ebuild");
1669
1670 # Prepare the build env for gentoo
1671 my $found = 0;
1672 my $pbbd = $ENV{'HOME'};
1673 $pbbd =~ s|/|\\/|g;
1674 if (-r "/etc/make.conf") {
1675 open(MAKE,"/etc/make.conf");
1676 while (<MAKE>) {
1677 $found = 1 if (/$pbbd\/portage/);
1678 }
1679 close(MAKE);
1680 }
1681 if ($found == 0) {
1682 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
1683 }
1684 #$found = 0;
1685 #if (-r "/etc/portage/package.keywords") {
1686 #open(KEYW,"/etc/portage/package.keywords");
1687 #while (<KEYW>) {
1688 #$found = 1 if (/portage\/pb/);
1689 #}
1690 #close(KEYW);
1691 #}
1692 #if ($found == 0) {
1693 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
1694 #}
1695
1696 # Build
1697 foreach my $f (@ebuildfile) {
1698 if ($f =~ /\.ebuild$/) {
1699 pb_distro_installdeps($f,$pbos);
1700 move($f,"$tmpe/$pbpkg-$pbver.ebuild");
1701 pb_system("cd $tmpe ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
1702 # Now move it where pb expects it
1703 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
1704 if ($pbtag eq 0) {
1705 # This is assumed to be a test version
1706 my $nver = substr($pbver,0,-14);
1707 my $ntag = substr($pbver,-14);
1708 my $ebtg = "portage/pb/sys-apps/$pbpkg/$pbpkg-$nver"."_p$ntag.ebuild";
1709 move("$tmpe/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/$ebtg");
1710 $made="$made $ebtg";
1711 } else {
1712 my $ebtg = "portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-r$pbtag.ebuild";
1713 move("$tmpe/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/$ebtg");
1714 $made="$made $ebtg";
1715 }
1716 }
1717 }
1718
1719 } elsif ($pbos->{'type'} eq "tgz") {
1720 # Slackware family
1721 $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
1722
1723 pb_system("tar xfz $src","Extracting sources");
1724 pb_system("tar xfz $src2","Extracting pbconf");
1725 chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
1726 symlink "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}","install" || die "Unable to symlink to pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
1727 if (-x "install/pbslack") {
1728 pb_distro_installdeps("./install/pbslack",$pbos);
1729 pb_system("./install/pbslack","Building software");
1730 pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
1731 }
1732 chdir ".." || die "Unable to chdir to parent dir";
1733 pb_rm_rf("$pbpkg-$pbver$pbextdir");
1734 } elsif ($pbos->{'type'} eq "pkg") {
1735 # Solaris
1736 $made="$made $pbpkg-$pbver-$pbtag.pkg.gz";
1737 my $pkgdestdir="$ENV{'PBBUILDDIR'}/install";
1738
1739 # Will host resulting packages
1740 pb_mkdir_p("$pbos->{'type'}");
1741 pb_mkdir_p("$pkgdestdir/delivery");
1742 pb_system("tar xfz $src","Extracting sources under $ENV{'PBBUILDDIR'}");
1743 pb_system("tar xfz $src2","Extracting pbconf under $ENV{'PBBUILDDIR'}");
1744 # We need to handle potential patches to upstream sources
1745 pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbpatch/","$ENV{'PBBUILDDIR'}","patch");
1746
1747 # We need to handle potential additional sources to upstream sources
1748 pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbsrc/","$ENV{'PBBUILDDIR'}","src");
1749
1750 chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
1751 if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild") {
1752 chmod 0755,"pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild";
1753 # pkginfo file is mandatory
1754 die "Unable to find pkginfo file in pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}" if (! -f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pkginfo");
1755 # Build
1756 pb_system("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild $pkgdestdir/delivery","Building software and installing under $pkgdestdir/delivery");
1757 # Copy complementary files
1758 if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/prototype") {
1759 copy("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/prototype", $pkgdestdir)
1760 } else {
1761 # No prototype provided, calculating it
1762 open(PROTO,"> $pkgdestdir/prototype") || die "Unable to create prototype file";
1763 print PROTO "i pkginfo\n";
1764 print PROTO "i depend\n" if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/depend");
1765 $ENV{'PBSOLDESTDIR'} = "$pkgdestdir/delivery";
1766 find(\&create_solaris_prototype, "$pkgdestdir/delivery");
1767 }
1768 copy("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/depend", $pkgdestdir) if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/depend");
1769 copy("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pkginfo", $pkgdestdir);
1770 pb_system("cd $pkgdestdir/delivery ; pkgmk -o -f ../prototype -r $pkgdestdir/delivery -d $ENV{'PBBUILDDIR'}/$pbos->{'type'}","Packaging $pbpkg","verbose");
1771 pb_system("cd $ENV{'PBBUILDDIR'}/$pbos->{'type'} ; echo \"\" | pkgtrans -o -n -s $ENV{'PBBUILDDIR'}/$pbos->{'type'} $ENV{'PBBUILDDIR'}/$pbpkg-$pbver-$pbtag.pkg all","Transforming $pbpkg","verbose");
1772 pb_system("cd $ENV{'PBBUILDDIR'} ; gzip -9f $pbpkg-$pbver-$pbtag.pkg","Compressing $pbpkg-$pbver-$pbtag.pkg","verbose");
1773 } else {
1774 pb_log(0,"No pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild file found for $pbpkg-$pbver in \n");
1775 }
1776 chdir ".." || die "Unable to chdir to parent dir";
1777 pb_rm_rf("$pbpkg-$pbver$pbextdir","$ENV{'PBBUILDDIR'}/$pbos->{'type'}","$pkgdestdir");
1778 } elsif ($pbos->{'type'} eq "hpux") {
1779 # HP-UX
1780 pb_system("tar xfz $src","Extracting sources");
1781 pb_system("tar xfz $src2","Extracting pbconf");
1782
1783 chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
1784 pb_system("buildpackage ","Building package","verbose");
1785 # Get the name of the generated packages
1786 open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to open $ENV{'PBTMP'}/system.$$.log";
1787 while (<LOG>) {
1788 chomp();
1789 my $tmp = $_;
1790 next if ($tmp !~ /^SD BUILD.*:/);
1791 $tmp =~ s|.*../(.*)_(.*).sd.*|$1|;
1792 $made = "$made $tmp"."_*.sd";
1793 }
1794 close(LOG);
1795 $made="$made $pbpkg-$pbver-$pbtag.sd";
1796
1797 chdir ".." || die "Unable to chdir to parent dir";
1798 pb_rm_rf("$pbpkg-$pbver$pbextdir");
1799 } else {
1800 die "Unknown OS type format $pbos->{'type'}";
1801 }
1802 if (defined $pbparallel) {
1803 # Communicate results back to parent
1804 pb_set_content("$tmpd/$$",$made);
1805 $pm->finish;
1806 }
1807 }
1808 if (defined $pbparallel) {
1809 # In the parent, we need to get the result from the children
1810 $pm->wait_all_children;
1811 foreach my $f (<$tmpd/*>) {
1812 $made .= " ".pb_get_content($f);
1813 }
1814 die "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error));
1815 pb_rm_rf($tmpd);
1816 }
1817
1818 # Sign packages
1819 pb_sign_pkgs($pbos,$made);
1820 pb_log(0,"INFO: ------ Finished building package ------\n");
1821
1822 # Find the appropriate check cmd/opts
1823 my ($chkcmd,$chkopt) = pb_distro_get_param($pbos,pb_conf_get_if("oschkcmd","oschkopt"));
1824
1825 my $ret = "";
1826 # Packages check if needed
1827 if ($pbos->{'type'} eq "rpm") {
1828 if ((defined $chkcmd) && (-x $chkcmd)) {
1829 my $cmd = "$chkcmd";
1830 $cmd .= " $chkopt" if (defined $chkopt);
1831 $cmd .= " $made";
1832 my $ret = pb_system("$cmd","Checking validity of rpms with $chkcmd","mayfail");
1833 pb_log(0,"ERROR: when checking packages validity\n") if ($ret ne 0);
1834 }
1835 my $rpms ="";
1836 my $srpms ="";
1837 foreach my $f (split(/ /,$made)) {
1838 $rpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^RPMS\//);
1839 $srpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^SRPMS\//);
1840 }
1841 pb_log(0,"SRPM packages generated: $srpms\n");
1842 pb_log(0,"RPM packages generated: $rpms\n");
1843 $ret = $rpms;
1844 } elsif ($pbos->{'type'} eq "deb") {
1845 my $made2 = "";
1846 foreach my $f (split(/ /,$made)) {
1847 $made2 .= "$f " if ($f =~ /\.deb$/);
1848 }
1849 if ((defined $chkcmd) && (-x $chkcmd)) {
1850 my $ret = pb_system("$chkcmd $chkopt $made2","Checking validity of debs with $chkcmd","mayfail");
1851 pb_log(0,"ERROR: when checking packages validity\n") if ($ret ne 0);
1852 }
1853 pb_log(0,"deb packages generated: $made2\n");
1854 $ret = $made2;
1855 } else {
1856 pb_log(0,"No check done for $pbos->{'type'} yet\n");
1857 pb_log(0,"Packages generated: $made\n");
1858 $ret = $made;
1859 }
1860
1861 # Keep track of what is generated so that we can get them back from VMs/RMs
1862 my $pbkeep = "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
1863 open(KEEP,"> $pbkeep") || die "Unable to create $pbkeep: $!";
1864 print KEEP "$made\n";
1865 close(KEEP);
1866 pb_distro_installdeps(undef,$pbos,$ret) if ($do_install);
1867}
1868
1869sub create_solaris_prototype {
1870
1871 my $uidgid = "bin bin";
1872 my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
1873
1874 return if ($_ =~ /^$pkgdestdir$/);
1875 if (-d $_) {
1876 my $n = $File::Find::name;
1877 $n =~ s~$pkgdestdir/~~;
1878 print PROTO "d none $n 0755 $uidgid\n";
1879 } elsif (-x $_) {
1880 my $n = $File::Find::name;
1881 $n =~ s~$pkgdestdir/~~;
1882 print PROTO "f none $n 0755 $uidgid\n";
1883 } elsif (-f $_) {
1884 my $n = $File::Find::name;
1885 $n =~ s~$pkgdestdir/~~;
1886 print PROTO "f none $n 0644 $uidgid\n";
1887 }
1888}
1889
1890sub pb_build2ssh {
1891 pb_send2target("Sources");
1892 pb_send2target("CPAN");
1893}
1894
1895sub pb_pkg2ssh {
1896 pb_send2target("Packages");
1897}
1898
1899# By default deliver to the the public site hosting the
1900# ftp structure (or whatever) or a VM/VE/RM
1901sub pb_send2target {
1902
1903 my $cmt = shift;
1904 my $v = shift || undef;
1905 my $vmexist = shift || 0; # 0 is FALSE
1906 my $vmpid = shift || 0; # 0 is FALSE
1907 my $snapme = shift || 0; # 0 is FALSE
1908
1909 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
1910 my $host = "sshhost";
1911 my $login = "sshlogin";
1912 my $dir = "sshdir";
1913 my $port = "sshport";
1914 my $conf = "sshconf";
1915 my $tmout = undef;
1916 my $path = undef;
1917 if ($cmt =~ /^VM/) {
1918 $login = "vmlogin";
1919 $dir = "pbdefdir";
1920 # Specific VM
1921 $tmout = "vmtmout";
1922 $path = "vmpath";
1923 $host = "vmhost";
1924 $port = "vmport";
1925 } elsif ($cmt =~ /^RM/) {
1926 $login = "rmlogin";
1927 $dir = "pbdefdir";
1928 # Specific RM
1929 $tmout = "rmtmout";
1930 $path = "rmpath";
1931 $host = "rmhost";
1932 $port = "rmport";
1933 } elsif ($cmt =~ /^VE/) {
1934 $login = "velogin";
1935 $dir = "pbdefdir";
1936 # Specific VE
1937 $path = "vepath";
1938 $conf = "rbsconf";
1939 } elsif ($cmt eq "Web") {
1940 $host = "websshhost";
1941 $login = "websshlogin";
1942 $dir = "websshdir";
1943 $port = "websshport";
1944 } elsif ($cmt eq "CPAN") {
1945 $host = "cpanpause";
1946 $login = "";
1947 $dir = "cpandir";
1948 $port = "";
1949 }
1950 my $cmd = "";
1951 my $src = "";
1952 my $cpanpkg = 0;
1953 my $pbos;
1954
1955 my $pbextdir = pb_get_extdir();
1956
1957 if ($cmt ne "Announce") {
1958 # Get list of packages to build
1959 my $ptr = pb_get_pkg();
1960 my @pkgs = ();
1961 @pkgs = @$ptr if (defined $ptr);
1962
1963 # Get the running distro to consider
1964 $pbos = pb_distro_get_context($v);
1965
1966 my $pkg = { };
1967 # Get content saved in cms2build
1968 if ((defined $ENV{'PBDESTDIR'}) && (defined $ENV{'PBPROJVER'}) && (defined $ENV{'PBPROJTAG'}) && (-f "$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb")) {
1969 ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
1970 $pkg = { } if (not defined $pkg);
1971 }
1972
1973 pb_mkdir_p("$ENV{'PBBUILDDIR'}") if (! -d "$ENV{'PBBUILDDIR'}");
1974 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1975 foreach my $pbpkg (@pkgs) {
1976 my $vertag = $pkg->{$pbpkg};
1977 # get the version of the current package - maybe different
1978 pb_log(2,"Vertag: $vertag\n");
1979 ($pbver,$pbtag) = split(/-/,$vertag);
1980
1981 if (($cmt eq "Sources") || ($cmt =~ /(V[EM]|RM)build/)) {
1982 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.pbconf.tar.gz";
1983 if ($cmd eq "") {
1984 $cmd = "ln -sf $pbpkg-$pbver$pbextdir.tar.gz $pbpkg-latest.tar.gz";
1985 } else {
1986 $cmd = "$cmd ; ln -sf $pbpkg-$pbver$pbextdir.tar.gz $pbpkg-latest.tar.gz";
1987 }
1988 } elsif ($cmt eq "Web") {
1989 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz"
1990 }
1991
1992 # Do we have one perl package
1993 my @nametype = pb_conf_get_if("namingtype");
1994 my $type = $nametype[0]->{$pbpkg};
1995 if ((defined $type) && ($type eq "perl")) {
1996 $cpanpkg = 1;
1997 }
1998 }
1999 # Adds conf file for availability of conf elements
2000 pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") if ((defined $ENV{'PBROOTDIR'}) && (-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb"));
2001 }
2002 my ($rbsconf,$testver,$delivery) = pb_conf_get_if($conf,"testver","delivery");
2003 if ($cmt eq "CPAN") {
2004 # Do not deliver on Pause if this is a test version
2005 return if (not defined $testver);
2006 return if ($testver =~ /true/);
2007 # Do not deliver on Pause if this is not a perl package
2008 return if ($cpanpkg == 0);
2009 }
2010
2011 if ($cmt =~ /(V[EM]|RM)build/) {
2012 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript.$$";
2013 } elsif ($cmt =~ /(V[EM]|RM)Script/) {
2014 $src="$src $ENV{'PBDESTDIR'}/pbscript.$$";
2015 } elsif ($cmt =~ /(V[EM]|RM)test/) {
2016 $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";
2017 } elsif (($cmt eq "Announce") || ($cmt eq "Web") || ($cmt eq "CPAN")) {
2018 $src="$src $ENV{'PBTMP'}/pbscript";
2019 } elsif ($cmt eq "Packages") {
2020 # Get package list from file made during build2pkg
2021 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
2022 $src = <KEEP>;
2023 chomp($src);
2024 close(KEEP);
2025 $src = "$src $ENV{'PBBUILDDIR'}/pbscript.$$";
2026 }
2027 if (($cmt eq "Sources") || ($cmt eq "Packages") || ($cmt eq "CPAN")) {
2028 my ($pbpackager) = pb_conf_get("pbpackager");
2029 $ENV{'PBPACKAGER'} = $pbpackager->{$ENV{'PBPROJ'}};
2030 pb_log(0,"Exporting public key for $ENV{'PBPACKAGER'}\n");
2031 # Using pb_system is not working due to redirection below
2032 system("gpg --export -a \'$ENV{'PBPACKAGER'}\' > $ENV{'PBDESTDIR'}/$ENV{'PBPROJ'}.pubkey");
2033 chmod 0644,"$ENV{'PBDESTDIR'}/$ENV{'PBPROJ'}.pubkey";
2034 $src = "$src $ENV{'PBDESTDIR'}/$ENV{'PBPROJ'}.pubkey";
2035 }
2036 # Remove potential leading spaces (cause problem with basename)
2037 $src =~ s/^ *//;
2038 my $basesrc = "";
2039 foreach my $i (split(/ +/,$src)) {
2040 $basesrc .= " ".basename($i);
2041 }
2042
2043 pb_log(0,"Sources handled ($cmt): $src\n");
2044 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$path,$conf))."\n");
2045 my ($sshhost,$sshdir) = pb_conf_get($host,$dir);
2046 # Not mandatory...
2047 $delivery->{$ENV{'PBPROJ'}} = "" if (not defined $delivery->{$ENV{'PBPROJ'}});
2048 my ($sshlogin,$sshport) = pb_conf_get_if($login,$port);
2049 $sshport->{$ENV{PBPROJ}} = 22 if (not defined $sshport->{$ENV{PBPROJ}});
2050 $sshlogin->{$ENV{PBPROJ}} = getpwuid($UID) if (not defined $sshlogin->{$ENV{PBPROJ}});
2051 my ($vtmout,$vepath);
2052 # ...Except those in virtual context
2053 if ($cmt =~ /^VE/) {
2054 ($vepath) = pb_conf_get($path);
2055 }
2056 if ($cmt =~ /^(V|R)M/) {
2057 $vtmout = pb_distro_get_param($pbos,pb_conf_get_if($tmout));
2058 }
2059 my $remhost = $sshhost->{$ENV{'PBPROJ'}};
2060 my $remdir = $sshdir->{$ENV{'PBPROJ'}};
2061 if ($cmt =~ /^V[EM]|RM/) {
2062 # In that case our real host is in the xxhost with the OS as key, not project as above
2063 $remhost = pb_distro_get_param($pbos,$sshhost);
2064 }
2065 pb_log(2,"ssh: ".Dumper(($remhost,$sshlogin,$remdir,$sshport,$vepath,$rbsconf))."\n");
2066 pb_log(2,"ssh: ".Dumper($vtmout)."\n") if (defined $vtmout);
2067
2068 my $mac;
2069 if ($cmt !~ /^VE/) {
2070 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$remhost";
2071 # Overwrite account value if passed as parameter
2072 $mac = "$pbaccount\@$remhost" if (defined $pbaccount);
2073 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
2074 } else {
2075 # VE
2076 # Overwrite account value if passed as parameter (typically for setup2v)
2077 $mac = $sshlogin->{$ENV{'PBPROJ'}};
2078 $mac = $pbaccount if (defined $pbaccount);
2079 }
2080
2081 my $tdir;
2082 my $bdir;
2083 if (($cmt eq "Sources") || ($cmt =~ /(V[EM]|RM)Script/)) {
2084 $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}/src";
2085 } elsif ($cmt eq "CPAN") {
2086 $tdir = "$remdir";
2087 } elsif ($cmt =~ /(V[EM]|RM)(build|test)/) {
2088 $tdir = $remdir."/$ENV{'PBPROJ'}/delivery";
2089 $bdir = $remdir."/$ENV{'PBPROJ'}/build";
2090 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
2091 $bdir =~ s|\$ENV.+\}/||;
2092 } elsif ($cmt eq "Announce") {
2093 $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}";
2094 } elsif ($cmt eq "Web") {
2095 $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}";
2096 } elsif ($cmt eq "Packages") {
2097 if (($pbos->{'type'} eq "rpm") || ($pbos->{'type'} eq "pkg") || ($pbos->{'type'} eq "hpux") || ($pbos->{'type'} eq "tgz")) {
2098 # put packages under an arch subdir
2099 $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
2100 } elsif (($pbos->{'type'} eq "deb") || ($pbos->{'type'} eq "ebuild")) {
2101 # No need for an arch subdir
2102 $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}";
2103 } else {
2104 die "Please teach the dev team where to deliver ($pbos->{'type'} type of packages\n";
2105 }
2106
2107 my $repodir = $tdir;
2108 $repodir =~ s|^$remdir/||;
2109 my $repotag = "";
2110 $repotag = "-$delivery->{$ENV{'PBPROJ'}}" if ($delivery->{$ENV{'PBPROJ'}} ne "");
2111
2112 my ($pbrepo) = pb_conf_get("pbrepo");
2113
2114 # Repository management
2115 open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript.$$") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript.$$";
2116 if ($pbos->{'type'} eq "rpm") {
2117 my $pbsha = pb_distro_get_param($pbos,pb_conf_get("ossha"));
2118 my $gpgcheck = pb_conf_get_if("pbgpgcheck");
2119 my $pbgpgcheck;
2120 $pbgpgcheck = $gpgcheck->{$ENV{PBPROJ}} if (defined $gpgcheck);
2121 # By default force GPG check in repo even if we support signature of packages to fail. This is a best practice
2122 $pbgpgcheck = 1 if (not defined $pbgpgcheck);
2123 # Also make a pbscript to generate yum/urpmi bases
2124 print PBS << "EOF";
2125#!/bin/bash
2126# Prepare a script to ease yum setup
2127EOF
2128 print PBS "set -x\n" if ($pbdebug gt 1);
2129 print PBS << "EOF";
2130cat > $ENV{'PBPROJ'}$repotag.repo << EOT
2131[$ENV{'PBPROJ'}$repotag]
2132name=$pbos->{'name'} $pbos->{'version'} $pbos->{'arch'} - $ENV{'PBPROJ'} Vanilla Packages
2133baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
2134enabled=1
2135gpgcheck=$pbgpgcheck
2136gpgkey=$pbrepo->{$ENV{'PBPROJ'}}/$repodir/$ENV{'PBPROJ'}.pubkey
2137EOT
2138chmod 644 $ENV{'PBPROJ'}$repotag.repo
2139
2140# Clean up old repo content
2141rm -rf headers/ repodata/
2142# Create yum repo
2143if [ -x /usr/bin/yum-arch ]; then
2144 yum-arch .
2145fi
2146# Create repodata
2147createrepo -s $pbsha .
2148# Link to the key
2149if [ -s $ENV{'PBPROJ'}.pubkey ]; then
2150 # Avoiding creating empty repomd.xml.key; fails on opensuse 12.1
2151 (cd repodata ; ln -sf ../$ENV{'PBPROJ'}.pubkey repomd.xml.key)
2152fi
2153# sign the repomd (at least useful for SLES - which requires a local key)
2154# gpg -a --detach-sign repodata/repomd.xml
2155# SLES also looks for media.1/info.txt
2156EOF
2157 if ($pbos->{'family'} eq "md") {
2158 # For Mandriva add urpmi management
2159 print PBS << "EOF";
2160# Prepare a script to ease urpmi setup
2161cat > $ENV{'PBPROJ'}$repotag.addmedia << EOT
2162urpmi.addmedia $ENV{'PBPROJ'}$repotag $pbrepo->{$ENV{'PBPROJ'}}/$repodir with media_info/hdlist.cz
2163EOT
2164chmod 755 $ENV{'PBPROJ'}$repotag.addmedia
2165
2166# Clean up old repo content
2167rm -f hdlist.cz synthesis.hdlist.cz
2168# Create urpmi repo
2169genhdlist2 --clean .
2170if [ \$\? -ne 0 ]; then
2171 genhdlist .
2172fi
2173EOF
2174 }
2175 if ($pbos->{'name'} eq "fedora") {
2176 # Extract the spec file to please Fedora maintainers :-(
2177 print PBS << "EOF";
2178for p in $basesrc; do
2179 echo \$p | grep -q 'src.rpm'
2180 if [ \$\? -eq 0 ]; then
2181 rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
2182 fi
2183done
2184EOF
2185 }
2186 if ($pbos->{'family'} eq "novell") {
2187 # Add ymp scripts for one-click install on SuSE
2188 print PBS << "EOF";
2189# Prepare a script to ease SuSE one-click install
2190# Cf: http://de.opensuse.org/1-Klick-Installation/ISV
2191#
2192cat > $ENV{'PBPROJ'}$repotag.ymp << EOT
2193<?xml version="1.0" encoding="utf-8"?>
2194<!-- vim: set sw=2 ts=2 ai et: -->
2195<metapackage xmlns:os="http://opensuse.org/Standards/One_Click_Install" xmlns="http://opensuse.org/Standards/One_Click_Install">
2196 <group><!-- The group of software, typically one for project-builder.org -->
2197 <name>$ENV{'PBPROJ'} Bundle</name> <!-- Name of the software group -->
2198 <summary>Software bundle for the $ENV{'PBPROJ'}$repotag project</summary> <!--This message is shown to the user and should describe the whole bundle -->
2199 <description>This is the summary of the $ENV{'PBPROJ'}$repotag Project
2200
2201 Details are available on a per package basis below
2202
2203 </description><!--This is also shown to the user -->
2204 <remainSubscribed>false</remainSubscribed> <!-- Don't know what it mean -->
2205 <repositories><!-- List of needed repositories -->
2206 <repository>
2207 <name>$ENV{'PBPROJ'}$repotag Repository</name> <!-- Name of the repository -->
2208 <summary>This repository contains the $ENV{'PBPROJ'}$repotag project packages.</summary> <!-- Summary of the repository -->
2209 <description>This repository contains the $ENV{'PBPROJ'}$repotag project packages.</description><!-- This description is shown to the user -->
2210 <url>$pbrepo->{$ENV{'PBPROJ'}}/$repodir</url><!--URL of repository, which is added -->
2211 </repository>
2212 </repositories>
2213 <software><!-- A List of packages, which should be added through the one-click-installation -->
2214EOT
2215for p in $basesrc; do
2216 sum=`rpm -q --qf '%{SUMMARY}' \$p`
2217 name=`rpm -q --qf '%{NAME}' \$p`
2218 desc=`rpm -q --qf '%{description}' \$p`
2219 cat >> $ENV{'PBPROJ'}$repotag.ymp << EOT
2220 <item>
2221 <name>\$name</name><!-- Name of the package, is shown to the user and used to identify the package at the repository -->
2222 <summary>\$sum</summary> <!-- Summary of the package -->
2223 <description>\$desc</description> <!-- Description, is shown to the user -->
2224 </item>
2225EOT
2226done
2227cat >> $ENV{'PBPROJ'}$repotag.ymp << EOT
2228 </software>
2229 </group>
2230</metapackage>
2231EOT
2232chmod 644 $ENV{'PBPROJ'}$repotag.ymp
2233EOF
2234 }
2235 } elsif ($pbos->{'type'} eq "deb") {
2236 # Also make a pbscript to generate apt bases
2237 # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
2238 # This dirname removes ver
2239 my $debarch = $pbos->{'arch'};
2240 $debarch = "amd64" if ($pbos->{'arch'} eq "x86_64");
2241 my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
2242 # Remove extra . in path to fix #522
2243 $rpd =~ s|/./|/|g;
2244 my ($projcomponent_map) = pb_conf_get_if("projcomponent");
2245 pb_log(2,"projcomponent = ".Dumper($projcomponent_map)."\n");
2246 my $projcomponent = $projcomponent_map->{$ENV{PBPROJ}};
2247 $projcomponent ||= 'contrib';
2248 print PBS << "EOF";
2249#!/bin/bash
2250# Prepare a script to ease apt setup
2251cat > $ENV{'PBPROJ'}$repotag.sources.list << EOT
2252deb $rpd $pbos->{'version'} $projcomponent
2253deb-src $rpd $pbos->{'version'} $projcomponent
2254EOT
2255chmod 644 $ENV{'PBPROJ'}$repotag.sources.list
2256
2257# Up two levels to deal with the dist dir cross versions
2258cd ..
2259mkdir -p dists/$pbos->{'version'}/$projcomponent/binary-$debarch dists/$pbos->{'version'}/$projcomponent/source
2260
2261# Prepare a script to create apt info file
2262# Reuse twice after
2263TMPD=`mktemp -d /tmp/pb.XXXXXXXXXX` || exit 1
2264mkdir -p \$TMPD
2265cat > \$TMPD/Release << EOT
2266Archive: unstable
2267Component: $projcomponent
2268Origin: $ENV{'PBPROJ'}$repotag
2269Label: $ENV{'PBPROJ'}$repotag dev repository $pbrepo->{$ENV{'PBPROJ'}}
2270EOT
2271
2272echo "Creating Packages metadata"
2273for i in dists/$pbos->{version}/$projcomponent/binary-*; do
2274 arch=`basename \$i | sed 's/binary-//'`
2275 echo "Packages for \$arch:"
2276 dpkg-scanpackages -a\$arch $pbos->{'version'} /dev/null > dists/$pbos->{'version'}/$projcomponent/binary-\$arch/Packages
2277 gzip -9 < dists/$pbos->{'version'}/$projcomponent/binary-\$arch/Packages > dists/$pbos->{'version'}/$projcomponent/binary-\$arch/Packages.gz
2278 bzip2 -9 < dists/$pbos->{'version'}/$projcomponent/binary-\$arch/Packages > dists/$pbos->{'version'}/$projcomponent/binary-\$arch/Packages.bz2
2279done
2280echo "Creating Contents metadata"
2281apt-ftparchive contents $pbos->{'version'} | gzip -c9 > dists/$pbos->{'version'}/Contents.gz
2282echo "Creating Release metadata ($pbos->{'arch'} aka $debarch)"
2283cat \$TMPD/Release > dists/$pbos->{'version'}/$projcomponent/binary-$debarch/Release
2284echo "Architecture: $debarch" >> dists/$pbos->{'version'}/$projcomponent/binary-$debarch/Release
2285echo "Creating Source metadata"
2286dpkg-scansources $pbos->{'version'} /dev/null > dists/$pbos->{'version'}/$projcomponent/source/Sources
2287gzip -9 < dists/$pbos->{'version'}/$projcomponent/source/Sources > dists/$pbos->{'version'}/$projcomponent/source/Sources.gz
2288bzip2 -9 < dists/$pbos->{'version'}/$projcomponent/source/Sources > dists/$pbos->{'version'}/$projcomponent/source/Sources.bz2
2289cat \$TMPD/Release > dists/$pbos->{'version'}/$projcomponent/source/Release
2290echo "Architecture: Source" >> dists/$pbos->{'version'}/$projcomponent/source/Release
2291echo "Creating Release metadata"
2292# Signing that file would be useful but uneasy as gpg keys are not there
2293# Cf: http://wiki.debian.org/SecureApt
2294# Same as for repomd
2295apt-ftparchive -o APT::FTPArchive::Release::Suite=$pbos->{version} release dists/$pbos->{'version'} > dists/$pbos->{'version'}/Release
2296rm -rf \$TMPD
2297EOF
2298 } elsif ($pbos->{'type'} eq "ebuild") {
2299 # make a pbscript to generate links to latest version
2300 print PBS << "EOF";
2301#!/bin/bash
2302# Prepare a script to create correct links
2303for p in $src; do
2304 echo \$p | grep -q '.ebuild'
2305 if [ \$\? -eq 0 ]; then
2306 j=`basename \$p`
2307 pp=`echo \$j | cut -d'-' -f1`
2308 ln -sf \$j \$pp.ebuild
2309 fi
2310done
2311EOF
2312 }
2313 close(PBS);
2314 chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript.$$";
2315 } else {
2316 return;
2317 }
2318
2319 # Useless for VE
2320 my $nport = pb_get_port($sshport,$pbos,$cmt) if ($cmt !~ /^VE/);
2321
2322 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
2323 if ($cmt =~ /^VE/o) {
2324 $tdir =~ s|\$ENV.+\}/|| or confess "for $cmt: $tdir must have \$ENV{'HOME'} in it or the remainder of the code won't work since some parts use relative pathing and others will try absolute. Use a symlink if necessary to place the real files in a different place than under your home directory";
2325 } else {
2326 # process, ok if not present.
2327 $tdir =~ s|\$ENV.+\}/||;
2328 }
2329
2330 my $tm = "";
2331 if ($cmt =~ /^(V|R)M/) {
2332 $tm = "sleep $vtmout" if (defined $vtmout);
2333 }
2334
2335 # ssh communication if not VE or CPAN
2336 # should use a hash instead...
2337 my ($shcmd,$shcmdroot,$cpcmd,$cptarget,$cp2target);
2338 my $tpdir;
2339 if ($cmt =~ /^VE/) {
2340 my $tp = pb_path_expand($vepath->{$ENV{'PBPROJ'}});
2341 $tpdir = pb_path_expand("$tp/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
2342 my ($ptr) = pb_conf_get("vetype");
2343 my $vetype = $ptr->{$ENV{'PBPROJ'}};
2344 my $arch = pb_get_arch();
2345 if ($vetype eq "chroot") {
2346 $shcmdroot = "sudo /usr/sbin/chroot $tpdir ";
2347 $shcmd = "$shcmdroot /bin/su - $mac -c ";
2348 } elsif ($vetype eq "schroot") {
2349 $shcmd = "schroot $tp -u $mac -- ";
2350 }
2351 $shcmd = "setarch i386 $shcmd" if (($pbos->{'arch'} =~ /i[3456]86/) && ($arch eq 'x86_64'));
2352 $cpcmd = "sudo /bin/cp -r ";
2353 # We need to get the home dir of the target account to deliver in the right place
2354 open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd: $!";
2355 my $homedir = "";
2356 while (<PASS>) {
2357 my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
2358 $homedir = $c6 if ($c1 =~ /^$mac$/);
2359 pb_log(3,"Homedir: $homedir - account: $c6\n");
2360 }
2361 close(PASS);
2362 $cptarget = "$tpdir/$homedir/$tdir";
2363 if ($cmt eq "VEbuild") {
2364 $cp2target = "$tpdir/$homedir/$bdir";
2365 }
2366 pb_log(2,"On VE using $cptarget as target dir to copy to\n");
2367 } elsif ($cmt eq "CPAN") {
2368 my $ftpput = pb_check_req("ncftpput",1);
2369 my $ftpget = pb_check_req("wget",1);
2370 my ($cpanuser,$cpanpasswd) = pb_conf_get_if("cpanuser","cpanpasswd");
2371 return if ((not defined $cpanuser) || (not defined $cpanuser->{$ENV{'PBPROJ'}}));
2372 return if ((not defined $cpanpasswd) || (not defined $cpanpasswd->{$ENV{'PBPROJ'}}));
2373 my ($cpansubdir) = pb_conf_get_if("cpansubdir");
2374 $shcmd = "$ftpget --post-data \'HIDDENNAME=".$cpanuser->{$ENV{'PBPROJ'}};
2375 $shcmd .= "&user=".$cpanuser->{$ENV{'PBPROJ'}};
2376 $shcmd .= "&password=".$cpanpasswd->{$ENV{'PBPROJ'}};
2377 $shcmd .= "&SUBMIT_pause99_add_uri_upload=\"Upload the checked files\"";
2378 $shcmd .= "&pause99_add_uri_subdirtext=".$cpansubdir->{$ENV{'PBPROJ'}} if ((defined $cpansubdir) && (defined $cpansubdir->{$ENV{'PBPROJ'}}));
2379 foreach my $s (split(/ /,$src)) {
2380 $shcmd .= "&pause99_add_uri_upload=".basename($s);
2381 }
2382 $shcmd .= "'";
2383 $cpcmd = "$ftpput $host $dir";
2384 $cptarget = "CPAN";
2385 } else {
2386 my $keyfile = pb_ssh_get(0);
2387 my $keyopt = "";
2388 $keyopt = "-i $keyfile" if ((defined $keyfile) && ($cmt !~ /Packages/));
2389 my $sshcmd = pb_check_req("ssh",1);
2390 my $scpcmd = pb_check_req("scp",1);
2391 $shcmd = "$sshcmd $keyopt -q -o NoHostAuthenticationForLocalhost=yes -p $nport $mac";
2392 $cpcmd = "$scpcmd $keyopt -p -o NoHostAuthenticationForLocalhost=yes -P $nport";
2393 $cptarget = "$mac:$tdir";
2394 if ($cmt =~ /^(V|R)Mbuild/) {
2395 $cp2target = "$mac:$bdir";
2396 }
2397 }
2398
2399 my $logres = "";
2400 # Do not touch when just announcing
2401 if (($cmt ne "Announce") && ($cmt ne "CPAN")) {
2402 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 -e\"","Preparing $tdir on $cptarget");
2403 } else {
2404 $logres = "> ";
2405 }
2406 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
2407
2408 my $chowncommand = pb_check_req("chown",0);
2409 # For VE we need to change the owner manually
2410 if ($cmt =~ /^VE/) {
2411 my $res = pb_system("$shcmdroot sed -i '/requiretty/d' /etc/sudoers","Removing potential requiretty in sudoers","quiet");
2412 pb_system("$shcmdroot sed '/requiretty/d' /etc/sudoers > /tmp/sudoers.new ; mv /tmp/sudoers.new $tpdir/tmp/sudoers.new ; $shcmdroot mv /tmp/sudoers.new /etc/sudoers ; $shcmdroot chown root:root /etc/sudoers ; $shcmdroot chmod 440 /etc/sudoers","Removing again potential requiretty in sudoers as sed -i failed") if (($res ne 0) && (-f "$tpdir/etc/sudoers"));
2413 pb_system("$shcmd \"sudo $chowncommand -R $mac $tdir\"","Adapt owner in $tdir to $mac");
2414 }
2415
2416 # Use the right script name depending on context
2417 my $pbscript;
2418 if (($cmt =~ /^(V[EM]|RM)/) || ($cmt =~ /Packages/)){
2419 $pbscript = "pbscript.$$";
2420 } else {
2421 $pbscript = "pbscript";
2422 }
2423
2424 # It's already ready for CPAN
2425 my $shcmdbase = $shcmd;
2426 if ($cmt ne "CPAN") {
2427 $shcmd .= " \"echo \'cd $tdir ; if [ -x $pbscript ]; then ./$pbscript; fi ; rm -f ./$pbscript\' | bash\"";
2428 }
2429 my $cmdverb = "verbose_\[$v\] ";
2430 if (($cmt eq "Announce") || ($cmt eq "CPAN")) {
2431 $cmdverb = undef;
2432 }
2433 pb_system("$shcmd","Executing pbscript on $cptarget if needed",$cmdverb);
2434 if ($cmt =~ /^(V[EM]|RM)build/) {
2435 # Get back info on pkg produced, compute their name and get them from the VM/RM
2436 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$ 2> /dev/null","Get package names in $cp2target");
2437 if (not -f "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$") {
2438 pb_log(0,"ERROR with VM/RM $v on getting $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$\n");
2439 } else {
2440 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$";
2441 my $src = <KEEP>;
2442 chomp($src);
2443 close(KEEP);
2444 unlink("$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$");
2445
2446 $src =~ s/^ *//;
2447 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
2448 # Change pgben to make the next send2target happy
2449 my $made = "";
2450
2451 # For VM/RM we don't want shell expansion to hapen locally but remotely
2452 my $delim = '\'';
2453 if ($cmt =~ /^VEbuild/) {
2454 # For VE we need to support shell expansion locally
2455 $delim = "";
2456 }
2457
2458 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
2459 foreach my $p (split(/ +/,$src)) {
2460 my $j = basename($p);
2461 pb_system("$cpcmd $cp2target/$delim$p$delim $ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} 2> /dev/null","Recovery of package $j in $ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
2462 $made="$made $pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/$j"; # if (($pbos->{'type'} ne "rpm") || ($j !~ /.src.rpm$/));
2463 }
2464 print KEEP "$made\n";
2465 close(KEEP);
2466 pb_system("$shcmdbase \"rm -rf $tdir $bdir\"","$cmt cleanup");
2467
2468 # Sign packages locally
2469 pb_sign_pkgs($pbos,$made);
2470
2471 # We want to send them to the ssh account so overwrite what has been done before
2472 undef $pbaccount;
2473 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
2474 pb_send2target("Packages",$pbos->{'name'}."-".$pbos->{'version'}."-".$pbos->{'arch'},$vmexist,$vmpid);
2475 pb_rm_rf("$ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
2476 }
2477 }
2478 unlink("$ENV{'PBDESTDIR'}/pbscript.$$") if ((($cmt =~ /^(V[ME]|RM)/) || ($cmt =~ /Packages/)) && ($pbkeep eq 0));
2479
2480 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
2481 if ((! $vmexist) && ($cmt =~ /^VM/)) {
2482 # If in setupvm then takes a snapshot just before halting
2483 if ($snapme != 0) {
2484 my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype");
2485 # For monitoring control
2486 if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) {
2487 eval
2488 {
2489 require Net::Telnet;
2490 Net::Telnet->import();
2491 };
2492 if ($@) {
2493 # Net::Telnet not found
2494 pb_log(1,"ADVISE: Install Net::Telnet to benefit from monitoring control and snapshot feature.\nWARNING: No snapshot created");
2495 } else {
2496 my $t = new Net::Telnet (Timeout => 120, Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor";
2497 # move to monitor mode
2498 my @lines = $t->cmd("c");
2499 # Create a snapshot named pb
2500 @lines = $t->cmd("savevm pb");
2501 # Write the new status in the VM
2502 @lines = $t->cmd("commit all");
2503 # End
2504 @lines = $t->cmd("quit");
2505 }
2506 }
2507 }
2508 my $hoption = "-p";
2509 my $hpath = pb_distro_get_param($pbos,pb_conf_get("ospathcmd-halt"));
2510 # Solaris doesn't support -p of halt
2511 if ($pbos->{'type'} eq "pkg") {
2512 $hoption = "" ;
2513 }
2514 pb_system("$shcmdbase \"sudo $hpath $hoption \"; $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
2515 }
2516 if (($cmt =~ /^VE/) && ($snapme != 0)) {
2517 my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
2518 pb_system("sudo tar cz -C $tpdir -f $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz .","Creating a snapshot of $tpdir");
2519 }
2520}
2521
2522sub pb_script2v {
2523 my $pbscript=shift;
2524 my $vtype=shift;
2525 my $pbforce=shift || 0; # Force stop of VM. Default not.
2526 my $vm1=shift || undef; # Only that VM/VE/RM to treat. Default all.
2527 my $snapme=shift || 0; # Do we have to create a snapshot. Default not.
2528 my $vm;
2529 my $all;
2530
2531 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce,".Dumper($vm1).",$snapme)\n");
2532 # Prepare the script to be executed on the VM/VE/RM
2533 # in $ENV{'PBDESTDIR'}/pbscript.$$
2534 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript.$$")) {
2535 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript.$$") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript.$$ from $pbscript";
2536 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript.$$";
2537 }
2538
2539 if (not defined $vm1) {
2540 ($vm,$all) = pb_get2v($vtype);
2541 } else {
2542 @$vm = ($vm1);
2543 }
2544 my ($vmexist,$vmpid) = (undef,undef);
2545
2546 foreach my $v (@$vm) {
2547 # Launch VM/VE
2548 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme,$pbsnap);
2549
2550 if ($vtype eq "vm") {
2551 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
2552
2553 # Skip that VM/RM if something went wrong
2554 next if (($vmpid == 0) && ($vmexist == 0));
2555
2556 # If force stopping the VM then reset vmexist
2557 if ($pbforce == 1) {
2558 $vmpid = $vmexist;
2559 $vmexist = 0;
2560 }
2561 } else {
2562 #VE
2563 $vmexist = 0;
2564 $vmpid = 0;
2565 }
2566
2567 # Gather all required files to send them to the VM/VE/RM
2568 # and launch the build through pbscript
2569 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
2570 pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme);
2571
2572 }
2573}
2574
2575sub pb_launchv {
2576 my $vtype = shift;
2577 my $v = shift;
2578 my $create = shift || 0; # By default do not create a VM/VE/RM
2579 my $snapme = shift || 0; # By default do not snap a VM/VE/RM
2580 my $usesnap = shift || 1; # By default study the usage of the snapshot feature of VM/VE/RM
2581
2582 # If creation or snapshot creation mode, no snapshot usable
2583 if (($create == 1) || ($snapme == 1)) {
2584 $usesnap = 0;
2585 }
2586
2587 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create,$snapme,$usesnap)\n");
2588 die "No VM/VE/RM defined, unable to launch" if (not defined $v);
2589 # Keep only the first VM in case many were given
2590 if ($v =~ /,/) {
2591 pb_log(0,"WARNING: pruning to just the first of several VM/VE/RMs listed ($v)\n");
2592 $v =~ s/,.*//;
2593 }
2594
2595 my $pbos = pb_distro_get_context($v);
2596
2597 pb_apply_conf_proxy($pbos);
2598
2599 # Launch the VMs/VEs
2600 if ($vtype eq "vm") {
2601 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
2602
2603 my ($ptr,$ptr2,$vmpath,$vmport,$vms) = pb_conf_get("vmtype","vmcmd","vmpath","vmport","vmsize");
2604 my ($vmopt,$vmmm,$vmtmout,$vmsnap,$vmbuildtm,$vmmonport) = pb_conf_get_if("vmopt","vmmem","vmtmout","vmsnap","vmbuildtm","vmmonport");
2605 my $vmsize = pb_distro_get_param($pbos,$vms);
2606
2607 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
2608 my $vmcmd = $ptr2->{$ENV{'PBPROJ'}};
2609
2610 if (defined $opts{'g'}) {
2611 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
2612 $ENV{'PBVMOPT'} = "--nographic";
2613 }
2614 }
2615 if (not defined $ENV{'PBVMOPT'}) {
2616 $ENV{'PBVMOPT'} = "";
2617 }
2618 # Save the current status for later restoration
2619 $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
2620 # Set a default timeout of 2 minutes
2621 if (not defined $ENV{'PBVMTMOUT'}) {
2622 $ENV{'PBVMTMOUT'} = "120";
2623 }
2624 if (defined $vmopt->{$v}) {
2625 $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
2626 } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
2627 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
2628 }
2629
2630 # How much memory to allocate for VMs
2631 if (defined $vmmm) {
2632 my $vmmem = pb_distro_get_param($pbos,$vmmm);
2633 if (defined $vmmem) {
2634 $ENV{'PBVMOPT'} .= " -m $vmmem";
2635 }
2636 }
2637
2638 # Are we allowed to use snapshot feature
2639 if ($usesnap == 1) {
2640 if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) {
2641 $ENV{'PBVMOPT'} .= " -snapshot";
2642 } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) {
2643 $ENV{'PBVMOPT'} .= " -snapshot";
2644 } elsif ($pbsnap eq 1) {
2645 $ENV{'PBVMOPT'} .= " -snapshot";
2646 }
2647 }
2648 if ($snapme != 0) {
2649 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
2650 # Configure the monitoring to automate the creation of the 'pb' snapshot
2651 $ENV{'PBVMOPT'} .= " -serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait" if ((defined $vmmonport) && (defined $vmmonport->{$ENV{'PBPROJ'}}));
2652 # In that case no snapshot call needed
2653 $ENV{'PBVMOPT'} =~ s/ -snapshot//;
2654 }
2655 }
2656 if (defined $vmtmout->{$v}) {
2657 $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
2658 } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
2659 $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
2660 }
2661 my $nport = pb_get_port($vmport,$pbos,$vtype);
2662
2663 my $cmd;
2664 my $vmm; # has to be used for pb_check_ps
2665 if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
2666 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
2667 if (($create != 0) || (defined $iso)) {
2668 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
2669 }
2670 # Always redirect the network and always try to use a 'pb' snapshot
2671 #$cmd = "$vmcmd $ENV{'PBVMOPT'} -net nic,model=virtio -net user,hostfwd=tcp::$nport-:22 -loadvm pb $vmm"
2672 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
2673 } elsif ($vmtype eq "xen") {
2674 } elsif ($vmtype eq "vmware") {
2675 } else {
2676 die "VM of type $vmtype not supported. Report to the dev team";
2677 }
2678 # Restore the ENV VAR Value
2679 $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
2680
2681 my ($tmpcmd,$void) = split(/ +/,$cmd);
2682 my $vmexist = pb_check_ps($tmpcmd,$vmm);
2683 my $vmpid = 0;
2684 if (! $vmexist) {
2685 if ($create != 0) {
2686 die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
2687 if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
2688 my $command = pb_check_req("qemu-img",0);
2689 pb_system("$command create -f qcow2 $vmm $vmsize","Creating the QEMU VM");
2690 } elsif ($vmtype eq "vmware") {
2691 } else {
2692 }
2693 }
2694 if (! -f "$vmm") {
2695 pb_log(0,"Unable to find VM $vmm\n");
2696 } else {
2697 # Is the SSH port free? if not kill the existing process using it after a build timeout period
2698 my $vmssh = pb_check_ps($tmpcmd,"tcp:$nport:10.0.2.15:22");
2699 if ($vmssh) {
2700 my $buildtm = $ENV{'PBVMTMOUT'};
2701 if (defined $vmbuildtm->{$v}) {
2702 $buildtm = $vmbuildtm->{$v};
2703 } elsif (defined $vmbuildtm->{$ENV{'PBPROJ'}}) {
2704 $buildtm = $vmbuildtm->{$ENV{'PBPROJ'}};
2705 }
2706
2707 sleep $buildtm;
2708 pb_log(0,"WARNING: Killing the process ($vmssh) using port $nport (previous failed VM ?)\n");
2709 kill 15,$vmssh;
2710 # Let it time to exit
2711 sleep 5;
2712 }
2713 pb_system("$cmd &","Launching the VM $vmm");
2714 # Using system allows to kill it externaly if needed,sosupport that in the call
2715 pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up","mayfail");
2716 $vmpid = pb_check_ps($tmpcmd,$vmm);
2717 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
2718 }
2719 } else {
2720 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
2721 }
2722 pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
2723 return($vmexist,$vmpid);
2724 } elsif ($vtype eq "ve") {
2725 # Force the creation of the VE and no snapshot usable
2726 pb_ve_launch($v,$create,$usesnap);
2727 } else {
2728 # RM here
2729 # Get distro context
2730 my $pbos = pb_distro_get_context($v);
2731
2732 # Get RM context
2733 my ($ptr,$rmpath) = pb_conf_get("rmtype","rmpath");
2734
2735 # Nothing more to do for RM. No real launch
2736 # For the moment we support the RM is already running
2737 # For ProLiant may be able to power them on if needed later on as an example.
2738 }
2739}
2740
2741# Return string for date synchro
2742sub pb_date2v {
2743
2744my $vtype = shift;
2745my $pbos = shift;
2746my $nontp = shift || 0;
2747
2748# VE gets time from parent OS.
2749return "/bin/true" if ($vtype) =~ /^ve/o;
2750
2751my ($ntp) = pb_conf_get_if($vtype."ntp");
2752my $vntp = $ntp->{$ENV{'PBPROJ'}} if (defined $ntp);
2753my $ntpline = undef;
2754
2755if ((defined $vntp) && ($vntp !~ /^\s*$/)) {
2756 # ntp command depends on pbos
2757 my $vntpcmd = pb_distro_get_param($pbos,pb_conf_get($vtype."ntpcmd"));
2758 $ntpline = "sudo $vntpcmd $vntp";
2759}
2760# Force new date to be in the future compared to the date
2761# of the host by adding 1 minute
2762my @date=pb_get_date();
2763$date[1]++;
2764my $upddate = strftime("%m%d%H%M%Y", @date);
2765my $dateline = "sudo /bin/date $upddate";
2766if ((defined $ntpline) && ($nontp == 0)) {
2767 return($ntpline);
2768} else {
2769 return($dateline);
2770}
2771}
2772
2773sub pb_build2v {
2774
2775my $vtype = shift;
2776my $action = shift || "build";
2777
2778my ($v,$all) = pb_get2v($vtype);
2779
2780# Send tar files when we do a global generation
2781pb_build2ssh() if (($all == 1) && ($action eq "build"));
2782
2783# Adapt // mode to memory size
2784$pbparallel = pb_set_parallel($vtype);
2785
2786my ($vmexist,$vmpid) = (undef,undef);
2787my $pm;
2788my $all_ok = 1;
2789if (defined $pbparallel) {
2790 $pm = new Parallel::ForkManager($pbparallel);
2791
2792 # Set which port the VM/RM will use to communicate
2793 $pm->run_on_start(\&pb_set_port);
2794 $pm->run_on_finish(sub { my ($pid, $code, $id, $signal, $dump) = @_;
2795 unless ($code == 0 && $signal == 0 && $dump == 0) {
2796 $all_ok = 0;
2797 pb_log(0,"ERROR: pid $pid failed\n");
2798 }
2799 });
2800}
2801
2802my $counter = 0;
2803foreach my $v (@$v) {
2804 $counter++;
2805 # Modulo 2 * pbparallel (to avoid synchronization problems)
2806 $counter = 1 if ((defined $pbparallel) && ($counter > 2 * $pbparallel));
2807 $pm->start($counter) and next if (defined $pbparallel);
2808 # Prepare the script to be executed on the VM/VE/RM
2809 # in $ENV{'PBDESTDIR'}/pbscript.$$
2810 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript.$$") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript.$$";
2811 print SCRIPT "#!/bin/bash\n";
2812
2813 # Transmit the verbosity level to the virtual env/mach.
2814 my $verbose = "";
2815 my $i = 0; # minimal debug level
2816 while ($i lt $pbdebug) {
2817 $verbose .= "-v ";
2818 $i++;
2819 }
2820 print SCRIPT "set -e\n" if ($Global::pb_stop_on_error);
2821 # Activate script verbosity if at least 2 for pbdebug
2822 print SCRIPT "set -x\n" if ($i gt 1);
2823 # Quiet if asked to be so on the original system
2824 $verbose = "-q" if ($pbdebug eq -1);
2825
2826 print SCRIPT "echo ... Execution needed\n";
2827 print SCRIPT "echo '==== Start of script $$ for $vtype $v =====\n";
2828 print SCRIPT "# This is in directory delivery\n";
2829 print SCRIPT "# Setup the variables required for building\n";
2830 print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
2831
2832 if ($action eq "build") {
2833 print SCRIPT "# Preparation for pb\n";
2834 print SCRIPT "rm -f \$HOME/.pbrc\n";
2835 print SCRIPT "mv .pbrc \$HOME\n";
2836 print SCRIPT "cd ..\n";
2837 }
2838
2839 # VE needs a good /proc, tolerate one being potentially left around after a failure
2840 if ($vtype eq "ve") {
2841 print SCRIPT "[ -d /proc/1 ] || sudo /bin/mount -t proc /proc /proc\n";
2842 }
2843
2844 # Get distro context
2845 my $pbos = pb_distro_get_context($v);
2846
2847 my $ntpline = pb_date2v($vtype,$pbos);
2848 print SCRIPT "# Time sync\n";
2849 print SCRIPT "echo setting up date with $ntpline\n";
2850 print SCRIPT "$ntpline\n";
2851 print SCRIPT 'if [ $? -ne 0 ]; then\n';
2852 # Force if bad status a trick using date
2853 $ntpline = pb_date2v($vtype,$pbos, 1);
2854 print SCRIPT " $ntpline\n";
2855 print SCRIPT "fi\n";
2856 # Use potential local proxy declaration in case we need it to download repo, pkgs, ...
2857 if (defined $ENV{'http_proxy'}) {
2858 print SCRIPT "export http_proxy=\"$ENV{'http_proxy'}\"\n";
2859 }
2860
2861 if (defined $ENV{'ftp_proxy'}) {
2862 print SCRIPT "export ftp_proxy=\"$ENV{'ftp_proxy'}\"\n";
2863 }
2864
2865 # Get list of packages to build/test and get some ENV vars as well
2866 my $ptr = pb_get_pkg();
2867 @pkgs = @$ptr;
2868 my $p = join(' ',@pkgs) if (@pkgs);
2869 print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
2870 print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
2871 print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
2872
2873 # We may need to do some other tasks before building. Read a script here to finish setup
2874 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
2875 print SCRIPT "# Special pre-instructions to be launched\n";
2876 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
2877 }
2878
2879 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
2880 print SCRIPT "# Special pre-$action instructions to be launched\n";
2881 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
2882 }
2883
2884 print SCRIPT "# $action\n";
2885 print SCRIPT "echo $action"."ing packages on $vtype...\n";
2886
2887 if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
2888 die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
2889 }
2890 print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
2891
2892 if ($vtype eq "ve") {
2893 print SCRIPT "sudo /bin/umount /proc\n";
2894 }
2895
2896 # We may need to do some other tasks after building. Read a script here to exit properly
2897 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
2898 print SCRIPT "# Special post-$action instructions to be launched\n";
2899 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
2900 }
2901
2902 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
2903 print SCRIPT "# Special post-instructions to be launched\n";
2904 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
2905 }
2906
2907 print SCRIPT "echo '==== End of script $$ for $vtype $v =====\n";
2908 close(SCRIPT);
2909 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript.$$";
2910
2911 # Launch the VM/VE/RM
2912 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
2913
2914
2915 if ($vtype eq "vm") {
2916 # Skip that VM if something went wrong
2917 if (($vmpid == 0) && ($vmexist == 0)) {
2918 $pm->finish if (defined $pbparallel);
2919 next;
2920 }
2921 } else {
2922 # VE/RM
2923 $vmexist = 0;
2924 $vmpid = 0;
2925 }
2926 # Gather all required files to send them to the VM/VE
2927 # and launch the build through pbscript
2928 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
2929 pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
2930 $pm->finish if (defined $pbparallel);
2931}
2932$pm->wait_all_children if (defined $pbparallel);
2933die "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error));
2934}
2935
2936
2937sub pb_clean {
2938
2939 my $sleep=10;
2940 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
2941 die "Unable to get env var PBBUILDDIR" if (not defined $ENV{'PBBUILDDIR'});
2942 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");
2943 sleep $sleep;
2944 pb_rm_rf($ENV{'PBDESTDIR'});
2945 pb_rm_rf($ENV{'PBBUILDDIR'});
2946}
2947
2948sub pb_newver {
2949
2950 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
2951
2952 # Need this call for PBDIR
2953 my ($scheme2,$uri) = pb_cms_init($pbinit);
2954
2955 my ($pbconf,$pburl) = pb_conf_get("pbconfurl","pburl");
2956 $uri = $pbconf->{$ENV{'PBPROJ'}};
2957 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
2958
2959 # Checking CMS repositories status
2960 ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
2961
2962 if ($scheme !~ /^svn/) {
2963 die "Only SVN is supported at the moment";
2964 }
2965
2966 my $res = pb_vcs_isdiff($scheme,$ENV{'PBROOTDIR'});
2967 die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
2968
2969 $res = pb_vcs_isdiff($scheme2,$ENV{'PBDIR'});
2970 die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
2971
2972 # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
2973 # we want to get for the root of the new URL
2974
2975 my $oldver = $ENV{'PBROOTDIR'};
2976 $oldver =~ s|^$ENV{'PBCONFDIR'}||;
2977
2978 pb_log(2, "PBCONFDIR: $ENV{'PBCONFDIR'}\nPBROOTDIR: $ENV{'PBROOTDIR'}\n");
2979
2980 my $newurl = "$uri/$newver";
2981 # Should probably use projver in the old file
2982 my $oldvertxt= basename($oldver);
2983 my $newvertxt = basename($newver);
2984
2985 # Duplicate and extract project-builder part
2986 pb_log(2,"Copying $uri/$oldver to $newurl\n");
2987 pb_vcs_copy($scheme,"$uri/$oldver",$newurl);
2988 pb_log(2,"Checkout $newurl to $ENV{'PBCONFDIR'}/$newver\n");
2989 pb_vcs_up($scheme,"$ENV{'PBCONFDIR'}");
2990
2991 # Duplicate and extract project
2992 my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/$newver";
2993
2994 pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$oldver to $newurl2\n");
2995 pb_vcs_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$oldver",$newurl2);
2996
2997 my $tmp = $ENV{'PBDIR'};
2998 $tmp =~ s|$oldver$||;
2999 pb_log(2,"Checkout $newurl2 to $tmp/$newver\n");
3000 pb_vcs_up($scheme2,"$tmp");
3001
3002 # Update the .pb file
3003 open(FILE,"$ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb";
3004 open(OUT,"> $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb.new";
3005 while(<FILE>) {
3006 if (/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldvertxt$/) {
3007 s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldvertxt$/projver $ENV{'PBPROJ'} = $newvertxt/;
3008 pb_log(0,"Changing projver from $oldvertxt to $newvertxt in $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb\n");
3009 }
3010 if (/^testver/) {
3011 s/^testver/#testver/;
3012 pb_log(0,"Commenting testver in $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
3013 }
3014 if (/^delivery/) {
3015 my $txt = $_;
3016 chomp($txt);
3017 pb_log(0,"Please check delivery ($txt) in $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb\n");
3018 }
3019 print OUT $_;
3020 }
3021 close(FILE);
3022 close(OUT);
3023 rename("$ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb");
3024
3025 # Checking pbcl files
3026 foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
3027 # Compute new pbcl file
3028 my $f2 = $f;
3029 $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBCONFDIR'}/$newver/|;
3030 open(PBCL,$f) || die "Unable to open $f";
3031 my $foundnew = 0;
3032 while (<PBCL>) {
3033 $foundnew = 1 if (/^$newvertxt \(/);
3034 }
3035 close(PBCL);
3036 open(OUT,"> $f2") || die "Unable to write to $f2: $!";
3037 open(PBCL,$f) || die "Unable to open $f";
3038 # We skip as long as we do not reach the new version in the log (case of devel)
3039 my $skip = 1;
3040 # We let the 4 first lines
3041 my $cnt = 0;
3042 while (<PBCL>) {
3043 $skip = 0 if (/^$newvertxt \(/);
3044 if ((/^$oldvertxt \(/) && ($foundnew == 0)) {
3045 print OUT "$newvertxt ($pbdate)\n";
3046 print OUT "- TBD\n";
3047 print OUT "\n";
3048 pb_log(0,"WARNING: version $newvertxt not found in $f so added to $f2...\n") if ($foundnew == 0);
3049 }
3050 if ($cnt <= 4) {
3051 print OUT "$_" if (not /^$oldvertxt \(/);
3052 } else {
3053 print OUT "$_" if ($skip == 0);
3054 }
3055 $cnt++;
3056 }
3057 close(OUT);
3058 close(PBCL);
3059 }
3060
3061 pb_log(2,"Checkin $ENV{'PBCONFDIR'}/$newver\n");
3062 pb_cms_checkin($scheme,"$ENV{'PBCONFDIR'}/$newver",undef);
3063}
3064
3065#
3066# Return the list of VMs/VEs/RMs we are working on
3067# $all is a flag to know if we return all of them
3068# or only some (if all we publish also tar files in addition to pkgs
3069#
3070sub pb_get2v {
3071
3072my $vtype = shift;
3073my @v;
3074my $all = 0;
3075my $pbv = 'PBV';
3076my $vlist = $vtype."list";
3077
3078# Get VM/VE list
3079if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
3080 my ($ptr) = pb_conf_get($vlist);
3081 $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
3082 $all = 1;
3083}
3084pb_log(2,"$vtype: $ENV{$pbv}\n");
3085@v = split(/,/,$ENV{$pbv});
3086return(\@v,$all);
3087}
3088
3089# This function creates a giant script to configure a particular VM/VE/RM, it then copies the
3090# script to the target.
3091
3092# Function to create a potentialy missing pb account on the VM/VE/RM, and adds it to sudo
3093# Needs to use root account to connect to the VM/VE/RM
3094# pb will take your local public SSH key to access
3095# the pb account in the VM/VE/RM later on if needed
3096sub pb_setup2v {
3097
3098my $vtype = shift;
3099my $sbx = shift || undef;
3100
3101my ($vm,$all) = pb_get2v($vtype);
3102
3103# Script generated
3104my $pbscript = "$ENV{'PBDESTDIR'}/setupv.$$";
3105
3106# Adapt // mode to memory size
3107$pbparallel = pb_set_parallel($vtype);
3108
3109my $pm;
3110my $all_ok = 1;
3111if (defined $pbparallel) {
3112 $pm = new Parallel::ForkManager($pbparallel);
3113
3114 # Set which port the VM/RM will use to communicate
3115 $pm->run_on_start(\&pb_set_port);
3116 $pm->run_on_finish(sub { my ($pid, $code, $id, $signal, $dump) = @_;
3117 $all_ok = 0 unless (($code == 0) && ($signal == 0) && ($dump == 0));
3118 });
3119}
3120
3121my $counter = 0;
3122foreach my $v (@$vm) {
3123 $counter++;
3124 # Modulo pbparallel
3125 $counter = 1 if ((defined $pbparallel) && ($counter > $pbparallel));
3126 $pm->start($counter) and next if (defined $pbparallel);
3127
3128 # Get distro context
3129 my $pbos = pb_distro_get_context($v);
3130
3131 # Deal with date sync.
3132 my $ntpline = pb_date2v($vtype,$pbos);
3133
3134 # Name of the account to deal with for VM/VE/RM
3135 # Do not use the one passed potentially with -a
3136 my ($pbac) = pb_conf_get($vtype."login");
3137 my ($key,$zero0,$zero1,$zero2);
3138 my ($vmexist,$vmpid);
3139
3140 # Prepare the script to be executed on the VM/VE/RM
3141 # in $ENV{'PBDESTDIR'}/setupv
3142 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
3143
3144 print SCRIPT << 'EOF';
3145#!/usr/bin/perl -w
3146
3147use strict;
3148use File::Copy;
3149
3150# We should not need in this script more functions than what is provided
3151# by Base, Conf and Distribution to avoid problems at exec time.
3152# They are appended at the end.
3153
3154# Define mandatory global vars
3155EOF
3156 my $ppref = "our";
3157 $ppref = "my" if (($pbos->{'name'} =~ /^redhat/) && ($pbos->{'version'} =~ /^6/));
3158 print SCRIPT << "EOF";
3159$ppref \$pbdebug = $pbdebug;
3160$ppref \$pbLOG;
3161$ppref \$pbsynmsg = "pbscript";
3162$ppref \$pbdisplaytype = "text";
3163$ppref \$pblocale = "";
3164EOF
3165 print SCRIPT << 'EOF';
3166pb_log_init($pbdebug, $pbLOG);
3167EOF
3168 print SCRIPT << "EOF";
3169\$Global::pb_stop_on_error = $Global::pb_stop_on_error;
3170pb_temp_init($pbkeep);
3171pb_conf_init("$ENV{'PBPROJ'}");
3172
3173EOF
3174
3175 # Launch the VM/VE/RM - Usage of snapshot disabled
3176 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,0,0);
3177
3178 my $keyfile;
3179 my $nport;
3180 my $vmhost;
3181
3182 # Prepare the key to be used and transfered remotely
3183 $keyfile = pb_ssh_get(1);
3184
3185 if ($vtype =~ /(v|r)m/) {
3186 my ($vmport);
3187 ($vmhost,$vmport) = pb_conf_get($vtype."host",$vtype."port");
3188 $nport = pb_get_port($vmport,$pbos,$vtype);
3189
3190 # Skip that VM/RM if something went wrong
3191 next if (($vmpid == 0) && ($vmexist == 0));
3192
3193 # Store the pub key part in a variable
3194 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
3195 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
3196 close(FILE);
3197
3198 $key = "\Q$zero1";
3199
3200 # We call true to avoid problems if SELinux is not activated, but chcon is present and returns in that case 1
3201 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; /bin/true; fi\"","Copying local keys to $vtype. This may require the root password");
3202 # once this is done, we can do what we need on the VM/RM remotely
3203 } elsif ($vtype eq "ve") {
3204 print SCRIPT << "EOF";
3205# For VE we first need to mount some FS
3206pb_system("mount -t proc /proc /proc") unless (-d "/proc/$$");
3207
3208# For VE we need a good null dev
3209# Except for RedHat 6.2 where it's good and doesnt like being recreated
3210EOF
3211 print SCRIPT "pb_system('rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null');\n" unless (($pbos->{'name'} =~ /^redhat/) && ($pbos->{'version'} =~ /^6/));
3212 } else {
3213 die "Unknown virtual type $vtype";
3214 }
3215
3216 if ($vtype =~ /(v|r)m/) {
3217 print SCRIPT << 'EOF';
3218# Removes duplicate in .ssh/authorized_keys of our key if needed
3219#
3220my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
3221open(PBFILE,$file1) || die "Unable to open $file1";
3222open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
3223my $count = 0;
3224while (<PBFILE>) {
3225
3226EOF
3227 print SCRIPT << "EOF";
3228 if (/ $key /) {
3229 \$count++;
3230 }
3231print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
3232}
3233close(PBFILE);
3234close(PBOUT);
3235rename("\$file1.new",\$file1);
3236chmod 0600,\$file1;
3237
3238EOF
3239 }
3240 print SCRIPT << 'EOF';
3241
3242# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
3243#
3244my $file="/etc/passwd";
3245open(PBFILE,$file) || die "Unable to open $file";
3246my $found = 0;
3247while (<PBFILE>) {
3248EOF
3249 print SCRIPT << "EOF";
3250 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
3251EOF
3252
3253# TODO: use an external parameter
3254my $home = "/home";
3255# Solaris doesn't like that we use /home
3256$home = "/export/home" if ($pbos->{'type'} eq "pkg");
3257
3258 print SCRIPT << "EOF";
3259}
3260close(PBFILE);
3261
3262if ( \$found == 0 ) {
3263 if ( ! -d "$home" ) {
3264 pb_mkdir_p("$home");
3265 }
3266EOF
3267 # TODO: Level of portability of these cmds ? Critical now for RM
3268 # TODO: Check existence before adding to avoid errors
3269 print SCRIPT << "EOF";
3270pb_system("/usr/sbin/groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
3271pb_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'}})");
3272}
3273EOF
3274
3275 # Copy the content of our local conf file to the VM/VE/RM
3276 my $content = pb_get_content(pb_distro_conffile());
3277 print SCRIPT << "EOF";
3278 #
3279 # Create a temporary local conf file for distribution support
3280 # This is created here before its use later. Its place is hardcoded, so no choice for the path
3281 #
3282 my \$tempconf = pb_distro_conffile();
3283 pb_mkdir_p(dirname(\$tempconf));
3284 open(CONF,"> \$tempconf") || die "Unable to create \$tempconf";
3285 print CONF q{$content};
3286 close(CONF);
3287EOF
3288
3289 if ($vtype =~ /(v|r)m/) {
3290 print SCRIPT << "EOF";
3291# allow ssh entry to build
3292#
3293mkdir "$home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
3294# Allow those accessing root to access the build account
3295copy("\$ENV{'HOME'}/.ssh/authorized_keys","$home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
3296chmod 0600,".ssh/authorized_keys";
3297pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} $home/$pbac->{$ENV{'PBPROJ'}}","Finish setting up the account env for $pbac->{$ENV{'PBPROJ'}}");
3298
3299EOF
3300}
3301 print SCRIPT << 'EOF';
3302# No passwd for build account only keys
3303$file="/etc/shadow";
3304if (-f $file) {
3305 open(PBFILE,$file) || die "Unable to open $file";
3306 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
3307 while (<PBFILE>) {
3308EOF
3309 print SCRIPT << "EOF";
3310 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
3311 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
3312 s/^$pbac->{$ENV{'PBPROJ'}}:\\*LK\\*:/$pbac->{$ENV{'PBPROJ'}}:NP:/; #Solaris e.g.
3313EOF
3314 print SCRIPT << 'EOF';
3315 print PBOUT $_;
3316 }
3317 close(PBFILE);
3318 close(PBOUT);
3319 rename("$file.new",$file);
3320 chmod 0640,$file;
3321 }
3322
3323# Keep the VM in text mode
3324$file="/etc/inittab";
3325if (-f $file) {
3326 open(PBFILE,$file) || die "Unable to open $file";
3327 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
3328 while (<PBFILE>) {
3329 s/^(..):5:initdefault:$/$1:3:initdefault:/;
3330 print PBOUT $_;
3331 }
3332 close(PBFILE);
3333 close(PBOUT);
3334 rename("$file.new",$file);
3335 chmod 0640,$file;
3336}
3337
3338# pb has to be added to portage group on gentoo
3339
3340# We need to have that pb_distro_get_context function
3341# Get it from Project-Builder::Distribution
3342# And we now need the conf file required for this to work created above
3343
3344my $pbos = pb_distro_get_context();
3345print "distro tuple: ".Dumper($pbos)."\n";
3346
3347# Adapt sudoers
3348# sudo is not default on Solaris and needs to be installed first
3349# from http://www.sunfreeware.com/programlistsparc10.html#sudo
3350if ($pbos->{'type'} eq "pkg") {
3351 $file="/usr/local/etc/sudoers";
3352} else {
3353 $file="/etc/sudoers";
3354}
3355open(PBFILE,$file) || die "Unable to open $file";
3356open(PBOUT,"> $file.new") || die "Unable to open $file.new";
3357while (<PBFILE>) {
3358EOF
3359 # Skip what will be generated
3360 print SCRIPT << "EOF";
3361 next if (/^$pbac->{$ENV{'PBPROJ'}}\\s+/);
3362 next if (/^Defaults:$pbac->{$ENV{'PBPROJ'}}\\s+/);
3363 next if (/^Defaults:root\\s+\!requiretty/);
3364 next if (/^Defaults:root\\s+env_keep/);
3365EOF
3366 print SCRIPT << 'EOF';
3367 s/Defaults\s+requiretty/# disable Defaults: requiretty/;
3368 print PBOUT $_;
3369}
3370close(PBFILE);
3371EOF
3372 print SCRIPT << "EOF";
3373# Some distro force requiretty at compile time, so disable here
3374print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} !requiretty\n";
3375print PBOUT "Defaults:root !requiretty\n";
3376EOF
3377 # RH 6.2 sudo doesn't support env_keep
3378 if (($pbos->{'name'} ne "redhat") && ($pbos->{'version'} ne "6.2")) {
3379 print SCRIPT << "EOF";
3380# Keep proxy configuration while using sudo
3381print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} env_keep += \\\"http_proxy ftp_proxy\\\"\n";
3382print PBOUT "Defaults:root env_keep += \\\"http_proxy ftp_proxy\\\"\n";
3383EOF
3384 }
3385 # Try to restrict security to what is really needed
3386 if ($vtype =~ /^vm/) {
3387 my $hpath = pb_distro_get_param($pbos,pb_conf_get("ospathcmd-halt"));
3388 my @sudocmds = pb_get_sudocmds($pbos,$ntpline,"sudo $hpath");
3389 print SCRIPT << "EOF";
3390# This is needed in order to be able on VM to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
3391# Build account $pbac->{$ENV{'PBPROJ'}} in VM also needs to setup date and install deps.
3392# Nothing else should be needed
3393EOF
3394 foreach my $c (@sudocmds) {
3395 print SCRIPT "print PBOUT \"$pbac->{$ENV{'PBPROJ'}} ALL = NOPASSWD: $c\\n\";\n";
3396 }
3397 } elsif ($vtype =~ /^rm/) {
3398 my @sudocmds = pb_get_sudocmds($pbos,$ntpline);
3399 print SCRIPT << "EOF";
3400# Build account $pbac->{$ENV{'PBPROJ'}} in RM only needs to setup date and install deps if needed each time
3401EOF
3402 foreach my $c (@sudocmds) {
3403 print SCRIPT "print PBOUT \"$pbac->{$ENV{'PBPROJ'}} ALL = NOPASSWD: $c\\n\";\n";
3404 }
3405 } else {
3406 print SCRIPT << "EOF";
3407# Build account $pbac->{$ENV{'PBPROJ'}} for VE needs to do a lot in the host (and chroot), so allow without restriction for now
3408print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
3409EOF
3410}
3411 print SCRIPT << 'EOF';
3412close(PBOUT);
3413rename("$file.new",$file);
3414chmod 0440,$file;
3415
3416EOF
3417
3418 if ($vtype =~ /(v|r)m/) {
3419 # Sync date
3420 # do it after sudoers is setup
3421 print SCRIPT "pb_system(\"$ntpline\",\"Updating time with $ntpline\",\"mayfail\");\n";
3422 }
3423
3424 print SCRIPT << 'EOF';
3425
3426# We may need a proxy configuration. Get it from the local env
3427pb_apply_conf_proxy($pbos);
3428
3429# Suse wants sudoers as 640
3430if ((($pbos->{'name'} eq "sles") && (($pbos->{'version'} =~ /10/) || ($pbos->{'version'} =~ /9/))) || (($pbos->{'name'} eq "opensuse") && ($pbos->{'version'} =~ /10.[012]/))) {
3431 chmod 0640,$file;
3432}
3433
3434# First install all required packages
3435pb_system("yum clean all","Cleaning yum env","mayfail") if (($pbos->{'name'} eq "fedora") || ($pbos->{'name'} eq "asianux") || ($pbos->{'name'} eq "rhel"));
3436my ($ospkgdep) = pb_conf_get_if("ospkgdep");
3437
3438my $pkgdep = pb_distro_get_param($pbos,$ospkgdep);
3439pb_distro_installdeps(undef,$pbos,pb_distro_only_deps_needed($pbos,join(' ',split(/,/,$pkgdep))));
3440
3441EOF
3442 my $itype = pb_distro_get_param($pbos,pb_conf_get("pbinstalltype"));
3443 # Install from sandbox mean a file base install
3444 $itype = "file" if (defined $sbx);
3445 if ($itype =~ /^file/) {
3446 my $cmdget;
3447 if (defined $sbx) {
3448 # Install from sandbox mean using the result of the just passed sbx2build command
3449 # Get content saved in cms2build
3450 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
3451 my $pbextdir = pb_get_extdir();
3452 die "Unable to get package list" if (not defined $pkg);
3453
3454 # We consider 2 specific packages
3455 my $vertag1 = $pkg->{"ProjectBuilder"};
3456 my $vertag2 = $pkg->{"project-builder"};
3457 # get the version of the current package - maybe different
3458 pb_log(2,"Vertag1: $vertag1\n");
3459 pb_log(2,"Vertag2: $vertag2\n");
3460 my ($pbver1,$tmp1) = split(/-/,$vertag1);
3461 my ($pbver2,$tmp2) = split(/-/,$vertag2);
3462 # Copy inside the VE
3463 if ($vtype eq "ve") {
3464 my ($vepath) = pb_conf_get("vepath");
3465 copy("$ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz","$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/tmp");
3466 copy("$ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz","$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/tmp");
3467 } else {
3468 pb_system("scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport $ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz $ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz root\@$vmhost->{$ENV{'PBPROJ'}}:/tmp","Copying local project files to $vtype.");
3469 }
3470 $cmdget = "mv /tmp/ProjectBuilder-$pbver1$pbextdir.tar.gz ProjectBuilder-latest.tar.gz ; mv /tmp/project-builder-$pbver2$pbextdir.tar.gz project-builder-latest.tar.gz";
3471 } else {
3472 # TODO: shouldn't we have a variable to specify the source file?
3473 # And shouldn't we be getting the one that matches the current pb version?
3474 # For the moment, just take the latest stable one
3475 $cmdget = "wget --passive-ftp ftp://ftp.project-builder.org/src/ProjectBuilder-latest.tar.gz; wget --passive-ftp ftp://ftp.project-builder.org/src/project-builder-latest.tar.gz";
3476 }
3477 print SCRIPT << 'EOF';
3478# Then install manually the missing perl modules
3479my ($osperldep,$osperlver) = pb_conf_get_if("osperldep","osperlver");
3480
3481my $perldep = pb_distro_get_param($pbos,$osperldep);
3482my $bashopt = "";
3483$bashopt = "-x" if ($pbdebug ge 1);
3484my $verbopt = "mayfail";
3485$verbopt = "mayfailverbose" if ($pbdebug ge 1);
3486foreach my $m (split(/,/,$perldep)) {
3487 # Skip empty deps
3488 next if ($m =~ /^\s*$/);
3489 my $dir = $m;
3490 $dir =~ s/-.*//;
3491 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 -e $bashopt" ,"Installing perl module $m-$osperlver->{$m}",$verbopt);
3492}
3493EOF
3494 print SCRIPT << 'EOF';
3495pb_system("rm -rf ProjectBuilder-* ; rm -rf project-builder-* ; rm -rf `perl -V:installvendorlib | awk -F\"'\" '{print \$2}'`/ProjectBuilder ;
3496EOF
3497 print SCRIPT " $cmdget ; ";
3498 print SCRIPT << 'EOF'
3499gzip -cd ProjectBuilder-latest.tar.gz | tar xf - ; cd ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf ProjectBuilder-* ; 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");
3500EOF
3501 } elsif ($itype =~ /^pkg/) {
3502 # pkg based install. We need to point to the project-builder.org repository
3503 print SCRIPT << 'EOF';
3504my $pkgforpb = pb_distro_get_param($pbos,pb_conf_get_if("ospkg"));
3505pb_distro_setuposrepo($pbos);
3506pb_distro_installdeps(undef,$pbos,pb_distro_only_deps_needed($pbos,join(' ',split(/,/,$pkgforpb))));
3507EOF
3508 } else {
3509 # Unknown install type
3510 die("Unknown install type $itype->{$ENV{'PBPROJ'}} for param pbinstalltype");
3511 }
3512 print SCRIPT << 'EOF';
3513pb_system("pb -h",undef,"verbose");
3514pb_system("pbdistrocheck",undef,"verbose");
3515EOF
3516 if ($vtype eq "ve") {
3517 print SCRIPT << 'EOF';
3518# For VE we need to umount some FS at the end
3519
3520pb_system("umount /proc","Unmounting /proc","mayfail");
3521
3522# Create a basic network file if not already there
3523
3524my $nf="/etc/sysconfig/network";
3525if ((! -f $nf) && ($pbos->{'type'} eq "rpm") && ($pbos->{'family'} ne "novell")) {
3526 open(NF,"> $nf") || die "Unable to create $nf";
3527 print NF "NETWORKING=yes\n";
3528 print NF "HOSTNAME=localhost\n";
3529 close(NF);
3530}
3531chmod 0755,$nf;
3532EOF
3533 }
3534
3535 # Adds pb_distro_get_context and all functions needed from ProjectBuilder::Distribution, Conf and Base
3536 foreach my $m ("ProjectBuilder/Base.pm","ProjectBuilder/Distribution.pm","ProjectBuilder/Conf.pm") {
3537 foreach my $d (@INC) {
3538 my $f = "$d/$m";
3539 if (-f "$f") {
3540 open(PBD,"$f") || die "Unable to open $f: $!";
3541 while (<PBD>) {
3542 next if (/^package/);
3543 next if (/^use Exporter/);
3544 next if (/^use ProjectBuilder::/);
3545 next if (/^our /);
3546 print SCRIPT $_;
3547 }
3548 close(PBD);
3549 # We just need the first one of each file wrt @INC - hopefully that's the right one.
3550 last;
3551 }
3552 }
3553 }
3554 # Use a fake pb_version_init version here
3555 print SCRIPT << "EOF";
3556sub pb_version_init {
3557
3558return("$projectbuilderver","$projectbuilderrev");
3559}
35601;
3561EOF
3562 close(SCRIPT);
3563 chmod 0755,"$pbscript";
3564
3565 # That build script needs to be run as root and force stop of VM at end
3566 $pbaccount = "root";
3567
3568 # Force shutdown of VM except if it was already launched
3569 my $pbforce = 0;
3570 if ((! $vmexist) && ($vtype eq "vm")) {
3571 $pbforce = 1;
3572 }
3573
3574 pb_script2v($pbscript,$vtype,$pbforce,$v);
3575 $pm->finish if (defined $pbparallel);
3576}
3577$pm->wait_all_children if (defined $pbparallel);
3578die "Aborting, one or more of the children failed." if ((not $all_ok) && ($Global::pb_stop_on_error));
3579return;
3580}
3581
3582# Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
3583sub pb_snap2v {
3584
3585my $vtype = shift;
3586
3587my ($vm,$all) = pb_get2v($vtype);
3588
3589# Script generated
3590my $pbscript = "$ENV{'PBDESTDIR'}/snapv.$$";
3591
3592my ($pbac) = pb_conf_get($vtype."login");
3593
3594foreach my $v (@$vm) {
3595 if ($vtype eq "ve") {
3596 # Get distro context
3597 my $pbos = pb_distro_get_context($v);
3598 my ($vepath) = pb_conf_get("vepath");
3599
3600 # Test if an existing snapshot exists and remove it if there is a VE
3601 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz") &&
3602 (! -d "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}")) {
3603 pb_system("sudo rm -f $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz","Removing previous snapshot $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz");
3604 }
3605 }
3606
3607 # Prepare the script to be executed on the VM/VE
3608 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
3609 print SCRIPT << 'EOF';
3610 #!/bin/bash
3611 sleep 2
3612EOF
3613 close(SCRIPT);
3614 chmod 0755,"$pbscript";
3615
3616 # Force shutdown of VM/VE
3617 # Force snapshot of VM/VE
3618 pb_script2v($pbscript,$vtype,1,$v,1);
3619}
3620return;
3621}
3622
3623# Function to update VMs/VEs/RMs with the latest distribution content
3624sub pb_update2v {
3625
3626my $vtype = shift;
3627
3628my ($vm,$all) = pb_get2v($vtype);
3629
3630# Script generated
3631my $pbscript = "$ENV{'PBDESTDIR'}/updatev.$$";
3632
3633my ($pbac) = pb_conf_get($vtype."login");
3634
3635foreach my $v (@$vm) {
3636 # Get distro context
3637 my $pbos = pb_distro_get_context($v);
3638
3639 # Prepare the script to be executed on the VM/VE/RM
3640 # in $ENV{'PBDESTDIR'}/updatev
3641 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
3642
3643 print SCRIPT << 'EOF';
3644 #!/bin/bash
3645 sleep 2
3646EOF
3647 # VE needs a good /proc
3648 if ($vtype eq "ve") {
3649 print SCRIPT "sudo /bin/mount -t proc /proc /proc\n";
3650 }
3651 print SCRIPT "$pbos->{'update'}\n";
3652 if ($vtype eq "ve") {
3653 print SCRIPT "sudo /bin/umount /proc\n";
3654 }
3655 close(SCRIPT);
3656 chmod 0755,"$pbscript";
3657
3658 # Force shutdown of VM except
3659 pb_script2v($pbscript,$vtype,1,$v);
3660}
3661return;
3662}
3663
3664sub pb_announce {
3665
3666 my $antype = shift;
3667
3668 # Get all required parameters
3669 my ($pbpackager,$pbrepo) = pb_conf_get("pbpackager","pbrepo");
3670 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
3671 if (((not defined $testver) || (not defined $testver->{$ENV{'PBPROJ'}}) || ($testver->{$ENV{'PBPROJ'}} !~ /true/i)) && ($antype eq "Clean")) {
3672 # We just clean for test versions
3673 pb_log(0,"Unable to clean SSH repository for non testver version\n");
3674 return;
3675 }
3676 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
3677 my @pkgs = @$pkg;
3678 my %pkgs;
3679 my $first = 0;
3680
3681 # Get all distros concerned
3682 my $pbos = pb_distro_get_context();
3683 my $distrolist = pb_get_distros($pbos,undef);
3684 my %dl;
3685 my %theorlist;
3686 my %archlist;
3687 foreach my $d (split(/,/,$distrolist)) {
3688 my ($d1,$d2,$d3) = split(/-/,$d);
3689 $dl{$d1}++;
3690 }
3691
3692 # Command to find packages on repo
3693 my $findstr = "find ".join(" ",keys %dl)." ";
3694 my $srcstr = "";
3695 # Generated announce files
3696 my @files;
3697
3698 foreach my $pbpkg (@pkgs) {
3699 if ($first != 0) {
3700 $findstr .= "-o ";
3701 }
3702 $first++;
3703 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
3704 $pbver = $pkgv->{$pbpkg};
3705 } else {
3706 $pbver = $ENV{'PBPROJVER'};
3707 }
3708 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
3709 $pbtag = $pkgt->{$pbpkg};
3710 } else {
3711 $pbtag = $ENV{'PBPROJTAG'};
3712 }
3713
3714 # TODO: use virtual/real names here now
3715 my $pbrealpkg = $pbpkg;
3716 my $pbrealpkgrpm = pb_cms_get_real_pkg($pbpkg,"rpm");
3717 my $pbrealpkgdeb = pb_cms_get_real_pkg($pbpkg,"deb");
3718 if ($antype eq "Clean") {
3719 # We only clean test versions anyway
3720 $pbtag = "0";
3721 my $nver = $pbver;
3722 my $ntag = "[2-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]";
3723 $pbver .= $ntag;
3724 $findstr .= "-name \'$pbrealpkgrpm-$pbver-$pbtag\.*.rpm\' -o -name \'$pbrealpkgrpm-debug-$pbver-$pbtag\.*.rpm\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag"."_*\.deb\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag.dsc\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag.tar.gz\' -o -name \'$pbrealpkg-$nver"."_p$ntag\.ebuild\' -o -name \'$pbrealpkg-$pbver-$pbtag*\.pkg\' -o -name \'$pbrealpkg-$pbver-$pbtag*\.sd\' ";
3725 $srcstr .= "src/$pbrealpkg-$pbver.tar.gz src/$pbrealpkg-$pbver.pbconf.tar.gz ";
3726 } else {
3727 # "Announce" and "Check"
3728 my @date=pb_get_date();
3729 # the matching is only done on packages made the same day for test version. Hopefully this is enough
3730 my $nver;
3731 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
3732 $pbtag = "0";
3733 my $ntag .= strftime("%Y%m%d*", @date);
3734 $nver = $pbver."_p$ntag";
3735 $pbver .= $ntag;
3736 } else {
3737 $nver = $pbver."-r$pbtag";
3738 }
3739 $findstr .= "-name \'$pbrealpkgrpm-$pbver-$pbtag\.*.rpm\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag"."_*\.deb\' -o -name \'$pbrealpkg-$nver\.ebuild\' -o -name \'$pbrealpkg-$pbver\.pkg\' -o -name \'$pbrealpkg-$pbver\.sd\' ";
3740 }
3741
3742 if ($antype eq "Announce") {
3743 my $chglog;
3744
3745 pb_cms_init($pbinit);
3746 # Get project info on log file and generate tmp files used later on
3747 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
3748 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
3749 $chglog = undef if (! -f $chglog);
3750
3751 open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
3752 my $pb;
3753 $pb->{'realpkg'} = $pbrealpkg;
3754 $pb->{'ver'} = $pbver;
3755 $pb->{'tag'} = $pbtag;
3756 $pb->{'date'} = $pbdate;
3757 $pb->{'extdir'} = pb_get_extdir();
3758 $pb->{'chglog'} = $chglog;
3759 $pb->{'packager'} = $pbpackager;
3760 $pb->{'proj'} = $ENV{'PBPROJ'};
3761 $pb->{'repo'} = $pbrepo;
3762 $pb->{'pbos'}->{'type'} = "announce";
3763 $pb->{'pbos'}->{'suffix'} = "none";
3764 pb_changelog($pb,\*OUT,"yes");
3765 close(OUT);
3766 push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
3767 } elsif ($antype eq "Check") {
3768 # For the check we also build the theoritical complete list we should get
3769 foreach my $d (split(/,/,$distrolist)) {
3770 $pbos = pb_distro_get_context($d);
3771 if ($pbos->{'type'} eq "rpm") {
3772 $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/$pbrealpkgrpm-$pbver-$pbtag$pbos->{'suffix'}"} = 0;
3773 } elsif ($pbos->{'type'} eq "deb") {
3774 $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkgdeb"."_$pbver-$pbtag"} = 0;
3775 # TODO are we always using the last arch ?
3776 $archlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkgdeb"."_$pbver-$pbtag"} = "$pbos->{'arch'}";
3777 } elsif ($pbos->{'type'} eq "ebuild") {
3778 my $prefix = "-r";
3779 $prefix = "_p" if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i));
3780 $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkg-$pbver$prefix$pbtag.ebuild"} = 0;
3781 $archlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkg-$pbver$prefix$pbtag.ebuild"} = "$pbos->{'arch'}";
3782 } elsif ($pbos->{'type'} eq "pkg") {
3783 $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/$pbrealpkg-$pbver-$pbtag.pkg"} = 0;
3784 } else {
3785 pb_log(1,"No theoritical list possible for type $pbos->{'type'}\n");
3786 }
3787 }
3788 }
3789 pb_log(2,"theorlist : ".Dumper(%theorlist)."\n");
3790 }
3791 if ($antype eq "Announce") {
3792 $findstr .= " | grep -Ev \'src.rpm\'";
3793 } elsif ($antype eq "Clean") {
3794 $findstr .= " | xargs rm -f -v $srcstr ";
3795 }
3796
3797 # Prepare the command to run and execute it
3798 open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
3799 print PBS "#!/bin/bash\n";
3800 print PBS "set -x\n" if ($pbdebug gt 1);
3801 print PBS "$findstr | sort 2> /dev/null\n";
3802 close(PBS);
3803 chmod 0755,"$ENV{'PBTMP'}/pbscript";
3804 pb_send2target("Announce");
3805
3806 my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
3807 if ($antype eq "Announce") {
3808 # Get subject line
3809 pb_log(0,"Please enter the title of your announce\n");
3810 pb_log(0,"(By default: $sl)\n");
3811 my $sl2 = <STDIN>;
3812 $sl = $sl2 if ($sl2 !~ /^$/);
3813
3814 # Prepare a template of announce
3815 open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
3816 print ANN << "EOF";
3817$sl</p>
3818
3819<p>The project team is happy to announce the availability of a newest version of $ENV{'PBPROJ'} $ENV{'PBPROJVER'}. Enjoy it as usual!</p>
3820<p>
3821Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
3822</p>
3823<p>
3824EOF
3825 }
3826
3827 open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to read $ENV{'PBTMP'}/system.$$.log: $!";
3828 if ($antype eq "Announce") {
3829 my $col = 2;
3830 my $i = 1;
3831 print ANN << 'EOF';
3832<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0">
3833<TR>
3834EOF
3835 while (<LOG>) {
3836 print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
3837 $i++;
3838 if ($i > $col) {
3839 print ANN "</TR>\n<TR>";
3840 $i = 1;
3841 }
3842 }
3843 } elsif ($antype eq "Clean") {
3844 while (<LOG>) {
3845 # skip errors
3846 next if ($_ !~ /^removed /);
3847 pb_log(0,"$_");
3848 }
3849 } else {
3850 # In "Check" mode we need to compare the 2 lists (real and theoritical)
3851 while (<LOG>) {
3852 # Get package name and remove what is in extra for the theoritical list (arch at the end)
3853 chomp();
3854 # skip find errors
3855 next if (/^find:/);
3856 my $p = $_;
3857 $p =~ s/\.(i[3456]86|x86_64|noarch|src)\.rpm$//;
3858 $p =~ s/_(i[3456]86|amd64|all)\.deb$//;
3859 $p =~ s/(-0\.[0-9]{8})[0-9]{6}/$1*/ if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i));
3860 $p =~ s/(-r|_p[0-9]+)\.ebuild/$1*/ if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i));
3861 $theorlist{$p} = -2 if (not defined $theorlist{$p});
3862 $theorlist{$p} = $theorlist{$p} + 1;
3863 }
3864 pb_log(2,"theorlist : ".Dumper(%theorlist)."\n");
3865 }
3866 close(LOG);
3867
3868 # Nothing more for the cleanssh case
3869 return if ($antype eq "Clean");
3870
3871 if ($antype eq "Check") {
3872 my ($chkex) = pb_conf_get_if("checkexclude");
3873 my $vmbuildlist = "";
3874 my $vebuildlist = "";
3875 my $rmbuildlist = "";
3876 my @pt = pb_conf_get_if("vmlist","velist","rmlist");
3877 foreach my $t (sort keys %theorlist) {
3878 if (defined $theorlist{$t} and $theorlist{$t} >= 1) {
3879 pb_log(1,"Packages found for $t\n");
3880 } elsif (defined $theorlist{$t} and $theorlist{$t} < 0) {
3881 pb_log(0,"Extra Package found for $t\n");
3882 } else {
3883 pb_log(2,"Analyzing $t\n");
3884 my ($os,$ver,$arch,$package) = split(/\//,$t);
3885 # Some distro have no arch subdir
3886 if (not defined $package) {
3887 $package = $arch;
3888 # TODO: If both arch have failed, we just make the last one
3889 $arch = $archlist{$t};
3890 }
3891 my $pbos = pb_distro_get_context("$os-$ver-$arch");
3892 my $pkgn = $package;
3893 if ($pbos->{'type'} ne "deb") {
3894 # package name is more easily found from the end for non deb
3895 # as '-' is the separator, but it can also be used in names
3896 $pkgn = reverse($package);
3897 # search the second '-' and isolate the now last part which is the full name
3898 $pkgn =~ s/([^-]+)-([^-]+)-([\S])+$/$3/;
3899 } else {
3900 $pkgn =~ s/([^_]+)_([\S])+$/$2/;
3901 }
3902 my $found = 0;
3903 # Handle the exclusion of OSes
3904 my $excl = "";
3905 $excl .= $chkex->{$pkgn} if (defined $chkex->{$pkgn});
3906 $excl .= $chkex->{"all"} if (defined $chkex->{"all"});
3907 foreach my $ex (split(/,/,$excl)) {
3908 $found = 1 if ("$os-$ver-$arch" =~ /^$ex/);
3909 }
3910 # Skip as excluded
3911 next if ($found == 1);
3912 pb_log(0,"Package NOT found for $t\n");
3913 # Avoid duplicates in list
3914 next if ($vmbuildlist =~ /$os-$ver-$arch/);
3915 next if ($vebuildlist =~ /$os-$ver-$arch/);
3916 next if ($rmbuildlist =~ /$os-$ver-$arch/);
3917 # check with which method we need to build
3918 if ((defined $pt[0]->{$ENV{'PBPROJ'}}) and ($pt[0]->{$ENV{'PBPROJ'}} =~ /$os-$ver-$arch/)) {
3919 $vmbuildlist = "$os-$ver-$arch" if ($vmbuildlist eq "");
3920 $vmbuildlist .= ",$os-$ver-$arch" if ($vmbuildlist !~ /$os-$ver-$arch/);
3921 next;
3922 }
3923 if ((defined $pt[1]->{$ENV{'PBPROJ'}}) and ($pt[1]->{$ENV{'PBPROJ'}} =~ /$os-$ver-$arch/)) {
3924 $vebuildlist = "$os-$ver-$arch" if ($vebuildlist eq "");
3925 $vebuildlist .= ",$os-$ver-$arch" if ($vebuildlist !~ /$os-$ver-$arch/);
3926 next;
3927 }
3928 if ((defined $pt[2]->{$ENV{'PBPROJ'}}) and ($pt[2]->{$ENV{'PBPROJ'}} =~ /$os-$ver-$arch/)) {
3929 $rmbuildlist = "$os-$ver-$arch" if ($rmbuildlist eq "");
3930 $rmbuildlist .= ",$os-$ver-$arch" if ($rmbuildlist !~ /$os-$ver-$arch/);
3931 }
3932 }
3933 }
3934 # If we want to rebuild automatically, let's do it
3935 if (defined $opts{'rebuild'}) {
3936 # SandBox or CMS
3937 pb_log(0,"Rebuilding from SandBox\n");
3938 pb_log(0,"for VMs: $vmbuildlist\n") if ($vmbuildlist ne "");
3939 pb_log(0,"for VEs: $vebuildlist\n") if ($vebuildlist ne "");
3940 pb_log(0,"for RMs: $rmbuildlist\n") if ($rmbuildlist ne "");
3941 pb_cms2build("SandBox");
3942 # Which mode
3943 $ENV{'PBV'} = $vmbuildlist;
3944 pb_build2v("vm","build") if ($vmbuildlist ne "");
3945 $ENV{'PBV'} = $vebuildlist;
3946 pb_build2v("ve","build") if ($vebuildlist ne "");
3947 $ENV{'PBV'} = $rmbuildlist;
3948 pb_build2v("rm","build") if ($rmbuildlist ne "");
3949 }
3950 # For the check part this is now finished
3951 return;
3952 }
3953
3954 print ANN << "EOF";
3955</TR>
3956</TABLE>
3957</p>
3958
3959<p>As usual source packages are also available in the same directory.</p>
3960
3961<p>
3962Changes are :
3963</p>
3964<p>
3965EOF
3966 # Get each package changelog content
3967 foreach my $f (sort(@files)) {
3968 open(IN,"$f") || die "Unable to read $f:$!";
3969 while (<IN>) {
3970 print ANN $_;
3971 }
3972 close(IN);
3973 print ANN "</p><p>\n";
3974 }
3975 print ANN "</p>\n";
3976 close(ANN);
3977
3978 # Allow for modification
3979 my $editor = "vi";
3980 $editor = $ENV{'EDITOR'} if (defined $ENV{'EDITOR'});
3981 pb_system("$editor $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
3982
3983 # Store it in DB for external usage (Web pages generation)
3984 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
3985
3986 my $precmd = "";
3987 if (! -f $db) {
3988 $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
3989 }
3990
3991 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
3992 { RaiseError => 1, AutoCommit => 1 })
3993 || die "Unable to connect to $db";
3994
3995 if ($precmd ne "") {
3996 my $sth = $dbh->prepare(qq{$precmd})
3997 || die "Unable to create table into $db";
3998 $sth->execute();
3999 }
4000
4001 # To read whole file
4002 local $/;
4003 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
4004 my $announce = <ANN>;
4005 close(ANN);
4006
4007 pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
4008 my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
4009 || die "Unable to insert into $db";
4010 $sth->execute($pbdate, $announce);
4011 $sth->finish();
4012 $dbh->disconnect;
4013
4014 # Then deliver it on the Web
4015 # $TOOLHOME/livwww www
4016
4017 # Mail it to project's ML
4018 open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
4019 print ML << 'EOF';
4020<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
4021
4022<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
4023 <head>
4024 </head>
4025 <body>
4026 <p>
4027EOF
4028 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
4029 while(<ANN>) {
4030 print ML $_;
4031 }
4032 print ML << 'EOF';
4033</body>
4034</html>
4035EOF
4036 close(ML);
4037
4038 # To read whole file
4039 local $/;
4040 open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
4041 my $msg = <ANN>;
4042 close(ANN);
4043
4044 # Preparation of headers
4045 eval
4046 {
4047 require Mail::Sendmail;
4048 Mail::Sendmail->import();
4049 };
4050 if ($@) {
4051 # Mail::Sendmail not found not sending mail !
4052 pb_log(0,"No Mail::Sendmail module found so not sending any mail !\n");
4053 } else {
4054 my ($pbml,$pbsmtp) = pb_conf_get("pbml","pbsmtp");
4055 my %mail = (
4056 To => $pbml->{$ENV{'PBPROJ'}},
4057 From => $pbpackager->{$ENV{'PBPROJ'}},
4058 Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
4059 Body => $msg,
4060 Subject => "[ANNOUNCE] $sl",
4061 );
4062
4063 # Send mail
4064 if (! sendmail(%mail)) {
4065 if ((defined $Mail::Sendmail::error) and (defined $Mail::Sendmail::log)) {
4066 die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
4067 }
4068 }
4069 }
4070}
4071
4072#
4073# Creates a set of HTML file containing the news for the project
4074# based on what has been generated by the pb_announce function
4075#
4076sub pb_web_news2html {
4077
4078 my $dest = shift || $ENV{'PBTMP'};
4079
4080 # Get all required parameters
4081 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
4082
4083 # DB of announces for external usage (Web pages generation)
4084 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
4085
4086 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
4087 { RaiseError => 1, AutoCommit => 1 })
4088 || die "Unable to connect to $db";
4089 # For date handling
4090 $ENV{LANGUAGE}="C";
4091 my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
4092 my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
4093 pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
4094 my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
4095 my %news;
4096 $news{"cy"} = ""; # current year's news
4097 $news{"ly"} = ""; # last year news
4098 $news{"py"} = ""; # previous years news
4099 $news{"fp"} = ""; # first page news
4100 my $cpt = 4; # how many news for first page
4101 # Extract info from DB
4102 foreach my $row (@$all) {
4103 my ($id, $date, $announce) = @$row;
4104 $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
4105 $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
4106 $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
4107 $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
4108 $cpt--;
4109 }
4110 pb_log(1,"news{fp}: ".$news{"fp"}."\n");
4111 $dbh->disconnect;
4112
4113 # Generate the HTML content
4114 foreach my $pref (keys %news) {
4115 open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
4116 print NEWS "$news{$pref}";
4117 close(NEWS);
4118 }
4119}
4120
4121
4122# Return the SSH key file to use
4123# Potentially create it if needed
4124
4125sub pb_ssh_get {
4126
4127my $create = shift || 0; # Do not create keys by default
4128
4129my ($pbagent) = pb_conf_get_if("pbusesshagent");
4130# use ssh-agent if asked so.
4131return(undef) if (($create == 0) && (defined $pbagent->{$ENV{'PBPROJ'}}) && ($pbagent->{$ENV{'PBPROJ'}} =~ /true/io));
4132
4133# Check the SSH environment
4134my $keyfile = undef;
4135
4136# We have specific keys by default
4137$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
4138if (!(-e $keyfile) && ($create eq 1)) {
4139 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
4140}
4141
4142$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
4143$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
4144$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
4145die "Unable to find your public ssh key under $ENV{'HOME'}/.ssh" if (not defined $keyfile);
4146return($keyfile);
4147}
4148
4149
4150# Returns the pid of a running VM command using a specific VM file
4151sub pb_check_ps {
4152 my $vmcmd = shift;
4153 my $vmm = shift;
4154 my $vmexist = 0; # FALSE by default
4155
4156 open(PS, "ps auxhww|") || die "Unable to call ps";
4157 while (<PS>) {
4158 next if (! /$vmcmd/);
4159 next if (! /$vmm/);
4160 my ($void1, $void2);
4161 ($void1, $vmexist, $void2) = split(/ +/);
4162 last;
4163 }
4164 return($vmexist);
4165}
4166
4167
4168sub pb_extract_build_files {
4169
4170my $src=shift;
4171my $dir=shift;
4172my $ddir=shift;
4173my $mandatory=shift || "spec";
4174my @files;
4175
4176my $flag = "mayfail" if (($mandatory eq "patch") || ($mandatory eq "src"));
4177my $res;
4178
4179if ($src =~ /tar\.gz$/) {
4180 $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
4181} elsif ($src =~ /tar\.bz2$/) {
4182 $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
4183} else {
4184 die "Unknown compression algorithm for $src";
4185}
4186# If not mandatory return now
4187return() if (($res != 0) and (($mandatory eq "patch") || ($mandatory eq "src")));
4188opendir(DIR,"$dir") || die "Unable to open directory $dir: $!";
4189foreach my $f (readdir(DIR)) {
4190 next if ($f =~ /^\./);
4191 # Skip potential patch dir
4192 next if ($f =~ /^pbpatch/);
4193 # Skip potential source dir
4194 next if ($f =~ /^pbsrc/);
4195 # Skip potential backup files
4196 next if ($f =~ /~$/);
4197 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
4198 pb_log(2,"mv $dir/$f $ddir\n");
4199 push @files,"$ddir/$f";
4200}
4201closedir(DIR);
4202# Not enough but still a first cleanup
4203pb_rm_rf("$dir");
4204return(@files);
4205}
4206
4207sub pb_list_bfiles {
4208
4209my $dir = shift;
4210my $pbpkg = shift;
4211my $bfiles = shift;
4212my $pkgfiles = shift;
4213my $supfiles = shift;
4214# subdir to keep if recursive mode, empty by default
4215my $subdir = shift || "";
4216# In a recursive function , we need a local var as DIR handle
4217my $bdir;
4218
4219pb_log(2,"DEBUG: entering pb_list_bfiles in $dir: ".Dumper($bfiles)."\n");
4220opendir($bdir,"$dir") || die "Unable to open dir $dir: $!";
4221foreach my $f (readdir($bdir)) {
4222 pb_log(3,"DEBUG: pb_list_bfiles found $f\n");
4223 next if ($f =~ /^\./);
4224 if (-d "$dir/$f") {
4225 # Recurse for directories (Debian 3.0 format e.g.)
4226 pb_log(2,"DEBUG: pb_list_bfiles recurse in $dir/$f\n");
4227 pb_list_bfiles("$dir/$f",$pbpkg,$bfiles,$pkgfiles,$supfiles,$f);
4228 next;
4229 }
4230
4231 my $key = $f;
4232 # if recursive then store also the subdir
4233 $key = "$subdir/$f" if ($subdir ne "");
4234 $bfiles->{$key} = "$dir/$f";
4235 $bfiles->{$key} =~ s~$ENV{'PBROOTDIR'}~~;
4236 if (defined $supfiles->{$pbpkg}) {
4237 $pkgfiles->{$key} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
4238 }
4239}
4240closedir($bdir);
4241pb_log(2,"DEBUG: exiting pb_list_bfiles: ".Dumper($bfiles)."\n");
4242}
4243
4244sub pb_add_comma {
4245
4246my $str = shift;
4247my $addstr = shift;
4248
4249$str .= "," if (defined $str);
4250$str .= $addstr;
4251return($str);
4252}
4253
4254sub pb_list_sfiles {
4255
4256my $sdir = shift;
4257my $ptr = shift;
4258my $pbos = shift;
4259my $extdir = shift;
4260
4261pb_log(2,"DEBUG: entering pb_list_sfiles: ".Dumper($ptr)."\n");
4262my $key = "$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
4263
4264# Prepare local sources for this distro - They are always applied first - May be a problem one day
4265# This function works for both patches and additional sources
4266foreach my $p (sort(<$sdir/*>)) {
4267 $ptr->{$key} = pb_add_comma($ptr->{$key},"file://$p") if (($p =~ /\.all$/) || ($p =~ /\.$pbos->{'os'}$/) || ($p =~ /\.$pbos->{'type'}$/) || ($p =~ /\.$pbos->{'family'}$/) || ($p =~ /\.$pbos->{'name'}$/) || ($p =~ /\.$pbos->{'name'}-$pbos->{'version'}$/) ||($p =~ /\.$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}$/));
4268}
4269
4270# Prepare also remote sources to be included - Applied after the local ones
4271foreach my $p ("all","$pbos->{'os'}","$pbos->{'type'}","$pbos->{'family'}","$pbos->{'name'}","$pbos->{'name'}-$pbos->{'version'}","$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") {
4272 my $f = "$extdir.".".$p";
4273 next if (not -f $f);
4274 if (not open(PATCH,$f)) {
4275 pb_display("Unable to open existing external source file content $f\n");
4276 next;
4277 }
4278 while (<PATCH>) {
4279 chomp();
4280 $ptr->{$key} = pb_add_comma($ptr->{$key},"$_");
4281 }
4282 close(PATCH);
4283}
4284pb_log(2,"DEBUG: exiting pb_list_sfiles: ".Dumper($ptr)."\n");
4285return($ptr);
4286}
4287
4288#
4289# Return the list of packages we are working on in a non CMS action
4290#
4291sub pb_get_pkg {
4292
4293my @pkgs = ();
4294
4295# In script actions that file may not exist.
4296return(\@pkgs) if ((not defined $ENV{'PBDESTDIR'}) || (not defined $ENV{'PBPROJVER'}) || (not defined $ENV{'PBPROJTAG'}) || (! -f "$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb"));
4297
4298my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
4299@pkgs = keys %$var if (defined $var);
4300
4301pb_log(0,"Packages: ".join(',',@pkgs)."\n") if (@pkgs);
4302return(\@pkgs);
4303}
4304
4305# Manages VM/RM SSH port communication
4306sub pb_get_port {
4307
4308my $port = shift;
4309my $pbos = shift;
4310my $cmt = shift;
4311my $nport;
4312
4313die "No port passed in parameter. Report to dev team\n" if (not defined $port);
4314# key is project on VM, but machine tuple for RM
4315if ($cmt =~ /^RM/i) {
4316 $nport = $port->{"$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"};
4317} else {
4318 $nport = $port->{$ENV{'PBPROJ'}};
4319}
4320pb_log(2,"pb_get_port with $nport\n");
4321# Maybe a port was given as parameter so overwrite
4322$nport = "$pbport" if (defined $pbport);
4323# Maybe in // mode so use the env var set up as an offset to the base port, except when called from send2target for Packages or for RM
4324if (($cmt ne "Packages") && ($cmt !~ /^RM/i)) {
4325 $nport += $ENV{'PBVMPORT'} if ((defined $pbparallel) && (defined $ENV{'PBVMPORT'}));
4326}
4327pb_log(2,"pb_get_port returns $nport\n");
4328return($nport);
4329}
4330
4331sub pb_set_port {
4332
4333my ($pid,$ident) = @_;
4334pb_log(2,"pb_set_port for VM ($pid), id $ident\n");
4335$ENV{'PBVMPORT'} = $ident;
4336pb_log(2,"pb_set_port sets PBVMPORT in env to $ENV{'PBVMPORT'}\n");
4337}
4338
4339sub pb_set_parallel {
4340
4341my $vtype = shift;
4342
4343pb_log(2,"pb_set_parallel vtype: $vtype\n");
4344# Take care of memory size if VM, parallel mode and more than 1 action
4345if ((defined $pbparallel) && ($pbparallel ne 1) && ($vtype eq "vm")) {
4346 eval
4347 {
4348 require Linux::SysInfo;
4349 Linux::SysInfo->import();
4350 };
4351 if ($@) {
4352 # Linux::SysInfo not found
4353 pb_log(1,"ADVISE: Install Linux::SysInfo to benefit from automatic parallelism optimization.\nOr optimize manually pbparallel in your pb.conf file\nUsing $pbparallel processes max at a time for the moment\nWARNING: This may consume too much memory for your system\n");
4354 } else {
4355 # Using the memory size
4356 my $si = Linux::SysInfo::sysinfo();
4357 if (not defined $si) {
4358 pb_log(1,"ADVISE: Install Linux::SysInfo to benefit from automatic parallelism optimization.\nOr optimize manually pbparallel in your pb.conf file\nUsing $pbparallel processes max at a time for the moment\nWARNING: This may consume too much memory for your system\n");
4359 } else {
4360 # Keep the number of VM whose memory can be allocated
4361 my $ram = $si->{"totalram"}-$si->{"sharedram"}-$si->{"bufferram"};
4362 my $ram2;
4363 my ($vmmem) = pb_conf_get_if("vmmem");
4364
4365 my $v = "default";
4366 if ((defined $vmmem) and (defined $vmmem->{$v})) {
4367 $ram2 = $vmmem->{$v};
4368 } else {
4369 # Default for KVM/QEMU
4370 $ram2 = 128;
4371 }
4372 $pbparallel = sprintf("%d",$ram/$ram2);
4373 }
4374 pb_log(1,"Using $pbparallel processes at a time\n");
4375 }
4376}
4377pb_log(2,"pb_set_parallel returns: $pbparallel\n") if (defined $pbparallel);
4378return($pbparallel);
4379}
4380
4381sub pb_get_sudocmds {
4382
4383my $pbos = shift;
4384my %sudocmds;
4385
4386pb_log(2,"pb_get_sudocmds entering with lines:".Dumper(@_)."\n");
4387foreach my $c (split(/;/,$pbos->{'update'}),split(/;/,$pbos->{'install'}),@_) {
4388 pb_log(2,"pb_get_sudocmds analyses $c\n");
4389 next if ($c !~ /^\s*sudo/);
4390 # remove sudo and leading spaces
4391 $c =~ s/^\s*sudo\s+//;
4392 # keep only the command, not the params
4393 $c =~ s/([^\s]+)\s.*$/$1/;
4394 $sudocmds{$c} = "";
4395}
4396pb_log(2,"pb_get_sudocmds returns ".Dumper(keys %sudocmds)."\n");
4397return(keys %sudocmds);
4398}
4399
4400sub pb_sign_pkgs {
4401
4402my $pbos = shift;
4403my $made = shift;
4404
4405pb_log(2,"entering pb_sign_pkg: $made ".Dumper($pbos)."\n");
4406my ($passfile, $passphrase, $passpath) = pb_conf_get_if("pbpassfile","pbpassphrase","pbpasspath");
4407$ENV{'PBPASSPHRASE'} = $passphrase->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSPHRASE'}) && (defined $passphrase->{$ENV{'PBPROJ'}}));
4408$ENV{'PBPASSFILE'} = $passfile->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSFILE'})&& (defined $passfile->{$ENV{'PBPROJ'}})) ;
4409$ENV{'PBPASSPATH'} = $passpath->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSPATH'})&& (defined $passpath->{$ENV{'PBPROJ'}})) ;
4410
4411# Remove extra spaces
4412$made =~ s/\s+/ /g;
4413$made =~ s/^\s//g;
4414$made =~ s/\s$//g;
4415
4416if ($pbos->{'type'} eq "rpm") {
4417 eval
4418 {
4419 require RPM4::Sign;
4420 RPM4::Sign->import();
4421 };
4422 if ($@) {
4423 # RPM4::Sign not found
4424 pb_log(1,"WARNING: Install RPM4::Sign to benefit from automatic package signing.\n");
4425 } else {
4426 return if ((not defined $ENV{'PBPASSPHRASE'}) and (not defined $ENV{'PBPASSFILE'}));
4427 my $sign = RPM4::Sign->new(
4428 passphrase => $ENV{'PBPASSPHRASE'},
4429 name => $ENV{'PBPACKAGER'},
4430 path => $ENV{'PBPASSPATH'},
4431 password_file => $ENV{'PBPASSFILE'},
4432 );
4433
4434 pb_log(0,"Signing RPM packages...\n");
4435 pb_log(2,"pb_sign_pkg: pkgs:".Dumper(split(/ /,$made))."\n");
4436 $sign->rpmssign(split(/ /,$made));
4437 }
4438} elsif ($pbos->{'type'} eq "deb") {
4439 my $changes = "";
4440 foreach my $c (split(/ /,$made)) {
4441 $changes .= " $ENV{'PBBUILDDIR'}/$c" if (($c =~ /\.changes$/) && (-f "$ENV{PBBUILDDIR}/$c"));
4442 }
4443 my $debsigncmd = pb_check_req("debsign",1);
4444 pb_system("$debsigncmd -m\'$ENV{'PBPACKAGER'}\' $changes","Signing DEB packages","mayfail") if (($changes ne "") && (defined $debsigncmd));
4445} else {
4446 pb_log(0,"I don't know yet how to sign packages for type $pbos->{'type'}.\nPlease give feedback to dev team\n");
4447}
4448pb_log(2,"exiting pb_sign_pkg\n");
4449}
4450
4451# return list of all distributins supported, comma separated
4452sub pb_get_distros {
4453
4454my $pbos = shift;
4455my $pbtarget = shift;
4456
4457my @dists = ("$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}");
4458
4459# Get list of distributions for which we need to generate build files if no target
4460if (not defined $pbtarget) {
4461 my @pt = pb_conf_get_if("vmlist","velist","rmlist");
4462 foreach my $pt (@pt) {
4463 push(@dists, split(/,/, $pt->{$ENV{PBPROJ}})) if defined $pt->{$ENV{PBPROJ}};
4464 }
4465 # remove any whitespace
4466 grep(s/\s+//go, @dists);
4467}
4468return(join(",",@dists));
4469}
4470
4471sub pb_get_extdir () {
4472
4473 # the pbrc file should contain it and whatever the key, we take it
4474 my ($ed) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbextdir");
4475 pb_log(2,"ed: ".Dumper($ed)."\n");
4476 my $pbextdir = "";
4477 foreach my $k (keys %$ed) {
4478 $pbextdir = $ed->{$k};
4479 # In case we have an empty field, empty it completely
4480 pb_log(2,"pbextdir: ***$pbextdir***\n");
4481 $pbextdir =~ s/^\s*$//;
4482 }
4483 pb_log(2,"pbextdir: ***$pbextdir***\n");
4484 return($pbextdir);
4485}
4486
44871;
Note: See TracBrowser for help on using the repository browser.