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

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