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

Last change on this file since 1134 was 1134, checked in by Bruno Cornec, 13 years ago
  • Fix the sendmail require bug for announce command
  • Fix warnings with param undefined for announce command
  • Property svn:executable set to *
File size: 107.0 KB
RevLine 
[5]1#!/usr/bin/perl -w
2#
3# Project Builder main application
4#
5# $Id$
6#
7# Copyright B. Cornec 2007
8# Provided under the GPL v2
9
[22]10# Syntax: see at end
[9]11
[18]12use strict 'vars';
[1107]13
14# The modules mentioned here are required by pb when used both
15# locally or inside a VE/VM
16# Additional required modules only used locally are called with a require
17# in their respective section
[331]18use Getopt::Long qw(:config auto_abbrev no_ignore_case);
[9]19use Data::Dumper;
20use English;
[16]21use File::Basename;
[26]22use File::Copy;
[395]23use File::stat;
24use File::Temp qw(tempdir);
[872]25use File::Find;
[547]26use Time::localtime qw(localtime);
[13]27use POSIX qw(strftime);
[17]28use lib qw (lib);
[329]29use ProjectBuilder::Version;
[318]30use ProjectBuilder::Base;
[512]31use ProjectBuilder::Display;
[405]32use ProjectBuilder::Conf;
33use ProjectBuilder::Distribution;
34use ProjectBuilder::CMS;
[416]35use ProjectBuilder::Env;
[405]36use ProjectBuilder::Filter;
[473]37use ProjectBuilder::Changelog;
38
[397]39# Global variables
[5]40my %opts; # CLI Options
[9]41my $action; # action to realize
[320]42my $test = "FALSE"; # Not used
[748]43my $pbforce = 0; # Force VE/VM rebuild
[968]44my $pbsnap = 0; # Do not use snapshot mode for VM/VE by default
[320]45my $option = ""; # Not used
46my @pkgs; # list of packages
[95]47my $pbtag; # Global Tag variable
48my $pbver; # Global Version variable
[141]49my $pbscript; # Name of the script
[77]50my %pbver; # per package
51my %pbtag; # per package
[53]52my $pbrev; # Global REVISION variable
[152]53my $pbaccount; # Login to use to connect to the VM
[1120]54my $pbtarget; # Target os-ver-arch you want to build for
[162]55my $pbport; # Port to use to connect to the VM
[199]56my $newver; # New version to create
[792]57my $iso = undef; # ISO image for the VM to create
[5]58
[320]59my @date = pb_get_date();
60my $pbdate = strftime("%Y-%m-%d", @date);
[5]61
[331]62=pod
63
64=head1 NAME
65
66pb, aka project-builder.org - builds packages for your projects
67
68=head1 DESCRIPTION
69
70pb helps you build various packages directly from your project sources.
71Those sources could be handled by a CMS (Configuration Management System)
[748]72such as Subversion, CVS, Git, Mercurial... or being a simple reference to a compressed tar file.
[331]73It's based on a set of configuration files, a set of provided macros to help
74you keeping build files as generic as possible. For example, a single .spec
75file should be required to generate for all rpm based distributions, even
76if you could also have multiple .spec files if required.
77
78=head1 SYNOPSIS
79
[1124]80pb [-vhSq][-r pbroot][-p project][[-s script -a account -P port][-t os-ver-arch][-m os-ver-arch[,...]]][-g][-i iso] <action> [<pkg1> ...]
[331]81
[1124]82pb [--verbose][--help][--man][--quiet][--snapshot][--revision pbroot][--project project][[--script script --account account --port port][--target os-ver-arch][--machine os-ver-arch[,...]]][--nographics][--iso iso] <action> [<pkg1> ...]
[331]83
84=head1 OPTIONS
85
86=over 4
87
88=item B<-v|--verbose>
89
90Print a brief help message and exits.
91
92=item B<-q|--quiet>
93
94Do not print any output.
95
96=item B<-h|--help>
97
98Print a brief help message and exits.
99
[748]100=item B<-S|--snapshot>
101
102Use the snapshot mode of VMs or VEs
103
[331]104=item B<--man>
105
106Prints the manual page and exits.
107
[1120]108=item B<-t|--target os-ver-arch>
[331]109
[1120]110Name of the target system you want to build for.
111All if none precised.
112
113=item B<-m|--machine os-ver-arch[,os-ver-arch,...]>
114
[331]115Name of the Virtual Machines (VM) or Virtual Environments (VE) you want to build on (coma separated).
116All if none precised (or use the env variable PBV).
117
118=item B<-s|--script script>
119
120Name of the script you want to execute on the related VMs or VEs.
121
[1124]122=item B<-g|--nographics>
123
124Do not launch VMs in graphical mode.
125
[331]126=item B<-i|--iso iso_image>
127
128Name of the ISO image of the distribution you want to install on the related VMs.
129
130=item B<-a|--account account>
131
132Name of the account to use to connect on the related VMs.
133
134=item B<-P|--port port_number>
135
136Port number to use to connect on the related VMs.\n";
137
138=item B<-p|--project project_name>
139
140Name of the project you're working on (or use the env variable PBPROJ)
141
142=item B<-r|--revision revision>
143
144Path Name of the project revision under the CMS (or use the env variable PBROOT)
145
146=item B<-V|--version new_version>
147
148New version of the project to create based on the current one.
149
150=back
151
152=head1 ARGUMENTS
153
154<action> can be:
155
156=over 4
157
[1097]158=item B<sbx2build>
159
160Create tar files for the project under your CMS.
161Current state of the exported content is taken.
162CMS supported are SVN, SVK, CVS, Git and Mercurial
163parameters are packages to build
164if not using default list
165
[331]166=item B<cms2build>
167
168Create tar files for the project under your CMS.
[1097]169Current state of the CMS is taken.
170CMS supported are SVN, SVK, CVS, Git and Mercurial
[331]171parameters are packages to build
172if not using default list
173
174=item B<build2pkg>
175
176Create packages for your running distribution
177
178=item B<cms2pkg>
179
180cms2build + build2pkg
181
[1097]182=item B<sbx2pkg>
183
184sbx2build + build2pkg
185
[331]186=item B<build2ssh>
187
188Send the tar files to a SSH host
189
[1097]190=item B<sbx2ssh>
191
192sbx2build + build2ssh
193
[331]194=item B<cms2ssh>
195
196cms2build + build2ssh
197
198=item B<pkg2ssh>
199
200Send the packages built to a SSH host
201
202=item B<build2vm>
203
204Create packages in VMs, launching them if needed
205and send those packages to a SSH host once built
206VM type supported are QEMU
207
208=item B<build2ve>
209
210Create packages in VEs, creating it if needed
211and send those packages to a SSH host once built
212
[1097]213=item B<sbx2vm>
214
215sbx2build + build2vm
216
217=item B<sbx2ve>
218
219sbx2build + build2ve
220
[331]221=item B<cms2vm>
222
223cms2build + build2vm
224
225=item B<cms2ve>
226
227cms2build + build2ve
228
229=item B<launchvm>
230
231Launch one virtual machine
232
233=item B<launchve>
234
235Launch one virtual environment
236
237=item B<script2vm>
238
239Launch one virtual machine if needed
240and executes a script on it
241
242=item B<script2ve>
243
244Execute a script in a virtual environment
245
246=item B<newvm>
247
248Create a new virtual machine
249
250=item B<newve>
251
252Create a new virtual environment
253
[346]254=item B<setupvm>
255
256Setup a virtual machine for pb usage
257
258=item B<setupve>
259
260Setup a virtual environment for pb usage
261
[748]262=item B<snapvm>
263
264Snapshot a virtual machine for pb usage
265
266=item B<snapve>
267
268Snapshot a virtual environment for pb usage
269
[1111]270=item B<updatevm>
271
272Update the distribution in the virtual machine
273
274=item B<updateve>
275
276Update the distribution in the virtual environment
277
[783]278=item B<test2pkg>
279
280Test a package locally
281
[772]282=item B<test2vm>
283
284Test a package in a virtual machine
285
286=item B<test2ve>
287
288Test a package in a virtual environment
289
[331]290=item B<newver>
291
292Create a new version of the project derived
293from the current one
294
295=item B<newproj>
296
297Create a new project and a template set of
298configuration files under pbconf
299
[471]300=item B<announce>
301
302Announce the availability of the project through various means
303
[1117]304=item B<sbx2webssh>
[557]305
[1117]306Create tar files for the website under your CMS.
307Current state of the exported content is taken.
308Deliver the content to the target server using ssh from the exported dir.
[557]309
[1117]310=item B<cms2webssh>
311
312Create tar files for the website from your CMS.
313Deliver the content to the target server using ssh from the DVCS.
314
315=item B<sbx2webpkg>
316
317Create tar files for the website under your CMS.
318Current state of the exported content is taken.
319
320=item B<cms2webpkg>
321
322Create tar files for the website under your CMS.
323
[739]324=item B<clean>
325
326Purge the build and delivery directories related to the current project
327
[557]328=back
329
[331]330<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).
331
332=head1 WEB SITES
333
334The 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/>.
335
336=head1 USER MAILING LIST
337
338None exists for the moment.
339
340=head1 CONFIGURATION FILES
341
342Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
343
344Here is an example of such a configuration file:
345
346 #
347 # Define for each project the URL of its pbconf repository
348 # No default option allowed here as they need to be all different
349 #
350 # URL of the pbconf content
351 # This is the format of a classical URL with the extension of additional schema such as
352 # svn+ssh, cvs+ssh, ...
353 #
354 pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
355
356 # This is normaly defined in the project's configuration file
357 # Url of the project
358 #
359 pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
360
361 # All these URLs needs to be defined here as the are the entry point
362 # for how to build packages for the project
363 #
364 pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
365 pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
366 pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
367 pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
368
369 # Under that dir will take place everything related to pb
370 # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
371 # to your VMs/chroot/...
372 # if not defined then /var/cache
373 pbdefdir default = $ENV{'HOME'}/project-builder
374 pbdefdir pb = $ENV{'HOME'}
375 pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
376 pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
377
378 # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
379 # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
380 pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
381 pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
382
383 # pbdir points to the directory where the CMS content of the pburl is checked out
384 # If not defined, pbdir is under pbdefdir/pbproj
385 # Only defined if we have access to the dev of the project
386 pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
387 pbdir mondorescue = $ENV{'HOME'}/mondo/svn
388
389 # -daemonize doesn't work with qemu 0.8.2
390 vmopt default = -m 384
391
392=head1 AUTHORS
393
394The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
395
396=head1 COPYRIGHT
397
398Project-Builder.org is distributed under the GPL v2.0 license
399described in the file C<COPYING> included with the distribution.
400
401=cut
402
403# ---------------------------------------------------------------------------
404
[75]405my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[974]406my $appname = "pb";
[331]407
[397]408# Initialize the syntax string
409
[974]410pb_syntax_init("$appname (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
[397]411
[331]412GetOptions("help|?|h" => \$opts{'h'},
413 "man" => \$opts{'man'},
414 "verbose|v+" => \$opts{'v'},
[748]415 "snapshot|S" => \$opts{'S'},
[331]416 "quiet|q" => \$opts{'q'},
417 "log-files|l=s" => \$opts{'l'},
418 "force|f" => \$opts{'f'},
419 "account|a=s" => \$opts{'a'},
420 "revision|r=s" => \$opts{'r'},
421 "script|s=s" => \$opts{'s'},
422 "machines|mock|m=s" => \$opts{'m'},
[1120]423 "target|t=s" => \$opts{'t'},
[1124]424 "nographics|g" => \$opts{'g'},
[331]425 "port|P=i" => \$opts{'P'},
426 "project|p=s" => \$opts{'p'},
427 "iso|i=s" => \$opts{'i'},
[815]428 "version|V=s" => \$opts{'V'},
[331]429) || pb_syntax(-1,0);
430
[21]431if (defined $opts{'h'}) {
[331]432 pb_syntax(0,1);
[21]433}
[331]434if (defined $opts{'man'}) {
435 pb_syntax(0,2);
436}
[21]437if (defined $opts{'v'}) {
[495]438 $pbdebug = $opts{'v'};
[21]439}
[320]440if (defined $opts{'f'}) {
[748]441 $pbforce=1;
[320]442}
[21]443if (defined $opts{'q'}) {
[495]444 $pbdebug=-1;
[21]445}
[748]446if (defined $opts{'S'}) {
447 $pbsnap=1;
448}
[22]449if (defined $opts{'l'}) {
[495]450 open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
451 $pbLOG = \*pbLOG;
452 $pbdebug = 0 if ($pbdebug == -1);
[22]453 }
[495]454pb_log_init($pbdebug, $pbLOG);
455pb_display_init("text","");
[315]456
[67]457# Handle root of the project if defined
458if (defined $opts{'r'}) {
[340]459 $ENV{'PBROOTDIR'} = $opts{'r'};
[67]460}
[91]461# Handle virtual machines if any
462if (defined $opts{'m'}) {
[320]463 $ENV{'PBV'} = $opts{'m'};
[91]464}
[141]465if (defined $opts{'s'}) {
466 $pbscript = $opts{'s'};
467}
[152]468if (defined $opts{'a'}) {
469 $pbaccount = $opts{'a'};
[347]470 die "option -a requires a -s script option" if (not defined $pbscript);
[152]471}
[162]472if (defined $opts{'P'}) {
473 $pbport = $opts{'P'};
474}
[199]475if (defined $opts{'V'}) {
476 $newver = $opts{'V'};
477}
[262]478if (defined $opts{'i'}) {
479 $iso = $opts{'i'};
480}
[1120]481if (defined $opts{'t'}) {
482 $pbtarget = $opts{'t'};
483}
[108]484
485# Get Action
486$action = shift @ARGV;
[331]487die pb_syntax(-1,1) if (not defined $action);
[108]488
[314]489my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
[273]490my $pbinit = undef;
491$pbinit = 1 if ($action =~ /^newproj$/);
[108]492
[59]493# Handles project name if any
[108]494# And get global params
[353]495($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action);
[59]496
[982]497#
498# Check for command requirements
499#
[1126]500my ($req,$opt,$pbpara) = pb_conf_get_if("oscmd","oscmdopt","pbparallel");
[1128]501pb_check_requirements($req,$opt,$appname);
[982]502
[1125]503#
504# Check if we can launch some actions in // with Parallel::ForkManager
505#
[1126]506my $pbparallel = $pbpara->{$appname} if (defined $pbpara);
507if (not defined $pbparallel) {
508 eval
509 {
510 require Sys::CPU;
511 Sys::CPU->import();
512 };
513 if ($@) {
514 # Sys::CPU not found, defaulting to 1
515 $pbparallel = 1;
516 } else {
517 # Using the number of cores
518 $pbparallel = Sys::CPU::cpu_count();
519 }
520}
521
[1125]522eval
523{
524 require Parallel::ForkManager;
525 Parallel::ForkManager->import();
526};
527# Parallel::ForkManager not found so no // actions
528if ($@) {
529 $pbparallel = undef;
530}
531
[315]532pb_log(0,"Project: $ENV{'PBPROJ'}\n");
533pb_log(0,"Action: $action\n");
[9]534
535# Act depending on action
536if ($action =~ /^cms2build$/) {
[1097]537 pb_cms2build("CMS");
538} elsif ($action =~ /^sbx2build$/) {
539 pb_cms2build("SandBox");
[77]540} elsif ($action =~ /^build2pkg$/) {
541 pb_build2pkg();
542} elsif ($action =~ /^cms2pkg$/) {
[1097]543 pb_cms2build("CMS");
[77]544 pb_build2pkg();
[1097]545} elsif ($action =~ /^sbx2pkg$/) {
546 pb_cms2build("SandBox");
547 pb_build2pkg();
[88]548} elsif ($action =~ /^build2ssh$/) {
549 pb_build2ssh();
[220]550} elsif ($action =~ /^cms2ssh$/) {
[1097]551 pb_cms2build("CMS");
[220]552 pb_build2ssh();
[1102]553} elsif ($action =~ /^sbx2ssh$/) {
[1097]554 pb_cms2build("SandBox");
555 pb_build2ssh();
[88]556} elsif ($action =~ /^pkg2ssh$/) {
557 pb_pkg2ssh();
[320]558} elsif ($action =~ /^build2ve$/) {
[772]559 pb_build2v("ve","build");
[91]560} elsif ($action =~ /^build2vm$/) {
[772]561 pb_build2v("vm","build");
[320]562} elsif ($action =~ /^cms2ve$/) {
[1097]563 pb_cms2build("CMS");
[772]564 pb_build2v("ve","build");
[1097]565} elsif ($action =~ /^sbx2ve$/) {
566 pb_cms2build("SandBox");
567 pb_build2v("ve","build");
[91]568} elsif ($action =~ /^cms2vm$/) {
[1097]569 pb_cms2build("CMS");
[772]570 pb_build2v("vm","build");
[1097]571} elsif ($action =~ /^sbx2vm$/) {
572 pb_cms2build("SandBox");
573 pb_build2v("vm","build");
[141]574} elsif ($action =~ /^launchvm$/) {
[320]575 pb_launchv("vm",$ENV{'PBV'},0);
576} elsif ($action =~ /^launchve$/) {
577 pb_launchv("ve",$ENV{'PBV'},0);
[142]578} elsif ($action =~ /^script2vm$/) {
[320]579 pb_script2v($pbscript,"vm");
580} elsif ($action =~ /^script2ve$/) {
581 pb_script2v($pbscript,"ve");
[199]582} elsif ($action =~ /^newver$/) {
583 pb_newver();
[320]584} elsif ($action =~ /^newve$/) {
585 pb_launchv("ve",$ENV{'PBV'},1);
[262]586} elsif ($action =~ /^newvm$/) {
[320]587 pb_launchv("vm",$ENV{'PBV'},1);
[909]588 pb_log(0, "Please ensure that sshd is running in your VM by default\n");
589 pb_log(0, "and that it allows remote root login (PermitRootLogin yes in /etc/ssh/sshd_config)\n");
[1105]590 pb_log(0, "Also ensure that network is up, firewalling correctly configured\n");
591 pb_log(0, "and perl, sudo, ntpdate and scp/ssh installed\n");
[1072]592 pb_log(0, "You should then be able to login with ssh -p VMPORT root\@localhost (if VM started with pb)\n");
[346]593} elsif ($action =~ /^setupve$/) {
[772]594 pb_setup2v("ve");
[346]595} elsif ($action =~ /^setupvm$/) {
[772]596 pb_setup2v("vm");
[1111]597} elsif ($action =~ /^updateve$/) {
598 pb_update2v("ve");
599} elsif ($action =~ /^updatevm$/) {
600 pb_update2v("vm");
[748]601} elsif ($action =~ /^snapve$/) {
[772]602 pb_snap2v("ve");
[748]603} elsif ($action =~ /^snapvm$/) {
[772]604 pb_snap2v("vm");
[783]605} elsif ($action =~ /^test2pkg$/) {
606 pb_test2pkg();
[772]607} elsif ($action =~ /^test2ve$/) {
608 pb_build2v("ve","test");
609} elsif ($action =~ /^test2vm$/) {
610 pb_build2v("vm","test");
[273]611} elsif ($action =~ /^newproj$/) {
612 # Nothing to do - already done in pb_env_init
[106]613} elsif ($action =~ /^clean$/) {
[739]614 pb_clean();
[471]615} elsif ($action =~ /^announce$/) {
[498]616 # For announce only. Require avoids the systematic load of these modules
617 require DBI;
[557]618 require DBD::SQLite;
[498]619
[471]620 pb_announce();
[1117]621} elsif ($action =~ /^sbx2webpkg$/) {
[547]622 require DBI;
[557]623 require DBD::SQLite;
[547]624
[1117]625 pb_cms2build("SandBox","Web");
626} elsif ($action =~ /^sbx2webssh$/) {
627 require DBI;
628 require DBD::SQLite;
629
630 pb_cms2build("SandBox","Web");
[556]631 pb_send2target("Web");
[1117]632} elsif ($action =~ /^cms2webpkg$/) {
633 require DBI;
634 require DBD::SQLite;
635
636 pb_cms2build("CMS","Web");
637} elsif ($action =~ /^cms2webssh$/) {
638 require DBI;
639 require DBD::SQLite;
640
641 pb_cms2build("CMS","Web");
642 pb_send2target("Web");
[77]643} else {
[315]644 pb_log(0,"\'$action\' is not available\n");
[331]645 pb_syntax(-2,1);
[77]646}
647
648sub pb_cms2build {
649
[556]650 my $param = shift || undef;
[1117]651 my $web = shift || undef;
[556]652
653 my $pkg;
654 my @pkgs;
[557]655 my $webdir;
[556]656
[557]657 my %pkgs;
658 my %pb; # Structure to store conf info
659
[1117]660 die "pb_cms2build requires a parameter: SandBox or CMS" if (not defined $param);
[1097]661
[556]662 # If Website, then pkg is only the website
[1117]663 if (defined $web) {
[557]664 ($webdir) = pb_conf_get("webdir");
665 pb_log(2,"webdir: ".Dumper($webdir)."\n");
666 $pkgs[0] = $webdir->{$ENV{'PBPROJ'}};
[556]667 $extpkgdir = $webdir;
[557]668 pb_log(0,"Package: $pkgs[0]\n");
[556]669 } else {
670 $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
671 @pkgs = @$pkg;
672 }
673
[1097]674 my ($scheme, $uri) = pb_cms_init($pbinit,$param);
[331]675
[898]676 # We need 2 lines here
677 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
[174]678
[429]679 # declare packager and repo for filtering
[940]680 # TODO: Is pbrepo needed so early in the process ?
[429]681 my ($tmp1, $tmp2) = pb_conf_get("pbpackager","pbrepo");
682 $ENV{'PBPACKAGER'} = $tmp1->{$ENV{'PBPROJ'}};
683 $ENV{'PBREPO'} = $tmp2->{$ENV{'PBPROJ'}};
[174]684
[27]685 foreach my $pbpkg (@pkgs) {
[115]686 $ENV{'PBPKG'} = $pbpkg;
[728]687
[98]688 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
689 $pbver = $pkgv->{$pbpkg};
[9]690 } else {
[353]691 $pbver = $ENV{'PBPROJVER'};
[9]692 }
[728]693 # If it's a test version, then tag == 0.date
[897]694 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
[728]695 $pbtag = "0.".strftime("%Y%m%d%H%M%S", @date);
696 $ENV{'PBPROJTAG'} = $pbtag;
697 } elsif ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
[98]698 $pbtag = $pkgt->{$pbpkg};
[9]699 } else {
[353]700 $pbtag = $ENV{'PBPROJTAG'};
[9]701 }
[95]702
[16]703 $pbrev = $ENV{'PBREVISION'};
[319]704 pb_log(0,"\n");
705 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
[9]706 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
[539]707
[16]708 # Clean up dest if necessary. The export will recreate it
[27]709 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
[74]710 pb_rm_rf($dest) if (-d $dest);
[9]711
712 # Export CMS tree for the concerned package to dest
713 # And generate some additional files
714 $OUTPUT_AUTOFLUSH=1;
[29]715
[9]716 # computes in which dir we have to work
[113]717 my $dir = $defpkgdir->{$pbpkg};
718 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
[1117]719 $dir = $webdir->{$ENV{'PBPROJ'}} if (defined $web);
720 die "Variable \$dir not defined. Please report to dev team with log of a verbose run and this info ".Dumper($webdir) if (not defined $dir);
[315]721 pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
[9]722
[537]723 # Exporting content from CMS
[1097]724 my $sourcedir = undef;
725 my $sourceuri = $uri;
726 if ($param eq "SandBox") {
727 # Point to the local instance
728 $sourcedir = "$ENV{'PBDIR'}/$dir";
729 } else {
730 # Get it from a subdir of the URI with same version as localy but different root
731 $sourceuri = "$ENV{'PBDIR'}/$dir";
732 $sourceuri =~ s|^$ENV{'PBPROJDIR'}/|$uri|;
733 }
734 my $preserve = pb_cms_export($sourceuri,$sourcedir,$dest);
[315]735
[435]736 # Generated fake content for test versions to speed up stuff
737 my $chglog;
[285]738
[448]739 # Get project info on authors and log file
740 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
741 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
742 $chglog = undef if (! -f $chglog);
[285]743
[448]744 my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
745 $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
746 $authors = "/dev/null" if (! -f $authors);
[435]747
[448]748 # Extract cms log history and store it
749 if ((defined $chglog) && (! -f "$dest/NEWS")) {
750 pb_log(2,"Generating NEWS file from $chglog\n");
751 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
[285]752 }
[448]753 pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
[29]754
[21]755 my %build;
[1120]756 my %patches;
[1130]757 my %sources;
[865]758 # We want to at least build for the underlying distro
[1120]759 # except if a target was given, in which case we only build for it
760 my ($tdir,$tver,$tarch);
761 ($tdir,$tver,$tarch) = split(/-/,$pbtarget) if (defined ($pbtarget));
762
763 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins, $arch) = pb_distro_init($tdir,$tver,$tarch);
[865]764 my $tmpl = "$ddir-$dver-$arch,";
[91]765
[1120]766 # Get list of distributions for which we need to generate build files if no target
767 if (not defined ($pbtarget)) {
768 my @pt = pb_conf_get_if("vmlist","velist");
769 if (defined $pt[0]->{$ENV{'PBPROJ'}}) {
770 $tmpl .= $pt[0]->{$ENV{'PBPROJ'}};
[340]771 }
[1120]772 if (defined $pt[1]->{$ENV{'PBPROJ'}}) {
773 # The 2 lists needs to be grouped with a ',' separating them
774 if ($tmpl ne "") {
775 $tmpl .= ",";
776 }
777 $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
778 }
[340]779 }
[556]780
[539]781 # Setup %pb structure to allow filtering later on, on files using that structure
[499]782 $pb{'tag'} = $pbtag;
783 $pb{'rev'} = $pbrev;
784 $pb{'ver'} = $pbver;
[540]785 $pb{'pkg'} = $pbpkg;
[1117]786 $pb{'realpkg'} = $pbpkg;
[499]787 $pb{'date'} = $pbdate;
788 $pb{'defpkgdir'} = $defpkgdir;
789 $pb{'extpkgdir'} = $extpkgdir;
790 $pb{'chglog'} = $chglog;
791 $pb{'packager'} = $ENV{'PBPACKAGER'};
792 $pb{'proj'} = $ENV{'PBPROJ'};
793 $pb{'repo'} = $ENV{'PBREPO'};
[500]794 $pb{'patches'} = \%patches;
[1130]795 $pb{'sources'} = \%sources;
[500]796 pb_log(2,"DEBUG: pb: ".Dumper(%pb)."\n");
[556]797
798 # Do not do that for website
[1117]799 if (not defined $web) {
[898]800 pb_log(0,"Build files are being generated for ...\n");
[665]801 my %virt;
802 # De-duplicate similar VM and VE
[556]803 foreach my $d (split(/,/,$tmpl)) {
[766]804 # skip ill-formatted vms (name-ver-arch)
805 next if ($d !~ /-/);
[665]806 $virt{$d} = $d;
807 }
808
[1125]809 # Try to use // processing here
810 my $pm = new Parallel::ForkManager($pbparallel) if (defined $pbparallel);
811
[665]812 foreach my $d (keys %virt) {
[1125]813 $pm->start and next if (defined $pbparallel);
[556]814 my ($name,$ver,$arch) = split(/-/,$d);
[766]815 pb_log(0,"Bad format for $d") if ((not defined $name) || (not defined $ver) || (not defined $arch)) ;
[556]816 chomp($arch);
817 my ($ddir, $dver, $dfam);
[1064]818 ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'os'}, $pb{'suf'}, $pb{'upd'}, $pb{'arch'}) = pb_distro_init($name,$ver,$arch);
[556]819 pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
820 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
821
822 # We need to compute the real name of the package
823 my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pb{'dtype'});
824 $pb{'realpkg'} = $pbrealpkg;
825 pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $ddir-$dver\n") if ($pbrealpkg ne $pbpkg);
826
827 # Filter build files from the less precise up to the most with overloading
828 # Filter all files found, keeping the name, and generating in dest
829
830 # Find all build files first relatively to PBROOTDIR
831 # Find also all specific files referenced in the .pb conf file
832 my %bfiles = ();
833 my %pkgfiles = ();
834 $build{"$ddir-$dver-$arch"} = "yes";
835
836 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
837 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
838 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
839 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
840 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
841 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
842 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
843 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
844 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
845 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
846 } else {
847 $build{"$ddir-$dver-$arch"} = "no";
[500]848 next;
849 }
[556]850 pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
851
852 # Get all filters to apply
853 my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
854
855 # Apply now all the filters on all the files concerned
856 # destination dir depends on the type of file
857 if (defined $ptr) {
858 # For patch support
859 $pb{'tuple'} = "$ddir-$dver-$arch";
860 foreach my $f (values %bfiles,values %pkgfiles) {
861 pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
862 }
863 }
[1130]864 pb_list_sfiles("$ENV{'PBROOTDIR'}/$pbpkg/pbpatch", \%patches, $pb{'dtype'}, $dfam, $ddir, $dver, $arch, "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch");
865 pb_list_sfiles("$ENV{'PBROOTDIR'}/$pbpkg/pbsrc", \%sources, $pb{'dtype'}, $dfam, $ddir, $dver, $arch, "$ENV{'PBROOTDIR'}/$pbpkg/pbextsrc");
866
[1125]867 $pm->finish if (defined $pbparallel);
[15]868 }
[1125]869 $pm->wait_all_children if (defined $pbparallel);
[556]870 my @found;
871 my @notfound;
872 foreach my $b (keys %build) {
873 push @found,$b if ($build{$b} =~ /yes/);
874 push @notfound,$b if ($build{$b} =~ /no/);
875 }
[898]876 pb_log(0," ... ".join(',',sort(@found))."\n");
[556]877 pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
878 pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
[1130]879 pb_log(2,"DEBUG: sources: ".Dumper(%sources)."\n");
[18]880 }
[500]881
[236]882 # Get the generic filter (all.pbf) and
883 # apply those to the non-build files including those
884 # generated by pbinit if applicable
885
886 # Get only all.pbf filter
[357]887 my $ptr = pb_get_filters($pbpkg);
[236]888
889 my $liste ="";
890 if (defined $filteredfiles->{$pbpkg}) {
891 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
[499]892 pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
[238]893 $liste = "$f $liste";
[236]894 }
895 }
[315]896 pb_log(2,"Files ".$liste."have been filtered\n");
[236]897
[556]898 # Do not do that for website
[1117]899 if (not defined $web) {
[556]900 my %tmp;
[1130]901 my $warnptcflag = 0;
902 my $warnsrcflag = 0;
[556]903 # Filter potential patches (local + remote)
904 pb_log(0,"Delivering and compressing patches ");
905 foreach my $v (keys %patches) {
906 pb_mkdir_p("$dest/pbconf/$v/pbpatch");
907 foreach my $pf (split(/,/,$patches{$v})) {
908 my $pp = basename($pf);
[1097]909 if ($param eq "SandBox") {
[1130]910 $warnptcflag = 1;
[1097]911 }
[556]912 pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
913 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
914 pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
915 $tmp{$pf} = "";
916 }
[500]917 }
[1130]918 pb_log(0,"Delivering additional sources ");
919 foreach my $v (keys %sources) {
920 pb_mkdir_p("$dest/pbconf/$v/pbsrc");
921 foreach my $pf (split(/,/,$sources{$v})) {
922 my $pp = basename($pf);
923 if ($param eq "SandBox") {
924 $warnsrcflag = 1;
925 }
926 pb_cms_export($pf,undef,"$dest/pbconf/$v/pbsrc");
927 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbsrc/$pp",\%pb);
928 $tmp{$pf} = "";
929 }
930 }
[556]931 foreach my $v (keys %tmp) {
932 pb_log(0,"$v ");
933 }
934 pb_log(0,"\n");
[1130]935 pb_log(0,"WARNING: Patches are always taken from repository not local export\n") if ($warnptcflag == 1);
936 pb_log(0,"WARNING: Sources are always taken from repository not local export\n") if ($warnsrcflag == 1);
[556]937 } else {
938 # Instead call News generation
939 pb_web_news2html($dest);
[559]940 # And create an empty pbconf
941 pb_mkdir_p("$dest/pbconf");
[560]942 # And prepare the pbscript to execute remotely
943 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
944 print SCRIPT "#!/bin/bash\n";
945 print SCRIPT "#set -x\n";
946 print SCRIPT "echo ... Extracting Website content\n";
947 print SCRIPT "find . -type f | grep -Ev '^./$pbpkg-$pbver.tar.gz|^./pbscript' | xargs rm -f non-existent\n";
948 print SCRIPT "find * -type d -depth | xargs rmdir 2> /dev/null \n";
949 print SCRIPT "tar xfz $pbpkg-$pbver.tar.gz\n";
950 print SCRIPT "mv $pbpkg-$pbver/* .\n";
951 print SCRIPT "rm -f $pbpkg-$pbver.tar.gz\n";
952 print SCRIPT "rmdir $pbpkg-$pbver\n";
953 close(SCRIPT);
[499]954 }
955
[265]956 # Prepare the dest directory for archive
[340]957 if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
[499]958 pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
[266]959 chmod 0755,"$ENV{'PBTMP'}/pbinit";
[490]960 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
[265]961 }
962
[721]963 # Do we have additional script to run to prepare the environement for the project ?
964 # Then include it in the pbconf delivery
[772]965 foreach my $pbvf (<$ENV{'PBROOTDIR'}/pbv*.pre>,<$ENV{'PBROOTDIR'}/pbv*.post>, <$ENV{'PBROOTDIR'}/pbtest*>) {
966 if (-x "$pbvf") {
967 my $target = "$ENV{'PBDESTDIR'}/".basename($pbvf);
968 pb_filter_file("$pbvf",$ptr,$target,\%pb);
969 chmod 0755,"$target";
[721]970 }
971 }
972
[18]973 # Archive dest dir
[69]974 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
[537]975 if (defined $preserve) {
976 # In that case we want to preserve the original tar file for checksum purposes
977 # The one created is btw equivalent in that case to this one
978 # Maybe check basename of both to be sure they are the same ?
979 pb_log(0,"Preserving original tar file ");
980 move("$preserve","$pbpkg-$pbver.tar.gz");
981 } else {
982 # Possibility to look at PBSRC to guess more the filename
983 pb_system("tar cfz $pbpkg-$pbver.tar.gz --exclude=$pbpkg-$pbver/pbconf $pbpkg-$pbver","Creating $pbpkg tar files compressed");
984 }
[344]985 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
[493]986 pb_system("tar cfz $pbpkg-$pbver.pbconf.tar.gz $pbpkg-$pbver/pbconf","Creating pbconf tar files compressed");
987 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz\n");
[83]988
[357]989 # Keep track of version-tag per pkg
990 $pkgs{$pbpkg} = "$pbver-$pbtag";
[83]991
[288]992 # Final cleanup
993 pb_rm_rf($dest) if (-d $dest);
[9]994 }
[357]995
996 # Keep track of per package version
997 pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
998 open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
[539]999 foreach my $pbpkg (keys %pkgs) {
[357]1000 print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
1001 }
1002 close(PKG);
1003
1004 # Keep track of what is generated by default
1005 # We need to store the dir and info on version-tag
1006 # Base our content on the existing .pb file
1007 copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
1008 open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
1009 print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
[702]1010 print LAST "projver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
1011 print LAST "projtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
[357]1012 print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
1013 close(LAST);
[77]1014}
[22]1015
[772]1016sub pb_test2pkg {
1017 # Get the running distro to test on
[1111]1018 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins, $arch) = pb_distro_init();
1019 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $pbins, $arch))."\n");
[772]1020
1021 # Get list of packages to test
1022 # Get content saved in cms2build
1023 my $ptr = pb_get_pkg();
1024 @pkgs = @$ptr;
1025
1026 # Additional potential repo
[1132]1027 pb_distro_setuprepo($ddir,$dver,$arch,$dtype,$dfam,$dos);
[772]1028 foreach my $pbpkg (@pkgs) {
1029 # We need to install the package to test, and deps brought with it
[1111]1030 pb_distro_installdeps(undef,$dtype,$pbins,$pbpkg);
[772]1031 pb_system("$ENV{'PBDESTDIR'}/pbtest","Launching test for $pbpkg","verbose");
1032 }
1033}
1034
[77]1035sub pb_build2pkg {
1036
[22]1037 # Get the running distro to build on
[1111]1038 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins, $arch) = pb_distro_init();
1039 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $pbins, $arch))."\n");
[22]1040
[353]1041 # Get list of packages to build
1042 my $ptr = pb_get_pkg();
1043 @pkgs = @$ptr;
1044
[898]1045 # Get content saved in cms2build
[353]1046 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
[83]1047 $pkg = { } if (not defined $pkg);
1048
[25]1049 chdir "$ENV{'PBBUILDDIR'}";
[126]1050 my $made = ""; # pkgs made during build
[27]1051 foreach my $pbpkg (@pkgs) {
[88]1052 my $vertag = $pkg->{$pbpkg};
[77]1053 # get the version of the current package - maybe different
1054 ($pbver,$pbtag) = split(/-/,$vertag);
1055
[27]1056 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[493]1057 my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
[315]1058 pb_log(2,"Source file: $src\n");
[493]1059 pb_log(2,"Pbconf file: $src2\n");
[25]1060
[315]1061 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
[25]1062 if ($dtype eq "rpm") {
1063 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
[28]1064 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
[96]1065 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d") || die "Please ensure that you can write into $ENV{'PBBUILDDIR'} to create $d\nchown the $ENV{'PBBUILDDIR'} directory to your uid";
[28]1066 }
[25]1067 }
1068
[315]1069 # Remove in case a previous link/file was there
[301]1070 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
[188]1071 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
[25]1072 # We need to first extract the spec file
[500]1073 my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$ENV{'PBBUILDDIR'}/SPECS","spec");
[25]1074
[493]1075 # We need to handle potential patches to upstream sources
[500]1076 pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
[493]1077
[315]1078 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
[25]1079 # set LANGUAGE to check for correct log messages
1080 $ENV{'LANGUAGE'}="C";
[459]1081 # Older Redhat use _target_platform in %configure incorrectly
1082 my $specialdef = "";
1083 if (($ddir eq "redhat") || (($ddir eq "rhel") && ($dver eq "2.1"))) {
1084 $specialdef = "--define \'_target_platform \"\"\'";
1085 }
[702]1086
1087 # If needed we may add repository to the build env
[1132]1088 pb_distro_setuprepo($ddir,$dver,$arch,$dtype,$dfam,$dos);
[28]1089 foreach my $f (@specfile) {
1090 if ($f =~ /\.spec$/) {
[1111]1091 pb_distro_installdeps($f,$dtype,$pbins);
[1085]1092 pb_system("rpmbuild $specialdef --define \"packager $ENV{'PBPACKAGER'}\" --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
[28]1093 last;
1094 }
1095 }
[540]1096 # Get the name of the generated packages
1097 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
1098 while (<LOG>) {
[572]1099 chomp($_);
[540]1100 next if ($_ !~ /^Wrote:/);
1101 s|.*/([S]*RPMS.*)|$1|;
[572]1102 $made .=" $_";
[540]1103 }
[541]1104 close(LOG);
[540]1105
[118]1106 } elsif ($dtype eq "deb") {
[149]1107 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
[274]1108 pb_system("tar xfz $src","Extracting sources");
[493]1109 pb_system("tar xfz $src2","Extracting pbconf");
[149]1110
1111 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[310]1112 pb_rm_rf("debian");
[500]1113 symlink "pbconf/$ddir-$dver-$arch","debian" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
[199]1114 chmod 0755,"debian/rules";
[544]1115
[1132]1116 pb_distro_setuprepo($ddir,$dver,$arch,$dtype,$dfam,$dos);
[1111]1117 pb_distro_installdeps("debian/control",$dtype,$pbins);
[544]1118 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
1119 # Get the name of the generated packages
1120 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
1121 while (<LOG>) {
1122 chomp();
1123 my $tmp = $_;
[567]1124 next if ($tmp !~ /^dpkg-deb.*:/);
[544]1125 $tmp =~ s|.*../(.*)_(.*).deb.*|$1|;
1126 $made="$made $tmp.dsc $tmp.tar.gz $tmp"."_*.deb $tmp"."_*.changes";
[448]1127 }
[544]1128 close(LOG);
[87]1129 } elsif ($dtype eq "ebuild") {
[149]1130 my @ebuildfile;
1131 # For gentoo we need to take pb as subsystem name
[295]1132 # We put every apps here under sys-apps. hope it's correct
[435]1133 # We use pb's home dir in order to have a single OVERLAY line
[295]1134 my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
1135 pb_mkdir_p($tmpd) if (! -d "$tmpd");
1136 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
[149]1137
[295]1138 # We need to first extract the ebuild file
[500]1139 @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$tmpd","ebuild");
[149]1140
1141 # Prepare the build env for gentoo
1142 my $found = 0;
[295]1143 my $pbbd = $ENV{'HOME'};
[150]1144 $pbbd =~ s|/|\\/|g;
[295]1145 if (-r "/etc/make.conf") {
1146 open(MAKE,"/etc/make.conf");
1147 while (<MAKE>) {
1148 $found = 1 if (/$pbbd\/portage/);
1149 }
1150 close(MAKE);
[149]1151 }
1152 if ($found == 0) {
[295]1153 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
[149]1154 }
[295]1155 #$found = 0;
1156 #if (-r "/etc/portage/package.keywords") {
1157 #open(KEYW,"/etc/portage/package.keywords");
1158 #while (<KEYW>) {
1159 #$found = 1 if (/portage\/pb/);
1160 #}
1161 #close(KEYW);
1162 #}
1163 #if ($found == 0) {
1164 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
1165 #}
[149]1166
1167 # Build
1168 foreach my $f (@ebuildfile) {
1169 if ($f =~ /\.ebuild$/) {
[1111]1170 pb_distro_installdeps($f,$dtype,$pbins);
[295]1171 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
[529]1172 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
[295]1173 # Now move it where pb expects it
1174 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
[1087]1175 move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-r$pbtag.ebuild");
[149]1176 }
1177 }
1178
[1087]1179 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-r$pbtag.ebuild";
[437]1180 } elsif ($dtype eq "tgz") {
1181 # Slackware family
[435]1182 $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
1183
1184 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1185 pb_system("tar xfz $src","Extracting sources");
[493]1186 pb_system("tar xfz $src2","Extracting pbconf");
[435]1187 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[500]1188 symlink "pbconf/$ddir-$dver-$arch","install" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
[435]1189 if (-x "install/pbslack") {
[1111]1190 pb_distro_installdeps("./install/pbslack",$dtype,$pbins);
[872]1191 pb_system("./install/pbslack","Building software");
[529]1192 pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
[435]1193 }
[873]1194 } elsif ($dtype eq "pkg") {
[872]1195 # Solaris
[916]1196 $made="$made $pbpkg-$pbver-$pbtag.pkg.gz";
[873]1197 my $pkgdestdir="$ENV{'PBBUILDDIR'}/install";
[872]1198
1199 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
1200 # Will host resulting packages
1201 pb_mkdir_p("$dtype");
[878]1202 pb_mkdir_p("$pkgdestdir/delivery");
[873]1203 pb_system("tar xfz $src","Extracting sources under $ENV{'PBBUILDDIR'}");
1204 pb_system("tar xfz $src2","Extracting pbconf under $ENV{'PBBUILDDIR'}");
[872]1205 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[914]1206 if (-f "pbconf/$ddir-$dver-$arch/pbbuild") {
1207 chmod 0755,"pbconf/$ddir-$dver-$arch/pbbuild";
[872]1208 # pkginfo file is mandatory
[914]1209 die "Unable to find pkginfo file in pbconf/$ddir-$dver-$arch" if (! -f "pbconf/$ddir-$dver-$arch/pkginfo");
[872]1210 # Build
[914]1211 pb_system("pbconf/$ddir-$dver-$arch/pbbuild $pkgdestdir/delivery","Building software and installing under $pkgdestdir/delivery");
[872]1212 # Copy complementary files
[914]1213 if (-f "pbconf/$ddir-$dver-$arch/prototype") {
1214 copy("pbconf/$ddir-$dver-$arch/prototype", $pkgdestdir)
[872]1215 } else {
1216 # No prototype provided, calculating it
[878]1217 open(PROTO,"> $pkgdestdir/prototype") || die "Unable to create prototype file";
[872]1218 print PROTO "i pkginfo\n";
[914]1219 print PROTO "i depend\n" if (-f "pbconf/$ddir-$dver-$arch/depend");
[879]1220 $ENV{'PBSOLDESTDIR'} = "$pkgdestdir/delivery";
1221 find(\&create_solaris_prototype, "$pkgdestdir/delivery");
[872]1222 }
[914]1223 copy("pbconf/$ddir-$dver-$arch/depend", $pkgdestdir) if (-f "pbconf/$ddir-$dver-$arch/depend");
1224 copy("pbconf/$ddir-$dver-$arch/pkginfo", $pkgdestdir);
[880]1225 pb_system("cd $pkgdestdir/delivery ; pkgmk -o -f ../prototype -r $pkgdestdir/delivery -d $ENV{'PBBUILDDIR'}/$dtype","Packaging $pbpkg","verbose");
[916]1226 pb_system("cd $ENV{'PBBUILDDIR'}/$dtype ; echo \"\" | pkgtrans -o -n -s $ENV{'PBBUILDDIR'}/$dtype $ENV{'PBBUILDDIR'}/$pbpkg-$pbver-$pbtag.pkg all","Transforming $pbpkg","verbose");
1227 pb_system("cd $ENV{'PBBUILDDIR'} ; gzip -9f $pbpkg-$pbver-$pbtag.pkg","Compressing $pbpkg-$pbver-$pbtag.pkg","verbose");
[913]1228 } else {
[914]1229 pb_log(0,"No pbconf/$ddir-$dver-$arch/pbbuild file found for $pbpkg-$pbver in \n");
[872]1230 }
[874]1231 chdir ".." || die "Unable to chdir to parent dir";
[880]1232 pb_system("rm -rf $pbpkg-$pbver $ENV{'PBBUILDDIR'}/$dtype $pkgdestdir", "Cleanup");
[87]1233 } else {
[118]1234 die "Unknown dtype format $dtype";
[87]1235 }
1236 }
[1109]1237 # Find the appropriate check cmd/opts
1238 my ($oschkcmd,$oschkopt) = pb_conf_get_if("oschkcmd","oschkopt");
1239 my $chkcmd .= pb_distro_get_param($ddir,$dver,$arch,$oschkcmd,$dtype,$dfam,$dos);
1240 my $chkopt .= pb_distro_get_param($ddir,$dver,$arch,$oschkopt,$dtype,$dfam,$dos);
1241
[541]1242 # Packages check if needed
1243 if ($dtype eq "rpm") {
[1109]1244 if (-x $chkcmd) {
1245 pb_system("$chkcmd $chkopt $made","Checking validity of rpms with $chkcmd","verbose");
[541]1246 }
[1098]1247 my $rpms ="";
1248 my $srpms ="";
1249 foreach my $f (split(/ /,$made)) {
1250 $rpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^RPMS\//);
1251 $srpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^SRPMS\//);
1252 }
1253 pb_log(0,"SRPM packages generated: $srpms\n");
1254 pb_log(0,"RPM packages generated: $rpms\n");
[541]1255 } elsif ($dtype eq "deb") {
[572]1256 my $made2 = "";
[971]1257 foreach my $f (split(/ /,$made)) {
1258 $made2 .= "../$f " if ($f =~ /\.changes$/);
1259 }
[1109]1260 if (-x $chkcmd) {
1261 pb_system("$chkcmd $chkopt $made2","Checking validity of debs with $chkcmd","verbose");
[572]1262 } else {
1263 pb_log(0,"deb packages generated: $made2\n");
[541]1264 }
1265 } else {
[572]1266 pb_log(0,"No check done for $dtype yet\n");
1267 pb_log(0,"Packages generated: $made\n");
[541]1268 }
1269
[118]1270 # Keep track of what is generated so that we can get them back from VMs
[353]1271 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]1272 print KEEP "$made\n";
1273 close(KEEP);
[87]1274}
1275
[874]1276sub create_solaris_prototype {
[872]1277
[873]1278 my $uidgid = "bin bin";
[877]1279 my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
[872]1280
[878]1281 return if ($_ =~ /^$pkgdestdir$/);
[875]1282 if (-d $_) {
1283 my $n = $File::Find::name;
1284 $n =~ s~$pkgdestdir/~~;
1285 print PROTO "d none $n 0755 $uidgid\n";
[877]1286 } elsif (-x $_) {
[875]1287 my $n = $File::Find::name;
1288 $n =~ s~$pkgdestdir/~~;
1289 print PROTO "f none $n 0755 $uidgid\n";
[872]1290 } elsif (-f $_) {
[875]1291 my $n = $File::Find::name;
1292 $n =~ s~$pkgdestdir/~~;
1293 print PROTO "f none $n 0644 $uidgid\n";
[872]1294 }
1295}
1296
[88]1297sub pb_build2ssh {
[320]1298 pb_send2target("Sources");
[90]1299}
[87]1300
[90]1301sub pb_pkg2ssh {
[320]1302 pb_send2target("Packages");
[90]1303}
1304
[108]1305# By default deliver to the the public site hosting the
[320]1306# ftp structure (or whatever) or a VM/VE
1307sub pb_send2target {
[90]1308
1309 my $cmt = shift;
[320]1310 my $v = shift || undef;
[142]1311 my $vmexist = shift || 0; # 0 is FALSE
[200]1312 my $vmpid = shift || 0; # 0 is FALSE
[748]1313 my $snapme = shift || 0; # 0 is FALSE
[320]1314
[444]1315 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
[320]1316 my $host = "sshhost";
1317 my $login = "sshlogin";
1318 my $dir = "sshdir";
1319 my $port = "sshport";
1320 my $conf = "sshconf";
[883]1321 my $tmout = undef;
1322 my $path = undef;
[772]1323 if ($cmt =~ /^VM/) {
[320]1324 $login = "vmlogin";
[322]1325 $dir = "pbdefdir";
[320]1326 # Specific VM
[883]1327 $tmout = "vmtmout";
1328 $path = "vmpath";
[320]1329 $host = "vmhost";
1330 $port = "vmport";
[772]1331 } elsif ($cmt =~ /^VE/) {
[320]1332 $login = "velogin";
[322]1333 $dir = "pbdefdir";
[320]1334 # Specific VE
1335 $path = "vepath";
[986]1336 $conf = "rbsconf";
[556]1337 } elsif ($cmt eq "Web") {
1338 $host = "websshhost";
1339 $login = "websshlogin";
1340 $dir = "websshdir";
1341 $port = "websshport";
[320]1342 }
[158]1343 my $cmd = "";
[471]1344 my $src = "";
1345 my ($odir,$over,$oarch) = (undef, undef, undef);
[1111]1346 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins, $darch);
[90]1347
[471]1348 if ($cmt ne "Announce") {
[898]1349 # Get list of packages to build
[471]1350 my $ptr = pb_get_pkg();
1351 @pkgs = @$ptr;
[87]1352
[471]1353 # Get the running distro to consider
1354 if (defined $v) {
1355 ($odir,$over,$oarch) = split(/-/,$v);
1356 }
[1111]1357 ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins, $darch) = pb_distro_init($odir,$over,$oarch);
1358 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $pbins, $darch))."\n");
[87]1359
[471]1360 # Get list of packages to build
1361 # Get content saved in cms2build
1362 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
1363 $pkg = { } if (not defined $pkg);
[87]1364
[471]1365 chdir "$ENV{'PBBUILDDIR'}";
1366 foreach my $pbpkg (@pkgs) {
1367 my $vertag = $pkg->{$pbpkg};
1368 # get the version of the current package - maybe different
1369 ($pbver,$pbtag) = split(/-/,$vertag);
[87]1370
[772]1371 if (($cmt eq "Sources") || ($cmt =~ /V[EM]build/)) {
[493]1372 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
[471]1373 if ($cmd eq "") {
1374 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
1375 } else {
1376 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
1377 }
[560]1378 } elsif ($cmt eq "Web") {
1379 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"
[166]1380 }
[118]1381 }
[471]1382 # Adds conf file for availability of conf elements
1383 pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
[118]1384 }
[417]1385
[772]1386 if ($cmt =~ /V[EM]build/) {
[444]1387 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
[681]1388 } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) {
[492]1389 $src="$src $ENV{'PBDESTDIR'}/pbscript";
[772]1390 } elsif ($cmt =~ /V[EM]test/) {
[773]1391 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript $ENV{'PBDESTDIR'}/pbtest";
[560]1392 } elsif ($cmt eq "Announce") {
[471]1393 $src="$src $ENV{'PBTMP'}/pbscript";
[118]1394 } elsif ($cmt eq "Packages") {
1395 # Get package list from file made during build2pkg
[353]1396 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[126]1397 $src = <KEEP>;
[118]1398 chomp($src);
1399 close(KEEP);
[681]1400 $src="$src $ENV{'PBBUILDDIR'}/pbscript";
[87]1401 }
[320]1402 # Remove potential leading spaces (cause problem with basename)
[132]1403 $src =~ s/^ *//;
[129]1404 my $basesrc = "";
[131]1405 foreach my $i (split(/ +/,$src)) {
1406 $basesrc .= " ".basename($i);
[130]1407 }
[118]1408
[320]1409 pb_log(0,"Sources handled ($cmt): $src\n");
[987]1410 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$path,$conf))."\n");
[883]1411 my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
1412 # Not mandatory...
[1066]1413 my ($rbsconf,$testver,$delivery) = pb_conf_get_if($conf,"testver","delivery");
[1102]1414 $delivery->{$ENV{'PBPROJ'}} = "" if (not defined $delivery->{$ENV{'PBPROJ'}});
[883]1415 my ($vtmout,$vepath);
1416 # ...Except those in virtual context
1417 if ($cmt =~ /^VE/) {
1418 ($vepath) = pb_conf_get($path);
1419 }
1420 if ($cmt =~ /^VM/) {
1421 ($vtmout) = pb_conf_get($tmout);
1422 }
[987]1423 pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vepath,$rbsconf))."\n");
[320]1424
1425 my $mac;
[772]1426 if ($cmt !~ /^VE/) {
[320]1427 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
1428 # Overwrite account value if passed as parameter
1429 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
[355]1430 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
[681]1431 } else {
1432 # VE
[772]1433 # Overwrite account value if passed as parameter (typically for setup2ve)
[681]1434 $mac = $sshlogin->{$ENV{'PBPROJ'}};
1435 $mac = $pbaccount if (defined $pbaccount);
[320]1436 }
1437
[108]1438 my $tdir;
[136]1439 my $bdir;
[783]1440 if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/)) {
[1078]1441 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}/src";
[783]1442 } elsif (($cmt =~ /V[EM]build/) || ($cmt =~ /V[EM]test/)) {
[320]1443 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
1444 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
[136]1445 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
1446 $bdir =~ s|\$ENV.+\}/||;
[471]1447 } elsif ($cmt eq "Announce") {
[1078]1448 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}";
[556]1449 } elsif ($cmt eq "Web") {
[1078]1450 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}";
[90]1451 } elsif ($cmt eq "Packages") {
[1080]1452 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch";
[429]1453
1454 my $repodir = $tdir;
1455 $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
1456
1457 my ($pbrepo) = pb_conf_get("pbrepo");
1458
1459 # Repository management
[444]1460 open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
[429]1461 if ($dtype eq "rpm") {
1462 # Also make a pbscript to generate yum/urpmi bases
1463 print PBS << "EOF";
[433]1464#!/bin/bash
[429]1465# Prepare a script to ease yum setup
1466cat > $ENV{'PBPROJ'}.repo << EOT
1467[$ENV{'PBPROJ'}]
[1080]1468name=$ddir $dver $darch - $ENV{'PBPROJ'} Vanilla Packages
[433]1469baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
[429]1470enabled=1
1471gpgcheck=0
1472EOT
1473chmod 644 $ENV{'PBPROJ'}.repo
1474
1475# Clean up old repo content
1476rm -rf headers/ repodata/
1477# Create yum repo
[1102]1478if [ -x /usr/bin/yum-arch ]; then
1479 yum-arch .
1480fi
[429]1481# Create repodata
1482createrepo .
1483EOF
1484 if ($dfam eq "md") {
1485 # For Mandriva add urpmi management
1486 print PBS << "EOF";
1487# Prepare a script to ease urpmi setup
1488cat > $ENV{'PBPROJ'}.addmedia << EOT
[1003]1489urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with media_info/hdlist.cz
[429]1490EOT
1491chmod 755 $ENV{'PBPROJ'}.addmedia
1492
1493# Clean up old repo content
[437]1494rm -f hdlist.cz synthesis.hdlist.cz
[429]1495# Create urpmi repo
[1002]1496genhdlist2 --clean .
1497if [ \$\? -ne 0 ]; then
1498 genhdlist .
1499fi
[429]1500EOF
1501 }
[484]1502 if ($ddir eq "fedora") {
1503 # Extract the spec file to please Fedora maintainers :-(
1504 print PBS << "EOF";
1505for p in $basesrc; do
1506 echo \$p | grep -q 'src.rpm'
1507 if [ \$\? -eq 0 ]; then
1508 rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
1509 fi
1510done
1511EOF
1512 }
[1089]1513 if ($dfam eq "novell") {
1514 # Add ymp scripts for one-click install on SuSE
1515 print PBS << "EOF";
1516# Prepare a script to ease SuSE one-click install
[1090]1517# Cf: http://de.opensuse.org/1-Klick-Installation/ISV
1518#
[1089]1519cat > $ENV{'PBPROJ'}.ymp << EOT
[1096]1520<?xml version="1.0" encoding="utf-8"?>
1521<!-- vim: set sw=2 ts=2 ai et: -->
[1089]1522<metapackage xmlns:os="http://opensuse.org/Standards/One_Click_Install" xmlns="http://opensuse.org/Standards/One_Click_Install">
1523 <group><!-- The group of software, typically one for project-builder.org -->
1524 <name>$ENV{'PBPROJ'} Bundle</name> <!-- Name of the software group -->
1525 <summary>Software bundle for the $ENV{'PBPROJ'} project</summary> <!--This message is shown to the user and should describe the whole bundle -->
[1095]1526 <description>This is the summary of the $ENV{'PBPROJ'} Project
[1089]1527
[1095]1528 Details are available on a per package basis below
1529
[1089]1530 </description><!--This is also shown to the user -->
1531 <remainSubscribed>false</remainSubscribed> <!-- Don't know what it mean -->
1532 <repositories><!-- List of needed repositories -->
1533 <repository>
1534 <name>$ENV{'PBPROJ'} Repository</name> <!-- Name of the repository -->
1535 <summary>This repository contains the $ENV{'PBPROJ'} project packages.</summary> <!-- Summary of the repository -->
1536 <description>This repository contains the $ENV{'PBPROJ'} project packages.</description><!-- This description is shown to the user -->
1537 <url>$pbrepo->{$ENV{'PBPROJ'}}/$repodir</url><!--URL of repository, which is added -->
1538 </repository>
1539 </repositories>
1540 <software><!-- A List of packages, which should be added through the one-click-installation -->
1541EOT
1542for p in $basesrc; do
1543 sum=`rpm -q --qf '%{SUMMARY}' \$p`
[1096]1544 name=`rpm -q --qf '%{NAME}' \$p`
[1089]1545 desc=`rpm -q --qf '%{description}' \$p`
1546 cat >> $ENV{'PBPROJ'}.ymp << EOT
1547 <item>
[1096]1548 <name>\$name</name><!-- Name of the package, is shown to the user and used to identify the package at the repository -->
[1089]1549 <summary>\$sum</summary> <!-- Summary of the package -->
1550 <description>\$desc</description> <!-- Description, is shown to the user -->
1551 </item>
1552EOT
1553done
1554cat >> $ENV{'PBPROJ'}.ymp << EOT
1555 </software>
1556 </group>
1557</metapackage>
1558EOT
1559chmod 644 $ENV{'PBPROJ'}.ymp
1560EOF
1561 }
[429]1562 } elsif ($dtype eq "deb") {
1563 # Also make a pbscript to generate apt bases
[460]1564 # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
[1122]1565 # This dirname removes arch
[465]1566 my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
[1122]1567 # this one removes the ver
1568 $rpd = dirname($rpd);
[460]1569 print PBS << "EOF";
[465]1570#!/bin/bash
1571# Prepare a script to ease apt setup
1572cat > $ENV{'PBPROJ'}.sources.list << EOT
1573deb $rpd $dver contrib
1574deb-src $rpd $dver contrib
[460]1575EOT
[465]1576chmod 644 $ENV{'PBPROJ'}.sources.list
[460]1577
[1112]1578# Up two levels to deal with the dist dir cross versions
1579cd ../..
1580mkdir -p dists/$dver/contrib/binary-$darch dists/$dver/contrib/source
1581
[460]1582# Prepare a script to create apt info file
[1112]1583TMPD=`mktemp -d /tmp/pb.XXXXXXXXXX` || exit 1
1584mkdir -p \$TMPD
1585cat > \$TMPD/Release << EOT
1586Archive: unstable
1587Component: contrib
1588Origin: $ENV{'PBPROJ'}
1589Label: $ENV{'PBPROJ'} dev repository $pbrepo->{$ENV{'PBPROJ'}}
1590EOT
1591
1592echo "Creating Packages metadata ($darch)"
1593dpkg-scanpackages -a$darch $dver/$darch /dev/null | gzip -c9 > dists/$dver/contrib/binary-$darch/Packages.gz
1594dpkg-scanpackages -a$darch $dver/$darch /dev/null | bzip2 -c9 > dists/$dver/contrib/binary-$darch/Packages.bz2
1595echo "Creating Contents metadata ($darch)"
[1121]1596apt-ftparchive contents $dver | gzip -c9 > dists/$dver/Contents-$darch.gz
[1112]1597echo "Creating Release metadata ($darch)"
1598cat \$TMPD/Release > dists/$dver/contrib/binary-$darch/Release
1599echo "Architecture: $darch" >> dists/$dver/contrib/binary-$darch/Release
1600echo "Creating Source metadata"
1601dpkg-scansources $dver/$darch /dev/null | gzip -c9 > dists/$dver/contrib/source/Sources.gz
1602cat \$TMPD/Release > dists/$dver/contrib/source/Release
1603echo "Architecture: Source" >> dists/$dver/contrib/source/Release
1604echo "Creating Release metadata"
1605apt-ftparchive release dists/$dver > dists/$dver/Release
1606rm -rf \$TMPD
[460]1607EOF
[586]1608 } elsif ($dtype eq "ebuild") {
1609 # make a pbscript to generate links to latest version
1610 print PBS << "EOF";
1611#!/bin/bash
1612# Prepare a script to create correct links
1613for p in $src; do
1614 echo \$p | grep -q '.ebuild'
1615 if [ \$\? -eq 0 ]; then
1616 j=`basename \$p`
1617 pp=`echo \$j | cut -d'-' -f1`
1618 ln -sf \$j \$pp.ebuild
1619 fi
1620done
1621EOF
[429]1622 }
1623 close(PBS);
[444]1624 chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
[90]1625 } else {
1626 return;
[22]1627 }
[239]1628
[320]1629 # Useless for VE
1630 my $nport;
[772]1631 if ($cmt !~ /^VE/) {
[320]1632 $nport = $sshport->{$ENV{'PBPROJ'}};
1633 $nport = "$pbport" if (defined $pbport);
1634 }
1635
[136]1636 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
[132]1637 $tdir =~ s|\$ENV.+\}/||;
1638
[883]1639 my $tm = undef;
1640 if ($cmt =~ /^VM/) {
1641 $tm = $vtmout->{$ENV{'PBPROJ'}};
1642 }
[320]1643
1644 # ssh communication if not VE
[349]1645 # should use a hash instead...
[320]1646 my ($shcmd,$cpcmd,$cptarget,$cp2target);
[772]1647 if ($cmt !~ /^VE/) {
[347]1648 my $keyfile = pb_ssh_get(0);
[435]1649 $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
1650 $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
[320]1651 $cptarget = "$mac:$tdir";
[776]1652 if ($cmt =~ /^VMbuild/) {
[351]1653 $cp2target = "$mac:$bdir";
1654 }
[320]1655 } else {
1656 my $tp = $vepath->{$ENV{'PBPROJ'}};
[681]1657 ($odir,$over,$oarch) = split(/-/,$v);
1658 my $tpdir = "$tp/$odir/$over/$oarch";
1659 my ($ptr) = pb_conf_get("vetype");
1660 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1661 if ($vetype eq "chroot") {
1662 $shcmd = "sudo chroot $tpdir /bin/su - $mac -c ";
1663 } elsif ($vetype eq "schroot") {
1664 $shcmd = "schroot $tp -u $mac -- ";
1665 }
[971]1666 $cpcmd = "sudo cp -r ";
[681]1667 # We need to get the home dir of the target account to deliver in the right place
1668 open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd";
1669 my $homedir = "";
1670 while (<PASS>) {
1671 my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
1672 $homedir = $c6 if ($c1 =~ /^$mac$/);
1673 pb_log(3,"Homedir: $homedir - account: $c6\n");
1674 }
1675 close(PASS);
1676 $cptarget = "$tpdir/$homedir/$tdir";
[773]1677 if ($cmt eq "VEbuild") {
[681]1678 $cp2target = "$tpdir/$homedir/$bdir";
1679 }
1680 pb_log(2,"On VE using $cptarget as target dir to copy to\n");
[320]1681 }
1682
[471]1683 my $logres = "";
1684 # Do not touch when just announcing
1685 if ($cmt ne "Announce") {
[908]1686 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\"","Preparing $tdir on $cptarget");
[471]1687 } else {
1688 $logres = "> ";
1689 }
[320]1690 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
[444]1691
[681]1692 # For VE we need to change the owner manually
[772]1693 if ($cmt =~ /^VE/) {
[681]1694 pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
1695 }
1696
[908]1697 pb_system("$shcmd \"echo \'cd $tdir ; if [ -x pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
[772]1698 if ($cmt =~ /^V[EM]build/) {
[128]1699 # Get back info on pkg produced, compute their name and get them from the VM
[353]1700 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
[681]1701 # For VE we need to change the owner manually
[772]1702 if ($cmt eq "VEbuild") {
[681]1703 pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID");
1704 }
[782]1705 # return here to avoid breaking the load on VMs/VEs in case of a bad one
1706 if (not -f "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") {
1707 pb_log(0,"Problem with VM $v on $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}");
1708 return;
1709 }
[353]1710 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]1711 my $src = <KEEP>;
1712 chomp($src);
1713 close(KEEP);
[131]1714 $src =~ s/^ *//;
[136]1715 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
[320]1716 # Change pgben to make the next send2target happy
[143]1717 my $made = "";
[353]1718 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[136]1719 foreach my $p (split(/ +/,$src)) {
[139]1720 my $j = basename($p);
[971]1721 # For VM we don't want shell expansion to hapen locally but remotely
1722 my $delim = '\'';
1723 if ($cmt =~ /^VEbuild/) {
1724 # For VE we need to support shell expansion locally
1725 $delim = "";
1726 }
1727 pb_system("$cpcmd $cp2target/$delim$p$delim $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Recovery of package $j in $ENV{'PBBUILDDIR'}/$odir/$over");
[572]1728 $made="$made $odir/$over/$j"; # if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
[136]1729 }
[143]1730 print KEEP "$made\n";
[139]1731 close(KEEP);
[320]1732 pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
[355]1733
[623]1734 # Sign packages locally
1735 if ($dtype eq "rpm") {
[1107]1736 #pb_system("rpm --addsign --define \"_signature gpg\" --define \"_gpg_name $ENV{'PBPACKAGER'}\" --define \"__gpg_sign_cmd /usr/bin/gpg --batch --no-verbose --no-armor --no-tty --no-secmem-warning -sbo %{__signature_filename} %{__plaintext_filename} --use-agent\" $made","Signing RPM packages packages");
[623]1737 } elsif ($dtype eq "deb") {
[626]1738 #pb_system("debsign $made","Signing DEB packages");
[623]1739 } else {
[913]1740 pb_log(0,"I don't know yet how to sign packages for type $dtype.\nPlease give feedback to dev team\n");
[623]1741 }
1742
[355]1743 # We want to send them to the ssh account so overwrite what has been done before
1744 undef $pbaccount;
[357]1745 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
[355]1746 pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
[141]1747 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
[108]1748 }
[442]1749 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
[772]1750 if ((! $vmexist) && ($cmt =~ /^VM/)) {
[748]1751 # If in setupvm then takes a snapshot just before halting
1752 if ($snapme != 0) {
1753 my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype");
1754 # For monitoring control
1755 if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) {
[804]1756 require Net::Telnet;
[776]1757 my $t = new Net::Telnet (Timeout => 120, Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor";
[748]1758 # move to monitor mode
1759 my @lines = $t->cmd("c");
1760 # Create a snapshot named pb
1761 @lines = $t->cmd("savevm pb");
1762 # Write the new status in the VM
1763 @lines = $t->cmd("commit all");
1764 # End
1765 @lines = $t->cmd("quit");
1766 }
1767 }
[914]1768 my $hoption = "-p";
[1091]1769 my $hpath = "/sbin";
1770 # Solaris doesn't support -h and has halt elsewhere
1771 if ($dtype eq "pkg") {
1772 $hoption = "" ;
1773 $hpath = "/usr/sbin";
1774 }
1775 pb_system("$shcmd \"sudo $hpath/halt $hoption \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
[442]1776 }
[772]1777 if (($cmt =~ /^VE/) && ($snapme != 0)) {
[752]1778 ($odir,$over,$oarch) = split(/-/,$v);
1779 my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$odir/$over/$oarch";
[754]1780 pb_system("sudo tar cz -f $vepath->{$ENV{'PBPROJ'}}/$odir-$over-$oarch.tar.gz -C $tpdir .","Creating a snapshot of $tpdir");
[752]1781 }
[9]1782}
[16]1783
[320]1784sub pb_script2v {
[142]1785 my $pbscript=shift;
[320]1786 my $vtype=shift;
[748]1787 my $pbforce=shift || 0; # Force stop of VM. Default not
[442]1788 my $vm1=shift || undef; # Only that VM to treat
[751]1789 my $snapme=shift || 0; # Do we have to create a snapshot
[442]1790 my $vm;
1791 my $all;
[141]1792
[767]1793 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce,".Dumper($vm1).",$snapme)\n");
[141]1794 # Prepare the script to be executed on the VM
1795 # in $ENV{'PBDESTDIR'}/pbscript
[142]1796 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
1797 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
1798 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
1799 }
[141]1800
[442]1801 if (not defined $vm1) {
[772]1802 ($vm,$all) = pb_get2v($vtype);
[442]1803 } else {
1804 @$vm = ($vm1);
1805 }
[320]1806 my ($vmexist,$vmpid) = (undef,undef);
[142]1807
[141]1808 foreach my $v (@$vm) {
[968]1809 # Launch VM/VE
1810 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme,$pbsnap);
[755]1811
[320]1812 if ($vtype eq "vm") {
[442]1813 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
[141]1814
[320]1815 # Skip that VM if something went wrong
[442]1816 next if (($vmpid == 0) && ($vmexist == 0));
1817
1818 # If force stopping the VM then reset vmexist
[748]1819 if ($pbforce == 1) {
[442]1820 $vmpid = $vmexist;
1821 $vmexist = 0;
1822 }
[670]1823 } else {
1824 #VE
1825 $vmexist = 0;
1826 $vmpid = 0;
[320]1827 }
[274]1828
[142]1829 # Gather all required files to send them to the VM
[320]1830 # and launch the build through pbscript
[442]1831 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
[748]1832 pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme);
[169]1833
[142]1834 }
1835}
1836
[320]1837sub pb_launchv {
1838 my $vtype = shift;
1839 my $v = shift;
[755]1840 my $create = shift || 0; # By default do not create a VM/VE
1841 my $snapme = shift || 0; # By default do not snap a VM/VE
[773]1842 my $usesnap = shift || 1; # By default study the usage of the snapshot feature of VM/VE
[310]1843
[773]1844 # If creation or snapshot creation mode, no snapshot usable
1845 if (($create == 1) || ($snapme == 1)) {
1846 $usesnap = 0;
1847 }
1848
1849 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create,$snapme,$usesnap)\n");
[320]1850 die "No VM/VE defined, unable to launch" if (not defined $v);
1851 # Keep only the first VM in case many were given
1852 $v =~ s/,.*//;
[310]1853
[500]1854 my $arch = pb_get_arch();
[310]1855
[320]1856 # Launch the VMs/VEs
1857 if ($vtype eq "vm") {
1858 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
[310]1859
[940]1860 # TODO: vmmonport should be optional
[1072]1861 my ($ptr,$ptr2,$vmpath,$vmport,$vmsize,$vmmonport) = pb_conf_get("vmtype","vmcmd","vmpath","vmport","vmsize","vmmonport");
[748]1862 my ($vmopt,$vmtmout,$vmsnap) = pb_conf_get_if("vmopt","vmtmout","vmsnap");
[320]1863
1864 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
[1072]1865 my $vmcmd = $ptr2->{$ENV{'PBPROJ'}};
[1124]1866
1867 if (defined $opts{'g'}) {
1868 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
1869 $ENV{'PBVMOPT'} = "--nographics";
1870 }
1871 }
[320]1872 if (not defined $ENV{'PBVMOPT'}) {
1873 $ENV{'PBVMOPT'} = "";
[310]1874 }
[639]1875 # Save the current status for later restoration
1876 $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
[483]1877 # Set a default timeout of 2 minutes
1878 if (not defined $ENV{'PBVMTMOUT'}) {
1879 $ENV{'PBVMTMOUT'} = "120";
1880 }
1881 if (defined $vmopt->{$v}) {
1882 $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
1883 } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
[320]1884 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
1885 }
[773]1886
1887 # Are we allowed to use snapshot feature
1888 if ($usesnap == 1) {
[748]1889 if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) {
[1070]1890 $ENV{'PBVMOPT'} .= " -snapshot";
[748]1891 } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) {
[1070]1892 $ENV{'PBVMOPT'} .= " -snapshot";
[748]1893 } elsif ($pbsnap eq 1) {
[1070]1894 $ENV{'PBVMOPT'} .= " -snapshot";
[748]1895 }
[767]1896 }
1897 if ($snapme != 0) {
[748]1898 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
1899 # Configure the monitoring to automize the creation of the 'pb' snapshot
[1070]1900 $ENV{'PBVMOPT'} .= " -serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait";
[773]1901 # In that case no snapshot call needed
[1070]1902 $ENV{'PBVMOPT'} =~ s/ -snapshot//;
[748]1903 }
1904 }
[483]1905 if (defined $vmtmout->{$v}) {
1906 $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
1907 } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
1908 $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
1909 }
[320]1910 my $nport = $vmport->{$ENV{'PBPROJ'}};
1911 $nport = "$pbport" if (defined $pbport);
1912
1913 my $cmd;
1914 my $vmm; # has to be used for pb_check_ps
[677]1915 if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
1916 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
[792]1917 if (($create != 0) || (defined $iso)) {
[677]1918 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
[320]1919 }
[748]1920 # Always redirect the network and always try to use a 'pb' snapshot
1921 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 -loadvm pb $vmm"
[320]1922 } elsif ($vmtype eq "xen") {
1923 } elsif ($vmtype eq "vmware") {
[310]1924 } else {
[320]1925 die "VM of type $vmtype not supported. Report to the dev team";
[310]1926 }
[639]1927 # Restore the ENV VAR Value
[641]1928 $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
[639]1929
[320]1930 my ($tmpcmd,$void) = split(/ +/,$cmd);
1931 my $vmexist = pb_check_ps($tmpcmd,$vmm);
1932 my $vmpid = 0;
1933 if (! $vmexist) {
1934 if ($create != 0) {
[653]1935 die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
[677]1936 if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
[1127]1937 my $command = pb_check_req("qemu-img",0);
1938 pb_system("$command create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
[320]1939 } elsif ($vmtype eq "vmware") {
1940 } else {
1941 }
1942 }
1943 if (! -f "$vmm") {
1944 pb_log(0,"Unable to find VM $vmm\n");
1945 } else {
1946 pb_system("$cmd &","Launching the VM $vmm");
[483]1947 pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
[320]1948 $vmpid = pb_check_ps($tmpcmd,$vmm);
[357]1949 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
[320]1950 }
[310]1951 } else {
[320]1952 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
[310]1953 }
[442]1954 pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
[320]1955 return($vmexist,$vmpid);
1956 # VE here
[310]1957 } else {
[320]1958 # Get distro context
1959 my ($name,$ver,$darch) = split(/-/,$v);
1960 chomp($darch);
[1064]1961 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
[142]1962
[963]1963 # Get VE context
[1015]1964 my ($ptr,$vepath) = pb_conf_get("vetype","vepath");
[963]1965 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1966
1967 # We can probably only get those params now we have the distro context
[1037]1968 my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv");
[963]1969
[1029]1970 # We need to avoid umask propagation to the VE
1971 umask 0022;
1972
[681]1973 if (($vetype eq "chroot") || ($vetype eq "schroot")) {
[320]1974 # Architecture consistency
1975 if ($arch ne $darch) {
[721]1976 die "Unable to launch a VE of architecture $darch on a $arch platform" if (($darch eq "x86_64") && ($arch =~ /i?86/));
[320]1977 }
[142]1978
[940]1979 my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
[987]1980 if (($create != 0) || ((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) {
[1030]1981 my ($rbsopt1) = pb_conf_get_if("rbsopt");
1982
[320]1983 # We have to rebuild the chroot
1984 if ($dtype eq "rpm") {
[670]1985
[1027]1986 # Which tool is used
[964]1987 my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}};
[1027]1988
1989 # Get potential rbs option
1990 my $rbsopt = "";
1991 if (defined $rbsopt1) {
1992 if (defined $rbsopt1->{$verpmstyle}) {
1993 $rbsopt = $rbsopt1->{$verpmstyle};
1994 } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
1995 $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
1996 } else {
1997 $rbsopt = "";
1998 }
1999 }
2000
[986]2001 my $postinstall = pb_get_postinstall($ddir,$dver,$darch,$rbspi,$verpmstyle);
[670]2002 if ($verpmstyle eq "rinse") {
[749]2003 # Need to reshape the mirrors generated with local before-post-install script
2004 my $b4post = "--before-post-install ";
[986]2005 my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbsb4pi);
[670]2006 if ($postparam eq "") {
[749]2007 $b4post = "";
2008 } else {
2009 $b4post .= $postparam;
2010 }
[670]2011
2012 # Need to reshape the package list for pb
2013 my $addpkgs;
[940]2014 $postparam = "";
2015 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
[987]2016 if ($postparam eq "") {
[670]2017 $addpkgs = "";
2018 } else {
2019 my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
2020 open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
2021 foreach my $p (split(/,/,$postparam)) {
2022 print PKG "$p\n";
2023 }
2024 close(PKG);
2025 $addpkgs = "--add-pkg-list $pkgfile";
2026 }
[940]2027
[681]2028 my $rinseverb = "";
2029 $rinseverb = "--verbose" if ($pbdebug gt 0);
[1015]2030 my ($rbsconf) = pb_conf_get("rbsconf");
[670]2031
[1027]2032 pb_system("sudo /usr/sbin/rinse --directory \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" --arch \"$darch\" --distribution \"$ddir-$dver\" --config \"$rbsconf->{$ENV{'PBPROJ'}}\" $b4post $postinstall $rbsopt $addpkgs $rinseverb","Creating the rinse VE for $ddir-$dver ($darch)", "verbose");
[974]2033 } elsif ($verpmstyle eq "rpmbootstrap") {
2034 my $rbsverb = "";
[1032]2035 foreach my $i (1..$pbdebug) {
2036 $rbsverb .= " -v";
2037 }
[991]2038 my $addpkgs = "";
2039 my $postparam = "";
2040 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
2041 if ($postparam eq "") {
2042 $addpkgs = "";
2043 } else {
2044 $addpkgs = "-a $postparam";
2045 }
[1127]2046 my $command = pb_check_req("rpmbootstrap",0);
2047 pb_system("sudo $command $rbsopt $postinstall $addpkgs $ddir-$dver-$darch $rbsverb","Creating the rpmbootstrap VE for $ddir-$dver ($darch)", "verbose");
[670]2048 } elsif ($verpmstyle eq "mock") {
[1015]2049 my ($rbsconf) = pb_conf_get("rbsconf");
[1127]2050 my $command = pb_check_req("mock",0);
2051 pb_system("sudo $command --init --resultdir=\"/tmp\" --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v $rbsopt","Creating the mock VE for $ddir-$dver ($darch)");
[670]2052 # Once setup we need to install some packages, the pb account, ...
[1127]2053 pb_system("sudo $command --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
[964]2054 } else {
2055 die "Unknown verpmtype type $verpmstyle. Report to dev team";
[658]2056 }
[320]2057 } elsif ($dtype eq "deb") {
[964]2058 my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
[1036]2059
[940]2060 my $codename = pb_distro_get_param($ddir,$dver,$darch,$oscodename);
2061 my $postparam = "";
2062 my $addpkgs;
2063 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
[987]2064 if ($postparam eq "") {
[940]2065 $addpkgs = "";
2066 } else {
2067 $addpkgs = "--include $postparam";
2068 }
[1036]2069 my $debmir = "";
2070 $debmir .= pb_distro_get_param($ddir,$dver,$darch,$rbsmirrorsrv);
[940]2071
[1030]2072 # Get potential rbs option
2073 my $rbsopt = "";
2074 if (defined $rbsopt1) {
2075 if (defined $rbsopt1->{$vedebstyle}) {
2076 $rbsopt = $rbsopt1->{$vedebstyle};
2077 } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
2078 $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
2079 } else {
2080 $rbsopt = "";
2081 }
2082 }
2083
[940]2084 # debootstrap works with amd64 not x86_64
[968]2085 my $debarch = $darch;
2086 $debarch = "amd64" if ($darch eq "x86_64");
[940]2087 if ($vedebstyle eq "debootstrap") {
[964]2088 my $dbsverb = "";
2089 $dbsverb = "--verbose" if ($pbdebug gt 0);
2090
[1030]2091 # Some perl modules are in Universe on Ubuntu
2092 $rbsopt .= " --components=main,universe" if ($ddir eq "ubuntu");
2093
[1036]2094 pb_system("sudo /usr/sbin/debootstrap $dbsverb $rbsopt --arch=$debarch $addpkgs $codename \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" $debmir","Creating the debootstrap VE for $ddir-$dver ($darch)", "verbose");
[968]2095 # debootstrap doesn't create an /etc/hosts file
2096 if (! -f "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts" ) {
2097 pb_system("sudo cp /etc/hosts $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts");
2098 }
[964]2099 } else {
2100 die "Unknown vedebtype type $vedebstyle. Report to dev team";
[940]2101 }
[320]2102 } elsif ($dtype eq "ebuild") {
2103 die "Please teach the dev team how to build gentoo chroot";
2104 } else {
2105 die "Unknown distribution type $dtype. Report to dev team";
2106 }
[310]2107 }
[1027]2108 # Fix modes to allow access to the VE for pb user
2109 pb_system("sudo chmod 755 $vepath->{$ENV{'PBPROJ'}}/$ddir $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch","Fixing permissions");
2110
[755]2111 # Test if an existing snapshot exists and use it if appropriate
2112 # And also use it of no local extracted VE is present
2113 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
2114 (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) ||
2115 ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i)) ||
2116 ($pbsnap eq 1) ||
2117 (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch"))) {
[769]2118 pb_system("sudo rm -rf $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch ; sudo mkdir -p $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch ; sudo tar xz -C $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Extracting snapshot of $ddir-$dver-$darch.tar.gz under $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch");
[755]2119 }
[320]2120 # Nothing more to do for VE. No real launch
[274]2121 } else {
[320]2122 die "VE of type $vetype not supported. Report to the dev team";
[262]2123 }
[141]2124 }
2125}
[142]2126
[639]2127# Return string for date synchro
[772]2128sub pb_date2v {
[639]2129
2130my $vtype = shift;
[652]2131my $v = shift;
[639]2132
[986]2133my ($ntp) = pb_conf_get_if($vtype."ntp");
2134my $vntp = $ntp->{$ENV{'PBPROJ'}} if (defined $ntp);
[639]2135my $ntpline;
2136
2137if (defined $vntp) {
[652]2138 my ($ntpcmd) = pb_conf_get($vtype."ntpcmd");
2139 my $vntpcmd;
2140 if (defined $ntpcmd->{$v}) {
2141 $vntpcmd = $ntpcmd->{$v};
[727]2142 } elsif (defined $ntpcmd->{$ENV{'PBPROJ'}}) {
[652]2143 $vntpcmd = $ntpcmd->{$ENV{'PBPROJ'}};
2144 } else {
2145 $vntpcmd = "/bin/true";
2146 }
2147 $ntpline = "sudo $vntpcmd $vntp";
[639]2148} else {
2149 $ntpline = undef;
2150}
2151# Force new date to be in the future compared to the date
2152# of the host by adding 1 minute
2153my @date=pb_get_date();
2154$date[1]++;
2155my $upddate = strftime("%m%d%H%M%Y", @date);
2156my $dateline = "sudo date $upddate";
2157return($ntpline,$dateline);
2158}
2159
[320]2160sub pb_build2v {
[118]2161
[320]2162my $vtype = shift;
[772]2163my $action = shift || "build";
[142]2164
[772]2165my ($v,$all) = pb_get2v($vtype);
[320]2166
2167# Send tar files when we do a global generation
[772]2168pb_build2ssh() if (($all == 1) && ($action eq "build"));
[320]2169
2170my ($vmexist,$vmpid) = (undef,undef);
2171
2172foreach my $v (@$v) {
[652]2173 # Prepare the script to be executed on the VM/VE
2174 # in $ENV{'PBDESTDIR'}/pbscript
2175 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
2176 print SCRIPT "#!/bin/bash\n";
[721]2177
2178 # Transmit the verbosity level to the virtual env/mach.
2179 my $verbose = "";
2180 my $i = 0; # minimal debug level
2181 while ($i lt $pbdebug) {
2182 $verbose .= "-v ";
2183 $i++;
2184 }
2185 # Activate script verbosity if at least 2 for pbdebug
2186 print SCRIPT "set -x\n" if ($i gt 1);
2187 # Quiet if asked to be so on the original system
2188 $verbose = "-q" if ($pbdebug eq -1);
2189
[652]2190 print SCRIPT "echo ... Execution needed\n";
2191 print SCRIPT "# This is in directory delivery\n";
2192 print SCRIPT "# Setup the variables required for building\n";
2193 print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
[686]2194
[772]2195 if ($action eq "build") {
2196 print SCRIPT "# Preparation for pb\n";
2197 print SCRIPT "mv .pbrc \$HOME\n";
2198 print SCRIPT "cd ..\n";
2199 }
2200
[686]2201 # VE needs a good /proc
[687]2202 if ($vtype eq "ve") {
[686]2203 print SCRIPT "sudo mount -t proc /proc /proc\n";
2204 }
[652]2205
[772]2206 my ($ntpline,$dateline) = pb_date2v($vtype,$v);
[652]2207 print SCRIPT "# Time sync\n";
[725]2208 print SCRIPT "echo 'setting up date with '";
[652]2209 if (defined $ntpline) {
[725]2210 print SCRIPT "echo $ntpline\n";
[652]2211 print SCRIPT "$ntpline\n";
2212 } else {
[725]2213 print SCRIPT "echo $dateline\n";
[652]2214 print SCRIPT "$dateline\n";
2215 }
[721]2216 # Use potential local proxy declaration in case we need it to download repo, pkgs, ...
2217 if (defined $ENV{'http_proxy'}) {
2218 print SCRIPT "export http_proxy=\"$ENV{'http_proxy'}\"\n";
2219 }
[652]2220
[721]2221 if (defined $ENV{'ftp_proxy'}) {
2222 print SCRIPT "export ftp_proxy=\"$ENV{'ftp_proxy'}\"\n";
[652]2223 }
2224
[772]2225 # Get list of packages to build/test and get some ENV vars as well
2226 my $ptr = pb_get_pkg();
2227 @pkgs = @$ptr;
2228 my $p = join(' ',@pkgs) if (@pkgs);
2229 print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
2230 print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
2231 print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
[721]2232
2233 # We may need to do some other tasks before building. Read a script here to finish setup
[772]2234 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
2235 print SCRIPT "# Special pre-instructions to be launched\n";
2236 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
[721]2237 }
2238
[772]2239 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
2240 print SCRIPT "# Special pre-$action instructions to be launched\n";
2241 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
2242 }
2243
2244 print SCRIPT "# $action\n";
2245 print SCRIPT "echo $action"."ing packages on $vtype...\n";
2246
2247 if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
2248 die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
2249 }
2250 print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
2251
[687]2252 if ($vtype eq "ve") {
[686]2253 print SCRIPT "sudo umount /proc\n";
2254 }
[721]2255
2256 # We may need to do some other tasks after building. Read a script here to exit properly
[772]2257 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
2258 print SCRIPT "# Special post-$action instructions to be launched\n";
2259 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
[721]2260 }
2261
[772]2262 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
2263 print SCRIPT "# Special post-instructions to be launched\n";
2264 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
2265 }
2266
[652]2267 close(SCRIPT);
2268 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
2269
[755]2270 # Launch the VM/VE
2271 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
2272
[320]2273 if ($vtype eq "vm") {
[274]2274 # Skip that VM if it something went wrong
2275 next if (($vmpid == 0) && ($vmexist == 0));
[658]2276 } else {
2277 # VE
2278 $vmexist = 0;
2279 $vmpid = 0;
[118]2280 }
[320]2281 # Gather all required files to send them to the VM/VE
[347]2282 # and launch the build through pbscript
[357]2283 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
[772]2284 pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
[105]2285}
[320]2286}
[105]2287
[262]2288
[739]2289sub pb_clean {
2290
2291 my $sleep=10;
2292 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
2293 die "Unable to get env var PBBUILDDIR" if (not defined $ENV{'PBBUILDDIR'});
2294 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");
2295 sleep $sleep;
2296 pb_rm_rf($ENV{'PBDESTDIR'});
2297 pb_rm_rf($ENV{'PBBUILDDIR'});
2298}
2299
[199]2300sub pb_newver {
2301
[204]2302 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
[340]2303
[366]2304 # Need this call for PBDIR
2305 my ($scheme2,$uri) = pb_cms_init($pbinit);
[361]2306
[898]2307 my ($pbconf,$pburl) = pb_conf_get("pbconfurl","pburl");
[366]2308 $uri = $pbconf->{$ENV{'PBPROJ'}};
2309 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
2310
[361]2311 # Checking CMS repositories status
[366]2312 ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
[340]2313
2314 if ($scheme !~ /^svn/) {
[199]2315 die "Only SVN is supported at the moment";
2316 }
[483]2317
[358]2318 my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
[361]2319 die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
[358]2320
2321 $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
[361]2322 die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
[358]2323
2324 # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
2325 # we want to get for the root of the new URL
2326
2327 my $tmp = $ENV{'PBROOTDIR'};
2328 $tmp =~ s|^$ENV{'PBCONFDIR'}||;
2329
2330 my $newurl = "$uri/".dirname($tmp)."/$newver";
[366]2331 # Should probably use projver in the old file
2332 my $oldver= basename($tmp);
[361]2333
[366]2334 # Duplicate and extract project-builder part
[361]2335 pb_log(2,"Copying $uri/$tmp to $newurl\n");
[366]2336 pb_cms_copy($scheme,"$uri/$tmp",$newurl);
2337 pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
[383]2338 pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
[361]2339
[366]2340 # Duplicate and extract project
2341 my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/".dirname($tmp)."/$newver";
2342
2343 pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$tmp to $newurl2\n");
[632]2344 pb_cms_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$tmp",$newurl2);
[366]2345 pb_log(2,"Checkout $newurl2 to $ENV{'PBDIR'}/../$newver\n");
[632]2346 pb_cms_up($scheme2,"$ENV{'PBDIR'}/..");
[366]2347
[361]2348 # Update the .pb file
[358]2349 open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
2350 open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
[208]2351 while(<FILE>) {
[361]2352 s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
2353 pb_log(0,"Changing projver from $oldver to $newver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/);
[897]2354 pb_log(0,"Commenting testver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
[361]2355 s/^testver/#testver/;
[211]2356 print OUT $_;
[1066]2357 pb_log(0,"Please check delivery ($_) in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^delivery/);
[208]2358 }
2359 close(FILE);
[211]2360 close(OUT);
[358]2361 rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
[363]2362
[479]2363 # Checking pbcl files
2364 foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
[590]2365 # Compute new pbcl file
2366 my $f2 = $f;
2367 $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBROOTDIR'}/../$newver/|;
[479]2368 open(PBCL,$f) || die "Unable to open $f";
2369 my $foundnew = 0;
2370 while (<PBCL>) {
2371 $foundnew = 1 if (/^$newver \(/);
2372 }
2373 close(PBCL);
[590]2374 open(OUT,"> $f2") || die "Unable to write to $f2: $!";
[479]2375 open(PBCL,$f) || die "Unable to open $f";
2376 while (<PBCL>) {
[480]2377 print OUT "$_" if (not /^$oldver \(/);
[479]2378 if ((/^$oldver \(/) && ($foundnew == 0)) {
2379 print OUT "$newver ($pbdate)\n";
2380 print OUT "- TBD\n";
2381 print OUT "\n";
[590]2382 pb_log(0,"WARNING: version $newver not found in $f so added to $f2...\n") if ($foundnew == 0);
[479]2383 }
2384 }
2385 close(OUT);
2386 close(PBCL);
2387 }
2388
[358]2389 pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
[452]2390 pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
[199]2391}
2392
[293]2393#
[320]2394# Return the list of VMs/VEs we are working on
[105]2395# $all is a flag to know if we return all of them
2396# or only some (if all we publish also tar files in addition to pkgs
2397#
[772]2398sub pb_get2v {
[91]2399
[320]2400my $vtype = shift;
2401my @v;
[105]2402my $all = 0;
[320]2403my $vlist;
2404my $pbv = 'PBV';
[91]2405
[320]2406if ($vtype eq "vm") {
2407 $vlist = "vmlist";
2408} elsif ($vtype eq "ve") {
2409 $vlist = "velist";
2410}
2411# Get VM/VE list
2412if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
2413 my ($ptr) = pb_conf_get($vlist);
2414 $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
[105]2415 $all = 1;
[91]2416}
[320]2417pb_log(2,"$vtype: $ENV{$pbv}\n");
2418@v = split(/,/,$ENV{$pbv});
2419return(\@v,$all);
[91]2420}
2421
[320]2422# Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
2423# Needs to use root account to connect to the VM/VE
2424# pb will take your local public SSH key to access
[346]2425# the pb account in the VM later on if needed
[772]2426sub pb_setup2v {
[320]2427
2428my $vtype = shift;
2429
[772]2430my ($vm,$all) = pb_get2v($vtype);
[353]2431
[346]2432# Script generated
2433my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
[320]2434
[652]2435foreach my $v (@$vm) {
2436 # Deal with date sync.
[772]2437 my ($ntpline,$dateline) = pb_date2v($vtype,$v);
[639]2438
[891]2439 # Get distro context
2440 my ($name,$ver,$darch) = split(/-/,$v);
2441 chomp($darch);
[1111]2442 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins) = pb_distro_init($name,$ver,$darch);
[891]2443
[353]2444 # Name of the account to deal with for VM/VE
2445 # Do not use the one passed potentially with -a
2446 my ($pbac) = pb_conf_get($vtype."login");
[354]2447 my ($key,$zero0,$zero1,$zero2);
[639]2448 my ($vmexist,$vmpid);
[346]2449
[681]2450 # Prepare the script to be executed on the VM/VE
2451 # in $ENV{'PBDESTDIR'}/setupv
2452 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2453
2454 print SCRIPT << 'EOF';
2455#!/usr/bin/perl -w
2456
2457use strict;
2458use File::Copy;
2459
2460# We should not need in this script more functions than what is provided
2461# by Base and Distribution to avoid problems at exec time.
2462# They are appended at the end.
2463
2464our $pbdebug;
2465our $pbLOG;
2466our $pbsynmsg = "pbscript";
2467our $pbdisplaytype = "text";
2468our $pblocale = "";
2469pb_log_init($pbdebug, $pbLOG);
2470pb_temp_init();
2471
2472EOF
2473
[773]2474 # Launch the VM/VE - Usage of snapshot disabled
2475 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,0,0);
[755]2476
[353]2477 if ($vtype eq "vm") {
2478 # Prepare the key to be used and transfered remotely
2479 my $keyfile = pb_ssh_get(1);
2480
[517]2481 my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
[353]2482 my $nport = $vmport->{$ENV{'PBPROJ'}};
2483 $nport = "$pbport" if (defined $pbport);
[347]2484
[353]2485 # Skip that VM if something went wrong
[442]2486 next if (($vmpid == 0) && ($vmexist == 0));
[353]2487
[354]2488 # Store the pub key part in a variable
2489 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
2490 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
2491 close(FILE);
2492
2493 $key = "\Q$zero1";
2494
[1105]2495 # We call true to avoid problems if SELinux is not activated, but chcon is present and returns in that case 1
2496 pb_system("cat $keyfile.pub | ssh -q -o UserKnownHostsFile=/dev/null -p $nport -i $keyfile root\@$vmhost->{$ENV{'PBPROJ'}} \"mkdir -p .ssh ; chmod 700 .ssh ; cat >> .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys ; if [ -x /usr/bin/chcon ]; then /usr/bin/chcon -Rt home_ssh_t .ssh 2> /dev/null; /bin/true; fi\"","Copying local keys to $vtype. This may require the root password");
[353]2497 # once this is done, we can do what we want on the VM remotely
[681]2498 } elsif ($vtype eq "ve") {
[1029]2499 print SCRIPT << "EOF";
[940]2500# For VE we need a good null dev
2501pb_system("rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null");
2502EOF
[1029]2503 print SCRIPT << "EOF";
[681]2504# For VE we first need to mount some FS
2505pb_system("mount -t proc /proc /proc");
[346]2506
[354]2507EOF
[681]2508 }
[1029]2509
2510if ($vtype eq "vm") {
[354]2511 print SCRIPT << 'EOF';
2512# Removes duplicate in .ssh/authorized_keys of our key if needed
2513#
2514my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
2515open(PBFILE,$file1) || die "Unable to open $file1";
2516open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
2517my $count = 0;
2518while (<PBFILE>) {
[517]2519
[354]2520EOF
2521 print SCRIPT << "EOF";
2522 if (/ $key /) {
2523 \$count++;
2524 }
2525print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
2526}
2527close(PBFILE);
2528close(PBOUT);
2529rename("\$file1.new",\$file1);
2530chmod 0600,\$file1;
[517]2531
2532# Sync date
[354]2533EOF
[639]2534 if (defined $ntpline) {
[891]2535 print SCRIPT "pb_system(\"$ntpline\");\n";
[652]2536 } else {
[891]2537 print SCRIPT "pb_system(\"$dateline\");\n";
[639]2538 }
[354]2539 }
2540 print SCRIPT << 'EOF';
2541
2542# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
2543#
[346]2544my $file="/etc/passwd";
[320]2545open(PBFILE,$file) || die "Unable to open $file";
2546my $found = 0;
2547while (<PBFILE>) {
[346]2548EOF
[353]2549 print SCRIPT << "EOF";
2550 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
[346]2551EOF
[891]2552
2553my $home = "/home";
2554# Solaris doesn't like that we use /home
2555$home = "/export/home" if ($dtype eq "pkg");
2556
2557 print SCRIPT << "EOF";
[320]2558}
2559close(PBFILE);
2560
[891]2561if ( \$found == 0 ) {
2562 if ( ! -d "$home" ) {
2563 pb_mkdir_p("$home");
[320]2564 }
[346]2565EOF
[353]2566 print SCRIPT << "EOF";
[1051]2567pb_system("/usr/sbin/groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
2568pb_system("/usr/sbin/useradd -g $pbac->{$ENV{'PBPROJ'}} -m -d $home/$pbac->{$ENV{'PBPROJ'}} $pbac->{$ENV{'PBPROJ'}}","Adding user $pbac->{$ENV{'PBPROJ'}} (group $pbac->{$ENV{'PBPROJ'}} - home $home/$pbac->{$ENV{'PBPROJ'}})");
[427]2569}
[661]2570EOF
[320]2571
[891]2572 # Copy the content of our local conf file to the VM/VE
2573 my $content = pb_get_content(pb_distro_conffile());
2574 print SCRIPT << "EOF";
2575 #
2576 # Create a temporary local conf file for distribution support
2577 # This is created here before its use later. Its place is hardcoded, so no choice for the path
2578 #
2579 my \$tempconf = pb_distro_conffile();
2580 pb_mkdir_p(dirname(\$tempconf));
2581 open(CONF,"> \$tempconf") || die "Unable to create \$tempconf";
2582 print CONF q{$content};
2583 close(CONF);
2584EOF
2585
[661]2586 if ($vtype eq "vm") {
2587 print SCRIPT << "EOF";
[354]2588# allow ssh entry to build
2589#
[891]2590mkdir "$home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
[347]2591# Allow those accessing root to access the build account
[891]2592copy("\$ENV{'HOME'}/.ssh/authorized_keys","$home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
[320]2593chmod 0600,".ssh/authorized_keys";
[891]2594pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} $home/$pbac->{$ENV{'PBPROJ'}}","Finish setting up the account env for $pbac->{$ENV{'PBPROJ'}}");
[320]2595
[346]2596EOF
[661]2597}
[353]2598 print SCRIPT << 'EOF';
[347]2599# No passwd for build account only keys
[320]2600$file="/etc/shadow";
[684]2601if (-f $file) {
2602 open(PBFILE,$file) || die "Unable to open $file";
2603 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2604 while (<PBFILE>) {
[346]2605EOF
[353]2606 print SCRIPT << "EOF";
[684]2607 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
2608 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
[910]2609 s/^$pbac->{$ENV{'PBPROJ'}}:\\*LK\\*:/$pbac->{$ENV{'PBPROJ'}}:NP:/; #Solaris e.g.
[346]2610EOF
[684]2611 print SCRIPT << 'EOF';
2612 print PBOUT $_;
2613 }
2614 close(PBFILE);
2615 close(PBOUT);
2616 rename("$file.new",$file);
2617 chmod 0640,$file;
2618 }
[320]2619
[448]2620# Keep the VM in text mode
2621$file="/etc/inittab";
[450]2622if (-f $file) {
2623 open(PBFILE,$file) || die "Unable to open $file";
2624 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2625 while (<PBFILE>) {
2626 s/^(..):5:initdefault:$/$1:3:initdefault:/;
2627 print PBOUT $_;
2628 }
2629 close(PBFILE);
2630 close(PBOUT);
2631 rename("$file.new",$file);
2632 chmod 0640,$file;
[448]2633}
2634
[320]2635# pb has to be added to portage group on gentoo
2636
[888]2637# We need to have that pb_distro_init function
2638# Get it from Project-Builder::Distribution
[891]2639# And we now need the conf file required for this to work created above
[888]2640
[1111]2641my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins, $darch) = pb_distro_init();
2642print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $pbins, $darch))."\n";
[891]2643
[346]2644# Adapt sudoers
[888]2645# sudo is not default on Solaris and needs to be installed first
2646# from http://www.sunfreeware.com/programlistsparc10.html#sudo
2647if ($dtype eq "pkg") {
2648 $file="/usr/local/etc/sudoers";
2649} else {
2650 $file="/etc/sudoers";
2651}
[346]2652open(PBFILE,$file) || die "Unable to open $file";
2653open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2654while (<PBFILE>) {
2655EOF
[353]2656 print SCRIPT << "EOF";
2657 next if (/^$pbac->{$ENV{'PBPROJ'}} /);
[346]2658EOF
[353]2659 print SCRIPT << 'EOF';
[346]2660 s/Defaults[ \t]+requiretty//;
2661 print PBOUT $_;
2662}
2663close(PBFILE);
2664EOF
[353]2665 print SCRIPT << "EOF";
[1032]2666# Some distro force requiretty at compile time, so disable here
2667print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} !requiretty\n";
[1035]2668print PBOUT "Defaults:root !requiretty\n";
[353]2669# This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
[1032]2670print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} env_keep += \\\"http_proxy ftp_proxy\\\"\n";
[353]2671print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
[346]2672EOF
[353]2673 print SCRIPT << 'EOF';
[346]2674close(PBOUT);
2675rename("$file.new",$file);
2676chmod 0440,$file;
2677
2678EOF
[891]2679
2680 # We may need a proxy configuration. Get it from the local env
2681
2682 if (defined $ENV{'http_proxy'}) {
2683 print SCRIPT "\$ENV\{'http_proxy'\}=\"$ENV{'http_proxy'}\";\n";
2684 }
2685
2686 if (defined $ENV{'ftp_proxy'}) {
2687 print SCRIPT "\$ENV\{'ftp_proxy'\}=\"$ENV{'ftp_proxy'}\";\n";
2688 }
2689
2690 print SCRIPT << 'EOF';
[353]2691
[346]2692# Suse wants sudoers as 640
[1012]2693if ((($ddir eq "sles") && (($dver =~ /10/) || ($dver =~ /9/))) || (($ddir eq "opensuse") && ($dver =~ /10.[012]/))) {
[346]2694 chmod 0640,$file;
2695}
2696
[1109]2697# First install all required packages
2698pb_system("yum clean all","Cleaning yum env") if (($ddir eq "fedora") || ($ddir eq "asianux") || ($ddir eq "rhel"));
2699my ($ospkgdep) = pb_conf_get_if("ospkgdep");
2700
2701my $pkgdep = pb_distro_get_param($ddir,$dver,$darch,$ospkgdep,$dfam,$dtype,$dos);
[1111]2702pb_distro_installdeps(undef,$dtype,$pbins,pb_distro_only_deps_needed($dtype,join(' ',split(/,/,$pkgdep))));
[1109]2703
2704EOF
[1132]2705 my ($instype) = pb_conf_get("pbinstalltype");
2706 my $itype = pb_distro_get_param($ddir,$dver,$darch,$instype,$dfam,$dtype,$dos);
2707 if ($itype =~ /^file/) {
[1109]2708 print SCRIPT << 'EOF';
2709# Then install manually the missing perl modules
2710my ($osperldep,$osperlver) = pb_conf_get_if("osperldep","osperlver");
2711
2712my $perldep = pb_distro_get_param($ddir,$dver,$darch,$osperldep,$dfam,$dtype,$dos);
2713foreach my $m (split(/,/,$perldep)) {
2714 # Skip empty deps
2715 next if ($m =~ /^\s*$/);
2716 my $dir = $m;
2717 $dir =~ s/-.*//;
2718 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" ,"Installing perl module $m-$osperlver->{$m}");
2719}
2720
[891]2721pb_system("rm -rf ProjectBuilder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/ProjectBuilder-latest.tar.gz ; gzip -cd ProjectBuilder-latest.tar.gz | tar xf - ; cd ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf ProjectBuilder-* ; rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; gzip -cd project-builder-latest.tar.gz | tar xf - ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf project-builder-* ;","Building Project-Builder");
[1109]2722EOF
[1132]2723 } elsif ($itype =~ /^pkg/) {
[1109]2724 # pkg based install. We need to point to the project-builder.org repository
2725 print SCRIPT << 'EOF';
[1132]2726my ($ospkg) = pb_conf_get_if("ospkg");
[1109]2727
[1132]2728my $pkgforpb = pb_distro_get_param($ddir,$dver,$darch,$ospkg,$dfam,$dtype,$dos);
2729pb_distro_setuposrepo($ddir,$dver,$darch,$dtype,$dfam,$dos);
[1111]2730pb_distro_installdeps(undef,$dtype,$pbins,pb_distro_only_deps_needed($dtype,join(' ',split(/,/,$pkgforpb))));
[1109]2731EOF
2732 } else {
2733 # Unknown install type
2734 die("Unknown install type $itype->{$ENV{'PBPROJ'}} for param pbinstalltype");
2735 }
2736 print SCRIPT << 'EOF';
[902]2737pb_system("pb 2>&1 | head -5",undef,"verbose");
[357]2738EOF
[681]2739 if ($vtype eq "ve") {
2740 print SCRIPT << 'EOF';
2741# For VE we need to umount some FS at the end
2742
2743pb_system("umount /proc");
[696]2744
2745# Create a basic network file if not already there
2746
2747my $nf="/etc/sysconfig/network";
[965]2748if ((! -f $nf) && ($dtype eq "rpm")) {
[696]2749 open(NF,"> $nf") || die "Unable to create $nf";
2750 print NF "NETWORKING=yes\n";
2751 print NF "HOSTNAME=localhost\n";
2752 close(NF);
2753}
2754chmod 0755,$nf;
[681]2755EOF
2756 }
2757
[891]2758 # Adds pb_distro_init and all functions needed from ProjectBuilder::Distribution and Base
[353]2759 foreach my $d (@INC) {
[891]2760 my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm","$d/ProjectBuilder/Conf.pm");
[405]2761 foreach my $f (@f) {
2762 if (-f "$f") {
2763 open(PBD,"$f") || die "Unable to open $f";
2764 while (<PBD>) {
[891]2765 next if (/^package/);
2766 next if (/^use Exporter/);
2767 next if (/^use ProjectBuilder::/);
2768 next if (/^our /);
[405]2769 print SCRIPT $_;
2770 }
2771 close(PBD);
[353]2772 }
[347]2773 }
2774 }
[353]2775 close(SCRIPT);
2776 chmod 0755,"$pbscript";
2777
[442]2778 # That build script needs to be run as root and force stop of VM at end
[353]2779 $pbaccount = "root";
[442]2780
[1111]2781 # Force shutdown of VM except if it was already launched
[748]2782 my $pbforce = 0;
[442]2783 if ((! $vmexist) && ($vtype eq "vm")) {
[748]2784 $pbforce = 1;
[442]2785 }
2786
[748]2787 pb_script2v($pbscript,$vtype,$pbforce,$v);
[347]2788}
[353]2789return;
[346]2790}
2791
[772]2792# Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
2793sub pb_snap2v {
[748]2794
2795my $vtype = shift;
2796
[772]2797my ($vm,$all) = pb_get2v($vtype);
[748]2798
2799# Script generated
2800my $pbscript = "$ENV{'PBDESTDIR'}/snapv";
2801
[898]2802my ($pbac) = pb_conf_get($vtype."login");
2803
[748]2804foreach my $v (@$vm) {
[971]2805 # Get distro context
2806 my ($name,$ver,$darch) = split(/-/,$v);
2807 chomp($darch);
[1064]2808 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
[971]2809 my ($vepath) = pb_conf_get("vepath");
2810
2811 # Test if an existing snapshot exists and remove it if there is a VE
2812 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
2813 (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch")) {
2814 pb_system("sudo rm -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Removing previous snapshot $ddir-$dver-$darch.tar.gz");
2815 }
2816
[748]2817 # Prepare the script to be executed on the VM/VE
2818 # in $ENV{'PBDESTDIR'}/setupv
2819 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2820
2821 print SCRIPT << 'EOF';
2822 #!/bin/bash
[776]2823 sleep 2
[748]2824EOF
2825 close(SCRIPT);
2826 chmod 0755,"$pbscript";
2827
2828 # Force shutdown of VM/VE
2829 # Force snapshot of VM/VE
[773]2830 pb_script2v($pbscript,$vtype,1,$v,1);
[748]2831}
2832return;
2833}
2834
[1111]2835# Function to update a VMs or VEs with the latest distribution content
2836sub pb_update2v {
2837
2838my $vtype = shift;
2839
2840my ($vm,$all) = pb_get2v($vtype);
2841
2842# Script generated
2843my $pbscript = "$ENV{'PBDESTDIR'}/updatev";
2844
2845my ($pbac) = pb_conf_get($vtype."login");
2846
2847foreach my $v (@$vm) {
2848 # Get distro context
2849 my ($name,$ver,$darch) = split(/-/,$v);
2850 chomp($darch);
2851 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $pbins) = pb_distro_init($name,$ver,$darch);
2852
2853 # Prepare the script to be executed on the VM/VE
2854 # in $ENV{'PBDESTDIR'}/updatev
2855 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2856
2857 print SCRIPT << 'EOF';
2858 #!/bin/bash
2859 sleep 2
2860EOF
2861 # VE needs a good /proc
2862 if ($vtype eq "ve") {
2863 print SCRIPT "sudo mount -t proc /proc /proc\n";
2864 }
2865 print SCRIPT "$pbupd\n";
2866 if ($vtype eq "ve") {
2867 print SCRIPT "sudo umount /proc\n";
2868 }
2869 close(SCRIPT);
2870 chmod 0755,"$pbscript";
2871
2872 # Force shutdown of VM except
2873 pb_script2v($pbscript,$vtype,1,$v);
2874}
2875return;
2876}
2877
[471]2878sub pb_announce {
2879
[473]2880 # Get all required parameters
[477]2881 my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
[471]2882 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
2883 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
2884 my @pkgs = @$pkg;
2885 my %pkgs;
2886 my $first = 0;
2887
[473]2888 # Command to find packages on repo
[471]2889 my $findstr = "find . ";
[473]2890 # Generated announce files
2891 my @files;
[471]2892
2893 foreach my $pbpkg (@pkgs) {
2894 if ($first != 0) {
2895 $findstr .= "-o ";
2896 }
2897 $first++;
2898 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
2899 $pbver = $pkgv->{$pbpkg};
2900 } else {
2901 $pbver = $ENV{'PBPROJVER'};
2902 }
2903 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
2904 $pbtag = $pkgt->{$pbpkg};
2905 } else {
2906 $pbtag = $ENV{'PBPROJTAG'};
2907 }
2908
[547]2909 # TODO: use virtual/real names here now
[1087]2910 $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver*\.ebuild\' ";
[473]2911
2912 my $chglog;
2913
2914 # Get project info on log file and generate tmp files used later on
2915 pb_cms_init($pbinit);
2916 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
2917 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
2918 $chglog = undef if (! -f $chglog);
2919
2920 open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
[585]2921 my %pb;
2922 $pb{'dtype'} = "announce";
2923 $pb{'realpkg'} = $pbpkg;
2924 $pb{'ver'} = $pbver;
2925 $pb{'tag'} = $pbtag;
2926 $pb{'suf'} = "N/A"; # Should not be empty even if unused
2927 $pb{'date'} = $pbdate;
2928 $pb{'chglog'} = $chglog;
2929 $pb{'packager'} = $pbpackager;
2930 $pb{'proj'} = $ENV{'PBPROJ'};
2931 $pb{'repo'} = $pbrepo;
2932 pb_changelog(\%pb,\*OUT,"yes");
[473]2933 close(OUT);
2934 push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
[471]2935 }
2936 $findstr .= " | grep -Ev \'src.rpm\'";
2937
2938 # Prepare the command to run and execute it
2939 open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
2940 print PBS "$findstr\n";
2941 close(PBS);
2942 chmod 0755,"$ENV{'PBTMP'}/pbscript";
2943 pb_send2target("Announce");
2944
[490]2945 # Get subject line
2946 my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
[495]2947 pb_log(0,"Please enter the title of your announce\n");
2948 pb_log(0,"(By default: $sl)\n");
[490]2949 my $sl2 = <STDIN>;
2950 $sl = $sl2 if ($sl2 !~ /^$/);
2951
[471]2952 # Prepare a template of announce
[473]2953 open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
[471]2954 print ANN << "EOF";
[490]2955$sl</p>
[471]2956
[473]2957<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]2958<p>
2959Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
2960</p>
2961<p>
2962EOF
2963 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
[473]2964 my $col = 2;
2965 my $i = 1;
2966 print ANN << 'EOF';
2967<TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
2968<TR>
2969EOF
[471]2970 while (<LOG>) {
[697]2971 print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
[473]2972 $i++;
2973 if ($i > $col) {
2974 print ANN "</TR>\n<TR>";
2975 $i = 1;
2976 }
[471]2977 }
2978 close(LOG);
[473]2979 print ANN << "EOF";
2980</TR>
2981</TABLE>
2982</p>
[471]2983
[473]2984<p>As usual source packages are also available in the same directory.</p>
2985
2986<p>
2987Changes are :
2988</p>
2989<p>
2990EOF
2991 # Get each package changelog content
2992 foreach my $f (sort(@files)) {
2993 open(IN,"$f") || die "Unable to read $f:$!";
2994 while (<IN>) {
2995 print ANN $_;
2996 }
2997 close(IN);
2998 print ANN "</p><p>\n";
2999 }
3000 print ANN "</p>\n";
[471]3001 close(ANN);
[473]3002
3003 # Allow for modification
[974]3004 my $editor = "vi";
3005 $editor = $ENV{'EDITOR'} if (defined $ENV{'EDITOR'});
3006 pb_system("$editor $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
[473]3007
3008 # Store it in DB for external usage (Web pages generation)
3009 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
3010
3011 my $precmd = "";
3012 if (! -f $db) {
3013 $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
3014 }
3015
3016 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
3017 { RaiseError => 1, AutoCommit => 1 })
3018 || die "Unable to connect to $db";
3019
3020 if ($precmd ne "") {
3021 my $sth = $dbh->prepare(qq{$precmd})
3022 || die "Unable to create table into $db";
3023 $sth->execute();
3024 }
3025
3026 # To read whole file
3027 local $/;
3028 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
3029 my $announce = <ANN>;
3030 close(ANN);
3031
3032 pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
3033 my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
3034 || die "Unable to insert into $db";
3035 $sth->execute($pbdate, $announce);
[698]3036 $sth->finish();
[473]3037 $dbh->disconnect;
3038
3039 # Then deliver it on the Web
3040 # $TOOLHOME/livwww www
3041
3042 # Mail it to project's ML
3043 open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
3044 print ML << 'EOF';
3045<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
3046
3047<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
3048 <head>
3049 </head>
3050 <body>
3051 <p>
3052EOF
3053 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
3054 while(<ANN>) {
3055 print ML $_;
3056 }
3057 print ML << 'EOF';
3058</body>
3059</html>
3060EOF
3061 close(ML);
3062
[477]3063 # To read whole file
3064 local $/;
3065 open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
3066 my $msg = <ANN>;
3067 close(ANN);
3068
3069 # Preparation of headers
[1134]3070 eval
3071 {
3072 require Mail::Sendmail;
3073 Mail::Sendmail->import();
3074 };
3075 if ($@) {
3076 # Mail::Sendmail not found not sending mail !
3077 pb_log(0,"No Mail::Sendmail module found so not sending any mail !\n");
3078 } else {
3079 my %mail = (
[477]3080 To => $pbml->{$ENV{'PBPROJ'}},
3081 From => $pbpackager->{$ENV{'PBPROJ'}},
3082 Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
3083 Body => $msg,
[490]3084 Subject => "[ANNOUNCE] $sl",
[477]3085 );
3086
[1134]3087 # Send mail
3088 if (! sendmail(%mail)) {
3089 if ((defined $Mail::Sendmail::error) and (defined $Mail::Sendmail::log)) {
3090 die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
3091 }
[1109]3092 }
3093 }
[471]3094}
3095
[547]3096#
3097# Creates a set of HTML file containing the news for the project
3098# based on what has been generated by the pb_announce function
3099#
3100sub pb_web_news2html {
3101
[556]3102 my $dest = shift || $ENV{'PBTMP'};
3103
[547]3104 # Get all required parameters
[1064]3105 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
[547]3106
3107 # DB of announces for external usage (Web pages generation)
3108 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
3109
3110 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
3111 { RaiseError => 1, AutoCommit => 1 })
3112 || die "Unable to connect to $db";
3113 # For date handling
3114 $ENV{LANGUAGE}="C";
[559]3115 my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
3116 my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
3117 pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
[547]3118 my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
[556]3119 my %news;
3120 $news{"cy"} = ""; # current year's news
3121 $news{"ly"} = ""; # last year news
3122 $news{"py"} = ""; # previous years news
3123 $news{"fp"} = ""; # first page news
[547]3124 my $cpt = 4; # how many news for first page
3125 # Extract info from DB
3126 foreach my $row (@$all) {
3127 my ($id, $date, $announce) = @$row;
[559]3128 $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
3129 $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
3130 $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
[556]3131 $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
[547]3132 $cpt--;
3133 }
[556]3134 pb_log(1,"news{fp}: ".$news{"fp"}."\n");
[547]3135 $dbh->disconnect;
[556]3136
3137 # Generate the HTML content
3138 foreach my $pref (keys %news) {
3139 open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
3140 print NEWS "$news{$pref}";
3141 close(NEWS);
3142 }
[547]3143}
3144
[556]3145
[347]3146# Return the SSH key file to use
3147# Potentially create it if needed
3148
3149sub pb_ssh_get {
3150
3151my $create = shift || 0; # Do not create keys by default
3152
3153# Check the SSH environment
3154my $keyfile = undef;
3155
3156# We have specific keys by default
3157$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
[348]3158if (!(-e $keyfile) && ($create eq 1)) {
[347]3159 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
3160}
3161
3162$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
3163$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
3164$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
3165die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
3166return($keyfile);
3167}
3168
3169
[145]3170# Returns the pid of a running VM command using a specific VM file
[142]3171sub pb_check_ps {
3172 my $vmcmd = shift;
3173 my $vmm = shift;
3174 my $vmexist = 0; # FALSE by default
3175
3176 open(PS, "ps auxhww|") || die "Unable to call ps";
3177 while (<PS>) {
3178 next if (! /$vmcmd/);
3179 next if (! /$vmm/);
3180 my ($void1, $void2);
3181 ($void1, $vmexist, $void2) = split(/ +/);
3182 last;
3183 }
3184 return($vmexist);
3185}
3186
3187
[77]3188sub pb_extract_build_files {
[25]3189
3190my $src=shift;
3191my $dir=shift;
[26]3192my $ddir=shift;
[500]3193my $mandatory=shift || "spec";
[28]3194my @files;
[25]3195
[500]3196my $flag = "mayfail" if ($mandatory eq "patch");
3197my $res;
3198
[188]3199if ($src =~ /tar\.gz$/) {
[500]3200 $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
[188]3201} elsif ($src =~ /tar\.bz2$/) {
[500]3202 $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
[188]3203} else {
3204 die "Unknown compression algorithm for $src";
3205}
[500]3206# If not mandatory return now
3207return() if (($res != 0) and ($mandatory eq "patch"));
[25]3208opendir(DIR,"$dir") || die "Unable to open directory $dir";
3209foreach my $f (readdir(DIR)) {
3210 next if ($f =~ /^\./);
[500]3211 # Skip potential patch dir
3212 next if ($f =~ /^pbpatch/);
[26]3213 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[315]3214 pb_log(2,"mv $dir/$f $ddir\n");
[28]3215 push @files,"$ddir/$f";
[25]3216}
3217closedir(DIR);
[26]3218# Not enough but still a first cleanup
[74]3219pb_rm_rf("$dir");
[28]3220return(@files);
[25]3221}
3222
[315]3223sub pb_list_bfiles {
3224
3225my $dir = shift;
3226my $pbpkg = shift;
3227my $bfiles = shift;
3228my $pkgfiles = shift;
3229my $supfiles = shift;
3230
3231opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
3232foreach my $f (readdir(BDIR)) {
3233 next if ($f =~ /^\./);
[1098]3234 if (-d $f) {
3235 # Recurse for directories (Debian 3.0 format e.g.)
3236 pb_list_bfiles($f,$pbpkg,$bfiles,$pkgfiles,$supfiles);
3237 next;
3238 }
[315]3239 $bfiles->{$f} = "$dir/$f";
[340]3240 $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
[315]3241 if (defined $supfiles->{$pbpkg}) {
3242 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
3243 }
3244}
3245closedir(BDIR);
3246}
3247
[1130]3248sub pb_list_sfiles {
[395]3249
[1130]3250my $sdir = shift;
3251my $sources = shift;
3252my $dtype = shift;
3253my $dfam = shift;
3254my $ddir = shift;
3255my $dver = shift;
3256my $arch = shift;
3257my $extdir = shift;
3258
3259# Prepare local sources for this distro - They are always applied first - May be a problem one day
3260# This function works for both patches and additional sources
3261foreach my $p (sort(<$sdir/*>)) {
3262 $sources->{"$ddir-$dver-$arch"} .= "," if ((defined $sources->{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
3263 $sources->{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
3264 $sources->{"$ddir-$dver-$arch"} .= "," if ((defined $sources->{"$ddir-$dver-$arch"}) and ($p =~ /\.$dtype$/));
3265 $sources->{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dtype$/);
3266 $sources->{"$ddir-$dver-$arch"} .= "," if ((defined $sources->{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
3267 $sources->{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
3268 $sources->{"$ddir-$dver-$arch"} .= "," if ((defined $sources->{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
3269 $sources->{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
3270 $sources->{"$ddir-$dver-$arch"} .= "," if ((defined $sources->{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
3271 $sources->{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
3272 $sources->{"$ddir-$dver-$arch"} .= "," if ((defined $sources->{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
3273 $sources->{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
3274}
3275
3276# Prepare also remote sources to be included - Applied after the local ones
3277foreach my $p ("all","$dtype","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
3278 my $f = "$extdir.".".$p";
3279 next if (not -f $f);
3280 if (not open(PATCH,$f)) {
3281 pb_display("Unable to open existing external source file content $f\n");
3282 next;
3283 }
3284 while (<PATCH>) {
3285 chomp();
3286 $sources->{"$ddir-$dver-$arch"} .= "," if (defined $sources->{"$ddir-$dver-$arch"});
3287 $sources->{"$ddir-$dver-$arch"} .= "$_";
3288 }
3289 close(PATCH);
3290}
3291pb_log(2,"DEBUG: sources: ".Dumper($sources)."\n");
3292}
3293
[395]3294#
3295# Return the list of packages we are working on in a non CMS action
3296#
3297sub pb_get_pkg {
3298
3299my @pkgs = ();
3300
3301my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
3302@pkgs = keys %$var;
3303
3304pb_log(0,"Packages: ".join(',',@pkgs)."\n");
3305return(\@pkgs);
3306}
3307
[986]3308#
3309# Return the postinstall line if needed
3310#
3311
3312sub pb_get_postinstall {
3313
[989]3314my $ddir = shift;
3315my $dver = shift;
3316my $darch = shift;
3317my $rbspi = shift;
3318my $vestyle = shift;
[986]3319my $post = "";
3320
3321# Do we have a local post-install script
3322if ($vestyle eq "rinse") {
3323 $post = "--post-install ";
3324} elsif ($vestyle eq "rpmbootstrap") {
3325 $post = "-s ";
3326}
3327
[989]3328my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbspi);
[986]3329if ($postparam eq "") {
3330 $post = "";
3331} else {
3332 $post .= $postparam;
3333}
3334return($post);
3335}
3336
[395]33371;
Note: See TracBrowser for help on using the repository browser.