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

Last change on this file since 529 was 529, checked in by Bruno Cornec, 16 years ago

Building packages other than rpms should also be verbose

  • Property svn:executable set to *
File size: 69.9 KB
RevLine 
[5]1#!/usr/bin/perl -w
2#
3# Project Builder main application
4#
5# $Id$
6#
7# Copyright B. Cornec 2007
8# Provided under the GPL v2
9
[22]10# Syntax: see at end
[9]11
[18]12use strict 'vars';
[331]13use Getopt::Long qw(:config auto_abbrev no_ignore_case);
[9]14use Data::Dumper;
15use English;
[16]16use File::Basename;
[26]17use File::Copy;
[395]18use File::stat;
19use File::Temp qw(tempdir);
[13]20use POSIX qw(strftime);
[17]21use lib qw (lib);
[329]22use ProjectBuilder::Version;
[318]23use ProjectBuilder::Base;
[512]24use ProjectBuilder::Display;
[405]25use ProjectBuilder::Conf;
26use ProjectBuilder::Distribution;
27use ProjectBuilder::CMS;
[416]28use ProjectBuilder::Env;
[405]29use ProjectBuilder::Filter;
[473]30use ProjectBuilder::Changelog;
[477]31use Mail::Sendmail;
[473]32
[397]33# Global variables
[5]34my %opts; # CLI Options
[9]35my $action; # action to realize
[320]36my $test = "FALSE"; # Not used
37my $force = 0; # Force VE/VM rebuild
38my $option = ""; # Not used
39my @pkgs; # list of packages
[95]40my $pbtag; # Global Tag variable
41my $pbver; # Global Version variable
[141]42my $pbscript; # Name of the script
[77]43my %pbver; # per package
44my %pbtag; # per package
[53]45my $pbrev; # Global REVISION variable
[152]46my $pbaccount; # Login to use to connect to the VM
[162]47my $pbport; # Port to use to connect to the VM
[199]48my $newver; # New version to create
[331]49my $iso; # ISO image for the VM to create
[5]50
[320]51my @date = pb_get_date();
52my $pbdate = strftime("%Y-%m-%d", @date);
[5]53
[331]54=pod
55
56=head1 NAME
57
58pb, aka project-builder.org - builds packages for your projects
59
60=head1 DESCRIPTION
61
62pb helps you build various packages directly from your project sources.
63Those sources could be handled by a CMS (Configuration Management System)
64such as Subversion, CVS, ... or being a simple reference to a compressed tar file.
65It's based on a set of configuration files, a set of provided macros to help
66you keeping build files as generic as possible. For example, a single .spec
67file should be required to generate for all rpm based distributions, even
68if you could also have multiple .spec files if required.
69
70=head1 SYNOPSIS
71
[332]72pb [-vhq][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...]
[331]73
[332]74pb [--verbose][--help][--man][--quiet][--revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...]
[331]75
76=head1 OPTIONS
77
78=over 4
79
80=item B<-v|--verbose>
81
82Print a brief help message and exits.
83
84=item B<-q|--quiet>
85
86Do not print any output.
87
88=item B<-h|--help>
89
90Print a brief help message and exits.
91
92=item B<--man>
93
94Prints the manual page and exits.
95
96=item B<-m|--machine machine1[,machine2,...]>
97
98Name of the Virtual Machines (VM) or Virtual Environments (VE) you want to build on (coma separated).
99All if none precised (or use the env variable PBV).
100
101=item B<-s|--script script>
102
103Name of the script you want to execute on the related VMs or VEs.
104
105=item B<-i|--iso iso_image>
106
107Name of the ISO image of the distribution you want to install on the related VMs.
108
109=item B<-a|--account account>
110
111Name of the account to use to connect on the related VMs.
112
113=item B<-P|--port port_number>
114
115Port number to use to connect on the related VMs.\n";
116
117=item B<-p|--project project_name>
118
119Name of the project you're working on (or use the env variable PBPROJ)
120
121=item B<-r|--revision revision>
122
123Path Name of the project revision under the CMS (or use the env variable PBROOT)
124
125=item B<-V|--version new_version>
126
127New version of the project to create based on the current one.
128
129=back
130
131=head1 ARGUMENTS
132
133<action> can be:
134
135=over 4
136
137=item B<cms2build>
138
139Create tar files for the project under your CMS.
140CMS supported are SVN and CVS
141parameters are packages to build
142if not using default list
143
144=item B<build2pkg>
145
146Create packages for your running distribution
147
148=item B<cms2pkg>
149
150cms2build + build2pkg
151
152=item B<build2ssh>
153
154Send the tar files to a SSH host
155
156=item B<cms2ssh>
157
158cms2build + build2ssh
159
160=item B<pkg2ssh>
161
162Send the packages built to a SSH host
163
164=item B<build2vm>
165
166Create packages in VMs, launching them if needed
167and send those packages to a SSH host once built
168VM type supported are QEMU
169
170=item B<build2ve>
171
172Create packages in VEs, creating it if needed
173and send those packages to a SSH host once built
174
175=item B<cms2vm>
176
177cms2build + build2vm
178
179=item B<cms2ve>
180
181cms2build + build2ve
182
183=item B<launchvm>
184
185Launch one virtual machine
186
187=item B<launchve>
188
189Launch one virtual environment
190
191=item B<script2vm>
192
193Launch one virtual machine if needed
194and executes a script on it
195
196=item B<script2ve>
197
198Execute a script in a virtual environment
199
200=item B<newvm>
201
202Create a new virtual machine
203
204=item B<newve>
205
206Create a new virtual environment
207
[346]208=item B<setupvm>
209
210Setup a virtual machine for pb usage
211
212=item B<setupve>
213
214Setup a virtual environment for pb usage
215
[331]216=item B<newver>
217
218Create a new version of the project derived
219from the current one
220
221=item B<newproj>
222
223Create a new project and a template set of
224configuration files under pbconf
225
[471]226=item B<announce>
227
228Announce the availability of the project through various means
229
[331]230=back
231
232<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).
233
234=head1 WEB SITES
235
236The 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/>.
237
238=head1 USER MAILING LIST
239
240None exists for the moment.
241
242=head1 CONFIGURATION FILES
243
244Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
245
246Here is an example of such a configuration file:
247
248 #
249 # Define for each project the URL of its pbconf repository
250 # No default option allowed here as they need to be all different
251 #
252 # URL of the pbconf content
253 # This is the format of a classical URL with the extension of additional schema such as
254 # svn+ssh, cvs+ssh, ...
255 #
256 pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
257
258 # This is normaly defined in the project's configuration file
259 # Url of the project
260 #
261 pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
262
263 # All these URLs needs to be defined here as the are the entry point
264 # for how to build packages for the project
265 #
266 pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
267 pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
268 pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
269 pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
270
271 # Under that dir will take place everything related to pb
272 # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
273 # to your VMs/chroot/...
274 # if not defined then /var/cache
275 pbdefdir default = $ENV{'HOME'}/project-builder
276 pbdefdir pb = $ENV{'HOME'}
277 pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
278 pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
279
280 # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
281 # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
282 pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
283 pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
284
285 # pbdir points to the directory where the CMS content of the pburl is checked out
286 # If not defined, pbdir is under pbdefdir/pbproj
287 # Only defined if we have access to the dev of the project
288 pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
289 pbdir mondorescue = $ENV{'HOME'}/mondo/svn
290
291 # -daemonize doesn't work with qemu 0.8.2
292 vmopt default = -m 384
293
294=head1 AUTHORS
295
296The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
297
298=head1 COPYRIGHT
299
300Project-Builder.org is distributed under the GPL v2.0 license
301described in the file C<COPYING> included with the distribution.
302
303=cut
304
305# ---------------------------------------------------------------------------
306
307# Old syntax
308#getopts('a:fhi:l:m:P:p:qr:s:vV:',\%opts);
309
[75]310my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[331]311
[397]312# Initialize the syntax string
313
314pb_syntax_init("pb (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
315
[331]316GetOptions("help|?|h" => \$opts{'h'},
317 "man" => \$opts{'man'},
318 "verbose|v+" => \$opts{'v'},
319 "quiet|q" => \$opts{'q'},
320 "log-files|l=s" => \$opts{'l'},
321 "force|f" => \$opts{'f'},
322 "account|a=s" => \$opts{'a'},
323 "revision|r=s" => \$opts{'r'},
324 "script|s=s" => \$opts{'s'},
325 "machines|mock|m=s" => \$opts{'m'},
326 "port|P=i" => \$opts{'P'},
327 "project|p=s" => \$opts{'p'},
328 "iso|i=s" => \$opts{'i'},
329 "version|V=s" => \$opts{'V'},
330) || pb_syntax(-1,0);
331
[21]332if (defined $opts{'h'}) {
[331]333 pb_syntax(0,1);
[21]334}
[331]335if (defined $opts{'man'}) {
336 pb_syntax(0,2);
337}
[21]338if (defined $opts{'v'}) {
[495]339 $pbdebug = $opts{'v'};
[21]340}
[320]341if (defined $opts{'f'}) {
342 $force=1;
343}
[21]344if (defined $opts{'q'}) {
[495]345 $pbdebug=-1;
[21]346}
[22]347if (defined $opts{'l'}) {
[495]348 open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
349 $pbLOG = \*pbLOG;
350 $pbdebug = 0 if ($pbdebug == -1);
[22]351 }
[495]352pb_log_init($pbdebug, $pbLOG);
353pb_display_init("text","");
[315]354
[67]355# Handle root of the project if defined
356if (defined $opts{'r'}) {
[340]357 $ENV{'PBROOTDIR'} = $opts{'r'};
[67]358}
[91]359# Handle virtual machines if any
360if (defined $opts{'m'}) {
[320]361 $ENV{'PBV'} = $opts{'m'};
[91]362}
[141]363if (defined $opts{'s'}) {
364 $pbscript = $opts{'s'};
365}
[152]366if (defined $opts{'a'}) {
367 $pbaccount = $opts{'a'};
[347]368 die "option -a requires a -s script option" if (not defined $pbscript);
[152]369}
[162]370if (defined $opts{'P'}) {
371 $pbport = $opts{'P'};
372}
[199]373if (defined $opts{'V'}) {
374 $newver = $opts{'V'};
375}
[262]376if (defined $opts{'i'}) {
377 $iso = $opts{'i'};
378}
[108]379
380# Get Action
381$action = shift @ARGV;
[331]382die pb_syntax(-1,1) if (not defined $action);
[108]383
[314]384my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
[273]385my $pbinit = undef;
386$pbinit = 1 if ($action =~ /^newproj$/);
[108]387
[59]388# Handles project name if any
[108]389# And get global params
[353]390($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action);
[59]391
[315]392pb_log(0,"Project: $ENV{'PBPROJ'}\n");
393pb_log(0,"Action: $action\n");
[9]394
395# Act depending on action
396if ($action =~ /^cms2build$/) {
[77]397 pb_cms2build();
398} elsif ($action =~ /^build2pkg$/) {
399 pb_build2pkg();
400} elsif ($action =~ /^cms2pkg$/) {
401 pb_cms2build();
402 pb_build2pkg();
[88]403} elsif ($action =~ /^build2ssh$/) {
404 pb_build2ssh();
[220]405} elsif ($action =~ /^cms2ssh$/) {
406 pb_cms2build();
407 pb_build2ssh();
[88]408} elsif ($action =~ /^pkg2ssh$/) {
409 pb_pkg2ssh();
[320]410} elsif ($action =~ /^build2ve$/) {
411 pb_build2v("ve");
[91]412} elsif ($action =~ /^build2vm$/) {
[320]413 pb_build2v("vm");
414} elsif ($action =~ /^cms2ve$/) {
415 pb_cms2build();
416 pb_build2v("ve");
[91]417} elsif ($action =~ /^cms2vm$/) {
418 pb_cms2build();
[320]419 pb_build2v("vm");
[141]420} elsif ($action =~ /^launchvm$/) {
[320]421 pb_launchv("vm",$ENV{'PBV'},0);
422} elsif ($action =~ /^launchve$/) {
423 pb_launchv("ve",$ENV{'PBV'},0);
[142]424} elsif ($action =~ /^script2vm$/) {
[320]425 pb_script2v($pbscript,"vm");
426} elsif ($action =~ /^script2ve$/) {
427 pb_script2v($pbscript,"ve");
[199]428} elsif ($action =~ /^newver$/) {
429 pb_newver();
[320]430} elsif ($action =~ /^newve$/) {
431 pb_launchv("ve",$ENV{'PBV'},1);
[262]432} elsif ($action =~ /^newvm$/) {
[320]433 pb_launchv("vm",$ENV{'PBV'},1);
[346]434} elsif ($action =~ /^setupve$/) {
[353]435 pb_setup_v("ve");
[346]436} elsif ($action =~ /^setupvm$/) {
[353]437 pb_setup_v("vm");
[273]438} elsif ($action =~ /^newproj$/) {
439 # Nothing to do - already done in pb_env_init
[106]440} elsif ($action =~ /^clean$/) {
[471]441 # TBC
442} elsif ($action =~ /^announce$/) {
[498]443 # For announce only. Require avoids the systematic load of these modules
444 require DBI;
445
[471]446 pb_announce();
[77]447} else {
[315]448 pb_log(0,"\'$action\' is not available\n");
[331]449 pb_syntax(-2,1);
[77]450}
451
452sub pb_cms2build {
453
[357]454 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
455 my @pkgs = @$pkg;
456 my %pkgs;
[499]457 my %pb; # Structure to store conf info
[9]458
[341]459 my ($scheme, $uri) = pb_cms_init($pbinit);
[331]460
[313]461 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
[174]462
[429]463 # declare packager and repo for filtering
464 my ($tmp1, $tmp2) = pb_conf_get("pbpackager","pbrepo");
465 $ENV{'PBPACKAGER'} = $tmp1->{$ENV{'PBPROJ'}};
466 $ENV{'PBREPO'} = $tmp2->{$ENV{'PBPROJ'}};
[174]467
[27]468 foreach my $pbpkg (@pkgs) {
[115]469 $ENV{'PBPKG'} = $pbpkg;
[98]470 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
471 $pbver = $pkgv->{$pbpkg};
[9]472 } else {
[353]473 $pbver = $ENV{'PBPROJVER'};
[9]474 }
[98]475 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
476 $pbtag = $pkgt->{$pbpkg};
[9]477 } else {
[353]478 $pbtag = $ENV{'PBPROJTAG'};
[9]479 }
[95]480
[16]481 $pbrev = $ENV{'PBREVISION'};
[319]482 pb_log(0,"\n");
483 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
[9]484 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
[16]485 # Clean up dest if necessary. The export will recreate it
[27]486 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
[74]487 pb_rm_rf($dest) if (-d $dest);
[9]488
489 # Export CMS tree for the concerned package to dest
490 # And generate some additional files
491 $OUTPUT_AUTOFLUSH=1;
[29]492
[9]493 # computes in which dir we have to work
[113]494 my $dir = $defpkgdir->{$pbpkg};
495 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
[315]496 pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
[9]497
[340]498 # Exporting from CMS
499 pb_cms_export($uri,"$ENV{'PBDIR'}/$dir",$dest);
[315]500
[435]501 # Generated fake content for test versions to speed up stuff
502 my ($testver) = pb_conf_get_if("testver");
503 my $chglog;
[285]504
[448]505 # Get project info on authors and log file
506 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
507 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
508 $chglog = undef if (! -f $chglog);
[285]509
[448]510 my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
511 $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
512 $authors = "/dev/null" if (! -f $authors);
[435]513
[448]514 # Extract cms log history and store it
515 if ((defined $chglog) && (! -f "$dest/NEWS")) {
516 pb_log(2,"Generating NEWS file from $chglog\n");
517 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
[285]518 }
[448]519 pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
[29]520
[21]521 my %build;
[435]522 my @pt;
523 my $tmpl = "";
[500]524 my %patches;
[91]525
[328]526 @pt = pb_conf_get_if("vmlist","velist");
[340]527 if (defined $pt[0]->{$ENV{'PBPROJ'}}) {
528 $tmpl .= $pt[0]->{$ENV{'PBPROJ'}};
529 }
530 if (defined $pt[1]->{$ENV{'PBPROJ'}}) {
531 # the 2 lists needs to be grouped with a ',' separated them
532 if ($tmpl ne "") {
533 $tmpl .= ",";
534 }
535 $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
536 }
[499]537
538 # Setup %pb structure to allow filtering later on on files using that structure
539 $pb{'tag'} = $pbtag;
540 $pb{'rev'} = $pbrev;
541 $pb{'pkg'} = $pbpkg;
542 $pb{'ver'} = $pbver;
543 $pb{'date'} = $pbdate;
544 $pb{'defpkgdir'} = $defpkgdir;
545 $pb{'extpkgdir'} = $extpkgdir;
546 $pb{'chglog'} = $chglog;
547 $pb{'packager'} = $ENV{'PBPACKAGER'};
548 $pb{'proj'} = $ENV{'PBPROJ'};
549 $pb{'repo'} = $ENV{'PBREPO'};
[500]550 $pb{'patches'} = \%patches;
551 pb_log(2,"DEBUG: pb: ".Dumper(%pb)."\n");
[499]552
[340]553 foreach my $d (split(/,/,$tmpl)) {
[315]554 my ($name,$ver,$arch) = split(/-/,$d);
555 chomp($arch);
[499]556 my ($ddir, $dver, $dfam);
557 ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'}) = pb_distro_init($name,$ver);
558 pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
[315]559 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
[13]560
[16]561 # Filter build files from the less precise up to the most with overloading
[13]562 # Filter all files found, keeping the name, and generating in dest
[16]563
[340]564 # Find all build files first relatively to PBROOTDIR
[300]565 # Find also all specific files referenced in the .pb conf file
[320]566 my %bfiles = ();
567 my %pkgfiles = ();
[500]568 $build{"$ddir-$dver-$arch"} = "yes";
[315]569
[499]570 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
571 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
[340]572 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
573 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
574 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
575 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
576 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
577 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
[500]578 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
579 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
[13]580 } else {
[500]581 $build{"$ddir-$dver-$arch"} = "no";
[13]582 next;
583 }
[315]584 pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
[13]585
[15]586 # Get all filters to apply
[499]587 my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
[15]588
[500]589 # Prepare local patches for this distro - They are always applied first - May be a problem one day
[494]590 foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
[500]591 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
592 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
593 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$pb{'dtype'}$/));
594 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$pb{'dtype'}$/);
595 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
596 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
597 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
598 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
599 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
600 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
601 $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
602 $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
[494]603 }
604
[500]605 # Prepare also remote patches to be included - Applied after the local ones
606 foreach my $p ("all","$pb{'dtype'}","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
607 my $f = "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch.$p";
608 next if (not -f $f);
609 if (not open(PATCH,$f)) {
610 pb_display("Unable to open existing external patch file content $f\n");
611 next;
612 }
613 while (<PATCH>) {
614 chomp();
615 $patches{"$ddir-$dver-$arch"} .= "," if (defined $patches{"$ddir-$dver-$arch"});
616 $patches{"$ddir-$dver-$arch"} .= "$_";
617 }
618 close(PATCH);
619 }
620 pb_log(2,"DEBUG: pb->patches: ".Dumper($pb{'patches'})."\n");
621
[19]622 # Apply now all the filters on all the files concerned
623 # destination dir depends on the type of file
624 if (defined $ptr) {
[500]625 # For patch support
626 $pb{'tuple'} = "$ddir-$dver-$arch";
[300]627 foreach my $f (values %bfiles,values %pkgfiles) {
[500]628 pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
[16]629 }
[15]630 }
[18]631 }
[315]632 my @found;
633 my @notfound;
634 foreach my $b (keys %build) {
635 push @found,$b if ($build{$b} =~ /yes/);
636 push @notfound,$b if ($build{$b} =~ /no/);
[21]637 }
[453]638 pb_log(0,"Build files generated for ".join(',',sort(@found))."\n");
639 pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
[500]640 pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
641
[236]642 # Get the generic filter (all.pbf) and
643 # apply those to the non-build files including those
644 # generated by pbinit if applicable
645
646 # Get only all.pbf filter
[357]647 my $ptr = pb_get_filters($pbpkg);
[236]648
649 my $liste ="";
650 if (defined $filteredfiles->{$pbpkg}) {
651 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
[499]652 pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
[238]653 $liste = "$f $liste";
[236]654 }
655 }
[315]656 pb_log(2,"Files ".$liste."have been filtered\n");
[236]657
[500]658 # Filter potential patches (local + remote)
659 pb_log(0,"Delivering and compressing patches ");
660 foreach my $v (keys %patches) {
661 pb_mkdir_p("$dest/pbconf/$v/pbpatch");
662 foreach my $pf (split(/,/,$patches{$v})) {
663 my $pp = basename($pf);
664 pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
665 pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
666 pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
667 }
668 pb_log(0,"$patches{$v} ");
[499]669 }
[500]670 pb_log(0,"\n");
[499]671
[265]672 # Prepare the dest directory for archive
[340]673 if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
[499]674 pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
[266]675 chmod 0755,"$ENV{'PBTMP'}/pbinit";
[490]676 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
[265]677 }
678
[18]679 # Archive dest dir
[69]680 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
[25]681 # Possibility to look at PBSRC to guess more the filename
[493]682 pb_system("tar cfz $pbpkg-$pbver.tar.gz --exclude=$pbpkg-$pbver/pbconf $pbpkg-$pbver","Creating $pbpkg tar files compressed");
[344]683 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
[493]684 pb_system("tar cfz $pbpkg-$pbver.pbconf.tar.gz $pbpkg-$pbver/pbconf","Creating pbconf tar files compressed");
685 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz\n");
[83]686
[357]687 # Keep track of version-tag per pkg
688 $pkgs{$pbpkg} = "$pbver-$pbtag";
[83]689
[288]690 # Final cleanup
691 pb_rm_rf($dest) if (-d $dest);
[9]692 }
[357]693
694 # Keep track of per package version
695 pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
696 open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
697 foreach my $pbpkg (@pkgs) {
698 print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
699 }
700 close(PKG);
701
702 # Keep track of what is generated by default
703 # We need to store the dir and info on version-tag
704 # Base our content on the existing .pb file
705 copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
706 open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
707 print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
708 print LAST "pbprojver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
709 print LAST "pbprojtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
710 print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
711 close(LAST);
[77]712}
[22]713
[77]714sub pb_build2pkg {
715
[22]716 # Get the running distro to build on
[99]717 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
[315]718 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
[22]719
[353]720 # Get list of packages to build
[83]721 # Get content saved in cms2build
[353]722 my $ptr = pb_get_pkg();
723 @pkgs = @$ptr;
724
[500]725 my $arch = pb_get_arch();
726
[353]727 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
[83]728 $pkg = { } if (not defined $pkg);
729
[25]730 chdir "$ENV{'PBBUILDDIR'}";
[126]731 my $made = ""; # pkgs made during build
[27]732 foreach my $pbpkg (@pkgs) {
[88]733 my $vertag = $pkg->{$pbpkg};
[77]734 # get the version of the current package - maybe different
735 ($pbver,$pbtag) = split(/-/,$vertag);
736
[27]737 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[493]738 my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
[315]739 pb_log(2,"Source file: $src\n");
[493]740 pb_log(2,"Pbconf file: $src2\n");
[25]741
[315]742 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
[25]743 if ($dtype eq "rpm") {
744 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
[28]745 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
[96]746 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]747 }
[25]748 }
749
[315]750 # Remove in case a previous link/file was there
[301]751 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
[188]752 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
[25]753 # We need to first extract the spec file
[500]754 my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$ENV{'PBBUILDDIR'}/SPECS","spec");
[25]755
[493]756 # We need to handle potential patches to upstream sources
[500]757 pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
[493]758
[315]759 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
[25]760 # set LANGUAGE to check for correct log messages
761 $ENV{'LANGUAGE'}="C";
[459]762 # Older Redhat use _target_platform in %configure incorrectly
763 my $specialdef = "";
764 if (($ddir eq "redhat") || (($ddir eq "rhel") && ($dver eq "2.1"))) {
765 $specialdef = "--define \'_target_platform \"\"\'";
766 }
[28]767 foreach my $f (@specfile) {
768 if ($f =~ /\.spec$/) {
[483]769 pb_system("rpmbuild $specialdef --define \'packager $ENV{'PBPACKAGER'}\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
[28]770 last;
771 }
772 }
[136]773 $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
[149]774 if (-f "/usr/bin/rpmlint") {
[471]775 pb_system("rpmlint $made","Checking validity of rpms with rpmlint","verbose");
[150]776 }
[118]777 } elsif ($dtype eq "deb") {
[149]778 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
[274]779 pb_system("tar xfz $src","Extracting sources");
[493]780 pb_system("tar xfz $src2","Extracting pbconf");
[149]781
782 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[310]783 pb_rm_rf("debian");
[500]784 symlink "pbconf/$ddir-$dver-$arch","debian" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
[199]785 chmod 0755,"debian/rules";
[448]786 if ($dver !~ /[0-9]/) {
787 # dpkg-deb doesn't accept non digit versions. removing checks
788 # dpkg-source checks upper case when generating perl modules
789 }
[529]790 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
[136]791 $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
[315]792 if (-f "/usr/bin/lintian") {
[529]793 pb_system("lintian $made","Checking validity of debs with lintian","verbose");
[315]794 }
[87]795 } elsif ($dtype eq "ebuild") {
[149]796 my @ebuildfile;
797 # For gentoo we need to take pb as subsystem name
[295]798 # We put every apps here under sys-apps. hope it's correct
[435]799 # We use pb's home dir in order to have a single OVERLAY line
[295]800 my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
801 pb_mkdir_p($tmpd) if (! -d "$tmpd");
802 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
[149]803
[295]804 # We need to first extract the ebuild file
[500]805 @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$tmpd","ebuild");
[149]806
807 # Prepare the build env for gentoo
808 my $found = 0;
[295]809 my $pbbd = $ENV{'HOME'};
[150]810 $pbbd =~ s|/|\\/|g;
[295]811 if (-r "/etc/make.conf") {
812 open(MAKE,"/etc/make.conf");
813 while (<MAKE>) {
814 $found = 1 if (/$pbbd\/portage/);
815 }
816 close(MAKE);
[149]817 }
818 if ($found == 0) {
[295]819 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
[149]820 }
[295]821 #$found = 0;
822 #if (-r "/etc/portage/package.keywords") {
823 #open(KEYW,"/etc/portage/package.keywords");
824 #while (<KEYW>) {
825 #$found = 1 if (/portage\/pb/);
826 #}
827 #close(KEYW);
828 #}
829 #if ($found == 0) {
830 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
831 #}
[149]832
833 # Build
834 foreach my $f (@ebuildfile) {
835 if ($f =~ /\.ebuild$/) {
[295]836 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
[529]837 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
[295]838 # Now move it where pb expects it
839 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
840 move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
[149]841 }
842 }
843
[295]844 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
[437]845 } elsif ($dtype eq "tgz") {
846 # Slackware family
[435]847 $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
848
849 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
850 pb_system("tar xfz $src","Extracting sources");
[493]851 pb_system("tar xfz $src2","Extracting pbconf");
[435]852 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[500]853 symlink "pbconf/$ddir-$dver-$arch","install" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
[435]854 if (-x "install/pbslack") {
855 pb_system("./install/pbslack","Building package");
[529]856 pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
[435]857 }
[87]858 } else {
[118]859 die "Unknown dtype format $dtype";
[87]860 }
861 }
[118]862 # Keep track of what is generated so that we can get them back from VMs
[353]863 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]864 print KEEP "$made\n";
865 close(KEEP);
[87]866}
867
[88]868sub pb_build2ssh {
[320]869 pb_send2target("Sources");
[90]870}
[87]871
[90]872sub pb_pkg2ssh {
[320]873 pb_send2target("Packages");
[90]874}
875
[108]876# By default deliver to the the public site hosting the
[320]877# ftp structure (or whatever) or a VM/VE
878sub pb_send2target {
[90]879
880 my $cmt = shift;
[320]881 my $v = shift || undef;
[142]882 my $vmexist = shift || 0; # 0 is FALSE
[200]883 my $vmpid = shift || 0; # 0 is FALSE
[320]884
[444]885 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
[320]886 my $host = "sshhost";
887 my $login = "sshlogin";
888 my $dir = "sshdir";
889 my $port = "sshport";
890 my $conf = "sshconf";
891 my $rebuild = "sshrebuild";
[415]892 my $tmout = "vmtmout";
893 my $path = "vmpath";
[348]894 if (($cmt eq "vm") || ($cmt eq "Script")) {
[320]895 $login = "vmlogin";
[322]896 $dir = "pbdefdir";
[320]897 $tmout = "vmtmout";
898 $rebuild = "vmrebuild";
899 # Specific VM
900 $host = "vmhost";
901 $port = "vmport";
902 } elsif ($cmt eq "ve") {
903 $login = "velogin";
[322]904 $dir = "pbdefdir";
[320]905 $tmout = "vetmout";
906 # Specific VE
907 $path = "vepath";
908 $conf = "veconf";
909 $rebuild = "verebuild";
910 }
[158]911 my $cmd = "";
[471]912 my $src = "";
913 my ($odir,$over,$oarch) = (undef, undef, undef);
914 my ($ddir, $dver, $dfam, $dtype, $pbsuf);
[90]915
[471]916 if ($cmt ne "Announce") {
917 my $ptr = pb_get_pkg();
918 @pkgs = @$ptr;
[87]919
[471]920 # Get the running distro to consider
921 if (defined $v) {
922 ($odir,$over,$oarch) = split(/-/,$v);
923 }
924 ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
925 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
[87]926
[471]927 # Get list of packages to build
928 # Get content saved in cms2build
929 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
930 $pkg = { } if (not defined $pkg);
[87]931
[471]932 chdir "$ENV{'PBBUILDDIR'}";
933 foreach my $pbpkg (@pkgs) {
934 my $vertag = $pkg->{$pbpkg};
935 # get the version of the current package - maybe different
936 ($pbver,$pbtag) = split(/-/,$vertag);
[87]937
[471]938 if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
[493]939 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
[471]940 if ($cmd eq "") {
941 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
942 } else {
943 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
944 }
[166]945 }
[118]946 }
[471]947 # Adds conf file for availability of conf elements
948 pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
[118]949 }
[417]950
[320]951 if (($cmt eq "vm") || ($cmt eq "ve")) {
[444]952 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
[492]953 } elsif ($cmt eq "Script") {
954 $src="$src $ENV{'PBDESTDIR'}/pbscript";
955 } elsif ($cmt eq "Announce") {
[471]956 $src="$src $ENV{'PBTMP'}/pbscript";
[118]957 } elsif ($cmt eq "Packages") {
958 # Get package list from file made during build2pkg
[353]959 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[126]960 $src = <KEEP>;
[118]961 chomp($src);
962 close(KEEP);
[444]963 $src="$src $ENV{'PBBUILDDIR'}/pbscript" if ($cmt ne "Sources");
[87]964 }
[320]965 # Remove potential leading spaces (cause problem with basename)
[132]966 $src =~ s/^ *//;
[129]967 my $basesrc = "";
[131]968 foreach my $i (split(/ +/,$src)) {
969 $basesrc .= " ".basename($i);
[130]970 }
[118]971
[320]972 pb_log(0,"Sources handled ($cmt): $src\n");
[355]973 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf))."\n");
[415]974 my ($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vepath) = pb_conf_get($host,$login,$dir,$port,$tmout,$path);
975 my ($vrebuild,$veconf) = pb_conf_get_if($rebuild,$conf);
[320]976 pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf))."\n");
977 # Not mandatory
978 my ($testver) = pb_conf_get_if("testver");
979
980 my $mac;
981 # Useless for VE
982 if ($cmt ne "ve") {
983 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
984 # Overwrite account value if passed as parameter
985 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
[355]986 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
[320]987 }
988
[108]989 my $tdir;
[136]990 my $bdir;
[142]991 if (($cmt eq "Sources") || ($cmt eq "Script")) {
[471]992 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/src";
[435]993 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
994 # This is a test pkg => target dir is under test
[471]995 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/src";
[435]996 }
[320]997 } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
998 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
999 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
[136]1000 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
1001 $bdir =~ s|\$ENV.+\}/||;
[471]1002 } elsif ($cmt eq "Announce") {
1003 $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
1004 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
1005 # This is a test pkg => target dir is under test
1006 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test";
1007 }
[90]1008 } elsif ($cmt eq "Packages") {
[471]1009 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ddir/$dver";
[429]1010
[337]1011 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
[289]1012 # This is a test pkg => target dir is under test
[471]1013 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/$ddir/$dver";
[291]1014 }
[429]1015
1016 my $repodir = $tdir;
1017 $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
1018
1019 my ($pbrepo) = pb_conf_get("pbrepo");
1020
1021 # Repository management
[444]1022 open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
[429]1023 if ($dtype eq "rpm") {
1024 # Also make a pbscript to generate yum/urpmi bases
1025 print PBS << "EOF";
[433]1026#!/bin/bash
[429]1027# Prepare a script to ease yum setup
1028cat > $ENV{'PBPROJ'}.repo << EOT
1029[$ENV{'PBPROJ'}]
1030name=$ddir $dver - $ENV{'PBPROJ'} Vanilla Packages
[433]1031baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
[429]1032enabled=1
1033gpgcheck=0
1034EOT
1035chmod 644 $ENV{'PBPROJ'}.repo
1036
1037# Clean up old repo content
1038rm -rf headers/ repodata/
1039# Create yum repo
1040yum-arch .
1041# Create repodata
1042createrepo .
1043EOF
1044 if ($dfam eq "md") {
1045 # For Mandriva add urpmi management
1046 print PBS << "EOF";
1047# Prepare a script to ease urpmi setup
1048cat > $ENV{'PBPROJ'}.addmedia << EOT
[433]1049urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with hdlist.cz
[429]1050EOT
1051chmod 755 $ENV{'PBPROJ'}.addmedia
1052
1053# Clean up old repo content
[437]1054rm -f hdlist.cz synthesis.hdlist.cz
[429]1055# Create urpmi repo
1056genhdlist .
1057EOF
1058 }
[484]1059 if ($ddir eq "fedora") {
1060 # Extract the spec file to please Fedora maintainers :-(
1061 print PBS << "EOF";
1062for p in $basesrc; do
1063 echo \$p | grep -q 'src.rpm'
1064 if [ \$\? -eq 0 ]; then
1065 rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
1066 fi
1067done
1068EOF
1069 }
[429]1070 } elsif ($dtype eq "deb") {
1071 # Also make a pbscript to generate apt bases
[460]1072 # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
[465]1073 my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
[460]1074 print PBS << "EOF";
[465]1075#!/bin/bash
1076# Prepare a script to ease apt setup
1077cat > $ENV{'PBPROJ'}.sources.list << EOT
1078deb $rpd $dver contrib
1079deb-src $rpd $dver contrib
[460]1080EOT
[465]1081chmod 644 $ENV{'PBPROJ'}.sources.list
[460]1082
1083# Prepare a script to create apt info file
[465]1084(cd .. ; for a in i386 amd64 ia64; do mkdir -p dists/$dver/contrib/binary-\$a; dpkg-scanpackages -a\$a $dver /dev/null | gzip -c9 > dists/$dver/contrib/binary-\$a/Packages.gz; done; mkdir -p dists/$dver/contrib/source; dpkg-scansources $dver /dev/null | gzip -c9 > dists/$dver/contrib/source/Sources.gz)
[484]1085#(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]1086EOF
[429]1087 }
1088 close(PBS);
[444]1089 chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
[429]1090
[90]1091 } else {
1092 return;
[22]1093 }
[239]1094
[320]1095 # Useless for VE
1096 my $nport;
1097 if ($cmt ne "ve") {
1098 $nport = $sshport->{$ENV{'PBPROJ'}};
1099 $nport = "$pbport" if (defined $pbport);
1100 }
1101
[136]1102 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
[132]1103 $tdir =~ s|\$ENV.+\}/||;
1104
[320]1105 my $tm = $vtmout->{$ENV{'PBPROJ'}};
1106
1107 # ssh communication if not VE
[349]1108 # should use a hash instead...
[320]1109 my ($shcmd,$cpcmd,$cptarget,$cp2target);
1110 if ($cmt ne "ve") {
[347]1111 my $keyfile = pb_ssh_get(0);
[435]1112 $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
1113 $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
[320]1114 $cptarget = "$mac:$tdir";
[351]1115 if ($cmt eq "vm") {
1116 $cp2target = "$mac:$bdir";
1117 }
[320]1118 } else {
1119 my $tp = $vepath->{$ENV{'PBPROJ'}};
1120 $shcmd = "sudo chroot $tp/$v /bin/su - $sshlogin->{$ENV{'PBPROJ'}} -c ";
1121 $cpcmd = "cp -a ";
1122 $cptarget = "$tp/$tdir";
1123 $cp2target = "$tp/$bdir";
1124 }
1125
[471]1126 my $logres = "";
1127 # Do not touch when just announcing
1128 if ($cmt ne "Announce") {
1129 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");
1130 } else {
1131 $logres = "> ";
1132 }
[320]1133 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
[444]1134
[320]1135 # For VE we need to change the owner manually - To be tested if needed
1136 #if ($cmt eq "ve") {
1137 #pb_system("cd $cptarget ; sudo chown -R $sshlogin->{$ENV{'PBPROJ'}} .","$cmt chown in $cptarget to $sshlogin->{$ENV{'PBPROJ'}}");
1138 #}
[492]1139 pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
[320]1140 if (($cmt eq "vm") || ($cmt eq "ve")) {
[128]1141 # Get back info on pkg produced, compute their name and get them from the VM
[353]1142 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
1143 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]1144 my $src = <KEEP>;
1145 chomp($src);
1146 close(KEEP);
[131]1147 $src =~ s/^ *//;
[136]1148 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
[320]1149 # Change pgben to make the next send2target happy
[143]1150 my $made = "";
[353]1151 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[136]1152 foreach my $p (split(/ +/,$src)) {
[139]1153 my $j = basename($p);
[320]1154 pb_system("$cpcmd $cp2target/\'$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $cp2target");
[144]1155 $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
[136]1156 }
[143]1157 print KEEP "$made\n";
[139]1158 close(KEEP);
[320]1159 pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
[355]1160
1161 # We want to send them to the ssh account so overwrite what has been done before
1162 undef $pbaccount;
[357]1163 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
[355]1164 pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
[141]1165 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
[108]1166 }
[442]1167 pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
1168 if ((! $vmexist) && (($cmt eq "vm") || ($cmt eq "Script"))) {
1169 pb_system("$shcmd \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
1170 }
[9]1171}
[16]1172
[320]1173sub pb_script2v {
[142]1174 my $pbscript=shift;
[320]1175 my $vtype=shift;
[442]1176 my $force=shift || 0; # Force stop of VM. Default not
1177 my $vm1=shift || undef; # Only that VM to treat
1178 my $vm;
1179 my $all;
[141]1180
[442]1181 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$force,$vm1)\n");
[141]1182 # Prepare the script to be executed on the VM
1183 # in $ENV{'PBDESTDIR'}/pbscript
[142]1184 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
1185 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
1186 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
1187 }
[141]1188
[442]1189 if (not defined $vm1) {
1190 ($vm,$all) = pb_get_v($vtype);
1191 } else {
1192 @$vm = ($vm1);
1193 }
[320]1194 my ($vmexist,$vmpid) = (undef,undef);
[142]1195
[141]1196 foreach my $v (@$vm) {
[320]1197 # Launch the VM/VE
1198 if ($vtype eq "vm") {
1199 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
[442]1200 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
[141]1201
[320]1202 # Skip that VM if something went wrong
[442]1203 next if (($vmpid == 0) && ($vmexist == 0));
1204
1205 # If force stopping the VM then reset vmexist
1206 if ($force == 1) {
1207 $vmpid = $vmexist;
1208 $vmexist = 0;
1209 }
[320]1210 }
[274]1211
[142]1212 # Gather all required files to send them to the VM
[320]1213 # and launch the build through pbscript
[442]1214 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
[320]1215 pb_send2target("Script","$v",$vmexist,$vmpid);
[169]1216
[142]1217 }
1218}
1219
[320]1220sub pb_launchv {
1221 my $vtype = shift;
1222 my $v = shift;
1223 my $create = shift || 0; # By default do not create a VM
[310]1224
[442]1225 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create)\n");
[320]1226 die "No VM/VE defined, unable to launch" if (not defined $v);
1227 # Keep only the first VM in case many were given
1228 $v =~ s/,.*//;
[310]1229
[500]1230 my $arch = pb_get_arch();
[310]1231
[320]1232 # Launch the VMs/VEs
1233 if ($vtype eq "vm") {
1234 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
[310]1235
[415]1236 my ($ptr,$vmopt,$vmpath,$vmport,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmpath","vmport","vmtmout","vmsize");
[320]1237
1238 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
1239 if (not defined $ENV{'PBVMOPT'}) {
1240 $ENV{'PBVMOPT'} = "";
[310]1241 }
[483]1242 # Set a default timeout of 2 minutes
1243 if (not defined $ENV{'PBVMTMOUT'}) {
1244 $ENV{'PBVMTMOUT'} = "120";
1245 }
1246 if (defined $vmopt->{$v}) {
1247 $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
1248 } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
[320]1249 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
1250 }
[483]1251 if (defined $vmtmout->{$v}) {
1252 $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
1253 } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
1254 $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
1255 }
[320]1256 my $nport = $vmport->{$ENV{'PBPROJ'}};
1257 $nport = "$pbport" if (defined $pbport);
1258
1259 my $cmd;
1260 my $vmcmd; # has to be used for pb_check_ps
1261 my $vmm; # has to be used for pb_check_ps
1262 if ($vmtype eq "qemu") {
1263 my $qemucmd32;
1264 my $qemucmd64;
1265 if ($arch eq "x86_64") {
1266 $qemucmd32 = "/usr/bin/qemu-system-i386";
1267 $qemucmd64 = "/usr/bin/qemu";
1268 } else {
1269 $qemucmd32 = "/usr/bin/qemu";
1270 $qemucmd64 = "/usr/bin/qemu-system-x86_64";
1271 }
1272 if ($v =~ /x86_64/) {
1273 $vmcmd = "$qemucmd64 -no-kqemu";
1274 } else {
1275 $vmcmd = "$qemucmd32";
1276 }
1277 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
1278 if ($create != 0) {
1279 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
1280 }
1281 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
1282 } elsif ($vmtype eq "xen") {
1283 } elsif ($vmtype eq "vmware") {
[310]1284 } else {
[320]1285 die "VM of type $vmtype not supported. Report to the dev team";
[310]1286 }
[320]1287 my ($tmpcmd,$void) = split(/ +/,$cmd);
1288 my $vmexist = pb_check_ps($tmpcmd,$vmm);
1289 my $vmpid = 0;
1290 if (! $vmexist) {
1291 if ($create != 0) {
1292 if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
1293 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
1294 } elsif ($vmtype eq "vmware") {
1295 } else {
1296 }
1297 }
1298 if (! -f "$vmm") {
1299 pb_log(0,"Unable to find VM $vmm\n");
1300 } else {
1301 pb_system("$cmd &","Launching the VM $vmm");
[483]1302 pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
[320]1303 $vmpid = pb_check_ps($tmpcmd,$vmm);
[357]1304 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
[320]1305 }
[310]1306 } else {
[320]1307 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
[310]1308 }
[442]1309 pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
[320]1310 return($vmexist,$vmpid);
1311 # VE here
[310]1312 } else {
[320]1313 # Get VE context
[415]1314 my ($ptr,$vetmout,$vepath,$verebuild,$veconf) = pb_conf_get("vetype","vetmout","vepath","verebuild","veconf");
[320]1315 my $vetype = $ptr->{$ENV{'PBPROJ'}};
[310]1316
[320]1317 # Get distro context
1318 my ($name,$ver,$darch) = split(/-/,$v);
1319 chomp($darch);
1320 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
[142]1321
[320]1322 if ($vetype eq "chroot") {
1323 # Architecture consistency
1324 if ($arch ne $darch) {
1325 die "Unable to launch a VE of architecture $darch on a $arch platform" if (not (($darch eq "x86_64") && ($arch =~ /i?86/)));
1326 }
[142]1327
[320]1328 if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($force == 1)) {
1329 # We have to rebuild the chroot
1330 if ($dtype eq "rpm") {
1331 pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
1332 # Once setup we need to install some packages, the pb account, ...
1333 pb_system("sudo /usr/sbin/mock --install --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
1334 #pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" --basedir=\"$vepath->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
1335 } elsif ($dtype eq "deb") {
1336 pb_system("","Creating the pbuilder VE");
1337 } elsif ($dtype eq "ebuild") {
1338 die "Please teach the dev team how to build gentoo chroot";
1339 } else {
1340 die "Unknown distribution type $dtype. Report to dev team";
1341 }
[310]1342 }
[320]1343 # Nothing more to do for VE. No real launch
[274]1344 } else {
[320]1345 die "VE of type $vetype not supported. Report to the dev team";
[262]1346 }
[141]1347 }
1348}
[142]1349
[320]1350sub pb_build2v {
[118]1351
[320]1352my $vtype = shift;
[142]1353
[320]1354# Prepare the script to be executed on the VM/VE
1355# in $ENV{'PBDESTDIR'}/pbscript
[353]1356#my ($ntp) = pb_conf_get($vtype."ntp");
1357#my $vntp = $ntp->{$ENV{'PBPROJ'}};
[118]1358
[320]1359open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
1360print SCRIPT "#!/bin/bash\n";
1361print SCRIPT "echo ... Execution needed\n";
1362print SCRIPT "# This is in directory delivery\n";
1363print SCRIPT "# Setup the variables required for building\n";
1364print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
1365print SCRIPT "# Preparation for pb\n";
1366print SCRIPT "mv .pbrc \$HOME\n";
1367print SCRIPT "cd ..\n";
1368# Force new date to be in the future compared to the date of the tar file by adding 1 minute
1369my @date=pb_get_date();
1370$date[1]++;
1371my $upddate = strftime("%m%d%H%M%Y", @date);
[353]1372#print SCRIPT "echo Setting up date on $vntp...\n";
[320]1373# Or use ntpdate if available TBC
1374print SCRIPT "sudo date $upddate\n";
[353]1375# Get list of packages to build and get some ENV vars as well
1376my $ptr = pb_get_pkg();
1377@pkgs = @$ptr;
1378my $p = join(' ',@pkgs) if (@pkgs);
1379print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
1380print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
[320]1381print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
1382print SCRIPT "# Build\n";
1383print SCRIPT "echo Building packages on $vtype...\n";
1384print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
1385close(SCRIPT);
1386chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
1387
1388my ($v,$all) = pb_get_v($vtype);
1389
1390# Send tar files when we do a global generation
1391pb_build2ssh() if ($all == 1);
1392
1393my ($vmexist,$vmpid) = (undef,undef);
1394
1395foreach my $v (@$v) {
1396 if ($vtype eq "vm") {
[142]1397 # Launch the VM
[357]1398 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
[118]1399
[274]1400 # Skip that VM if it something went wrong
1401 next if (($vmpid == 0) && ($vmexist == 0));
[118]1402 }
[320]1403 # Gather all required files to send them to the VM/VE
[347]1404 # and launch the build through pbscript
[357]1405 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
[320]1406 pb_send2target($vtype,"$v",$vmexist,$vmpid);
[105]1407}
[320]1408}
[105]1409
[262]1410
[199]1411sub pb_newver {
1412
[204]1413 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
[340]1414
[366]1415 # Need this call for PBDIR
1416 my ($scheme2,$uri) = pb_cms_init($pbinit);
[361]1417
[415]1418 my ($pbconf) = pb_conf_get("pbconfurl");
[366]1419 $uri = $pbconf->{$ENV{'PBPROJ'}};
1420 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
1421
[361]1422 # Checking CMS repositories status
[358]1423 my ($pburl) = pb_conf_get("pburl");
[366]1424 ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
[340]1425
1426 if ($scheme !~ /^svn/) {
[199]1427 die "Only SVN is supported at the moment";
1428 }
[483]1429
[358]1430 my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
[361]1431 die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
[358]1432
1433 $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
[361]1434 die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
[358]1435
1436 # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
1437 # we want to get for the root of the new URL
1438
1439 my $tmp = $ENV{'PBROOTDIR'};
1440 $tmp =~ s|^$ENV{'PBCONFDIR'}||;
1441
1442 my $newurl = "$uri/".dirname($tmp)."/$newver";
[366]1443 # Should probably use projver in the old file
1444 my $oldver= basename($tmp);
[361]1445
[366]1446 # Duplicate and extract project-builder part
[361]1447 pb_log(2,"Copying $uri/$tmp to $newurl\n");
[366]1448 pb_cms_copy($scheme,"$uri/$tmp",$newurl);
1449 pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
[383]1450 pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
[361]1451
[366]1452 # Duplicate and extract project
1453 my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/".dirname($tmp)."/$newver";
1454
1455 pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$tmp to $newurl2\n");
1456 pb_cms_copy($scheme,"$pburl->{$ENV{'PBPROJ'}}/$tmp",$newurl2);
1457 pb_log(2,"Checkout $newurl2 to $ENV{'PBDIR'}/../$newver\n");
[383]1458 pb_cms_up($scheme,"$ENV{'PBDIR'}/..");
[366]1459
[361]1460 # Update the .pb file
[358]1461 open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
1462 open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
[208]1463 while(<FILE>) {
[361]1464 s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
1465 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/);
1466 s/^testver/#testver/;
1467 pb_log(0,"Commenting testver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
[211]1468 print OUT $_;
[208]1469 }
1470 close(FILE);
[211]1471 close(OUT);
[358]1472 rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
[363]1473
[479]1474 # Checking pbcl files
1475 foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
1476 open(PBCL,$f) || die "Unable to open $f";
1477 my $foundnew = 0;
1478 while (<PBCL>) {
1479 $foundnew = 1 if (/^$newver \(/);
1480 }
1481 close(PBCL);
1482 open(OUT,"> $f.new") || die "Unable to write to $f.new: $!";
1483 open(PBCL,$f) || die "Unable to open $f";
1484 while (<PBCL>) {
[480]1485 print OUT "$_" if (not /^$oldver \(/);
[479]1486 if ((/^$oldver \(/) && ($foundnew == 0)) {
1487 print OUT "$newver ($pbdate)\n";
1488 print OUT "- TBD\n";
1489 print OUT "\n";
[480]1490 pb_log(0,"WARNING: version $newver not found in $f so added...") if ($foundnew == 0);
[479]1491 }
1492 }
1493 close(OUT);
1494 close(PBCL);
1495 rename("$f.new","$f");
1496 }
1497
[358]1498 pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
[452]1499 pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
[199]1500}
1501
[293]1502#
[320]1503# Return the list of VMs/VEs we are working on
[105]1504# $all is a flag to know if we return all of them
1505# or only some (if all we publish also tar files in addition to pkgs
1506#
[320]1507sub pb_get_v {
[91]1508
[320]1509my $vtype = shift;
1510my @v;
[105]1511my $all = 0;
[320]1512my $vlist;
1513my $pbv = 'PBV';
[91]1514
[320]1515if ($vtype eq "vm") {
1516 $vlist = "vmlist";
1517} elsif ($vtype eq "ve") {
1518 $vlist = "velist";
1519}
1520# Get VM/VE list
1521if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
1522 my ($ptr) = pb_conf_get($vlist);
1523 $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
[105]1524 $all = 1;
[91]1525}
[320]1526pb_log(2,"$vtype: $ENV{$pbv}\n");
1527@v = split(/,/,$ENV{$pbv});
1528return(\@v,$all);
[91]1529}
1530
[320]1531# Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
1532# Needs to use root account to connect to the VM/VE
1533# pb will take your local public SSH key to access
[346]1534# the pb account in the VM later on if needed
1535sub pb_setup_v {
[320]1536
1537my $vtype = shift;
1538
[353]1539my ($vm,$all) = pb_get_v($vtype);
1540
[346]1541# Script generated
1542my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
[320]1543
[353]1544foreach my $v (@$vm) {
1545 # Name of the account to deal with for VM/VE
1546 # Do not use the one passed potentially with -a
1547 my ($pbac) = pb_conf_get($vtype."login");
[354]1548 my ($key,$zero0,$zero1,$zero2);
[527]1549 my ($vmexist,$vmpid,$ntps);
[346]1550
[353]1551 if ($vtype eq "vm") {
1552 # Prepare the key to be used and transfered remotely
1553 my $keyfile = pb_ssh_get(1);
1554
[517]1555 my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
[353]1556 my $nport = $vmport->{$ENV{'PBPROJ'}};
[527]1557 $ntps = $vmntp->{$ENV{'PBPROJ'}};
[353]1558 $nport = "$pbport" if (defined $pbport);
[347]1559
[353]1560 # Launch the VM
[357]1561 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
[347]1562
[353]1563 # Skip that VM if something went wrong
[442]1564 next if (($vmpid == 0) && ($vmexist == 0));
[353]1565
[354]1566 # Store the pub key part in a variable
1567 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
1568 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
1569 close(FILE);
1570
1571 $key = "\Q$zero1";
1572
[498]1573 pb_system("cat $keyfile.pub | ssh -q -o UserKnownHostsFile=/dev/null -p $nport -i $keyfile root\@$vmhost->{$ENV{'PBPROJ'}} \"mkdir -p .ssh ; chmod 700 .ssh ; cat >> .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys\"","Copying local keys to $vtype. This may require the root password");
[353]1574 # once this is done, we can do what we want on the VM remotely
1575 }
1576
1577 # Prepare the script to be executed on the VM/VE
1578 # in $ENV{'PBDESTDIR'}/setupv
1579
1580 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
1581 print SCRIPT << 'EOF';
[320]1582#!/usr/bin/perl -w
1583
[346]1584use strict;
1585use File::Copy;
1586
[517]1587# We should not need in this script more functions than what is provided
1588# by Base and Distribution to avoid problems at exec time.
1589# They are appended at the end.
1590
[495]1591our $pbdebug;
1592our $pbLOG;
1593our $pbsynmsg = "pbscript";
[498]1594our $pbdisplaytype = "text";
1595our $pblocale = "";
[495]1596pb_log_init($pbdebug, $pbLOG);
[427]1597pb_temp_init();
1598
[354]1599EOF
1600 if ($vtype eq "vm") {
1601 print SCRIPT << 'EOF';
1602# Removes duplicate in .ssh/authorized_keys of our key if needed
1603#
1604my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
1605open(PBFILE,$file1) || die "Unable to open $file1";
1606open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
1607my $count = 0;
1608while (<PBFILE>) {
[517]1609
[354]1610EOF
1611 print SCRIPT << "EOF";
1612 if (/ $key /) {
1613 \$count++;
1614 }
1615print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
1616}
1617close(PBFILE);
1618close(PBOUT);
1619rename("\$file1.new",\$file1);
1620chmod 0600,\$file1;
[517]1621
1622# Sync date
[527]1623pb_system("/usr/sbin/ntpdate $ntps","Syncing date to $ntps");
[517]1624
[354]1625EOF
1626 }
1627 print SCRIPT << 'EOF';
1628
1629# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
1630#
[346]1631my $file="/etc/passwd";
[320]1632open(PBFILE,$file) || die "Unable to open $file";
1633my $found = 0;
1634while (<PBFILE>) {
[346]1635EOF
[353]1636 print SCRIPT << "EOF";
1637 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
[346]1638EOF
[353]1639 print SCRIPT << 'EOF';
[320]1640}
1641close(PBFILE);
1642
1643if ( $found == 0 ) {
1644 if ( ! -d "/home" ) {
[427]1645 pb_mkdir("/home");
[320]1646 }
[346]1647EOF
[353]1648 print SCRIPT << "EOF";
[427]1649pb_system("groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
1650pb_system("useradd $pbac->{$ENV{'PBPROJ'}} -g $pbac->{$ENV{'PBPROJ'}} -m -d /home/$pbac->{$ENV{'PBPROJ'}}","Adding user $pbac->{$ENV{'PBPROJ'}} (group $pbac->{$ENV{'PBPROJ'}} - home /home/$pbac->{$ENV{'PBPROJ'}}");
1651}
[320]1652
[354]1653# allow ssh entry to build
1654#
[427]1655mkdir "/home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
[347]1656# Allow those accessing root to access the build account
[427]1657copy("\$ENV{'HOME'}/.ssh/authorized_keys","/home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
[320]1658chmod 0600,".ssh/authorized_keys";
[427]1659pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} /home/$pbac->{$ENV{'PBPROJ'}}/.ssh","Finish setting up the SSH env for $pbac->{$ENV{'PBPROJ'}}");
[320]1660
[346]1661EOF
[353]1662 print SCRIPT << 'EOF';
[347]1663# No passwd for build account only keys
[320]1664$file="/etc/shadow";
1665open(PBFILE,$file) || die "Unable to open $file";
1666open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1667while (<PBFILE>) {
[346]1668EOF
[353]1669 print SCRIPT << "EOF";
1670 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
1671 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
[346]1672EOF
[353]1673 print SCRIPT << 'EOF';
[320]1674 print PBOUT $_;
1675}
1676close(PBFILE);
1677close(PBOUT);
1678rename("$file.new",$file);
1679chmod 0640,$file;
1680
[448]1681# Keep the VM in text mode
1682$file="/etc/inittab";
[450]1683if (-f $file) {
1684 open(PBFILE,$file) || die "Unable to open $file";
1685 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1686 while (<PBFILE>) {
1687 s/^(..):5:initdefault:$/$1:3:initdefault:/;
1688 print PBOUT $_;
1689 }
1690 close(PBFILE);
1691 close(PBOUT);
1692 rename("$file.new",$file);
1693 chmod 0640,$file;
[448]1694}
1695
[320]1696# pb has to be added to portage group on gentoo
1697
[346]1698# Adapt sudoers
1699$file="/etc/sudoers";
1700open(PBFILE,$file) || die "Unable to open $file";
1701open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1702while (<PBFILE>) {
1703EOF
[353]1704 print SCRIPT << "EOF";
1705 next if (/^$pbac->{$ENV{'PBPROJ'}} /);
[346]1706EOF
[353]1707 print SCRIPT << 'EOF';
[346]1708 s/Defaults[ \t]+requiretty//;
1709 print PBOUT $_;
1710}
1711close(PBFILE);
1712EOF
[353]1713 print SCRIPT << "EOF";
1714# This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
1715print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
[346]1716EOF
[353]1717 print SCRIPT << 'EOF';
[346]1718close(PBOUT);
1719rename("$file.new",$file);
1720chmod 0440,$file;
1721
1722EOF
[353]1723
1724 my $SCRIPT = \*SCRIPT;
1725
1726 pb_install_deps($SCRIPT);
1727
1728 print SCRIPT << 'EOF';
[346]1729# Suse wants sudoers as 640
[528]1730if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver =~ /10.[012]/)) {
[346]1731 chmod 0640,$file;
1732}
1733
[427]1734pb_system("rm -rf perl-ProjectBuilder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/perl-ProjectBuilder-latest.tar.gz ; tar xvfz perl-ProjectBuilder-latest.tar.gz ; cd perl-ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf perl-ProjectBuilder-* ; rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; tar xvfz project-builder-latest.tar.gz ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf project-builder-* ;","Building Project-Builder");
[358]1735system "pb 2>&1 | head -5";
[357]1736EOF
[517]1737 # Adds pb_distro_init from ProjectBuilder::Distribution and Base
[353]1738 foreach my $d (@INC) {
[405]1739 my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm");
1740 foreach my $f (@f) {
1741 if (-f "$f") {
1742 open(PBD,"$f") || die "Unable to open $f";
1743 while (<PBD>) {
[427]1744 next if (/^package/);
1745 next if (/^use Exporter/);
1746 next if (/^use ProjectBuilder::/);
1747 next if (/^our /);
[405]1748 print SCRIPT $_;
1749 }
1750 close(PBD);
[353]1751 }
[347]1752 }
1753 }
[353]1754 close(SCRIPT);
1755 chmod 0755,"$pbscript";
1756
[442]1757 # That build script needs to be run as root and force stop of VM at end
[353]1758 $pbaccount = "root";
[442]1759
1760 # Force shutdown of VM exept if it was already launched
1761 my $force = 0;
1762 if ((! $vmexist) && ($vtype eq "vm")) {
1763 $force = 1;
1764 }
1765
1766 pb_script2v($pbscript,$vtype,$force,$v);
[347]1767}
[353]1768return;
[346]1769}
1770
[347]1771sub pb_install_deps {
[346]1772
[348]1773my $SCRIPT = shift;
[346]1774
[348]1775print {$SCRIPT} << 'EOF';
[346]1776# We need to have that pb_distro_init function
[347]1777# Get it from Project-Builder::Distribution
[320]1778my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
1779print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
1780
1781# Get and install pb
[437]1782my $insdm = "rm -rf Date-Manip* ; wget http://search.cpan.org/CPAN/authors/id/S/SB/SBECK/Date-Manip-5.54.tar.gz ; tar xvfz Date-Manip-5.54.tar.gz ; cd Date-Manip* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf Date-Manip*";
[357]1783my $insmb = "rm -rf Module-Build* ; wget http://search.cpan.org/CPAN/authors/id/K/KW/KWILLIAMS/Module-Build-0.2808.tar.gz ; tar xvfz Module-Build-0.2808.tar.gz ; cd Module-Build* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf Module-Build*";
[498]1784my $insfm = "rm -rf File-MimeInfo* ; wget http://search.cpan.org/CPAN/authors/id/P/PA/PARDUS/File-MimeInfo/File-MimeInfo-0.15.tar.gz ; tar xvfz File-MimeInfo-0.15.tar.gz ; cd File-MimeInfo* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf File-MimeInfo*";
[357]1785my $insfb = "rm -rf File-Basedir* ; wget http://search.cpan.org/CPAN/authors/id/P/PA/PARDUS/File-BaseDir-0.03.tar.gz ; tar xvfz File-BaseDir-0.03.tar.gz ; cd File-BaseDir* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf File-BaseDir*";
[498]1786my $insms = "rm -rf Mail-Sendmail* ; wget http://search.cpan.org/CPAN/authors/id/M/MI/MIVKOVIC/Mail-Sendmail-0.79.tar.gz ; tar xvfz Mail-Sendmail-0.79.tar.gz ; cd Mail-Sendmail* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf Mail-Sendmail*";
[507]1787my $inslg = "rm -rf gettext* ; wget http://search.cpan.org/CPAN/authors/id/P/PV/PVANDRY/gettext-1.05.tar.gz ; tar xvfz gettext-1.05.tar.gz ; cd gettext* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf gettext*";
[427]1788my $cmtdm = "Installing Date-Manip perl module";
1789my $cmtmb = "Installing Module-Build perl module";
1790my $cmtfm = "Installing File-MimeInfo perl module";
1791my $cmtfb = "Installing File-Basedir perl module";
[498]1792my $cmtms = "Installing Perl-Sendmail perl module";
[507]1793my $cmtlg = "Installing Perl-Locale-gettext perl module";
[427]1794my $cmtall = "Installing required modules";
[357]1795
[320]1796if ( $ddir eq "fedora" ) {
[427]1797 pb_system("yum clean all","Cleaning yum env");
[346]1798 #system "yum update -y";
[320]1799 my $arch=`uname -m`;
1800 my $opt = "";
1801 chomp($arch);
1802 if ($arch eq "x86_64") {
1803 $opt="--exclude=*.i?86";
1804 }
1805
[357]1806 if ($dver eq 4) {
[517]1807 pb_system("yum -y $opt install rpm-build wget patch ntp sudo perl-DateManip perl-ExtUtils-MakeMaker",$cmtall);
[427]1808 pb_system("$insmb","$cmtmb");
1809 pb_system("$insfm","$cmtfm");
1810 pb_system("$insfb","$cmtfb");
[517]1811 pb_system("$insms","$cmtms");
[507]1812 pb_system("$inslg","$cmtlg");
[517]1813 } else {
1814 pb_system("yum -y $opt install rpm-build wget patch ntp sudo perl-DateManip perl-ExtUtils-MakeMaker perl-File-MimeInfo perl-Mail-Sendmail",$cmtall);
1815 pb_system("$inslg","$cmtlg");
[357]1816 }
1817} elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || ($ddir eq "slackware")) {
[358]1818 # Suppose pkg are installed already as no online mirror available
[427]1819 pb_system("rpm -e lsb 2>&1 > /dev/null","Removing lsb package");
1820 pb_system("$insdm","$cmtdm");
1821 pb_system("$insmb","$cmtmb");
1822 pb_system("$insfm","$cmtfm");
1823 pb_system("$insfb","$cmtfb");
[498]1824 pb_system("$insms","$cmtms");
[507]1825 pb_system("$inslg","$cmtlg");
[320]1826} elsif ($ddir eq "suse") {
1827 # New OpenSuSE
[427]1828 pb_system("$insmb","$cmtmb");
1829 pb_system("$insfm","$cmtfm");
1830 pb_system("$insfb","$cmtfb");
[527]1831 pb_system("$insms","$cmtms");
[528]1832 pb_system("export TERM=linux ; liste=\"\" ; for i in make wget patch sudo perl-DateManip perl-File-HomeDir perl-Mail-Sendmail ntp; do rpm -q \$i 1> /dev/null 2> /dev/null ; if [ \$\? != 0 ]; then liste=\"\$liste \$i\"; fi; done; echo \"Liste: \$liste\" ; if [ \"\$liste\" != \"\" ]; then yast2 -i \$liste ; fi","$cmtall");
[320]1833} elsif ( $dfam eq "md" ) {
[507]1834 pb_system("urpmi.update -a ; urpmi --auto rpm-build wget sudo patch ntp-client perl-File-MimeInfo perl-Mail-Sendmail perl-Locale-gettext","$cmtall");
[357]1835 if (($ddir eq "mandrake") && ($dver eq "10.1")) {
[427]1836 pb_system("$insdm","$cmtdm");
[507]1837 pb_system("$inslg","$cmtlg");
[357]1838 } else {
[427]1839 pb_system("urpmi --auto perl-DateManip","$cmtdm");
[507]1840 pb_system("urpmi --auto perl-Locale-gettext","$cmtdm");
[357]1841 }
[320]1842} elsif ( $dfam eq "du" ) {
1843 if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
[346]1844 #system "apt-get update";
[427]1845 pb_system("$insfb","$cmtfb");
1846 pb_system("$insfm","$cmtfm");
[507]1847 pb_system("apt-get -y install wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libmodule-build-perl libdate-manip-perl libmail-sendmail-perl liblocale-gettext-perl","$cmtall");
[320]1848 } else {
[507]1849 pb_system("apt-get update; apt-get -y install wget patch openssh-server dpkg-dev sudo debian-builder dh-make fakeroot ntpdate libfile-mimeinfo-perl libmodule-build-perl libdate-manip-perl libmail-sendmail-perl liblocale-gettext-perl","$cmtall");
[320]1850 }
1851} elsif ( $dfam eq "gen" ) {
[427]1852 #system "emerge -u system";
[507]1853 pb_system("emerge wget sudo ntp DateManip File-MimeInfo Mail-Sendmail Locale-gettext","$cmtall");
[320]1854} else {
[495]1855 pb_log(0,"No pkg to install\n");
[320]1856}
1857EOF
1858}
1859
[471]1860sub pb_announce {
1861
[473]1862 # Get all required parameters
[477]1863 my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
[471]1864 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
1865 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
1866 my @pkgs = @$pkg;
1867 my %pkgs;
1868 my $first = 0;
1869
[473]1870 # Command to find packages on repo
[471]1871 my $findstr = "find . ";
[473]1872 # Generated announce files
1873 my @files;
[471]1874
1875 foreach my $pbpkg (@pkgs) {
1876 if ($first != 0) {
1877 $findstr .= "-o ";
1878 }
1879 $first++;
1880 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
1881 $pbver = $pkgv->{$pbpkg};
1882 } else {
1883 $pbver = $ENV{'PBPROJVER'};
1884 }
1885 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
1886 $pbtag = $pkgt->{$pbpkg};
1887 } else {
1888 $pbtag = $ENV{'PBPROJTAG'};
1889 }
1890
1891 $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver\.ebuild\' ";
[473]1892
1893 my $chglog;
1894
1895 # Get project info on log file and generate tmp files used later on
1896 pb_cms_init($pbinit);
1897 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
1898 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
1899 $chglog = undef if (! -f $chglog);
1900
1901 open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
1902 pb_changelog("announce",$pbpkg,$pbver,"N/A","N/A","N/A",\*OUT,"yes",$chglog);
1903 close(OUT);
1904 push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
[471]1905 }
1906 $findstr .= " | grep -Ev \'src.rpm\'";
1907 if ((not defined $testver) || (not defined $testver->{$ENV{'PBPROJ'}}) || ($testver->{$ENV{'PBPROJ'}} !~ /true/i)) {
1908 $findstr .= " | grep -v ./test/";
1909 }
1910
1911 # Prepare the command to run and execute it
1912 open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
1913 print PBS "$findstr\n";
1914 close(PBS);
1915 chmod 0755,"$ENV{'PBTMP'}/pbscript";
1916 pb_send2target("Announce");
1917
[490]1918 # Get subject line
1919 my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
[495]1920 pb_log(0,"Please enter the title of your announce\n");
1921 pb_log(0,"(By default: $sl)\n");
[490]1922 my $sl2 = <STDIN>;
1923 $sl = $sl2 if ($sl2 !~ /^$/);
1924
[471]1925 # Prepare a template of announce
[473]1926 open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
[471]1927 print ANN << "EOF";
[490]1928$sl</p>
[471]1929
[473]1930<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]1931<p>
1932Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
1933</p>
1934<p>
1935EOF
1936 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
[473]1937 my $col = 2;
1938 my $i = 1;
1939 print ANN << 'EOF';
1940<TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
1941<TR>
1942EOF
[471]1943 while (<LOG>) {
[473]1944 print ANN "<TD>$_</TD>";
1945 $i++;
1946 if ($i > $col) {
1947 print ANN "</TR>\n<TR>";
1948 $i = 1;
1949 }
[471]1950 }
1951 close(LOG);
[473]1952 print ANN << "EOF";
1953</TR>
1954</TABLE>
1955</p>
[471]1956
[473]1957<p>As usual source packages are also available in the same directory.</p>
1958
1959<p>
1960Changes are :
1961</p>
1962<p>
1963EOF
1964 # Get each package changelog content
1965 foreach my $f (sort(@files)) {
1966 open(IN,"$f") || die "Unable to read $f:$!";
1967 while (<IN>) {
1968 print ANN $_;
1969 }
1970 close(IN);
1971 print ANN "</p><p>\n";
1972 }
1973 print ANN "</p>\n";
[471]1974 close(ANN);
[473]1975
1976 # Allow for modification
1977 pb_system("vi $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
1978
1979 # Store it in DB for external usage (Web pages generation)
1980 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
1981
1982 my $precmd = "";
1983 if (! -f $db) {
1984 $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
1985 }
1986
1987 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
1988 { RaiseError => 1, AutoCommit => 1 })
1989 || die "Unable to connect to $db";
1990
1991 if ($precmd ne "") {
1992 my $sth = $dbh->prepare(qq{$precmd})
1993 || die "Unable to create table into $db";
1994 $sth->execute();
1995 }
1996
1997 # To read whole file
1998 local $/;
1999 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2000 my $announce = <ANN>;
2001 close(ANN);
2002
2003 pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
2004 my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
2005 || die "Unable to insert into $db";
2006 $sth->execute($pbdate, $announce);
2007 $dbh->disconnect;
2008
2009 # Then deliver it on the Web
2010 # $TOOLHOME/livwww www
2011
2012 # Mail it to project's ML
2013 open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
2014 print ML << 'EOF';
2015<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
2016
2017<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
2018 <head>
2019 </head>
2020 <body>
2021 <p>
2022EOF
2023 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2024 while(<ANN>) {
2025 print ML $_;
2026 }
2027 print ML << 'EOF';
2028</body>
2029</html>
2030EOF
2031 close(ML);
2032
[477]2033 # To read whole file
2034 local $/;
2035 open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
2036 my $msg = <ANN>;
2037 close(ANN);
2038
2039 # Preparation of headers
2040
2041 my %mail = (
2042 To => $pbml->{$ENV{'PBPROJ'}},
2043 From => $pbpackager->{$ENV{'PBPROJ'}},
2044 Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
2045 Body => $msg,
[490]2046 Subject => "[ANNOUNCE] $sl",
[477]2047 );
2048
2049 # Send mail
2050 sendmail(%mail) or die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
[471]2051}
2052
[347]2053# Return the SSH key file to use
2054# Potentially create it if needed
2055
2056sub pb_ssh_get {
2057
2058my $create = shift || 0; # Do not create keys by default
2059
2060# Check the SSH environment
2061my $keyfile = undef;
2062
2063# We have specific keys by default
2064$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
[348]2065if (!(-e $keyfile) && ($create eq 1)) {
[347]2066 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
2067}
2068
2069$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
2070$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
2071$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
2072die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
2073return($keyfile);
2074}
2075
2076
[145]2077# Returns the pid of a running VM command using a specific VM file
[142]2078sub pb_check_ps {
2079 my $vmcmd = shift;
2080 my $vmm = shift;
2081 my $vmexist = 0; # FALSE by default
2082
2083 open(PS, "ps auxhww|") || die "Unable to call ps";
2084 while (<PS>) {
2085 next if (! /$vmcmd/);
2086 next if (! /$vmm/);
2087 my ($void1, $void2);
2088 ($void1, $vmexist, $void2) = split(/ +/);
2089 last;
2090 }
2091 return($vmexist);
2092}
2093
2094
[77]2095sub pb_extract_build_files {
[25]2096
2097my $src=shift;
2098my $dir=shift;
[26]2099my $ddir=shift;
[500]2100my $mandatory=shift || "spec";
[28]2101my @files;
[25]2102
[500]2103my $flag = "mayfail" if ($mandatory eq "patch");
2104my $res;
2105
[188]2106if ($src =~ /tar\.gz$/) {
[500]2107 $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
[188]2108} elsif ($src =~ /tar\.bz2$/) {
[500]2109 $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
[188]2110} else {
2111 die "Unknown compression algorithm for $src";
2112}
[500]2113# If not mandatory return now
2114return() if (($res != 0) and ($mandatory eq "patch"));
[25]2115opendir(DIR,"$dir") || die "Unable to open directory $dir";
2116foreach my $f (readdir(DIR)) {
2117 next if ($f =~ /^\./);
[500]2118 # Skip potential patch dir
2119 next if ($f =~ /^pbpatch/);
[26]2120 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[315]2121 pb_log(2,"mv $dir/$f $ddir\n");
[28]2122 push @files,"$ddir/$f";
[25]2123}
2124closedir(DIR);
[26]2125# Not enough but still a first cleanup
[74]2126pb_rm_rf("$dir");
[28]2127return(@files);
[25]2128}
2129
[315]2130sub pb_list_bfiles {
2131
2132my $dir = shift;
2133my $pbpkg = shift;
2134my $bfiles = shift;
2135my $pkgfiles = shift;
2136my $supfiles = shift;
2137
2138opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
2139foreach my $f (readdir(BDIR)) {
2140 next if ($f =~ /^\./);
2141 $bfiles->{$f} = "$dir/$f";
[340]2142 $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
[315]2143 if (defined $supfiles->{$pbpkg}) {
2144 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
2145 }
2146}
2147closedir(BDIR);
2148}
2149
[395]2150
2151#
2152# Return the list of packages we are working on in a non CMS action
2153#
2154sub pb_get_pkg {
2155
2156my @pkgs = ();
2157
2158my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
2159@pkgs = keys %$var;
2160
2161pb_log(0,"Packages: ".join(',',@pkgs)."\n");
2162return(\@pkgs);
2163}
2164
[500]2165# Which is our local arch ? (standardize on i386 for those platforms)
2166sub pb_get_arch {
2167
2168my $arch = `uname -m`;
2169chomp($arch);
2170$arch =~ s/i.86/i386/;
2171return($arch);
2172}
2173
[395]21741;
Note: See TracBrowser for help on using the repository browser.