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

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

Fix #32 for RPMS based packages

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