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

Last change on this file since 1107 was 1107, checked in by Bruno Cornec, 13 years ago

r4032@localhost: bruno | 2010-11-08 15:51:53 +0100

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