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

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

r4041@localhost: bruno | 2010-11-17 11:40:41 +0100

  • Adds new configuration parameters (oschkcmd, oschkopt) to externalize package checking command
  • Adds new configuration parameters (pbinstalltype, pbpkg) to start allowing installation of pb in VM/VE with packages or files (this last is only needed by upstream)
  • Remove dependency on Mail::Sendmail to where it's really needed (part of Log, not used yet, and annouce). In particular this removes one non std dep for VE/VM build.
  • Property svn:executable set to *
File size: 101.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 }
[1109]1150 # Find the appropriate check cmd/opts
1151 my ($oschkcmd,$oschkopt) = pb_conf_get_if("oschkcmd","oschkopt");
1152 my $chkcmd .= pb_distro_get_param($ddir,$dver,$arch,$oschkcmd,$dtype,$dfam,$dos);
1153 my $chkopt .= pb_distro_get_param($ddir,$dver,$arch,$oschkopt,$dtype,$dfam,$dos);
1154
[541]1155 # Packages check if needed
1156 if ($dtype eq "rpm") {
[1109]1157 if (-x $chkcmd) {
1158 pb_system("$chkcmd $chkopt $made","Checking validity of rpms with $chkcmd","verbose");
[541]1159 }
[1098]1160 my $rpms ="";
1161 my $srpms ="";
1162 foreach my $f (split(/ /,$made)) {
1163 $rpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^RPMS\//);
1164 $srpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^SRPMS\//);
1165 }
1166 pb_log(0,"SRPM packages generated: $srpms\n");
1167 pb_log(0,"RPM packages generated: $rpms\n");
[541]1168 } elsif ($dtype eq "deb") {
[572]1169 my $made2 = "";
[971]1170 foreach my $f (split(/ /,$made)) {
1171 $made2 .= "../$f " if ($f =~ /\.changes$/);
1172 }
[1109]1173 if (-x $chkcmd) {
1174 pb_system("$chkcmd $chkopt $made2","Checking validity of debs with $chkcmd","verbose");
[572]1175 } else {
1176 pb_log(0,"deb packages generated: $made2\n");
[541]1177 }
1178 } else {
[572]1179 pb_log(0,"No check done for $dtype yet\n");
1180 pb_log(0,"Packages generated: $made\n");
[541]1181 }
1182
[118]1183 # Keep track of what is generated so that we can get them back from VMs
[353]1184 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]1185 print KEEP "$made\n";
1186 close(KEEP);
[87]1187}
1188
[874]1189sub create_solaris_prototype {
[872]1190
[873]1191 my $uidgid = "bin bin";
[877]1192 my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
[872]1193
[878]1194 return if ($_ =~ /^$pkgdestdir$/);
[875]1195 if (-d $_) {
1196 my $n = $File::Find::name;
1197 $n =~ s~$pkgdestdir/~~;
1198 print PROTO "d none $n 0755 $uidgid\n";
[877]1199 } elsif (-x $_) {
[875]1200 my $n = $File::Find::name;
1201 $n =~ s~$pkgdestdir/~~;
1202 print PROTO "f none $n 0755 $uidgid\n";
[872]1203 } elsif (-f $_) {
[875]1204 my $n = $File::Find::name;
1205 $n =~ s~$pkgdestdir/~~;
1206 print PROTO "f none $n 0644 $uidgid\n";
[872]1207 }
1208}
1209
[88]1210sub pb_build2ssh {
[320]1211 pb_send2target("Sources");
[90]1212}
[87]1213
[90]1214sub pb_pkg2ssh {
[320]1215 pb_send2target("Packages");
[90]1216}
1217
[108]1218# By default deliver to the the public site hosting the
[320]1219# ftp structure (or whatever) or a VM/VE
1220sub pb_send2target {
[90]1221
1222 my $cmt = shift;
[320]1223 my $v = shift || undef;
[142]1224 my $vmexist = shift || 0; # 0 is FALSE
[200]1225 my $vmpid = shift || 0; # 0 is FALSE
[748]1226 my $snapme = shift || 0; # 0 is FALSE
[320]1227
[444]1228 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
[320]1229 my $host = "sshhost";
1230 my $login = "sshlogin";
1231 my $dir = "sshdir";
1232 my $port = "sshport";
1233 my $conf = "sshconf";
[883]1234 my $tmout = undef;
1235 my $path = undef;
[772]1236 if ($cmt =~ /^VM/) {
[320]1237 $login = "vmlogin";
[322]1238 $dir = "pbdefdir";
[320]1239 # Specific VM
[883]1240 $tmout = "vmtmout";
1241 $path = "vmpath";
[320]1242 $host = "vmhost";
1243 $port = "vmport";
[772]1244 } elsif ($cmt =~ /^VE/) {
[320]1245 $login = "velogin";
[322]1246 $dir = "pbdefdir";
[320]1247 # Specific VE
1248 $path = "vepath";
[986]1249 $conf = "rbsconf";
[556]1250 } elsif ($cmt eq "Web") {
1251 $host = "websshhost";
1252 $login = "websshlogin";
1253 $dir = "websshdir";
1254 $port = "websshport";
[320]1255 }
[158]1256 my $cmd = "";
[471]1257 my $src = "";
1258 my ($odir,$over,$oarch) = (undef, undef, undef);
[1080]1259 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch);
[90]1260
[471]1261 if ($cmt ne "Announce") {
[898]1262 # Get list of packages to build
[471]1263 my $ptr = pb_get_pkg();
1264 @pkgs = @$ptr;
[87]1265
[471]1266 # Get the running distro to consider
1267 if (defined $v) {
1268 ($odir,$over,$oarch) = split(/-/,$v);
1269 }
[1080]1270 ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch) = pb_distro_init($odir,$over,$oarch);
1271 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $darch))."\n");
[87]1272
[471]1273 # Get list of packages to build
1274 # Get content saved in cms2build
1275 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
1276 $pkg = { } if (not defined $pkg);
[87]1277
[471]1278 chdir "$ENV{'PBBUILDDIR'}";
1279 foreach my $pbpkg (@pkgs) {
1280 my $vertag = $pkg->{$pbpkg};
1281 # get the version of the current package - maybe different
1282 ($pbver,$pbtag) = split(/-/,$vertag);
[87]1283
[772]1284 if (($cmt eq "Sources") || ($cmt =~ /V[EM]build/)) {
[493]1285 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
[471]1286 if ($cmd eq "") {
1287 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
1288 } else {
1289 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
1290 }
[560]1291 } elsif ($cmt eq "Web") {
1292 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"
[166]1293 }
[118]1294 }
[471]1295 # Adds conf file for availability of conf elements
1296 pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
[118]1297 }
[417]1298
[772]1299 if ($cmt =~ /V[EM]build/) {
[444]1300 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
[681]1301 } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) {
[492]1302 $src="$src $ENV{'PBDESTDIR'}/pbscript";
[772]1303 } elsif ($cmt =~ /V[EM]test/) {
[773]1304 $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]1305 } elsif ($cmt eq "Announce") {
[471]1306 $src="$src $ENV{'PBTMP'}/pbscript";
[118]1307 } elsif ($cmt eq "Packages") {
1308 # Get package list from file made during build2pkg
[353]1309 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[126]1310 $src = <KEEP>;
[118]1311 chomp($src);
1312 close(KEEP);
[681]1313 $src="$src $ENV{'PBBUILDDIR'}/pbscript";
[87]1314 }
[320]1315 # Remove potential leading spaces (cause problem with basename)
[132]1316 $src =~ s/^ *//;
[129]1317 my $basesrc = "";
[131]1318 foreach my $i (split(/ +/,$src)) {
1319 $basesrc .= " ".basename($i);
[130]1320 }
[118]1321
[320]1322 pb_log(0,"Sources handled ($cmt): $src\n");
[987]1323 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$path,$conf))."\n");
[883]1324 my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
1325 # Not mandatory...
[1066]1326 my ($rbsconf,$testver,$delivery) = pb_conf_get_if($conf,"testver","delivery");
[1102]1327 $delivery->{$ENV{'PBPROJ'}} = "" if (not defined $delivery->{$ENV{'PBPROJ'}});
[883]1328 my ($vtmout,$vepath);
1329 # ...Except those in virtual context
1330 if ($cmt =~ /^VE/) {
1331 ($vepath) = pb_conf_get($path);
1332 }
1333 if ($cmt =~ /^VM/) {
1334 ($vtmout) = pb_conf_get($tmout);
1335 }
[987]1336 pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vepath,$rbsconf))."\n");
[320]1337
1338 my $mac;
[772]1339 if ($cmt !~ /^VE/) {
[320]1340 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
1341 # Overwrite account value if passed as parameter
1342 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
[355]1343 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
[681]1344 } else {
1345 # VE
[772]1346 # Overwrite account value if passed as parameter (typically for setup2ve)
[681]1347 $mac = $sshlogin->{$ENV{'PBPROJ'}};
1348 $mac = $pbaccount if (defined $pbaccount);
[320]1349 }
1350
[108]1351 my $tdir;
[136]1352 my $bdir;
[783]1353 if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/)) {
[1078]1354 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}/src";
[783]1355 } elsif (($cmt =~ /V[EM]build/) || ($cmt =~ /V[EM]test/)) {
[320]1356 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
1357 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
[136]1358 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
1359 $bdir =~ s|\$ENV.+\}/||;
[471]1360 } elsif ($cmt eq "Announce") {
[1078]1361 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}";
[556]1362 } elsif ($cmt eq "Web") {
[1078]1363 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}";
[90]1364 } elsif ($cmt eq "Packages") {
[1080]1365 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch";
[429]1366
1367 my $repodir = $tdir;
1368 $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
1369
1370 my ($pbrepo) = pb_conf_get("pbrepo");
1371
1372 # Repository management
[444]1373 open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
[429]1374 if ($dtype eq "rpm") {
1375 # Also make a pbscript to generate yum/urpmi bases
1376 print PBS << "EOF";
[433]1377#!/bin/bash
[429]1378# Prepare a script to ease yum setup
1379cat > $ENV{'PBPROJ'}.repo << EOT
1380[$ENV{'PBPROJ'}]
[1080]1381name=$ddir $dver $darch - $ENV{'PBPROJ'} Vanilla Packages
[433]1382baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
[429]1383enabled=1
1384gpgcheck=0
1385EOT
1386chmod 644 $ENV{'PBPROJ'}.repo
1387
1388# Clean up old repo content
1389rm -rf headers/ repodata/
1390# Create yum repo
[1102]1391if [ -x /usr/bin/yum-arch ]; then
1392 yum-arch .
1393fi
[429]1394# Create repodata
1395createrepo .
1396EOF
1397 if ($dfam eq "md") {
1398 # For Mandriva add urpmi management
1399 print PBS << "EOF";
1400# Prepare a script to ease urpmi setup
1401cat > $ENV{'PBPROJ'}.addmedia << EOT
[1003]1402urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with media_info/hdlist.cz
[429]1403EOT
1404chmod 755 $ENV{'PBPROJ'}.addmedia
1405
1406# Clean up old repo content
[437]1407rm -f hdlist.cz synthesis.hdlist.cz
[429]1408# Create urpmi repo
[1002]1409genhdlist2 --clean .
1410if [ \$\? -ne 0 ]; then
1411 genhdlist .
1412fi
[429]1413EOF
1414 }
[484]1415 if ($ddir eq "fedora") {
1416 # Extract the spec file to please Fedora maintainers :-(
1417 print PBS << "EOF";
1418for p in $basesrc; do
1419 echo \$p | grep -q 'src.rpm'
1420 if [ \$\? -eq 0 ]; then
1421 rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
1422 fi
1423done
1424EOF
1425 }
[1089]1426 if ($dfam eq "novell") {
1427 # Add ymp scripts for one-click install on SuSE
1428 print PBS << "EOF";
1429# Prepare a script to ease SuSE one-click install
[1090]1430# Cf: http://de.opensuse.org/1-Klick-Installation/ISV
1431#
[1089]1432cat > $ENV{'PBPROJ'}.ymp << EOT
[1096]1433<?xml version="1.0" encoding="utf-8"?>
1434<!-- vim: set sw=2 ts=2 ai et: -->
[1089]1435<metapackage xmlns:os="http://opensuse.org/Standards/One_Click_Install" xmlns="http://opensuse.org/Standards/One_Click_Install">
1436 <group><!-- The group of software, typically one for project-builder.org -->
1437 <name>$ENV{'PBPROJ'} Bundle</name> <!-- Name of the software group -->
1438 <summary>Software bundle for the $ENV{'PBPROJ'} project</summary> <!--This message is shown to the user and should describe the whole bundle -->
[1095]1439 <description>This is the summary of the $ENV{'PBPROJ'} Project
[1089]1440
[1095]1441 Details are available on a per package basis below
1442
[1089]1443 </description><!--This is also shown to the user -->
1444 <remainSubscribed>false</remainSubscribed> <!-- Don't know what it mean -->
1445 <repositories><!-- List of needed repositories -->
1446 <repository>
1447 <name>$ENV{'PBPROJ'} Repository</name> <!-- Name of the repository -->
1448 <summary>This repository contains the $ENV{'PBPROJ'} project packages.</summary> <!-- Summary of the repository -->
1449 <description>This repository contains the $ENV{'PBPROJ'} project packages.</description><!-- This description is shown to the user -->
1450 <url>$pbrepo->{$ENV{'PBPROJ'}}/$repodir</url><!--URL of repository, which is added -->
1451 </repository>
1452 </repositories>
1453 <software><!-- A List of packages, which should be added through the one-click-installation -->
1454EOT
1455for p in $basesrc; do
1456 sum=`rpm -q --qf '%{SUMMARY}' \$p`
[1096]1457 name=`rpm -q --qf '%{NAME}' \$p`
[1089]1458 desc=`rpm -q --qf '%{description}' \$p`
1459 cat >> $ENV{'PBPROJ'}.ymp << EOT
1460 <item>
[1096]1461 <name>\$name</name><!-- Name of the package, is shown to the user and used to identify the package at the repository -->
[1089]1462 <summary>\$sum</summary> <!-- Summary of the package -->
1463 <description>\$desc</description> <!-- Description, is shown to the user -->
1464 </item>
1465EOT
1466done
1467cat >> $ENV{'PBPROJ'}.ymp << EOT
1468 </software>
1469 </group>
1470</metapackage>
1471EOT
1472chmod 644 $ENV{'PBPROJ'}.ymp
1473EOF
1474 }
[429]1475 } elsif ($dtype eq "deb") {
1476 # Also make a pbscript to generate apt bases
[460]1477 # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
[465]1478 my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
[460]1479 print PBS << "EOF";
[465]1480#!/bin/bash
1481# Prepare a script to ease apt setup
1482cat > $ENV{'PBPROJ'}.sources.list << EOT
1483deb $rpd $dver contrib
1484deb-src $rpd $dver contrib
[460]1485EOT
[465]1486chmod 644 $ENV{'PBPROJ'}.sources.list
[460]1487
1488# Prepare a script to create apt info file
[1080]1489(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]1490#(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]1491EOF
[586]1492 } elsif ($dtype eq "ebuild") {
1493 # make a pbscript to generate links to latest version
1494 print PBS << "EOF";
1495#!/bin/bash
1496# Prepare a script to create correct links
1497for p in $src; do
1498 echo \$p | grep -q '.ebuild'
1499 if [ \$\? -eq 0 ]; then
1500 j=`basename \$p`
1501 pp=`echo \$j | cut -d'-' -f1`
1502 ln -sf \$j \$pp.ebuild
1503 fi
1504done
1505EOF
[429]1506 }
1507 close(PBS);
[444]1508 chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
[90]1509 } else {
1510 return;
[22]1511 }
[239]1512
[320]1513 # Useless for VE
1514 my $nport;
[772]1515 if ($cmt !~ /^VE/) {
[320]1516 $nport = $sshport->{$ENV{'PBPROJ'}};
1517 $nport = "$pbport" if (defined $pbport);
1518 }
1519
[136]1520 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
[132]1521 $tdir =~ s|\$ENV.+\}/||;
1522
[883]1523 my $tm = undef;
1524 if ($cmt =~ /^VM/) {
1525 $tm = $vtmout->{$ENV{'PBPROJ'}};
1526 }
[320]1527
1528 # ssh communication if not VE
[349]1529 # should use a hash instead...
[320]1530 my ($shcmd,$cpcmd,$cptarget,$cp2target);
[772]1531 if ($cmt !~ /^VE/) {
[347]1532 my $keyfile = pb_ssh_get(0);
[435]1533 $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
1534 $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
[320]1535 $cptarget = "$mac:$tdir";
[776]1536 if ($cmt =~ /^VMbuild/) {
[351]1537 $cp2target = "$mac:$bdir";
1538 }
[320]1539 } else {
1540 my $tp = $vepath->{$ENV{'PBPROJ'}};
[681]1541 ($odir,$over,$oarch) = split(/-/,$v);
1542 my $tpdir = "$tp/$odir/$over/$oarch";
1543 my ($ptr) = pb_conf_get("vetype");
1544 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1545 if ($vetype eq "chroot") {
1546 $shcmd = "sudo chroot $tpdir /bin/su - $mac -c ";
1547 } elsif ($vetype eq "schroot") {
1548 $shcmd = "schroot $tp -u $mac -- ";
1549 }
[971]1550 $cpcmd = "sudo cp -r ";
[681]1551 # We need to get the home dir of the target account to deliver in the right place
1552 open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd";
1553 my $homedir = "";
1554 while (<PASS>) {
1555 my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
1556 $homedir = $c6 if ($c1 =~ /^$mac$/);
1557 pb_log(3,"Homedir: $homedir - account: $c6\n");
1558 }
1559 close(PASS);
1560 $cptarget = "$tpdir/$homedir/$tdir";
[773]1561 if ($cmt eq "VEbuild") {
[681]1562 $cp2target = "$tpdir/$homedir/$bdir";
1563 }
1564 pb_log(2,"On VE using $cptarget as target dir to copy to\n");
[320]1565 }
1566
[471]1567 my $logres = "";
1568 # Do not touch when just announcing
1569 if ($cmt ne "Announce") {
[908]1570 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]1571 } else {
1572 $logres = "> ";
1573 }
[320]1574 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
[444]1575
[681]1576 # For VE we need to change the owner manually
[772]1577 if ($cmt =~ /^VE/) {
[681]1578 pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
1579 }
1580
[908]1581 pb_system("$shcmd \"echo \'cd $tdir ; if [ -x pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
[772]1582 if ($cmt =~ /^V[EM]build/) {
[128]1583 # Get back info on pkg produced, compute their name and get them from the VM
[353]1584 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
[681]1585 # For VE we need to change the owner manually
[772]1586 if ($cmt eq "VEbuild") {
[681]1587 pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID");
1588 }
[782]1589 # return here to avoid breaking the load on VMs/VEs in case of a bad one
1590 if (not -f "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") {
1591 pb_log(0,"Problem with VM $v on $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}");
1592 return;
1593 }
[353]1594 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]1595 my $src = <KEEP>;
1596 chomp($src);
1597 close(KEEP);
[131]1598 $src =~ s/^ *//;
[136]1599 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
[320]1600 # Change pgben to make the next send2target happy
[143]1601 my $made = "";
[353]1602 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[136]1603 foreach my $p (split(/ +/,$src)) {
[139]1604 my $j = basename($p);
[971]1605 # For VM we don't want shell expansion to hapen locally but remotely
1606 my $delim = '\'';
1607 if ($cmt =~ /^VEbuild/) {
1608 # For VE we need to support shell expansion locally
1609 $delim = "";
1610 }
1611 pb_system("$cpcmd $cp2target/$delim$p$delim $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Recovery of package $j in $ENV{'PBBUILDDIR'}/$odir/$over");
[572]1612 $made="$made $odir/$over/$j"; # if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
[136]1613 }
[143]1614 print KEEP "$made\n";
[139]1615 close(KEEP);
[320]1616 pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
[355]1617
[623]1618 # Sign packages locally
1619 if ($dtype eq "rpm") {
[1107]1620 #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]1621 } elsif ($dtype eq "deb") {
[626]1622 #pb_system("debsign $made","Signing DEB packages");
[623]1623 } else {
[913]1624 pb_log(0,"I don't know yet how to sign packages for type $dtype.\nPlease give feedback to dev team\n");
[623]1625 }
1626
[355]1627 # We want to send them to the ssh account so overwrite what has been done before
1628 undef $pbaccount;
[357]1629 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
[355]1630 pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
[141]1631 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
[108]1632 }
[442]1633 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
[772]1634 if ((! $vmexist) && ($cmt =~ /^VM/)) {
[748]1635 # If in setupvm then takes a snapshot just before halting
1636 if ($snapme != 0) {
1637 my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype");
1638 # For monitoring control
1639 if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) {
[804]1640 require Net::Telnet;
[776]1641 my $t = new Net::Telnet (Timeout => 120, Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor";
[748]1642 # move to monitor mode
1643 my @lines = $t->cmd("c");
1644 # Create a snapshot named pb
1645 @lines = $t->cmd("savevm pb");
1646 # Write the new status in the VM
1647 @lines = $t->cmd("commit all");
1648 # End
1649 @lines = $t->cmd("quit");
1650 }
1651 }
[914]1652 my $hoption = "-p";
[1091]1653 my $hpath = "/sbin";
1654 # Solaris doesn't support -h and has halt elsewhere
1655 if ($dtype eq "pkg") {
1656 $hoption = "" ;
1657 $hpath = "/usr/sbin";
1658 }
1659 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]1660 }
[772]1661 if (($cmt =~ /^VE/) && ($snapme != 0)) {
[752]1662 ($odir,$over,$oarch) = split(/-/,$v);
1663 my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$odir/$over/$oarch";
[754]1664 pb_system("sudo tar cz -f $vepath->{$ENV{'PBPROJ'}}/$odir-$over-$oarch.tar.gz -C $tpdir .","Creating a snapshot of $tpdir");
[752]1665 }
[9]1666}
[16]1667
[320]1668sub pb_script2v {
[142]1669 my $pbscript=shift;
[320]1670 my $vtype=shift;
[748]1671 my $pbforce=shift || 0; # Force stop of VM. Default not
[442]1672 my $vm1=shift || undef; # Only that VM to treat
[751]1673 my $snapme=shift || 0; # Do we have to create a snapshot
[442]1674 my $vm;
1675 my $all;
[141]1676
[767]1677 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce,".Dumper($vm1).",$snapme)\n");
[141]1678 # Prepare the script to be executed on the VM
1679 # in $ENV{'PBDESTDIR'}/pbscript
[142]1680 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
1681 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
1682 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
1683 }
[141]1684
[442]1685 if (not defined $vm1) {
[772]1686 ($vm,$all) = pb_get2v($vtype);
[442]1687 } else {
1688 @$vm = ($vm1);
1689 }
[320]1690 my ($vmexist,$vmpid) = (undef,undef);
[142]1691
[141]1692 foreach my $v (@$vm) {
[968]1693 # Launch VM/VE
1694 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme,$pbsnap);
[755]1695
[320]1696 if ($vtype eq "vm") {
[442]1697 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
[141]1698
[320]1699 # Skip that VM if something went wrong
[442]1700 next if (($vmpid == 0) && ($vmexist == 0));
1701
1702 # If force stopping the VM then reset vmexist
[748]1703 if ($pbforce == 1) {
[442]1704 $vmpid = $vmexist;
1705 $vmexist = 0;
1706 }
[670]1707 } else {
1708 #VE
1709 $vmexist = 0;
1710 $vmpid = 0;
[320]1711 }
[274]1712
[142]1713 # Gather all required files to send them to the VM
[320]1714 # and launch the build through pbscript
[442]1715 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
[748]1716 pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme);
[169]1717
[142]1718 }
1719}
1720
[320]1721sub pb_launchv {
1722 my $vtype = shift;
1723 my $v = shift;
[755]1724 my $create = shift || 0; # By default do not create a VM/VE
1725 my $snapme = shift || 0; # By default do not snap a VM/VE
[773]1726 my $usesnap = shift || 1; # By default study the usage of the snapshot feature of VM/VE
[310]1727
[773]1728 # If creation or snapshot creation mode, no snapshot usable
1729 if (($create == 1) || ($snapme == 1)) {
1730 $usesnap = 0;
1731 }
1732
1733 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create,$snapme,$usesnap)\n");
[320]1734 die "No VM/VE defined, unable to launch" if (not defined $v);
1735 # Keep only the first VM in case many were given
1736 $v =~ s/,.*//;
[310]1737
[500]1738 my $arch = pb_get_arch();
[310]1739
[320]1740 # Launch the VMs/VEs
1741 if ($vtype eq "vm") {
1742 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
[310]1743
[940]1744 # TODO: vmmonport should be optional
[1072]1745 my ($ptr,$ptr2,$vmpath,$vmport,$vmsize,$vmmonport) = pb_conf_get("vmtype","vmcmd","vmpath","vmport","vmsize","vmmonport");
[748]1746 my ($vmopt,$vmtmout,$vmsnap) = pb_conf_get_if("vmopt","vmtmout","vmsnap");
[320]1747
1748 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
[1072]1749 my $vmcmd = $ptr2->{$ENV{'PBPROJ'}};
[320]1750 if (not defined $ENV{'PBVMOPT'}) {
1751 $ENV{'PBVMOPT'} = "";
[310]1752 }
[639]1753 # Save the current status for later restoration
1754 $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
[483]1755 # Set a default timeout of 2 minutes
1756 if (not defined $ENV{'PBVMTMOUT'}) {
1757 $ENV{'PBVMTMOUT'} = "120";
1758 }
1759 if (defined $vmopt->{$v}) {
1760 $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
1761 } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
[320]1762 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
1763 }
[773]1764
1765 # Are we allowed to use snapshot feature
1766 if ($usesnap == 1) {
[748]1767 if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) {
[1070]1768 $ENV{'PBVMOPT'} .= " -snapshot";
[748]1769 } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) {
[1070]1770 $ENV{'PBVMOPT'} .= " -snapshot";
[748]1771 } elsif ($pbsnap eq 1) {
[1070]1772 $ENV{'PBVMOPT'} .= " -snapshot";
[748]1773 }
[767]1774 }
1775 if ($snapme != 0) {
[748]1776 if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
1777 # Configure the monitoring to automize the creation of the 'pb' snapshot
[1070]1778 $ENV{'PBVMOPT'} .= " -serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait";
[773]1779 # In that case no snapshot call needed
[1070]1780 $ENV{'PBVMOPT'} =~ s/ -snapshot//;
[748]1781 }
1782 }
[483]1783 if (defined $vmtmout->{$v}) {
1784 $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
1785 } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
1786 $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
1787 }
[320]1788 my $nport = $vmport->{$ENV{'PBPROJ'}};
1789 $nport = "$pbport" if (defined $pbport);
1790
1791 my $cmd;
1792 my $vmm; # has to be used for pb_check_ps
[677]1793 if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
1794 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
[792]1795 if (($create != 0) || (defined $iso)) {
[677]1796 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
[320]1797 }
[748]1798 # Always redirect the network and always try to use a 'pb' snapshot
1799 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 -loadvm pb $vmm"
[320]1800 } elsif ($vmtype eq "xen") {
1801 } elsif ($vmtype eq "vmware") {
[310]1802 } else {
[320]1803 die "VM of type $vmtype not supported. Report to the dev team";
[310]1804 }
[639]1805 # Restore the ENV VAR Value
[641]1806 $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
[639]1807
[320]1808 my ($tmpcmd,$void) = split(/ +/,$cmd);
1809 my $vmexist = pb_check_ps($tmpcmd,$vmm);
1810 my $vmpid = 0;
1811 if (! $vmexist) {
1812 if ($create != 0) {
[653]1813 die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
[677]1814 if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
[320]1815 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
1816 } elsif ($vmtype eq "vmware") {
1817 } else {
1818 }
1819 }
1820 if (! -f "$vmm") {
1821 pb_log(0,"Unable to find VM $vmm\n");
1822 } else {
1823 pb_system("$cmd &","Launching the VM $vmm");
[483]1824 pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
[320]1825 $vmpid = pb_check_ps($tmpcmd,$vmm);
[357]1826 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
[320]1827 }
[310]1828 } else {
[320]1829 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
[310]1830 }
[442]1831 pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
[320]1832 return($vmexist,$vmpid);
1833 # VE here
[310]1834 } else {
[320]1835 # Get distro context
1836 my ($name,$ver,$darch) = split(/-/,$v);
1837 chomp($darch);
[1064]1838 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
[142]1839
[963]1840 # Get VE context
[1015]1841 my ($ptr,$vepath) = pb_conf_get("vetype","vepath");
[963]1842 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1843
1844 # We can probably only get those params now we have the distro context
[1037]1845 my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv");
[963]1846
[1029]1847 # We need to avoid umask propagation to the VE
1848 umask 0022;
1849
[681]1850 if (($vetype eq "chroot") || ($vetype eq "schroot")) {
[320]1851 # Architecture consistency
1852 if ($arch ne $darch) {
[721]1853 die "Unable to launch a VE of architecture $darch on a $arch platform" if (($darch eq "x86_64") && ($arch =~ /i?86/));
[320]1854 }
[142]1855
[940]1856 my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
[987]1857 if (($create != 0) || ((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) {
[1030]1858 my ($rbsopt1) = pb_conf_get_if("rbsopt");
1859
[320]1860 # We have to rebuild the chroot
1861 if ($dtype eq "rpm") {
[670]1862
[1027]1863 # Which tool is used
[964]1864 my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}};
[1027]1865
1866 # Get potential rbs option
1867 my $rbsopt = "";
1868 if (defined $rbsopt1) {
1869 if (defined $rbsopt1->{$verpmstyle}) {
1870 $rbsopt = $rbsopt1->{$verpmstyle};
1871 } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
1872 $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
1873 } else {
1874 $rbsopt = "";
1875 }
1876 }
1877
[986]1878 my $postinstall = pb_get_postinstall($ddir,$dver,$darch,$rbspi,$verpmstyle);
[670]1879 if ($verpmstyle eq "rinse") {
[749]1880 # Need to reshape the mirrors generated with local before-post-install script
1881 my $b4post = "--before-post-install ";
[986]1882 my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbsb4pi);
[670]1883 if ($postparam eq "") {
[749]1884 $b4post = "";
1885 } else {
1886 $b4post .= $postparam;
1887 }
[670]1888
1889 # Need to reshape the package list for pb
1890 my $addpkgs;
[940]1891 $postparam = "";
1892 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
[987]1893 if ($postparam eq "") {
[670]1894 $addpkgs = "";
1895 } else {
1896 my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
1897 open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
1898 foreach my $p (split(/,/,$postparam)) {
1899 print PKG "$p\n";
1900 }
1901 close(PKG);
1902 $addpkgs = "--add-pkg-list $pkgfile";
1903 }
[940]1904
[681]1905 my $rinseverb = "";
1906 $rinseverb = "--verbose" if ($pbdebug gt 0);
[1015]1907 my ($rbsconf) = pb_conf_get("rbsconf");
[670]1908
[1027]1909 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]1910 } elsif ($verpmstyle eq "rpmbootstrap") {
1911 my $rbsverb = "";
[1032]1912 foreach my $i (1..$pbdebug) {
1913 $rbsverb .= " -v";
1914 }
[991]1915 my $addpkgs = "";
1916 my $postparam = "";
1917 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
1918 if ($postparam eq "") {
1919 $addpkgs = "";
1920 } else {
1921 $addpkgs = "-a $postparam";
1922 }
[1027]1923 pb_system("sudo /usr/bin/rpmbootstrap $rbsopt $postinstall $addpkgs $ddir-$dver-$darch $rbsverb","Creating the rpmbootstrap VE for $ddir-$dver ($darch)", "verbose");
[670]1924 } elsif ($verpmstyle eq "mock") {
[1015]1925 my ($rbsconf) = pb_conf_get("rbsconf");
[1027]1926 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]1927 # Once setup we need to install some packages, the pb account, ...
[986]1928 pb_system("sudo /usr/sbin/mock --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
[964]1929 } else {
1930 die "Unknown verpmtype type $verpmstyle. Report to dev team";
[658]1931 }
[320]1932 } elsif ($dtype eq "deb") {
[964]1933 my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
[1036]1934
[940]1935 my $codename = pb_distro_get_param($ddir,$dver,$darch,$oscodename);
1936 my $postparam = "";
1937 my $addpkgs;
1938 $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
[987]1939 if ($postparam eq "") {
[940]1940 $addpkgs = "";
1941 } else {
1942 $addpkgs = "--include $postparam";
1943 }
[1036]1944 my $debmir = "";
1945 $debmir .= pb_distro_get_param($ddir,$dver,$darch,$rbsmirrorsrv);
[940]1946
[1030]1947 # Get potential rbs option
1948 my $rbsopt = "";
1949 if (defined $rbsopt1) {
1950 if (defined $rbsopt1->{$vedebstyle}) {
1951 $rbsopt = $rbsopt1->{$vedebstyle};
1952 } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
1953 $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
1954 } else {
1955 $rbsopt = "";
1956 }
1957 }
1958
[940]1959 # debootstrap works with amd64 not x86_64
[968]1960 my $debarch = $darch;
1961 $debarch = "amd64" if ($darch eq "x86_64");
[940]1962 if ($vedebstyle eq "debootstrap") {
[964]1963 my $dbsverb = "";
1964 $dbsverb = "--verbose" if ($pbdebug gt 0);
1965
[1030]1966 # Some perl modules are in Universe on Ubuntu
1967 $rbsopt .= " --components=main,universe" if ($ddir eq "ubuntu");
1968
[1036]1969 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]1970 # debootstrap doesn't create an /etc/hosts file
1971 if (! -f "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts" ) {
1972 pb_system("sudo cp /etc/hosts $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts");
1973 }
[964]1974 } else {
1975 die "Unknown vedebtype type $vedebstyle. Report to dev team";
[940]1976 }
[320]1977 } elsif ($dtype eq "ebuild") {
1978 die "Please teach the dev team how to build gentoo chroot";
1979 } else {
1980 die "Unknown distribution type $dtype. Report to dev team";
1981 }
[310]1982 }
[1027]1983 # Fix modes to allow access to the VE for pb user
1984 pb_system("sudo chmod 755 $vepath->{$ENV{'PBPROJ'}}/$ddir $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch","Fixing permissions");
1985
[755]1986 # Test if an existing snapshot exists and use it if appropriate
1987 # And also use it of no local extracted VE is present
1988 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
1989 (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) ||
1990 ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i)) ||
1991 ($pbsnap eq 1) ||
1992 (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch"))) {
[769]1993 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]1994 }
[320]1995 # Nothing more to do for VE. No real launch
[274]1996 } else {
[320]1997 die "VE of type $vetype not supported. Report to the dev team";
[262]1998 }
[141]1999 }
2000}
[142]2001
[639]2002# Return string for date synchro
[772]2003sub pb_date2v {
[639]2004
2005my $vtype = shift;
[652]2006my $v = shift;
[639]2007
[986]2008my ($ntp) = pb_conf_get_if($vtype."ntp");
2009my $vntp = $ntp->{$ENV{'PBPROJ'}} if (defined $ntp);
[639]2010my $ntpline;
2011
2012if (defined $vntp) {
[652]2013 my ($ntpcmd) = pb_conf_get($vtype."ntpcmd");
2014 my $vntpcmd;
2015 if (defined $ntpcmd->{$v}) {
2016 $vntpcmd = $ntpcmd->{$v};
[727]2017 } elsif (defined $ntpcmd->{$ENV{'PBPROJ'}}) {
[652]2018 $vntpcmd = $ntpcmd->{$ENV{'PBPROJ'}};
2019 } else {
2020 $vntpcmd = "/bin/true";
2021 }
2022 $ntpline = "sudo $vntpcmd $vntp";
[639]2023} else {
2024 $ntpline = undef;
2025}
2026# Force new date to be in the future compared to the date
2027# of the host by adding 1 minute
2028my @date=pb_get_date();
2029$date[1]++;
2030my $upddate = strftime("%m%d%H%M%Y", @date);
2031my $dateline = "sudo date $upddate";
2032return($ntpline,$dateline);
2033}
2034
[320]2035sub pb_build2v {
[118]2036
[320]2037my $vtype = shift;
[772]2038my $action = shift || "build";
[142]2039
[772]2040my ($v,$all) = pb_get2v($vtype);
[320]2041
2042# Send tar files when we do a global generation
[772]2043pb_build2ssh() if (($all == 1) && ($action eq "build"));
[320]2044
2045my ($vmexist,$vmpid) = (undef,undef);
2046
2047foreach my $v (@$v) {
[652]2048 # Prepare the script to be executed on the VM/VE
2049 # in $ENV{'PBDESTDIR'}/pbscript
2050 open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
2051 print SCRIPT "#!/bin/bash\n";
[721]2052
2053 # Transmit the verbosity level to the virtual env/mach.
2054 my $verbose = "";
2055 my $i = 0; # minimal debug level
2056 while ($i lt $pbdebug) {
2057 $verbose .= "-v ";
2058 $i++;
2059 }
2060 # Activate script verbosity if at least 2 for pbdebug
2061 print SCRIPT "set -x\n" if ($i gt 1);
2062 # Quiet if asked to be so on the original system
2063 $verbose = "-q" if ($pbdebug eq -1);
2064
[652]2065 print SCRIPT "echo ... Execution needed\n";
2066 print SCRIPT "# This is in directory delivery\n";
2067 print SCRIPT "# Setup the variables required for building\n";
2068 print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
[686]2069
[772]2070 if ($action eq "build") {
2071 print SCRIPT "# Preparation for pb\n";
2072 print SCRIPT "mv .pbrc \$HOME\n";
2073 print SCRIPT "cd ..\n";
2074 }
2075
[686]2076 # VE needs a good /proc
[687]2077 if ($vtype eq "ve") {
[686]2078 print SCRIPT "sudo mount -t proc /proc /proc\n";
2079 }
[652]2080
[772]2081 my ($ntpline,$dateline) = pb_date2v($vtype,$v);
[652]2082 print SCRIPT "# Time sync\n";
[725]2083 print SCRIPT "echo 'setting up date with '";
[652]2084 if (defined $ntpline) {
[725]2085 print SCRIPT "echo $ntpline\n";
[652]2086 print SCRIPT "$ntpline\n";
2087 } else {
[725]2088 print SCRIPT "echo $dateline\n";
[652]2089 print SCRIPT "$dateline\n";
2090 }
[721]2091 # Use potential local proxy declaration in case we need it to download repo, pkgs, ...
2092 if (defined $ENV{'http_proxy'}) {
2093 print SCRIPT "export http_proxy=\"$ENV{'http_proxy'}\"\n";
2094 }
[652]2095
[721]2096 if (defined $ENV{'ftp_proxy'}) {
2097 print SCRIPT "export ftp_proxy=\"$ENV{'ftp_proxy'}\"\n";
[652]2098 }
2099
[772]2100 # Get list of packages to build/test and get some ENV vars as well
2101 my $ptr = pb_get_pkg();
2102 @pkgs = @$ptr;
2103 my $p = join(' ',@pkgs) if (@pkgs);
2104 print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
2105 print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
2106 print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
[721]2107
2108 # We may need to do some other tasks before building. Read a script here to finish setup
[772]2109 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
2110 print SCRIPT "# Special pre-instructions to be launched\n";
2111 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
[721]2112 }
2113
[772]2114 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
2115 print SCRIPT "# Special pre-$action instructions to be launched\n";
2116 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
2117 }
2118
2119 print SCRIPT "# $action\n";
2120 print SCRIPT "echo $action"."ing packages on $vtype...\n";
2121
2122 if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
2123 die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
2124 }
2125 print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
2126
[687]2127 if ($vtype eq "ve") {
[686]2128 print SCRIPT "sudo umount /proc\n";
2129 }
[721]2130
2131 # We may need to do some other tasks after building. Read a script here to exit properly
[772]2132 if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
2133 print SCRIPT "# Special post-$action instructions to be launched\n";
2134 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
[721]2135 }
2136
[772]2137 if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
2138 print SCRIPT "# Special post-instructions to be launched\n";
2139 print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
2140 }
2141
[652]2142 close(SCRIPT);
2143 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
2144
[755]2145 # Launch the VM/VE
2146 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
2147
[320]2148 if ($vtype eq "vm") {
[274]2149 # Skip that VM if it something went wrong
2150 next if (($vmpid == 0) && ($vmexist == 0));
[658]2151 } else {
2152 # VE
2153 $vmexist = 0;
2154 $vmpid = 0;
[118]2155 }
[320]2156 # Gather all required files to send them to the VM/VE
[347]2157 # and launch the build through pbscript
[357]2158 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
[772]2159 pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
[105]2160}
[320]2161}
[105]2162
[262]2163
[739]2164sub pb_clean {
2165
2166 my $sleep=10;
2167 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
2168 die "Unable to get env var PBBUILDDIR" if (not defined $ENV{'PBBUILDDIR'});
2169 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");
2170 sleep $sleep;
2171 pb_rm_rf($ENV{'PBDESTDIR'});
2172 pb_rm_rf($ENV{'PBBUILDDIR'});
2173}
2174
[199]2175sub pb_newver {
2176
[204]2177 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
[340]2178
[366]2179 # Need this call for PBDIR
2180 my ($scheme2,$uri) = pb_cms_init($pbinit);
[361]2181
[898]2182 my ($pbconf,$pburl) = pb_conf_get("pbconfurl","pburl");
[366]2183 $uri = $pbconf->{$ENV{'PBPROJ'}};
2184 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
2185
[361]2186 # Checking CMS repositories status
[366]2187 ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
[340]2188
2189 if ($scheme !~ /^svn/) {
[199]2190 die "Only SVN is supported at the moment";
2191 }
[483]2192
[358]2193 my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
[361]2194 die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
[358]2195
2196 $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
[361]2197 die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
[358]2198
2199 # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
2200 # we want to get for the root of the new URL
2201
2202 my $tmp = $ENV{'PBROOTDIR'};
2203 $tmp =~ s|^$ENV{'PBCONFDIR'}||;
2204
2205 my $newurl = "$uri/".dirname($tmp)."/$newver";
[366]2206 # Should probably use projver in the old file
2207 my $oldver= basename($tmp);
[361]2208
[366]2209 # Duplicate and extract project-builder part
[361]2210 pb_log(2,"Copying $uri/$tmp to $newurl\n");
[366]2211 pb_cms_copy($scheme,"$uri/$tmp",$newurl);
2212 pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
[383]2213 pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
[361]2214
[366]2215 # Duplicate and extract project
2216 my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/".dirname($tmp)."/$newver";
2217
2218 pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$tmp to $newurl2\n");
[632]2219 pb_cms_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$tmp",$newurl2);
[366]2220 pb_log(2,"Checkout $newurl2 to $ENV{'PBDIR'}/../$newver\n");
[632]2221 pb_cms_up($scheme2,"$ENV{'PBDIR'}/..");
[366]2222
[361]2223 # Update the .pb file
[358]2224 open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
2225 open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
[208]2226 while(<FILE>) {
[361]2227 s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
2228 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]2229 pb_log(0,"Commenting testver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
[361]2230 s/^testver/#testver/;
[211]2231 print OUT $_;
[1066]2232 pb_log(0,"Please check delivery ($_) in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^delivery/);
[208]2233 }
2234 close(FILE);
[211]2235 close(OUT);
[358]2236 rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
[363]2237
[479]2238 # Checking pbcl files
2239 foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
[590]2240 # Compute new pbcl file
2241 my $f2 = $f;
2242 $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBROOTDIR'}/../$newver/|;
[479]2243 open(PBCL,$f) || die "Unable to open $f";
2244 my $foundnew = 0;
2245 while (<PBCL>) {
2246 $foundnew = 1 if (/^$newver \(/);
2247 }
2248 close(PBCL);
[590]2249 open(OUT,"> $f2") || die "Unable to write to $f2: $!";
[479]2250 open(PBCL,$f) || die "Unable to open $f";
2251 while (<PBCL>) {
[480]2252 print OUT "$_" if (not /^$oldver \(/);
[479]2253 if ((/^$oldver \(/) && ($foundnew == 0)) {
2254 print OUT "$newver ($pbdate)\n";
2255 print OUT "- TBD\n";
2256 print OUT "\n";
[590]2257 pb_log(0,"WARNING: version $newver not found in $f so added to $f2...\n") if ($foundnew == 0);
[479]2258 }
2259 }
2260 close(OUT);
2261 close(PBCL);
2262 }
2263
[358]2264 pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
[452]2265 pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
[199]2266}
2267
[293]2268#
[320]2269# Return the list of VMs/VEs we are working on
[105]2270# $all is a flag to know if we return all of them
2271# or only some (if all we publish also tar files in addition to pkgs
2272#
[772]2273sub pb_get2v {
[91]2274
[320]2275my $vtype = shift;
2276my @v;
[105]2277my $all = 0;
[320]2278my $vlist;
2279my $pbv = 'PBV';
[91]2280
[320]2281if ($vtype eq "vm") {
2282 $vlist = "vmlist";
2283} elsif ($vtype eq "ve") {
2284 $vlist = "velist";
2285}
2286# Get VM/VE list
2287if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
2288 my ($ptr) = pb_conf_get($vlist);
2289 $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
[105]2290 $all = 1;
[91]2291}
[320]2292pb_log(2,"$vtype: $ENV{$pbv}\n");
2293@v = split(/,/,$ENV{$pbv});
2294return(\@v,$all);
[91]2295}
2296
[320]2297# Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
2298# Needs to use root account to connect to the VM/VE
2299# pb will take your local public SSH key to access
[346]2300# the pb account in the VM later on if needed
[772]2301sub pb_setup2v {
[320]2302
2303my $vtype = shift;
2304
[772]2305my ($vm,$all) = pb_get2v($vtype);
[353]2306
[346]2307# Script generated
2308my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
[320]2309
[652]2310foreach my $v (@$vm) {
2311 # Deal with date sync.
[772]2312 my ($ntpline,$dateline) = pb_date2v($vtype,$v);
[639]2313
[891]2314 # Get distro context
2315 my ($name,$ver,$darch) = split(/-/,$v);
2316 chomp($darch);
[1064]2317 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd) = pb_distro_init($name,$ver,$darch);
[891]2318
[353]2319 # Name of the account to deal with for VM/VE
2320 # Do not use the one passed potentially with -a
2321 my ($pbac) = pb_conf_get($vtype."login");
[354]2322 my ($key,$zero0,$zero1,$zero2);
[639]2323 my ($vmexist,$vmpid);
[346]2324
[681]2325 # Prepare the script to be executed on the VM/VE
2326 # in $ENV{'PBDESTDIR'}/setupv
2327 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2328
2329 print SCRIPT << 'EOF';
2330#!/usr/bin/perl -w
2331
2332use strict;
2333use File::Copy;
2334
2335# We should not need in this script more functions than what is provided
2336# by Base and Distribution to avoid problems at exec time.
2337# They are appended at the end.
2338
2339our $pbdebug;
2340our $pbLOG;
2341our $pbsynmsg = "pbscript";
2342our $pbdisplaytype = "text";
2343our $pblocale = "";
2344pb_log_init($pbdebug, $pbLOG);
2345pb_temp_init();
2346
2347EOF
2348
[773]2349 # Launch the VM/VE - Usage of snapshot disabled
2350 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,0,0);
[755]2351
[353]2352 if ($vtype eq "vm") {
2353 # Prepare the key to be used and transfered remotely
2354 my $keyfile = pb_ssh_get(1);
2355
[517]2356 my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
[353]2357 my $nport = $vmport->{$ENV{'PBPROJ'}};
2358 $nport = "$pbport" if (defined $pbport);
[347]2359
[353]2360 # Skip that VM if something went wrong
[442]2361 next if (($vmpid == 0) && ($vmexist == 0));
[353]2362
[354]2363 # Store the pub key part in a variable
2364 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
2365 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
2366 close(FILE);
2367
2368 $key = "\Q$zero1";
2369
[1105]2370 # We call true to avoid problems if SELinux is not activated, but chcon is present and returns in that case 1
2371 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]2372 # once this is done, we can do what we want on the VM remotely
[681]2373 } elsif ($vtype eq "ve") {
[1029]2374 print SCRIPT << "EOF";
[940]2375# For VE we need a good null dev
2376pb_system("rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null");
2377EOF
[1029]2378 print SCRIPT << "EOF";
[681]2379# For VE we first need to mount some FS
2380pb_system("mount -t proc /proc /proc");
[346]2381
[354]2382EOF
[681]2383 }
[1029]2384
2385if ($vtype eq "vm") {
[354]2386 print SCRIPT << 'EOF';
2387# Removes duplicate in .ssh/authorized_keys of our key if needed
2388#
2389my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
2390open(PBFILE,$file1) || die "Unable to open $file1";
2391open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
2392my $count = 0;
2393while (<PBFILE>) {
[517]2394
[354]2395EOF
2396 print SCRIPT << "EOF";
2397 if (/ $key /) {
2398 \$count++;
2399 }
2400print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
2401}
2402close(PBFILE);
2403close(PBOUT);
2404rename("\$file1.new",\$file1);
2405chmod 0600,\$file1;
[517]2406
2407# Sync date
[354]2408EOF
[639]2409 if (defined $ntpline) {
[891]2410 print SCRIPT "pb_system(\"$ntpline\");\n";
[652]2411 } else {
[891]2412 print SCRIPT "pb_system(\"$dateline\");\n";
[639]2413 }
[354]2414 }
2415 print SCRIPT << 'EOF';
2416
2417# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
2418#
[346]2419my $file="/etc/passwd";
[320]2420open(PBFILE,$file) || die "Unable to open $file";
2421my $found = 0;
2422while (<PBFILE>) {
[346]2423EOF
[353]2424 print SCRIPT << "EOF";
2425 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
[346]2426EOF
[891]2427
2428my $home = "/home";
2429# Solaris doesn't like that we use /home
2430$home = "/export/home" if ($dtype eq "pkg");
2431
2432 print SCRIPT << "EOF";
[320]2433}
2434close(PBFILE);
2435
[891]2436if ( \$found == 0 ) {
2437 if ( ! -d "$home" ) {
2438 pb_mkdir_p("$home");
[320]2439 }
[346]2440EOF
[353]2441 print SCRIPT << "EOF";
[1051]2442pb_system("/usr/sbin/groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
2443pb_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]2444}
[661]2445EOF
[320]2446
[891]2447 # Copy the content of our local conf file to the VM/VE
2448 my $content = pb_get_content(pb_distro_conffile());
2449 print SCRIPT << "EOF";
2450 #
2451 # Create a temporary local conf file for distribution support
2452 # This is created here before its use later. Its place is hardcoded, so no choice for the path
2453 #
2454 my \$tempconf = pb_distro_conffile();
2455 pb_mkdir_p(dirname(\$tempconf));
2456 open(CONF,"> \$tempconf") || die "Unable to create \$tempconf";
2457 print CONF q{$content};
2458 close(CONF);
2459EOF
2460
[661]2461 if ($vtype eq "vm") {
2462 print SCRIPT << "EOF";
[354]2463# allow ssh entry to build
2464#
[891]2465mkdir "$home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
[347]2466# Allow those accessing root to access the build account
[891]2467copy("\$ENV{'HOME'}/.ssh/authorized_keys","$home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
[320]2468chmod 0600,".ssh/authorized_keys";
[891]2469pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} $home/$pbac->{$ENV{'PBPROJ'}}","Finish setting up the account env for $pbac->{$ENV{'PBPROJ'}}");
[320]2470
[346]2471EOF
[661]2472}
[353]2473 print SCRIPT << 'EOF';
[347]2474# No passwd for build account only keys
[320]2475$file="/etc/shadow";
[684]2476if (-f $file) {
2477 open(PBFILE,$file) || die "Unable to open $file";
2478 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2479 while (<PBFILE>) {
[346]2480EOF
[353]2481 print SCRIPT << "EOF";
[684]2482 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
2483 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
[910]2484 s/^$pbac->{$ENV{'PBPROJ'}}:\\*LK\\*:/$pbac->{$ENV{'PBPROJ'}}:NP:/; #Solaris e.g.
[346]2485EOF
[684]2486 print SCRIPT << 'EOF';
2487 print PBOUT $_;
2488 }
2489 close(PBFILE);
2490 close(PBOUT);
2491 rename("$file.new",$file);
2492 chmod 0640,$file;
2493 }
[320]2494
[448]2495# Keep the VM in text mode
2496$file="/etc/inittab";
[450]2497if (-f $file) {
2498 open(PBFILE,$file) || die "Unable to open $file";
2499 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2500 while (<PBFILE>) {
2501 s/^(..):5:initdefault:$/$1:3:initdefault:/;
2502 print PBOUT $_;
2503 }
2504 close(PBFILE);
2505 close(PBOUT);
2506 rename("$file.new",$file);
2507 chmod 0640,$file;
[448]2508}
2509
[320]2510# pb has to be added to portage group on gentoo
2511
[888]2512# We need to have that pb_distro_init function
2513# Get it from Project-Builder::Distribution
[891]2514# And we now need the conf file required for this to work created above
[888]2515
[1064]2516my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch) = pb_distro_init();
[891]2517print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $darch))."\n";
2518
[346]2519# Adapt sudoers
[888]2520# sudo is not default on Solaris and needs to be installed first
2521# from http://www.sunfreeware.com/programlistsparc10.html#sudo
2522if ($dtype eq "pkg") {
2523 $file="/usr/local/etc/sudoers";
2524} else {
2525 $file="/etc/sudoers";
2526}
[346]2527open(PBFILE,$file) || die "Unable to open $file";
2528open(PBOUT,"> $file.new") || die "Unable to open $file.new";
2529while (<PBFILE>) {
2530EOF
[353]2531 print SCRIPT << "EOF";
2532 next if (/^$pbac->{$ENV{'PBPROJ'}} /);
[346]2533EOF
[353]2534 print SCRIPT << 'EOF';
[346]2535 s/Defaults[ \t]+requiretty//;
2536 print PBOUT $_;
2537}
2538close(PBFILE);
2539EOF
[353]2540 print SCRIPT << "EOF";
[1032]2541# Some distro force requiretty at compile time, so disable here
2542print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} !requiretty\n";
[1035]2543print PBOUT "Defaults:root !requiretty\n";
[353]2544# This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
[1032]2545print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} env_keep += \\\"http_proxy ftp_proxy\\\"\n";
[353]2546print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
[346]2547EOF
[353]2548 print SCRIPT << 'EOF';
[346]2549close(PBOUT);
2550rename("$file.new",$file);
2551chmod 0440,$file;
2552
2553EOF
[891]2554
2555 # We may need a proxy configuration. Get it from the local env
2556
2557 if (defined $ENV{'http_proxy'}) {
2558 print SCRIPT "\$ENV\{'http_proxy'\}=\"$ENV{'http_proxy'}\";\n";
2559 }
2560
2561 if (defined $ENV{'ftp_proxy'}) {
2562 print SCRIPT "\$ENV\{'ftp_proxy'\}=\"$ENV{'ftp_proxy'}\";\n";
2563 }
2564
2565 print SCRIPT << 'EOF';
[353]2566
[346]2567# Suse wants sudoers as 640
[1012]2568if ((($ddir eq "sles") && (($dver =~ /10/) || ($dver =~ /9/))) || (($ddir eq "opensuse") && ($dver =~ /10.[012]/))) {
[346]2569 chmod 0640,$file;
2570}
2571
[1109]2572# First install all required packages
2573pb_system("yum clean all","Cleaning yum env") if (($ddir eq "fedora") || ($ddir eq "asianux") || ($ddir eq "rhel"));
2574my ($ospkgdep) = pb_conf_get_if("ospkgdep");
2575
2576my $pkgdep = pb_distro_get_param($ddir,$dver,$darch,$ospkgdep,$dfam,$dtype,$dos);
2577pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,join(' ',split(/,/,$pkgdep))));
2578
2579EOF
2580 my $itype = pb_conf_get("pbinstalltype");
2581 if ($itype->{$ENV{'PBPROJ'}} =~ /^file/) {
2582 print SCRIPT << 'EOF';
2583# Then install manually the missing perl modules
2584my ($osperldep,$osperlver) = pb_conf_get_if("osperldep","osperlver");
2585
2586my $perldep = pb_distro_get_param($ddir,$dver,$darch,$osperldep,$dfam,$dtype,$dos);
2587foreach my $m (split(/,/,$perldep)) {
2588 # Skip empty deps
2589 next if ($m =~ /^\s*$/);
2590 my $dir = $m;
2591 $dir =~ s/-.*//;
2592 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}");
2593}
2594
[891]2595pb_system("rm -rf ProjectBuilder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/ProjectBuilder-latest.tar.gz ; gzip -cd ProjectBuilder-latest.tar.gz | tar xf - ; cd ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf ProjectBuilder-* ; rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; gzip -cd project-builder-latest.tar.gz | tar xf - ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf project-builder-* ;","Building Project-Builder");
[1109]2596EOF
2597 } elsif ($itype->{$ENV{'PBPROJ'}} =~ /^pkg/) {
2598 # pkg based install. We need to point to the project-builder.org repository
2599 print SCRIPT << 'EOF';
2600my ($pbpkg) = pb_conf_get_if("pbpkg");
2601
2602my $pkgforpb = pb_distro_get_param($ddir,$dver,$darch,$pbpkg,$dfam,$dtype,$depdos);
2603pb_distro_setuprepo($ddir,$dver,$darch,$dtype);
2604pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,join(' ',split(/,/,$pkgforpb))));
2605EOF
2606 } else {
2607 # Unknown install type
2608 die("Unknown install type $itype->{$ENV{'PBPROJ'}} for param pbinstalltype");
2609 }
2610 print SCRIPT << 'EOF';
[902]2611pb_system("pb 2>&1 | head -5",undef,"verbose");
[357]2612EOF
[681]2613 if ($vtype eq "ve") {
2614 print SCRIPT << 'EOF';
2615# For VE we need to umount some FS at the end
2616
2617pb_system("umount /proc");
[696]2618
2619# Create a basic network file if not already there
2620
2621my $nf="/etc/sysconfig/network";
[965]2622if ((! -f $nf) && ($dtype eq "rpm")) {
[696]2623 open(NF,"> $nf") || die "Unable to create $nf";
2624 print NF "NETWORKING=yes\n";
2625 print NF "HOSTNAME=localhost\n";
2626 close(NF);
2627}
2628chmod 0755,$nf;
[681]2629EOF
2630 }
2631
[891]2632 # Adds pb_distro_init and all functions needed from ProjectBuilder::Distribution and Base
[353]2633 foreach my $d (@INC) {
[891]2634 my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm","$d/ProjectBuilder/Conf.pm");
[405]2635 foreach my $f (@f) {
2636 if (-f "$f") {
2637 open(PBD,"$f") || die "Unable to open $f";
2638 while (<PBD>) {
[891]2639 next if (/^package/);
2640 next if (/^use Exporter/);
2641 next if (/^use ProjectBuilder::/);
2642 next if (/^our /);
[405]2643 print SCRIPT $_;
2644 }
2645 close(PBD);
[353]2646 }
[347]2647 }
2648 }
[353]2649 close(SCRIPT);
2650 chmod 0755,"$pbscript";
2651
[442]2652 # That build script needs to be run as root and force stop of VM at end
[353]2653 $pbaccount = "root";
[442]2654
2655 # Force shutdown of VM exept if it was already launched
[748]2656 my $pbforce = 0;
[442]2657 if ((! $vmexist) && ($vtype eq "vm")) {
[748]2658 $pbforce = 1;
[442]2659 }
2660
[748]2661 pb_script2v($pbscript,$vtype,$pbforce,$v);
[347]2662}
[353]2663return;
[346]2664}
2665
[772]2666# Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
2667sub pb_snap2v {
[748]2668
2669my $vtype = shift;
2670
[772]2671my ($vm,$all) = pb_get2v($vtype);
[748]2672
2673# Script generated
2674my $pbscript = "$ENV{'PBDESTDIR'}/snapv";
2675
[898]2676my ($pbac) = pb_conf_get($vtype."login");
2677
[748]2678foreach my $v (@$vm) {
[971]2679 # Get distro context
2680 my ($name,$ver,$darch) = split(/-/,$v);
2681 chomp($darch);
[1064]2682 my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
[971]2683 my ($vepath) = pb_conf_get("vepath");
2684
2685 # Test if an existing snapshot exists and remove it if there is a VE
2686 if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
2687 (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch")) {
2688 pb_system("sudo rm -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Removing previous snapshot $ddir-$dver-$darch.tar.gz");
2689 }
2690
[748]2691 # Name of the account to deal with for VM/VE
2692 # Do not use the one passed potentially with -a
2693 my ($vmexist,$vmpid);
2694
2695 # Prepare the script to be executed on the VM/VE
2696 # in $ENV{'PBDESTDIR'}/setupv
2697 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
2698
2699 print SCRIPT << 'EOF';
2700 #!/bin/bash
[776]2701 sleep 2
[748]2702EOF
2703 close(SCRIPT);
2704 chmod 0755,"$pbscript";
2705
2706 # Force shutdown of VM/VE
2707 # Force snapshot of VM/VE
[773]2708 pb_script2v($pbscript,$vtype,1,$v,1);
[748]2709}
2710return;
2711}
2712
[471]2713sub pb_announce {
2714
[473]2715 # Get all required parameters
[477]2716 my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
[471]2717 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
2718 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
2719 my @pkgs = @$pkg;
2720 my %pkgs;
2721 my $first = 0;
2722
[473]2723 # Command to find packages on repo
[471]2724 my $findstr = "find . ";
[473]2725 # Generated announce files
2726 my @files;
[471]2727
2728 foreach my $pbpkg (@pkgs) {
2729 if ($first != 0) {
2730 $findstr .= "-o ";
2731 }
2732 $first++;
2733 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
2734 $pbver = $pkgv->{$pbpkg};
2735 } else {
2736 $pbver = $ENV{'PBPROJVER'};
2737 }
2738 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
2739 $pbtag = $pkgt->{$pbpkg};
2740 } else {
2741 $pbtag = $ENV{'PBPROJTAG'};
2742 }
2743
[547]2744 # TODO: use virtual/real names here now
[1087]2745 $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver*\.ebuild\' ";
[473]2746
2747 my $chglog;
2748
2749 # Get project info on log file and generate tmp files used later on
2750 pb_cms_init($pbinit);
2751 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
2752 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
2753 $chglog = undef if (! -f $chglog);
2754
2755 open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
[585]2756 my %pb;
2757 $pb{'dtype'} = "announce";
2758 $pb{'realpkg'} = $pbpkg;
2759 $pb{'ver'} = $pbver;
2760 $pb{'tag'} = $pbtag;
2761 $pb{'suf'} = "N/A"; # Should not be empty even if unused
2762 $pb{'date'} = $pbdate;
2763 $pb{'chglog'} = $chglog;
2764 $pb{'packager'} = $pbpackager;
2765 $pb{'proj'} = $ENV{'PBPROJ'};
2766 $pb{'repo'} = $pbrepo;
2767 pb_changelog(\%pb,\*OUT,"yes");
[473]2768 close(OUT);
2769 push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
[471]2770 }
2771 $findstr .= " | grep -Ev \'src.rpm\'";
2772
2773 # Prepare the command to run and execute it
2774 open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
2775 print PBS "$findstr\n";
2776 close(PBS);
2777 chmod 0755,"$ENV{'PBTMP'}/pbscript";
2778 pb_send2target("Announce");
2779
[490]2780 # Get subject line
2781 my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
[495]2782 pb_log(0,"Please enter the title of your announce\n");
2783 pb_log(0,"(By default: $sl)\n");
[490]2784 my $sl2 = <STDIN>;
2785 $sl = $sl2 if ($sl2 !~ /^$/);
2786
[471]2787 # Prepare a template of announce
[473]2788 open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
[471]2789 print ANN << "EOF";
[490]2790$sl</p>
[471]2791
[473]2792<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]2793<p>
2794Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
2795</p>
2796<p>
2797EOF
2798 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
[473]2799 my $col = 2;
2800 my $i = 1;
2801 print ANN << 'EOF';
2802<TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
2803<TR>
2804EOF
[471]2805 while (<LOG>) {
[697]2806 print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
[473]2807 $i++;
2808 if ($i > $col) {
2809 print ANN "</TR>\n<TR>";
2810 $i = 1;
2811 }
[471]2812 }
2813 close(LOG);
[473]2814 print ANN << "EOF";
2815</TR>
2816</TABLE>
2817</p>
[471]2818
[473]2819<p>As usual source packages are also available in the same directory.</p>
2820
2821<p>
2822Changes are :
2823</p>
2824<p>
2825EOF
2826 # Get each package changelog content
2827 foreach my $f (sort(@files)) {
2828 open(IN,"$f") || die "Unable to read $f:$!";
2829 while (<IN>) {
2830 print ANN $_;
2831 }
2832 close(IN);
2833 print ANN "</p><p>\n";
2834 }
2835 print ANN "</p>\n";
[471]2836 close(ANN);
[473]2837
2838 # Allow for modification
[974]2839 my $editor = "vi";
2840 $editor = $ENV{'EDITOR'} if (defined $ENV{'EDITOR'});
2841 pb_system("$editor $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
[473]2842
2843 # Store it in DB for external usage (Web pages generation)
2844 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
2845
2846 my $precmd = "";
2847 if (! -f $db) {
2848 $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
2849 }
2850
2851 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
2852 { RaiseError => 1, AutoCommit => 1 })
2853 || die "Unable to connect to $db";
2854
2855 if ($precmd ne "") {
2856 my $sth = $dbh->prepare(qq{$precmd})
2857 || die "Unable to create table into $db";
2858 $sth->execute();
2859 }
2860
2861 # To read whole file
2862 local $/;
2863 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2864 my $announce = <ANN>;
2865 close(ANN);
2866
2867 pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
2868 my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
2869 || die "Unable to insert into $db";
2870 $sth->execute($pbdate, $announce);
[698]2871 $sth->finish();
[473]2872 $dbh->disconnect;
2873
2874 # Then deliver it on the Web
2875 # $TOOLHOME/livwww www
2876
2877 # Mail it to project's ML
2878 open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
2879 print ML << 'EOF';
2880<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
2881
2882<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
2883 <head>
2884 </head>
2885 <body>
2886 <p>
2887EOF
2888 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2889 while(<ANN>) {
2890 print ML $_;
2891 }
2892 print ML << 'EOF';
2893</body>
2894</html>
2895EOF
2896 close(ML);
2897
[477]2898 # To read whole file
2899 local $/;
2900 open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
2901 my $msg = <ANN>;
2902 close(ANN);
2903
2904 # Preparation of headers
[1109]2905 require Mail::Sendmail;
[477]2906
2907 my %mail = (
2908 To => $pbml->{$ENV{'PBPROJ'}},
2909 From => $pbpackager->{$ENV{'PBPROJ'}},
2910 Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
2911 Body => $msg,
[490]2912 Subject => "[ANNOUNCE] $sl",
[477]2913 );
2914
2915 # Send mail
[1109]2916 if (! sendmail(%mail)) {
2917 if ((defined $Mail::Sendmail::error) and (defined $Mail::Sendmail::log)) {
2918 die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
2919 }
2920 }
[471]2921}
2922
[547]2923#
2924# Creates a set of HTML file containing the news for the project
2925# based on what has been generated by the pb_announce function
2926#
2927sub pb_web_news2html {
2928
[556]2929 my $dest = shift || $ENV{'PBTMP'};
2930
[547]2931 # Get all required parameters
[1064]2932 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
[547]2933
2934 # DB of announces for external usage (Web pages generation)
2935 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
2936
2937 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
2938 { RaiseError => 1, AutoCommit => 1 })
2939 || die "Unable to connect to $db";
2940 # For date handling
2941 $ENV{LANGUAGE}="C";
[559]2942 my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
2943 my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
2944 pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
[547]2945 my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
[556]2946 my %news;
2947 $news{"cy"} = ""; # current year's news
2948 $news{"ly"} = ""; # last year news
2949 $news{"py"} = ""; # previous years news
2950 $news{"fp"} = ""; # first page news
[547]2951 my $cpt = 4; # how many news for first page
2952 # Extract info from DB
2953 foreach my $row (@$all) {
2954 my ($id, $date, $announce) = @$row;
[559]2955 $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
2956 $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
2957 $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
[556]2958 $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
[547]2959 $cpt--;
2960 }
[556]2961 pb_log(1,"news{fp}: ".$news{"fp"}."\n");
[547]2962 $dbh->disconnect;
[556]2963
2964 # Generate the HTML content
2965 foreach my $pref (keys %news) {
2966 open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
2967 print NEWS "$news{$pref}";
2968 close(NEWS);
2969 }
[547]2970}
2971
[556]2972
[347]2973# Return the SSH key file to use
2974# Potentially create it if needed
2975
2976sub pb_ssh_get {
2977
2978my $create = shift || 0; # Do not create keys by default
2979
2980# Check the SSH environment
2981my $keyfile = undef;
2982
2983# We have specific keys by default
2984$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
[348]2985if (!(-e $keyfile) && ($create eq 1)) {
[347]2986 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
2987}
2988
2989$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
2990$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
2991$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
2992die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
2993return($keyfile);
2994}
2995
2996
[145]2997# Returns the pid of a running VM command using a specific VM file
[142]2998sub pb_check_ps {
2999 my $vmcmd = shift;
3000 my $vmm = shift;
3001 my $vmexist = 0; # FALSE by default
3002
3003 open(PS, "ps auxhww|") || die "Unable to call ps";
3004 while (<PS>) {
3005 next if (! /$vmcmd/);
3006 next if (! /$vmm/);
3007 my ($void1, $void2);
3008 ($void1, $vmexist, $void2) = split(/ +/);
3009 last;
3010 }
3011 return($vmexist);
3012}
3013
3014
[77]3015sub pb_extract_build_files {
[25]3016
3017my $src=shift;
3018my $dir=shift;
[26]3019my $ddir=shift;
[500]3020my $mandatory=shift || "spec";
[28]3021my @files;
[25]3022
[500]3023my $flag = "mayfail" if ($mandatory eq "patch");
3024my $res;
3025
[188]3026if ($src =~ /tar\.gz$/) {
[500]3027 $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
[188]3028} elsif ($src =~ /tar\.bz2$/) {
[500]3029 $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
[188]3030} else {
3031 die "Unknown compression algorithm for $src";
3032}
[500]3033# If not mandatory return now
3034return() if (($res != 0) and ($mandatory eq "patch"));
[25]3035opendir(DIR,"$dir") || die "Unable to open directory $dir";
3036foreach my $f (readdir(DIR)) {
3037 next if ($f =~ /^\./);
[500]3038 # Skip potential patch dir
3039 next if ($f =~ /^pbpatch/);
[26]3040 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[315]3041 pb_log(2,"mv $dir/$f $ddir\n");
[28]3042 push @files,"$ddir/$f";
[25]3043}
3044closedir(DIR);
[26]3045# Not enough but still a first cleanup
[74]3046pb_rm_rf("$dir");
[28]3047return(@files);
[25]3048}
3049
[315]3050sub pb_list_bfiles {
3051
3052my $dir = shift;
3053my $pbpkg = shift;
3054my $bfiles = shift;
3055my $pkgfiles = shift;
3056my $supfiles = shift;
3057
3058opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
3059foreach my $f (readdir(BDIR)) {
3060 next if ($f =~ /^\./);
[1098]3061 if (-d $f) {
3062 # Recurse for directories (Debian 3.0 format e.g.)
3063 pb_list_bfiles($f,$pbpkg,$bfiles,$pkgfiles,$supfiles);
3064 next;
3065 }
[315]3066 $bfiles->{$f} = "$dir/$f";
[340]3067 $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
[315]3068 if (defined $supfiles->{$pbpkg}) {
3069 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
3070 }
3071}
3072closedir(BDIR);
3073}
3074
[395]3075
3076#
3077# Return the list of packages we are working on in a non CMS action
3078#
3079sub pb_get_pkg {
3080
3081my @pkgs = ();
3082
3083my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
3084@pkgs = keys %$var;
3085
3086pb_log(0,"Packages: ".join(',',@pkgs)."\n");
3087return(\@pkgs);
3088}
3089
[986]3090#
3091# Return the postinstall line if needed
3092#
3093
3094sub pb_get_postinstall {
3095
[989]3096my $ddir = shift;
3097my $dver = shift;
3098my $darch = shift;
3099my $rbspi = shift;
3100my $vestyle = shift;
[986]3101my $post = "";
3102
3103# Do we have a local post-install script
3104if ($vestyle eq "rinse") {
3105 $post = "--post-install ";
3106} elsif ($vestyle eq "rpmbootstrap") {
3107 $post = "-s ";
3108}
3109
[989]3110my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbspi);
[986]3111if ($postparam eq "") {
3112 $post = "";
3113} else {
3114 $post .= $postparam;
3115}
3116return($post);
3117}
3118
[395]31191;
Note: See TracBrowser for help on using the repository browser.