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

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