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

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