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

Last change on this file since 2458 was 2458, checked in by Bruno Cornec, 4 years ago

Fix #183 by pushing the repomd.xml.asc file for SUSE and fix also repo names

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