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

Last change on this file since 2426 was 2426, checked in by Bruno Cornec, 5 years ago

Start adding install and test target for pb - local install works already

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