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

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