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

Last change on this file since 888 was 888, checked in by Bruno Cornec, 14 years ago

Begin to adapt setup_v for a Solaris guest

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