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

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

r4002@localhost: bruno | 2010-09-02 23:55:24 +0200

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