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

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