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

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