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

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