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

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