source: ProjectBuilder/0.9.3/pb/bin/pb@ 513

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

Transport pb_display functions using gettext from Base into a separate module to allow Base to have only basic perl deps only abd be used in setupvm easily. (retrofiy in 0.9.3 to allow for setupvm to work)

  • Property svn:executable set to *
File size: 69.5 KB
Line 
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
10# Syntax: see at end
11
12use strict 'vars';
13use Getopt::Long qw(:config auto_abbrev no_ignore_case);
14use Data::Dumper;
15use English;
16use File::Basename;
17use File::Copy;
18use File::stat;
19use File::Temp qw(tempdir);
20use POSIX qw(strftime);
21use lib qw (lib);
22use ProjectBuilder::Version;
23use ProjectBuilder::Base;
24use ProjectBuilder::Display;
25use ProjectBuilder::Conf;
26use ProjectBuilder::Distribution;
27use ProjectBuilder::CMS;
28use ProjectBuilder::Env;
29use ProjectBuilder::Filter;
30use ProjectBuilder::Changelog;
31use Mail::Sendmail;
32
33# Global variables
34my %opts; # CLI Options
35my $action; # action to realize
36my $test = "FALSE"; # Not used
37my $force = 0; # Force VE/VM rebuild
38my $option = ""; # Not used
39my @pkgs; # list of packages
40my $pbtag; # Global Tag variable
41my $pbver; # Global Version variable
42my $pbscript; # Name of the script
43my %pbver; # per package
44my %pbtag; # per package
45my $pbrev; # Global REVISION variable
46my $pbaccount; # Login to use to connect to the VM
47my $pbport; # Port to use to connect to the VM
48my $newver; # New version to create
49my $iso; # ISO image for the VM to create
50
51my @date = pb_get_date();
52my $pbdate = strftime("%Y-%m-%d", @date);
53
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
72pb [-vhq][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...]
73
74pb [--verbose][--help][--man][--quiet][--revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...]
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
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
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
226=item B<announce>
227
228Announce the availability of the project through various means
229
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
310my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
311
312# Initialize the syntax string
313
314pb_syntax_init("pb (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
315
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
332if (defined $opts{'h'}) {
333 pb_syntax(0,1);
334}
335if (defined $opts{'man'}) {
336 pb_syntax(0,2);
337}
338if (defined $opts{'v'}) {
339 $pbdebug = $opts{'v'};
340}
341if (defined $opts{'f'}) {
342 $force=1;
343}
344if (defined $opts{'q'}) {
345 $pbdebug=-1;
346}
347if (defined $opts{'l'}) {
348 open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
349 $pbLOG = \*pbLOG;
350 $pbdebug = 0 if ($pbdebug == -1);
351 }
352pb_log_init($pbdebug, $pbLOG);
353pb_display_init("text","");
354
355# Handle root of the project if defined
356if (defined $opts{'r'}) {
357 $ENV{'PBROOTDIR'} = $opts{'r'};
358}
359# Handle virtual machines if any
360if (defined $opts{'m'}) {
361 $ENV{'PBV'} = $opts{'m'};
362}
363if (defined $opts{'s'}) {
364 $pbscript = $opts{'s'};
365}
366if (defined $opts{'a'}) {
367 $pbaccount = $opts{'a'};
368 die "option -a requires a -s script option" if (not defined $pbscript);
369}
370if (defined $opts{'P'}) {
371 $pbport = $opts{'P'};
372}
373if (defined $opts{'V'}) {
374 $newver = $opts{'V'};
375}
376if (defined $opts{'i'}) {
377 $iso = $opts{'i'};
378}
379
380# Get Action
381$action = shift @ARGV;
382die pb_syntax(-1,1) if (not defined $action);
383
384my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
385my $pbinit = undef;
386$pbinit = 1 if ($action =~ /^newproj$/);
387
388# Handles project name if any
389# And get global params
390($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action);
391
392pb_log(0,"Project: $ENV{'PBPROJ'}\n");
393pb_log(0,"Action: $action\n");
394
395# Act depending on action
396if ($action =~ /^cms2build$/) {
397 pb_cms2build();
398} elsif ($action =~ /^build2pkg$/) {
399 pb_build2pkg();
400} elsif ($action =~ /^cms2pkg$/) {
401 pb_cms2build();
402 pb_build2pkg();
403} elsif ($action =~ /^build2ssh$/) {
404 pb_build2ssh();
405} elsif ($action =~ /^cms2ssh$/) {
406 pb_cms2build();
407 pb_build2ssh();
408} elsif ($action =~ /^pkg2ssh$/) {
409 pb_pkg2ssh();
410} elsif ($action =~ /^build2ve$/) {
411 pb_build2v("ve");
412} elsif ($action =~ /^build2vm$/) {
413 pb_build2v("vm");
414} elsif ($action =~ /^cms2ve$/) {
415 pb_cms2build();
416 pb_build2v("ve");
417} elsif ($action =~ /^cms2vm$/) {
418 pb_cms2build();
419 pb_build2v("vm");
420} elsif ($action =~ /^launchvm$/) {
421 pb_launchv("vm",$ENV{'PBV'},0);
422} elsif ($action =~ /^launchve$/) {
423 pb_launchv("ve",$ENV{'PBV'},0);
424} elsif ($action =~ /^script2vm$/) {
425 pb_script2v($pbscript,"vm");
426} elsif ($action =~ /^script2ve$/) {
427 pb_script2v($pbscript,"ve");
428} elsif ($action =~ /^newver$/) {
429 pb_newver();
430} elsif ($action =~ /^newve$/) {
431 pb_launchv("ve",$ENV{'PBV'},1);
432} elsif ($action =~ /^newvm$/) {
433 pb_launchv("vm",$ENV{'PBV'},1);
434} elsif ($action =~ /^setupve$/) {
435 pb_setup_v("ve");
436} elsif ($action =~ /^setupvm$/) {
437 pb_setup_v("vm");
438} elsif ($action =~ /^newproj$/) {
439 # Nothing to do - already done in pb_env_init
440} elsif ($action =~ /^clean$/) {
441 # TBC
442} elsif ($action =~ /^announce$/) {
443 # For announce only. Require avoids the systematic load of these modules
444 require DBI;
445
446 pb_announce();
447} else {
448 pb_log(0,"\'$action\' is not available\n");
449 pb_syntax(-2,1);
450}
451
452sub pb_cms2build {
453
454 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
455 my @pkgs = @$pkg;
456 my %pkgs;
457 my %pb; # Structure to store conf info
458
459 my ($scheme, $uri) = pb_cms_init($pbinit);
460
461 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
462
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'}};
467
468 foreach my $pbpkg (@pkgs) {
469 $ENV{'PBPKG'} = $pbpkg;
470 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
471 $pbver = $pkgv->{$pbpkg};
472 } else {
473 $pbver = $ENV{'PBPROJVER'};
474 }
475 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
476 $pbtag = $pkgt->{$pbpkg};
477 } else {
478 $pbtag = $ENV{'PBPROJTAG'};
479 }
480
481 $pbrev = $ENV{'PBREVISION'};
482 pb_log(0,"\n");
483 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
484 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
485 # Clean up dest if necessary. The export will recreate it
486 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
487 pb_rm_rf($dest) if (-d $dest);
488
489 # Export CMS tree for the concerned package to dest
490 # And generate some additional files
491 $OUTPUT_AUTOFLUSH=1;
492
493 # computes in which dir we have to work
494 my $dir = $defpkgdir->{$pbpkg};
495 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
496 pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
497
498 # Exporting from CMS
499 pb_cms_export($uri,"$ENV{'PBDIR'}/$dir",$dest);
500
501 # Generated fake content for test versions to speed up stuff
502 my ($testver) = pb_conf_get_if("testver");
503 my $chglog;
504
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);
509
510 my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
511 $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
512 $authors = "/dev/null" if (! -f $authors);
513
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";
518 }
519 pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
520
521 my %build;
522 my @pt;
523 my $tmpl = "";
524 my %patches;
525
526 @pt = pb_conf_get_if("vmlist","velist");
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 }
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'};
550 $pb{'patches'} = \%patches;
551 pb_log(2,"DEBUG: pb: ".Dumper(%pb)."\n");
552
553 foreach my $d (split(/,/,$tmpl)) {
554 my ($name,$ver,$arch) = split(/-/,$d);
555 chomp($arch);
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");
559 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
560
561 # Filter build files from the less precise up to the most with overloading
562 # Filter all files found, keeping the name, and generating in dest
563
564 # Find all build files first relatively to PBROOTDIR
565 # Find also all specific files referenced in the .pb conf file
566 my %bfiles = ();
567 my %pkgfiles = ();
568 $build{"$ddir-$dver-$arch"} = "yes";
569
570 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
571 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
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);
578 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
579 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
580 } else {
581 $build{"$ddir-$dver-$arch"} = "no";
582 next;
583 }
584 pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
585
586 # Get all filters to apply
587 my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
588
589 # Prepare local patches for this distro - They are always applied first - May be a problem one day
590 foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
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$/);
603 }
604
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
622 # Apply now all the filters on all the files concerned
623 # destination dir depends on the type of file
624 if (defined $ptr) {
625 # For patch support
626 $pb{'tuple'} = "$ddir-$dver-$arch";
627 foreach my $f (values %bfiles,values %pkgfiles) {
628 pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
629 }
630 }
631 }
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/);
637 }
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);
640 pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
641
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
647 my $ptr = pb_get_filters($pbpkg);
648
649 my $liste ="";
650 if (defined $filteredfiles->{$pbpkg}) {
651 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
652 pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
653 $liste = "$f $liste";
654 }
655 }
656 pb_log(2,"Files ".$liste."have been filtered\n");
657
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} ");
669 }
670 pb_log(0,"\n");
671
672 # Prepare the dest directory for archive
673 if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
674 pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
675 chmod 0755,"$ENV{'PBTMP'}/pbinit";
676 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
677 }
678
679 # Archive dest dir
680 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
681 # Possibility to look at PBSRC to guess more the filename
682 pb_system("tar cfz $pbpkg-$pbver.tar.gz --exclude=$pbpkg-$pbver/pbconf $pbpkg-$pbver","Creating $pbpkg tar files compressed");
683 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
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");
686
687 # Keep track of version-tag per pkg
688 $pkgs{$pbpkg} = "$pbver-$pbtag";
689
690 # Final cleanup
691 pb_rm_rf($dest) if (-d $dest);
692 }
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);
712}
713
714sub pb_build2pkg {
715
716 # Get the running distro to build on
717 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
718 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
719
720 # Get list of packages to build
721 # Get content saved in cms2build
722 my $ptr = pb_get_pkg();
723 @pkgs = @$ptr;
724
725 my $arch = pb_get_arch();
726
727 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
728 $pkg = { } if (not defined $pkg);
729
730 chdir "$ENV{'PBBUILDDIR'}";
731 my $made = ""; # pkgs made during build
732 foreach my $pbpkg (@pkgs) {
733 my $vertag = $pkg->{$pbpkg};
734 # get the version of the current package - maybe different
735 ($pbver,$pbtag) = split(/-/,$vertag);
736
737 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
738 my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
739 pb_log(2,"Source file: $src\n");
740 pb_log(2,"Pbconf file: $src2\n");
741
742 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
743 if ($dtype eq "rpm") {
744 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
745 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
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";
747 }
748 }
749
750 # Remove in case a previous link/file was there
751 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
752 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
753 # We need to first extract the spec file
754 my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$ENV{'PBBUILDDIR'}/SPECS","spec");
755
756 # We need to handle potential patches to upstream sources
757 pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
758
759 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
760 # set LANGUAGE to check for correct log messages
761 $ENV{'LANGUAGE'}="C";
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 }
767 foreach my $f (@specfile) {
768 if ($f =~ /\.spec$/) {
769 pb_system("rpmbuild $specialdef --define \'packager $ENV{'PBPACKAGER'}\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
770 last;
771 }
772 }
773 $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
774 if (-f "/usr/bin/rpmlint") {
775 pb_system("rpmlint $made","Checking validity of rpms with rpmlint","verbose");
776 }
777 } elsif ($dtype eq "deb") {
778 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
779 pb_system("tar xfz $src","Extracting sources");
780 pb_system("tar xfz $src2","Extracting pbconf");
781
782 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
783 pb_rm_rf("debian");
784 symlink "pbconf/$ddir-$dver-$arch","debian" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
785 chmod 0755,"debian/rules";
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 }
790 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
791 $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
792 if (-f "/usr/bin/lintian") {
793 pb_system("lintian $made","Checking validity of debs with lintian");
794 }
795 } elsif ($dtype eq "ebuild") {
796 my @ebuildfile;
797 # For gentoo we need to take pb as subsystem name
798 # We put every apps here under sys-apps. hope it's correct
799 # We use pb's home dir in order to have a single OVERLAY line
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");
803
804 # We need to first extract the ebuild file
805 @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$tmpd","ebuild");
806
807 # Prepare the build env for gentoo
808 my $found = 0;
809 my $pbbd = $ENV{'HOME'};
810 $pbbd =~ s|/|\\/|g;
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);
817 }
818 if ($found == 0) {
819 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
820 }
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 #}
832
833 # Build
834 foreach my $f (@ebuildfile) {
835 if ($f =~ /\.ebuild$/) {
836 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
837 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package");
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");
841 }
842 }
843
844 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
845 } elsif ($dtype eq "tgz") {
846 # Slackware family
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");
851 pb_system("tar xfz $src2","Extracting pbconf");
852 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
853 symlink "pbconf/$ddir-$dver-$arch","install" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
854 if (-x "install/pbslack") {
855 pb_system("./install/pbslack","Building package");
856 pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg");
857 }
858 } else {
859 die "Unknown dtype format $dtype";
860 }
861 }
862 # Keep track of what is generated so that we can get them back from VMs
863 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
864 print KEEP "$made\n";
865 close(KEEP);
866}
867
868sub pb_build2ssh {
869 pb_send2target("Sources");
870}
871
872sub pb_pkg2ssh {
873 pb_send2target("Packages");
874}
875
876# By default deliver to the the public site hosting the
877# ftp structure (or whatever) or a VM/VE
878sub pb_send2target {
879
880 my $cmt = shift;
881 my $v = shift || undef;
882 my $vmexist = shift || 0; # 0 is FALSE
883 my $vmpid = shift || 0; # 0 is FALSE
884
885 pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
886 my $host = "sshhost";
887 my $login = "sshlogin";
888 my $dir = "sshdir";
889 my $port = "sshport";
890 my $conf = "sshconf";
891 my $rebuild = "sshrebuild";
892 my $tmout = "vmtmout";
893 my $path = "vmpath";
894 if (($cmt eq "vm") || ($cmt eq "Script")) {
895 $login = "vmlogin";
896 $dir = "pbdefdir";
897 $tmout = "vmtmout";
898 $rebuild = "vmrebuild";
899 # Specific VM
900 $host = "vmhost";
901 $port = "vmport";
902 } elsif ($cmt eq "ve") {
903 $login = "velogin";
904 $dir = "pbdefdir";
905 $tmout = "vetmout";
906 # Specific VE
907 $path = "vepath";
908 $conf = "veconf";
909 $rebuild = "verebuild";
910 }
911 my $cmd = "";
912 my $src = "";
913 my ($odir,$over,$oarch) = (undef, undef, undef);
914 my ($ddir, $dver, $dfam, $dtype, $pbsuf);
915
916 if ($cmt ne "Announce") {
917 my $ptr = pb_get_pkg();
918 @pkgs = @$ptr;
919
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");
926
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);
931
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);
937
938 if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
939 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
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 }
945 }
946 }
947 # Adds conf file for availability of conf elements
948 pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
949 }
950
951 if (($cmt eq "vm") || ($cmt eq "ve")) {
952 $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
953 } elsif ($cmt eq "Script") {
954 $src="$src $ENV{'PBDESTDIR'}/pbscript";
955 } elsif ($cmt eq "Announce") {
956 $src="$src $ENV{'PBTMP'}/pbscript";
957 } elsif ($cmt eq "Packages") {
958 # Get package list from file made during build2pkg
959 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
960 $src = <KEEP>;
961 chomp($src);
962 close(KEEP);
963 $src="$src $ENV{'PBBUILDDIR'}/pbscript" if ($cmt ne "Sources");
964 }
965 # Remove potential leading spaces (cause problem with basename)
966 $src =~ s/^ *//;
967 my $basesrc = "";
968 foreach my $i (split(/ +/,$src)) {
969 $basesrc .= " ".basename($i);
970 }
971
972 pb_log(0,"Sources handled ($cmt): $src\n");
973 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf))."\n");
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);
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);
986 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
987 }
988
989 my $tdir;
990 my $bdir;
991 if (($cmt eq "Sources") || ($cmt eq "Script")) {
992 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/src";
993 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
994 # This is a test pkg => target dir is under test
995 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/src";
996 }
997 } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
998 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
999 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
1000 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
1001 $bdir =~ s|\$ENV.+\}/||;
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 }
1008 } elsif ($cmt eq "Packages") {
1009 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ddir/$dver";
1010
1011 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
1012 # This is a test pkg => target dir is under test
1013 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/$ddir/$dver";
1014 }
1015
1016 my $repodir = $tdir;
1017 $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
1018
1019 my ($pbrepo) = pb_conf_get("pbrepo");
1020
1021 # Repository management
1022 open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
1023 if ($dtype eq "rpm") {
1024 # Also make a pbscript to generate yum/urpmi bases
1025 print PBS << "EOF";
1026#!/bin/bash
1027# Prepare a script to ease yum setup
1028cat > $ENV{'PBPROJ'}.repo << EOT
1029[$ENV{'PBPROJ'}]
1030name=$ddir $dver - $ENV{'PBPROJ'} Vanilla Packages
1031baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
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
1049urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with hdlist.cz
1050EOT
1051chmod 755 $ENV{'PBPROJ'}.addmedia
1052
1053# Clean up old repo content
1054rm -f hdlist.cz synthesis.hdlist.cz
1055# Create urpmi repo
1056genhdlist .
1057EOF
1058 }
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 }
1070 } elsif ($dtype eq "deb") {
1071 # Also make a pbscript to generate apt bases
1072 # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
1073 my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
1074 print PBS << "EOF";
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
1080EOT
1081chmod 644 $ENV{'PBPROJ'}.sources.list
1082
1083# Prepare a script to create apt info file
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)
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)
1086EOF
1087 }
1088 close(PBS);
1089 chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
1090
1091 } else {
1092 return;
1093 }
1094
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
1102 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
1103 $tdir =~ s|\$ENV.+\}/||;
1104
1105 my $tm = $vtmout->{$ENV{'PBPROJ'}};
1106
1107 # ssh communication if not VE
1108 # should use a hash instead...
1109 my ($shcmd,$cpcmd,$cptarget,$cp2target);
1110 if ($cmt ne "ve") {
1111 my $keyfile = pb_ssh_get(0);
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";
1114 $cptarget = "$mac:$tdir";
1115 if ($cmt eq "vm") {
1116 $cp2target = "$mac:$bdir";
1117 }
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
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 }
1133 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
1134
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 #}
1139 pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
1140 if (($cmt eq "vm") || ($cmt eq "ve")) {
1141 # Get back info on pkg produced, compute their name and get them from the VM
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'}";
1144 my $src = <KEEP>;
1145 chomp($src);
1146 close(KEEP);
1147 $src =~ s/^ *//;
1148 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
1149 # Change pgben to make the next send2target happy
1150 my $made = "";
1151 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
1152 foreach my $p (split(/ +/,$src)) {
1153 my $j = basename($p);
1154 pb_system("$cpcmd $cp2target/\'$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $cp2target");
1155 $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
1156 }
1157 print KEEP "$made\n";
1158 close(KEEP);
1159 pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
1160
1161 # We want to send them to the ssh account so overwrite what has been done before
1162 undef $pbaccount;
1163 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
1164 pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
1165 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
1166 }
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 }
1171}
1172
1173sub pb_script2v {
1174 my $pbscript=shift;
1175 my $vtype=shift;
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;
1180
1181 pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$force,$vm1)\n");
1182 # Prepare the script to be executed on the VM
1183 # in $ENV{'PBDESTDIR'}/pbscript
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 }
1188
1189 if (not defined $vm1) {
1190 ($vm,$all) = pb_get_v($vtype);
1191 } else {
1192 @$vm = ($vm1);
1193 }
1194 my ($vmexist,$vmpid) = (undef,undef);
1195
1196 foreach my $v (@$vm) {
1197 # Launch the VM/VE
1198 if ($vtype eq "vm") {
1199 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
1200 pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
1201
1202 # Skip that VM if something went wrong
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 }
1210 }
1211
1212 # Gather all required files to send them to the VM
1213 # and launch the build through pbscript
1214 pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
1215 pb_send2target("Script","$v",$vmexist,$vmpid);
1216
1217 }
1218}
1219
1220sub pb_launchv {
1221 my $vtype = shift;
1222 my $v = shift;
1223 my $create = shift || 0; # By default do not create a VM
1224
1225 pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create)\n");
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/,.*//;
1229
1230 my $arch = pb_get_arch();
1231
1232 # Launch the VMs/VEs
1233 if ($vtype eq "vm") {
1234 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
1235
1236 my ($ptr,$vmopt,$vmpath,$vmport,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmpath","vmport","vmtmout","vmsize");
1237
1238 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
1239 if (not defined $ENV{'PBVMOPT'}) {
1240 $ENV{'PBVMOPT'} = "";
1241 }
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'}}) {
1249 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
1250 }
1251 if (defined $vmtmout->{$v}) {
1252 $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
1253 } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
1254 $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
1255 }
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") {
1284 } else {
1285 die "VM of type $vmtype not supported. Report to the dev team";
1286 }
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");
1302 pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
1303 $vmpid = pb_check_ps($tmpcmd,$vmm);
1304 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
1305 }
1306 } else {
1307 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
1308 }
1309 pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
1310 return($vmexist,$vmpid);
1311 # VE here
1312 } else {
1313 # Get VE context
1314 my ($ptr,$vetmout,$vepath,$verebuild,$veconf) = pb_conf_get("vetype","vetmout","vepath","verebuild","veconf");
1315 my $vetype = $ptr->{$ENV{'PBPROJ'}};
1316
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);
1321
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 }
1327
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 }
1342 }
1343 # Nothing more to do for VE. No real launch
1344 } else {
1345 die "VE of type $vetype not supported. Report to the dev team";
1346 }
1347 }
1348}
1349
1350sub pb_build2v {
1351
1352my $vtype = shift;
1353
1354# Prepare the script to be executed on the VM/VE
1355# in $ENV{'PBDESTDIR'}/pbscript
1356#my ($ntp) = pb_conf_get($vtype."ntp");
1357#my $vntp = $ntp->{$ENV{'PBPROJ'}};
1358
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);
1372#print SCRIPT "echo Setting up date on $vntp...\n";
1373# Or use ntpdate if available TBC
1374print SCRIPT "sudo date $upddate\n";
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";
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") {
1397 # Launch the VM
1398 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
1399
1400 # Skip that VM if it something went wrong
1401 next if (($vmpid == 0) && ($vmexist == 0));
1402 }
1403 # Gather all required files to send them to the VM/VE
1404 # and launch the build through pbscript
1405 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
1406 pb_send2target($vtype,"$v",$vmexist,$vmpid);
1407}
1408}
1409
1410
1411sub pb_newver {
1412
1413 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
1414
1415 # Need this call for PBDIR
1416 my ($scheme2,$uri) = pb_cms_init($pbinit);
1417
1418 my ($pbconf) = pb_conf_get("pbconfurl");
1419 $uri = $pbconf->{$ENV{'PBPROJ'}};
1420 my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
1421
1422 # Checking CMS repositories status
1423 my ($pburl) = pb_conf_get("pburl");
1424 ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
1425
1426 if ($scheme !~ /^svn/) {
1427 die "Only SVN is supported at the moment";
1428 }
1429
1430 my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
1431 die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
1432
1433 $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
1434 die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
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";
1443 # Should probably use projver in the old file
1444 my $oldver= basename($tmp);
1445
1446 # Duplicate and extract project-builder part
1447 pb_log(2,"Copying $uri/$tmp to $newurl\n");
1448 pb_cms_copy($scheme,"$uri/$tmp",$newurl);
1449 pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
1450 pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
1451
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");
1458 pb_cms_up($scheme,"$ENV{'PBDIR'}/..");
1459
1460 # Update the .pb file
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";
1463 while(<FILE>) {
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/);
1468 print OUT $_;
1469 }
1470 close(FILE);
1471 close(OUT);
1472 rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
1473
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>) {
1485 print OUT "$_" if (not /^$oldver \(/);
1486 if ((/^$oldver \(/) && ($foundnew == 0)) {
1487 print OUT "$newver ($pbdate)\n";
1488 print OUT "- TBD\n";
1489 print OUT "\n";
1490 pb_log(0,"WARNING: version $newver not found in $f so added...") if ($foundnew == 0);
1491 }
1492 }
1493 close(OUT);
1494 close(PBCL);
1495 rename("$f.new","$f");
1496 }
1497
1498 pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
1499 pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
1500}
1501
1502#
1503# Return the list of VMs/VEs we are working on
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#
1507sub pb_get_v {
1508
1509my $vtype = shift;
1510my @v;
1511my $all = 0;
1512my $vlist;
1513my $pbv = 'PBV';
1514
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'}};
1524 $all = 1;
1525}
1526pb_log(2,"$vtype: $ENV{$pbv}\n");
1527@v = split(/,/,$ENV{$pbv});
1528return(\@v,$all);
1529}
1530
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
1534# the pb account in the VM later on if needed
1535sub pb_setup_v {
1536
1537my $vtype = shift;
1538
1539my ($vm,$all) = pb_get_v($vtype);
1540
1541# Script generated
1542my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
1543
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");
1548 my ($key,$zero0,$zero1,$zero2);
1549 my ($vmexist,$vmpid);
1550
1551 if ($vtype eq "vm") {
1552 # Prepare the key to be used and transfered remotely
1553 my $keyfile = pb_ssh_get(1);
1554
1555 my ($vmhost,$vmport) = pb_conf_get("vmhost","vmport");
1556 my $nport = $vmport->{$ENV{'PBPROJ'}};
1557 $nport = "$pbport" if (defined $pbport);
1558
1559 # Launch the VM
1560 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
1561
1562 # Skip that VM if something went wrong
1563 next if (($vmpid == 0) && ($vmexist == 0));
1564
1565 # Store the pub key part in a variable
1566 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
1567 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
1568 close(FILE);
1569
1570 $key = "\Q$zero1";
1571
1572 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");
1573 # once this is done, we can do what we want on the VM remotely
1574 }
1575
1576 # Prepare the script to be executed on the VM/VE
1577 # in $ENV{'PBDESTDIR'}/setupv
1578
1579 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
1580 print SCRIPT << 'EOF';
1581#!/usr/bin/perl -w
1582
1583use strict;
1584use File::Copy;
1585
1586our $pbdebug;
1587our $pbLOG;
1588our $pbsynmsg = "pbscript";
1589our $pbdisplaytype = "text";
1590our $pblocale = "";
1591pb_log_init($pbdebug, $pbLOG);
1592pb_temp_init();
1593
1594EOF
1595 if ($vtype eq "vm") {
1596 print SCRIPT << 'EOF';
1597# Removes duplicate in .ssh/authorized_keys of our key if needed
1598#
1599my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
1600open(PBFILE,$file1) || die "Unable to open $file1";
1601open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
1602my $count = 0;
1603while (<PBFILE>) {
1604EOF
1605 print SCRIPT << "EOF";
1606 if (/ $key /) {
1607 \$count++;
1608 }
1609print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
1610}
1611close(PBFILE);
1612close(PBOUT);
1613rename("\$file1.new",\$file1);
1614chmod 0600,\$file1;
1615EOF
1616 }
1617 print SCRIPT << 'EOF';
1618
1619# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
1620#
1621my $file="/etc/passwd";
1622open(PBFILE,$file) || die "Unable to open $file";
1623my $found = 0;
1624while (<PBFILE>) {
1625EOF
1626 print SCRIPT << "EOF";
1627 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
1628EOF
1629 print SCRIPT << 'EOF';
1630}
1631close(PBFILE);
1632
1633if ( $found == 0 ) {
1634 if ( ! -d "/home" ) {
1635 pb_mkdir("/home");
1636 }
1637EOF
1638 print SCRIPT << "EOF";
1639pb_system("groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
1640pb_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'}}");
1641}
1642
1643# allow ssh entry to build
1644#
1645mkdir "/home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
1646# Allow those accessing root to access the build account
1647copy("\$ENV{'HOME'}/.ssh/authorized_keys","/home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
1648chmod 0600,".ssh/authorized_keys";
1649pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} /home/$pbac->{$ENV{'PBPROJ'}}/.ssh","Finish setting up the SSH env for $pbac->{$ENV{'PBPROJ'}}");
1650
1651EOF
1652 print SCRIPT << 'EOF';
1653# No passwd for build account only keys
1654$file="/etc/shadow";
1655open(PBFILE,$file) || die "Unable to open $file";
1656open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1657while (<PBFILE>) {
1658EOF
1659 print SCRIPT << "EOF";
1660 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
1661 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
1662EOF
1663 print SCRIPT << 'EOF';
1664 print PBOUT $_;
1665}
1666close(PBFILE);
1667close(PBOUT);
1668rename("$file.new",$file);
1669chmod 0640,$file;
1670
1671# Keep the VM in text mode
1672$file="/etc/inittab";
1673if (-f $file) {
1674 open(PBFILE,$file) || die "Unable to open $file";
1675 open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1676 while (<PBFILE>) {
1677 s/^(..):5:initdefault:$/$1:3:initdefault:/;
1678 print PBOUT $_;
1679 }
1680 close(PBFILE);
1681 close(PBOUT);
1682 rename("$file.new",$file);
1683 chmod 0640,$file;
1684}
1685
1686# pb has to be added to portage group on gentoo
1687
1688# Adapt sudoers
1689$file="/etc/sudoers";
1690open(PBFILE,$file) || die "Unable to open $file";
1691open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1692while (<PBFILE>) {
1693EOF
1694 print SCRIPT << "EOF";
1695 next if (/^$pbac->{$ENV{'PBPROJ'}} /);
1696EOF
1697 print SCRIPT << 'EOF';
1698 s/Defaults[ \t]+requiretty//;
1699 print PBOUT $_;
1700}
1701close(PBFILE);
1702EOF
1703 print SCRIPT << "EOF";
1704# This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
1705print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
1706EOF
1707 print SCRIPT << 'EOF';
1708close(PBOUT);
1709rename("$file.new",$file);
1710chmod 0440,$file;
1711
1712EOF
1713
1714 my $SCRIPT = \*SCRIPT;
1715
1716 pb_install_deps($SCRIPT);
1717
1718 print SCRIPT << 'EOF';
1719# Suse wants sudoers as 640
1720if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {
1721 chmod 0640,$file;
1722}
1723
1724# Sync date
1725#system "/usr/sbin/ntpdate ntp.pool.org";
1726
1727pb_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");
1728system "pb 2>&1 | head -5";
1729EOF
1730 # Adds pb_distro_init from ProjectBuilder::Distribution
1731 foreach my $d (@INC) {
1732 my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm");
1733 foreach my $f (@f) {
1734 if (-f "$f") {
1735 open(PBD,"$f") || die "Unable to open $f";
1736 while (<PBD>) {
1737 next if (/^package/);
1738 next if (/^use Exporter/);
1739 next if (/^use ProjectBuilder::/);
1740 next if (/^our /);
1741 print SCRIPT $_;
1742 }
1743 close(PBD);
1744 }
1745 }
1746 }
1747 close(SCRIPT);
1748 chmod 0755,"$pbscript";
1749
1750 # That build script needs to be run as root and force stop of VM at end
1751 $pbaccount = "root";
1752
1753 # Force shutdown of VM exept if it was already launched
1754 my $force = 0;
1755 if ((! $vmexist) && ($vtype eq "vm")) {
1756 $force = 1;
1757 }
1758
1759 pb_script2v($pbscript,$vtype,$force,$v);
1760}
1761return;
1762}
1763
1764sub pb_install_deps {
1765
1766my $SCRIPT = shift;
1767
1768print {$SCRIPT} << 'EOF';
1769# We need to have that pb_distro_init function
1770# Get it from Project-Builder::Distribution
1771my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
1772print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
1773
1774# Get and install pb
1775my $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*";
1776my $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*";
1777my $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*";
1778my $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*";
1779my $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*";
1780my $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*";
1781my $cmtdm = "Installing Date-Manip perl module";
1782my $cmtmb = "Installing Module-Build perl module";
1783my $cmtfm = "Installing File-MimeInfo perl module";
1784my $cmtfb = "Installing File-Basedir perl module";
1785my $cmtms = "Installing Perl-Sendmail perl module";
1786my $cmtlg = "Installing Perl-Locale-gettext perl module";
1787my $cmtall = "Installing required modules";
1788
1789if ( $ddir eq "fedora" ) {
1790 pb_system("yum clean all","Cleaning yum env");
1791 #system "yum update -y";
1792 my $arch=`uname -m`;
1793 my $opt = "";
1794 chomp($arch);
1795 if ($arch eq "x86_64") {
1796 $opt="--exclude=*.i?86";
1797 }
1798
1799 pb_system("yum -y $opt install rpm-build wget patch ntp sudo perl-DateManip perl-File-MimeInfo perl-ExtUtils-MakeMaker perl-Mail-Sendmail perl-Locale-gettext",$cmtall);
1800 if ($dver eq 4) {
1801 pb_system("$insmb","$cmtmb");
1802 pb_system("$insfm","$cmtfm");
1803 pb_system("$insfb","$cmtfb");
1804 pb_system("$inslg","$cmtlg");
1805 }
1806} elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || ($ddir eq "slackware")) {
1807 # Suppose pkg are installed already as no online mirror available
1808 pb_system("rpm -e lsb 2>&1 > /dev/null","Removing lsb package");
1809 pb_system("$insdm","$cmtdm");
1810 pb_system("$insmb","$cmtmb");
1811 pb_system("$insfm","$cmtfm");
1812 pb_system("$insfb","$cmtfb");
1813 pb_system("$insms","$cmtms");
1814 pb_system("$inslg","$cmtlg");
1815} elsif ($ddir eq "suse") {
1816 # New OpenSuSE
1817 pb_system("$insmb","$cmtmb");
1818 pb_system("$insfm","$cmtfm");
1819 pb_system("$insfb","$cmtfb");
1820 pb_system("export TERM=linux ; liste=\"\" ; for i in make wget patch sudo perl-DateManip perl-File-HomeDir perl-Mail-Sendmail perl-Locale-gettext xntp; 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");
1821} elsif ( $dfam eq "md" ) {
1822 pb_system("urpmi.update -a ; urpmi --auto rpm-build wget sudo patch ntp-client perl-File-MimeInfo perl-Mail-Sendmail perl-Locale-gettext","$cmtall");
1823 if (($ddir eq "mandrake") && ($dver eq "10.1")) {
1824 pb_system("$insdm","$cmtdm");
1825 pb_system("$inslg","$cmtlg");
1826 } else {
1827 pb_system("urpmi --auto perl-DateManip","$cmtdm");
1828 pb_system("urpmi --auto perl-Locale-gettext","$cmtdm");
1829 }
1830} elsif ( $dfam eq "du" ) {
1831 if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
1832 #system "apt-get update";
1833 pb_system("$insfb","$cmtfb");
1834 pb_system("$insfm","$cmtfm");
1835 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");
1836 } else {
1837 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");
1838 }
1839} elsif ( $dfam eq "gen" ) {
1840 #system "emerge -u system";
1841 pb_system("emerge wget sudo ntp DateManip File-MimeInfo Mail-Sendmail Locale-gettext","$cmtall");
1842} else {
1843 pb_log(0,"No pkg to install\n");
1844}
1845EOF
1846}
1847
1848sub pb_announce {
1849
1850 # Get all required parameters
1851 my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
1852 my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
1853 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
1854 my @pkgs = @$pkg;
1855 my %pkgs;
1856 my $first = 0;
1857
1858 # Command to find packages on repo
1859 my $findstr = "find . ";
1860 # Generated announce files
1861 my @files;
1862
1863 foreach my $pbpkg (@pkgs) {
1864 if ($first != 0) {
1865 $findstr .= "-o ";
1866 }
1867 $first++;
1868 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
1869 $pbver = $pkgv->{$pbpkg};
1870 } else {
1871 $pbver = $ENV{'PBPROJVER'};
1872 }
1873 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
1874 $pbtag = $pkgt->{$pbpkg};
1875 } else {
1876 $pbtag = $ENV{'PBPROJTAG'};
1877 }
1878
1879 $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver\.ebuild\' ";
1880
1881 my $chglog;
1882
1883 # Get project info on log file and generate tmp files used later on
1884 pb_cms_init($pbinit);
1885 $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
1886 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
1887 $chglog = undef if (! -f $chglog);
1888
1889 open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
1890 pb_changelog("announce",$pbpkg,$pbver,"N/A","N/A","N/A",\*OUT,"yes",$chglog);
1891 close(OUT);
1892 push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
1893 }
1894 $findstr .= " | grep -Ev \'src.rpm\'";
1895 if ((not defined $testver) || (not defined $testver->{$ENV{'PBPROJ'}}) || ($testver->{$ENV{'PBPROJ'}} !~ /true/i)) {
1896 $findstr .= " | grep -v ./test/";
1897 }
1898
1899 # Prepare the command to run and execute it
1900 open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
1901 print PBS "$findstr\n";
1902 close(PBS);
1903 chmod 0755,"$ENV{'PBTMP'}/pbscript";
1904 pb_send2target("Announce");
1905
1906 # Get subject line
1907 my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
1908 pb_log(0,"Please enter the title of your announce\n");
1909 pb_log(0,"(By default: $sl)\n");
1910 my $sl2 = <STDIN>;
1911 $sl = $sl2 if ($sl2 !~ /^$/);
1912
1913 # Prepare a template of announce
1914 open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
1915 print ANN << "EOF";
1916$sl</p>
1917
1918<p>The project team is happy to announce the availability of a newest version of $ENV{'PBPROJ'} $ENV{'PBPROJVER'}. Enjoy it as usual!</p>
1919<p>
1920Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
1921</p>
1922<p>
1923EOF
1924 open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
1925 my $col = 2;
1926 my $i = 1;
1927 print ANN << 'EOF';
1928<TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
1929<TR>
1930EOF
1931 while (<LOG>) {
1932 print ANN "<TD>$_</TD>";
1933 $i++;
1934 if ($i > $col) {
1935 print ANN "</TR>\n<TR>";
1936 $i = 1;
1937 }
1938 }
1939 close(LOG);
1940 print ANN << "EOF";
1941</TR>
1942</TABLE>
1943</p>
1944
1945<p>As usual source packages are also available in the same directory.</p>
1946
1947<p>
1948Changes are :
1949</p>
1950<p>
1951EOF
1952 # Get each package changelog content
1953 foreach my $f (sort(@files)) {
1954 open(IN,"$f") || die "Unable to read $f:$!";
1955 while (<IN>) {
1956 print ANN $_;
1957 }
1958 close(IN);
1959 print ANN "</p><p>\n";
1960 }
1961 print ANN "</p>\n";
1962 close(ANN);
1963
1964 # Allow for modification
1965 pb_system("vi $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
1966
1967 # Store it in DB for external usage (Web pages generation)
1968 my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
1969
1970 my $precmd = "";
1971 if (! -f $db) {
1972 $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
1973 }
1974
1975 my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
1976 { RaiseError => 1, AutoCommit => 1 })
1977 || die "Unable to connect to $db";
1978
1979 if ($precmd ne "") {
1980 my $sth = $dbh->prepare(qq{$precmd})
1981 || die "Unable to create table into $db";
1982 $sth->execute();
1983 }
1984
1985 # To read whole file
1986 local $/;
1987 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
1988 my $announce = <ANN>;
1989 close(ANN);
1990
1991 pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
1992 my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
1993 || die "Unable to insert into $db";
1994 $sth->execute($pbdate, $announce);
1995 $dbh->disconnect;
1996
1997 # Then deliver it on the Web
1998 # $TOOLHOME/livwww www
1999
2000 # Mail it to project's ML
2001 open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
2002 print ML << 'EOF';
2003<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
2004
2005<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
2006 <head>
2007 </head>
2008 <body>
2009 <p>
2010EOF
2011 open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
2012 while(<ANN>) {
2013 print ML $_;
2014 }
2015 print ML << 'EOF';
2016</body>
2017</html>
2018EOF
2019 close(ML);
2020
2021 # To read whole file
2022 local $/;
2023 open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
2024 my $msg = <ANN>;
2025 close(ANN);
2026
2027 # Preparation of headers
2028
2029 my %mail = (
2030 To => $pbml->{$ENV{'PBPROJ'}},
2031 From => $pbpackager->{$ENV{'PBPROJ'}},
2032 Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
2033 Body => $msg,
2034 Subject => "[ANNOUNCE] $sl",
2035 );
2036
2037 # Send mail
2038 sendmail(%mail) or die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
2039}
2040
2041# Return the SSH key file to use
2042# Potentially create it if needed
2043
2044sub pb_ssh_get {
2045
2046my $create = shift || 0; # Do not create keys by default
2047
2048# Check the SSH environment
2049my $keyfile = undef;
2050
2051# We have specific keys by default
2052$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
2053if (!(-e $keyfile) && ($create eq 1)) {
2054 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
2055}
2056
2057$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
2058$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
2059$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
2060die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
2061return($keyfile);
2062}
2063
2064
2065# Returns the pid of a running VM command using a specific VM file
2066sub pb_check_ps {
2067 my $vmcmd = shift;
2068 my $vmm = shift;
2069 my $vmexist = 0; # FALSE by default
2070
2071 open(PS, "ps auxhww|") || die "Unable to call ps";
2072 while (<PS>) {
2073 next if (! /$vmcmd/);
2074 next if (! /$vmm/);
2075 my ($void1, $void2);
2076 ($void1, $vmexist, $void2) = split(/ +/);
2077 last;
2078 }
2079 return($vmexist);
2080}
2081
2082
2083sub pb_extract_build_files {
2084
2085my $src=shift;
2086my $dir=shift;
2087my $ddir=shift;
2088my $mandatory=shift || "spec";
2089my @files;
2090
2091my $flag = "mayfail" if ($mandatory eq "patch");
2092my $res;
2093
2094if ($src =~ /tar\.gz$/) {
2095 $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
2096} elsif ($src =~ /tar\.bz2$/) {
2097 $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
2098} else {
2099 die "Unknown compression algorithm for $src";
2100}
2101# If not mandatory return now
2102return() if (($res != 0) and ($mandatory eq "patch"));
2103opendir(DIR,"$dir") || die "Unable to open directory $dir";
2104foreach my $f (readdir(DIR)) {
2105 next if ($f =~ /^\./);
2106 # Skip potential patch dir
2107 next if ($f =~ /^pbpatch/);
2108 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
2109 pb_log(2,"mv $dir/$f $ddir\n");
2110 push @files,"$ddir/$f";
2111}
2112closedir(DIR);
2113# Not enough but still a first cleanup
2114pb_rm_rf("$dir");
2115return(@files);
2116}
2117
2118sub pb_list_bfiles {
2119
2120my $dir = shift;
2121my $pbpkg = shift;
2122my $bfiles = shift;
2123my $pkgfiles = shift;
2124my $supfiles = shift;
2125
2126opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
2127foreach my $f (readdir(BDIR)) {
2128 next if ($f =~ /^\./);
2129 $bfiles->{$f} = "$dir/$f";
2130 $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
2131 if (defined $supfiles->{$pbpkg}) {
2132 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
2133 }
2134}
2135closedir(BDIR);
2136}
2137
2138
2139#
2140# Return the list of packages we are working on in a non CMS action
2141#
2142sub pb_get_pkg {
2143
2144my @pkgs = ();
2145
2146my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
2147@pkgs = keys %$var;
2148
2149pb_log(0,"Packages: ".join(',',@pkgs)."\n");
2150return(\@pkgs);
2151}
2152
2153# Which is our local arch ? (standardize on i386 for those platforms)
2154sub pb_get_arch {
2155
2156my $arch = `uname -m`;
2157chomp($arch);
2158$arch =~ s/i.86/i386/;
2159return($arch);
2160}
2161
21621;
Note: See TracBrowser for help on using the repository browser.