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

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