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

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

Preliminary tests for the new newvm action (test only)

  • Property svn:executable set to *
File size: 50.0 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);
14use Pod::Usage;
[9]15use Data::Dumper;
16use English;
[16]17use File::Basename;
[26]18use File::Copy;
[13]19use Time::localtime qw(localtime);
20use POSIX qw(strftime);
[5]21
[73]22# Global variables
[17]23use lib qw (lib);
[329]24use ProjectBuilder::Distribution;
25use ProjectBuilder::Version;
[318]26use ProjectBuilder::Base;
[5]27
28my %opts; # CLI Options
[9]29my $action; # action to realize
[320]30my $test = "FALSE"; # Not used
31my $force = 0; # Force VE/VM rebuild
32my $option = ""; # Not used
33my @pkgs; # list of packages
[95]34my $pbtag; # Global Tag variable
35my $pbver; # Global Version variable
[141]36my $pbscript; # Name of the script
[77]37my %pbver; # per package
38my %pbtag; # per package
[53]39my $pbrev; # Global REVISION variable
[152]40my $pbaccount; # Login to use to connect to the VM
[162]41my $pbport; # Port to use to connect to the VM
[199]42my $newver; # New version to create
[331]43my $iso; # ISO image for the VM to create
[5]44
[320]45my @date = pb_get_date();
46my $pbdate = strftime("%Y-%m-%d", @date);
[5]47
[331]48=pod
49
50=head1 NAME
51
52pb, aka project-builder.org - builds packages for your projects
53
54=head1 DESCRIPTION
55
56pb helps you build various packages directly from your project sources.
57Those sources could be handled by a CMS (Configuration Management System)
58such as Subversion, CVS, ... or being a simple reference to a compressed tar file.
59It's based on a set of configuration files, a set of provided macros to help
60you keeping build files as generic as possible. For example, a single .spec
61file should be required to generate for all rpm based distributions, even
62if you could also have multiple .spec files if required.
63
64=head1 SYNOPSIS
65
[332]66pb [-vhq][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...]
[331]67
[332]68pb [--verbose][--help][--man][--quiet][--revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...]
[331]69
70=head1 OPTIONS
71
72=over 4
73
74=item B<-v|--verbose>
75
76Print a brief help message and exits.
77
78=item B<-q|--quiet>
79
80Do not print any output.
81
82=item B<-h|--help>
83
84Print a brief help message and exits.
85
86=item B<--man>
87
88Prints the manual page and exits.
89
90=item B<-m|--machine machine1[,machine2,...]>
91
92Name of the Virtual Machines (VM) or Virtual Environments (VE) you want to build on (coma separated).
93All if none precised (or use the env variable PBV).
94
95=item B<-s|--script script>
96
97Name of the script you want to execute on the related VMs or VEs.
98
99=item B<-i|--iso iso_image>
100
101Name of the ISO image of the distribution you want to install on the related VMs.
102
103=item B<-a|--account account>
104
105Name of the account to use to connect on the related VMs.
106
107=item B<-P|--port port_number>
108
109Port number to use to connect on the related VMs.\n";
110
111=item B<-p|--project project_name>
112
113Name of the project you're working on (or use the env variable PBPROJ)
114
115=item B<-r|--revision revision>
116
117Path Name of the project revision under the CMS (or use the env variable PBROOT)
118
119=item B<-V|--version new_version>
120
121New version of the project to create based on the current one.
122
123=back
124
125=head1 ARGUMENTS
126
127<action> can be:
128
129=over 4
130
131=item B<cms2build>
132
133Create tar files for the project under your CMS.
134CMS supported are SVN and CVS
135parameters are packages to build
136if not using default list
137
138=item B<build2pkg>
139
140Create packages for your running distribution
141
142=item B<cms2pkg>
143
144cms2build + build2pkg
145
146=item B<build2ssh>
147
148Send the tar files to a SSH host
149
150=item B<cms2ssh>
151
152cms2build + build2ssh
153
154=item B<pkg2ssh>
155
156Send the packages built to a SSH host
157
158=item B<build2vm>
159
160Create packages in VMs, launching them if needed
161and send those packages to a SSH host once built
162VM type supported are QEMU
163
164=item B<build2ve>
165
166Create packages in VEs, creating it if needed
167and send those packages to a SSH host once built
168
169=item B<cms2vm>
170
171cms2build + build2vm
172
173=item B<cms2ve>
174
175cms2build + build2ve
176
177=item B<launchvm>
178
179Launch one virtual machine
180
181=item B<launchve>
182
183Launch one virtual environment
184
185=item B<script2vm>
186
187Launch one virtual machine if needed
188and executes a script on it
189
190=item B<script2ve>
191
192Execute a script in a virtual environment
193
194=item B<newvm>
195
196Create a new virtual machine
197
198=item B<newve>
199
200Create a new virtual environment
201
[346]202=item B<setupvm>
203
204Setup a virtual machine for pb usage
205
206=item B<setupve>
207
208Setup a virtual environment for pb usage
209
[331]210=item B<newver>
211
212Create a new version of the project derived
213from the current one
214
215=item B<newproj>
216
217Create a new project and a template set of
218configuration files under pbconf
219
220=back
221
222<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).
223
224=head1 WEB SITES
225
226The 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/>.
227
228=head1 USER MAILING LIST
229
230None exists for the moment.
231
232=head1 CONFIGURATION FILES
233
234Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
235
236Here is an example of such a configuration file:
237
238 #
239 # Define for each project the URL of its pbconf repository
240 # No default option allowed here as they need to be all different
241 #
242 # URL of the pbconf content
243 # This is the format of a classical URL with the extension of additional schema such as
244 # svn+ssh, cvs+ssh, ...
245 #
246 pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
247
248 # This is normaly defined in the project's configuration file
249 # Url of the project
250 #
251 pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
252
253 # All these URLs needs to be defined here as the are the entry point
254 # for how to build packages for the project
255 #
256 pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
257 pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
258 pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
259 pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
260
261 # Under that dir will take place everything related to pb
262 # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
263 # to your VMs/chroot/...
264 # if not defined then /var/cache
265 pbdefdir default = $ENV{'HOME'}/project-builder
266 pbdefdir pb = $ENV{'HOME'}
267 pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
268 pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
269
270 # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
271 # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
272 pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
273 pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
274
275 # pbdir points to the directory where the CMS content of the pburl is checked out
276 # If not defined, pbdir is under pbdefdir/pbproj
277 # Only defined if we have access to the dev of the project
278 pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
279 pbdir mondorescue = $ENV{'HOME'}/mondo/svn
280
281 # -daemonize doesn't work with qemu 0.8.2
282 vmopt default = -m 384
283
284=head1 AUTHORS
285
286The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
287
288=head1 COPYRIGHT
289
290Project-Builder.org is distributed under the GPL v2.0 license
291described in the file C<COPYING> included with the distribution.
292
293=cut
294
295# ---------------------------------------------------------------------------
296
297# Old syntax
298#getopts('a:fhi:l:m:P:p:qr:s:vV:',\%opts);
299
[75]300my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
[331]301
302GetOptions("help|?|h" => \$opts{'h'},
303 "man" => \$opts{'man'},
304 "verbose|v+" => \$opts{'v'},
305 "quiet|q" => \$opts{'q'},
306 "log-files|l=s" => \$opts{'l'},
307 "force|f" => \$opts{'f'},
308 "account|a=s" => \$opts{'a'},
309 "revision|r=s" => \$opts{'r'},
310 "script|s=s" => \$opts{'s'},
311 "machines|mock|m=s" => \$opts{'m'},
312 "port|P=i" => \$opts{'P'},
313 "project|p=s" => \$opts{'p'},
314 "iso|i=s" => \$opts{'i'},
315 "version|V=s" => \$opts{'V'},
316) || pb_syntax(-1,0);
317
[21]318if (defined $opts{'h'}) {
[331]319 pb_syntax(0,1);
[21]320}
[331]321if (defined $opts{'man'}) {
322 pb_syntax(0,2);
323}
[21]324if (defined $opts{'v'}) {
[331]325 $debug = $opts{'v'};
[318]326 pb_log(0,"Debug value: $debug\n");
[21]327}
[320]328if (defined $opts{'f'}) {
329 $force=1;
330}
[21]331if (defined $opts{'q'}) {
332 $debug=-1;
333}
[22]334if (defined $opts{'l'}) {
335 open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
[348]336 $LOG = \*LOG;
[22]337 $debug = 0 if ($debug == -1);
338 }
[315]339pb_log_init($debug, $LOG);
340
[67]341# Handle root of the project if defined
342if (defined $opts{'r'}) {
[340]343 $ENV{'PBROOTDIR'} = $opts{'r'};
[67]344}
[91]345# Handle virtual machines if any
346if (defined $opts{'m'}) {
[320]347 $ENV{'PBV'} = $opts{'m'};
[91]348}
[141]349if (defined $opts{'s'}) {
350 $pbscript = $opts{'s'};
351}
[152]352if (defined $opts{'a'}) {
353 $pbaccount = $opts{'a'};
[347]354 die "option -a requires a -s script option" if (not defined $pbscript);
[152]355}
[162]356if (defined $opts{'P'}) {
357 $pbport = $opts{'P'};
358}
[199]359if (defined $opts{'V'}) {
360 $newver = $opts{'V'};
361}
[262]362if (defined $opts{'i'}) {
363 $iso = $opts{'i'};
364}
[108]365
366# Get Action
367$action = shift @ARGV;
[331]368die pb_syntax(-1,1) if (not defined $action);
[108]369
[314]370my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
[273]371my $pbinit = undef;
372$pbinit = 1 if ($action =~ /^newproj$/);
[108]373
[59]374# Handles project name if any
[108]375# And get global params
[353]376($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action);
[59]377
[315]378pb_log(0,"Project: $ENV{'PBPROJ'}\n");
379pb_log(0,"Action: $action\n");
[9]380
381# Act depending on action
382if ($action =~ /^cms2build$/) {
[77]383 pb_cms2build();
384} elsif ($action =~ /^build2pkg$/) {
385 pb_build2pkg();
386} elsif ($action =~ /^cms2pkg$/) {
387 pb_cms2build();
388 pb_build2pkg();
[88]389} elsif ($action =~ /^build2ssh$/) {
390 pb_build2ssh();
[220]391} elsif ($action =~ /^cms2ssh$/) {
392 pb_cms2build();
393 pb_build2ssh();
[88]394} elsif ($action =~ /^pkg2ssh$/) {
395 pb_pkg2ssh();
[320]396} elsif ($action =~ /^build2ve$/) {
397 pb_build2v("ve");
[91]398} elsif ($action =~ /^build2vm$/) {
[320]399 pb_build2v("vm");
400} elsif ($action =~ /^cms2ve$/) {
401 pb_cms2build();
402 pb_build2v("ve");
[91]403} elsif ($action =~ /^cms2vm$/) {
404 pb_cms2build();
[320]405 pb_build2v("vm");
[141]406} elsif ($action =~ /^launchvm$/) {
[320]407 pb_launchv("vm",$ENV{'PBV'},0);
408} elsif ($action =~ /^launchve$/) {
409 pb_launchv("ve",$ENV{'PBV'},0);
[142]410} elsif ($action =~ /^script2vm$/) {
[320]411 pb_script2v($pbscript,"vm");
412} elsif ($action =~ /^script2ve$/) {
413 pb_script2v($pbscript,"ve");
[199]414} elsif ($action =~ /^newver$/) {
415 pb_newver();
[320]416} elsif ($action =~ /^newve$/) {
417 pb_launchv("ve",$ENV{'PBV'},1);
[262]418} elsif ($action =~ /^newvm$/) {
[320]419 pb_launchv("vm",$ENV{'PBV'},1);
[346]420} elsif ($action =~ /^setupve$/) {
[353]421 pb_setup_v("ve");
[346]422} elsif ($action =~ /^setupvm$/) {
[353]423 pb_setup_v("vm");
[273]424} elsif ($action =~ /^newproj$/) {
425 # Nothing to do - already done in pb_env_init
[106]426} elsif ($action =~ /^clean$/) {
[77]427} else {
[315]428 pb_log(0,"\'$action\' is not available\n");
[331]429 pb_syntax(-2,1);
[77]430}
431
432sub pb_cms2build {
433
[357]434 my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
435 my @pkgs = @$pkg;
436 my %pkgs;
[9]437
[341]438 my ($scheme, $uri) = pb_cms_init($pbinit);
[331]439
[313]440 my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
[174]441
442 # declare packager for filtering
[320]443 my ($tmp) = pb_conf_get("pbpackager");
[353]444 $ENV{'PBPACKAGER'} = $tmp->{$ENV{'PBPROJ'}};
[174]445
[27]446 foreach my $pbpkg (@pkgs) {
[115]447 $ENV{'PBPKG'} = $pbpkg;
[98]448 if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
449 $pbver = $pkgv->{$pbpkg};
[9]450 } else {
[353]451 $pbver = $ENV{'PBPROJVER'};
[9]452 }
[98]453 if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
454 $pbtag = $pkgt->{$pbpkg};
[9]455 } else {
[353]456 $pbtag = $ENV{'PBPROJTAG'};
[9]457 }
[95]458
[16]459 $pbrev = $ENV{'PBREVISION'};
[319]460 pb_log(0,"\n");
461 pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
[9]462 die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
[16]463 # Clean up dest if necessary. The export will recreate it
[27]464 my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
[74]465 pb_rm_rf($dest) if (-d $dest);
[9]466
467 # Export CMS tree for the concerned package to dest
468 # And generate some additional files
469 $OUTPUT_AUTOFLUSH=1;
[29]470
[9]471 # computes in which dir we have to work
[113]472 my $dir = $defpkgdir->{$pbpkg};
473 $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
[315]474 pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
[9]475
[340]476 # Exporting from CMS
477 pb_cms_export($uri,"$ENV{'PBDIR'}/$dir",$dest);
[315]478
[285]479 # Get project info on authors and log file
[340]480 my $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
481 $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
[285]482 $chglog = undef if (! -f $chglog);
483
[340]484 my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
485 $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
[285]486 $authors = "/dev/null" if (! -f $authors);
487
[9]488 # Extract cms log history and store it
[285]489 if ((defined $chglog) && (! -f "$dest/NEWS")) {
[315]490 pb_log(2,"Generating NEWS file from $chglog\n");
[285]491 copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
492 }
[340]493 pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors);
[29]494
[21]495 my %build;
[91]496
[328]497 my @pt;
498 @pt = pb_conf_get_if("vmlist","velist");
[340]499 my $tmpl = "";
500 if (defined $pt[0]->{$ENV{'PBPROJ'}}) {
501 $tmpl .= $pt[0]->{$ENV{'PBPROJ'}};
502 }
503 if (defined $pt[1]->{$ENV{'PBPROJ'}}) {
504 # the 2 lists needs to be grouped with a ',' separated them
505 if ($tmpl ne "") {
506 $tmpl .= ",";
507 }
508 $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
509 }
510 foreach my $d (split(/,/,$tmpl)) {
[315]511 my ($name,$ver,$arch) = split(/-/,$d);
512 chomp($arch);
[99]513 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
[315]514 pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n");
515 pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
[13]516
[16]517 # Filter build files from the less precise up to the most with overloading
[13]518 # Filter all files found, keeping the name, and generating in dest
[16]519
[340]520 # Find all build files first relatively to PBROOTDIR
[300]521 # Find also all specific files referenced in the .pb conf file
[320]522 my %bfiles = ();
523 my %pkgfiles = ();
[21]524 $build{"$ddir-$dver"} = "yes";
[315]525
[340]526 if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dtype") {
527 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dtype",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
528 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
529 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
530 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
531 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
532 } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
533 pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
[13]534 } else {
[21]535 $build{"$ddir-$dver"} = "no";
[13]536 next;
537 }
[315]538 pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
[13]539
[15]540 # Get all filters to apply
[77]541 my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
[15]542
[19]543 # Apply now all the filters on all the files concerned
544 # destination dir depends on the type of file
545 if (defined $ptr) {
[300]546 foreach my $f (values %bfiles,values %pkgfiles) {
[353]547 pb_filter_file_pb("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$ENV{'PBPACKAGER'},$chglog);
[16]548 }
[15]549 }
[18]550 }
[315]551 my @found;
552 my @notfound;
553 foreach my $b (keys %build) {
554 push @found,$b if ($build{$b} =~ /yes/);
555 push @notfound,$b if ($build{$b} =~ /no/);
[21]556 }
[315]557 pb_log(0,"Build files generated for ".join(',',@found)."\n");
558 pb_log(0,"No Build files found for ".join(',',@notfound)."\n") if (@notfound);
[236]559 # Get the generic filter (all.pbf) and
560 # apply those to the non-build files including those
561 # generated by pbinit if applicable
562
563 # Get only all.pbf filter
[357]564 my $ptr = pb_get_filters($pbpkg);
[236]565
566 my $liste ="";
567 if (defined $filteredfiles->{$pbpkg}) {
568 foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
[353]569 pb_filter_file_inplace($ptr,"$dest/$f",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$ENV{'PBPACKAGER'});
[238]570 $liste = "$f $liste";
[236]571 }
572 }
[315]573 pb_log(2,"Files ".$liste."have been filtered\n");
[236]574
[265]575 # Prepare the dest directory for archive
[340]576 if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
[353]577 pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$ENV{'PBPACKAGER'});
[266]578 chmod 0755,"$ENV{'PBTMP'}/pbinit";
[340]579 pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit");
[265]580 }
581
[18]582 # Archive dest dir
[69]583 chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
[25]584 # Possibility to look at PBSRC to guess more the filename
[94]585 pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
[344]586 pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
[83]587
[357]588 # Keep track of version-tag per pkg
589 $pkgs{$pbpkg} = "$pbver-$pbtag";
[83]590
[288]591 # Final cleanup
592 pb_rm_rf($dest) if (-d $dest);
[9]593 }
[357]594
595 # Keep track of per package version
596 pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
597 open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
598 foreach my $pbpkg (@pkgs) {
599 print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
600 }
601 close(PKG);
602
603 # Keep track of what is generated by default
604 # We need to store the dir and info on version-tag
605 # Base our content on the existing .pb file
606 copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
607 open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
608 print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
609 print LAST "pbprojver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
610 print LAST "pbprojtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
611 print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
612 close(LAST);
[77]613}
[22]614
[77]615sub pb_build2pkg {
616
[22]617 # Get the running distro to build on
[99]618 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
[315]619 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
[22]620
[353]621 # Get list of packages to build
[83]622 # Get content saved in cms2build
[353]623 my $ptr = pb_get_pkg();
624 @pkgs = @$ptr;
625
626 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
[83]627 $pkg = { } if (not defined $pkg);
628
[25]629 chdir "$ENV{'PBBUILDDIR'}";
[126]630 my $made = ""; # pkgs made during build
[27]631 foreach my $pbpkg (@pkgs) {
[88]632 my $vertag = $pkg->{$pbpkg};
[77]633 # get the version of the current package - maybe different
634 ($pbver,$pbtag) = split(/-/,$vertag);
635
[27]636 my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[315]637 pb_log(2,"Source file: $src\n");
[25]638
[315]639 pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
[25]640 if ($dtype eq "rpm") {
641 foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
[28]642 if (! -d "$ENV{'PBBUILDDIR'}/$d") {
[96]643 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]644 }
[25]645 }
646
[315]647 # Remove in case a previous link/file was there
[301]648 unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
[188]649 symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
[25]650 # We need to first extract the spec file
[28]651 my @specfile;
[77]652 @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
[25]653
[315]654 pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
[25]655 # set LANGUAGE to check for correct log messages
656 $ENV{'LANGUAGE'}="C";
[28]657 foreach my $f (@specfile) {
658 if ($f =~ /\.spec$/) {
[353]659 pb_system("rpmbuild --define \'packager $ENV{'PBPACKAGER'}\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
[28]660 last;
661 }
662 }
[136]663 $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
[149]664 if (-f "/usr/bin/rpmlint") {
665 pb_system("rpmlint $made","Checking validity of rpms with rpmlint");
[150]666 }
[118]667 } elsif ($dtype eq "deb") {
[149]668 chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
[274]669 pb_system("tar xfz $src","Extracting sources");
[149]670
671 chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
[310]672 pb_rm_rf("debian");
[149]673 symlink "pbconf/$ddir-$dver","debian" || die "Unable to symlink to pbconf/$ddir-$dver";
[199]674 chmod 0755,"debian/rules";
[149]675 pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
[136]676 $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
[315]677 if (-f "/usr/bin/lintian") {
678 pb_system("lintian $made","Checking validity of debs with lintian");
679 }
[87]680 } elsif ($dtype eq "ebuild") {
[149]681 my @ebuildfile;
682 # For gentoo we need to take pb as subsystem name
[295]683 # We put every apps here under sys-apps. hope it's correct
684 # We use pb's home dir in order o have a single OVERLAY line
685 my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
686 pb_mkdir_p($tmpd) if (! -d "$tmpd");
687 pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
[149]688
[295]689 # We need to first extract the ebuild file
690 @ebuildfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$tmpd");
[149]691
692 # Prepare the build env for gentoo
693 my $found = 0;
[295]694 my $pbbd = $ENV{'HOME'};
[150]695 $pbbd =~ s|/|\\/|g;
[295]696 if (-r "/etc/make.conf") {
697 open(MAKE,"/etc/make.conf");
698 while (<MAKE>) {
699 $found = 1 if (/$pbbd\/portage/);
700 }
701 close(MAKE);
[149]702 }
703 if ($found == 0) {
[295]704 pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
[149]705 }
[295]706 #$found = 0;
707 #if (-r "/etc/portage/package.keywords") {
708 #open(KEYW,"/etc/portage/package.keywords");
709 #while (<KEYW>) {
710 #$found = 1 if (/portage\/pb/);
711 #}
712 #close(KEYW);
713 #}
714 #if ($found == 0) {
715 #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
716 #}
[149]717
718 # Build
719 foreach my $f (@ebuildfile) {
720 if ($f =~ /\.ebuild$/) {
[295]721 move($f,"$tmpd/$pbpkg-$pbver.ebuild");
722 pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package");
723 # Now move it where pb expects it
724 pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
725 move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
[149]726 }
727 }
728
[295]729 $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
[118]730 } elsif ($dtype eq "slackware") {
[136]731 $made="$made build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
[118]732 pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
[87]733 } else {
[118]734 die "Unknown dtype format $dtype";
[87]735 }
736 }
[118]737 # Keep track of what is generated so that we can get them back from VMs
[353]738 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]739 print KEEP "$made\n";
740 close(KEEP);
[87]741}
742
[88]743sub pb_build2ssh {
[320]744 pb_send2target("Sources");
[90]745}
[87]746
[90]747sub pb_pkg2ssh {
[320]748 pb_send2target("Packages");
[90]749}
750
[108]751# By default deliver to the the public site hosting the
[320]752# ftp structure (or whatever) or a VM/VE
753sub pb_send2target {
[90]754
755 my $cmt = shift;
[320]756 my $v = shift || undef;
[142]757 my $vmexist = shift || 0; # 0 is FALSE
[200]758 my $vmpid = shift || 0; # 0 is FALSE
[320]759
760 my $host = "sshhost";
761 my $login = "sshlogin";
762 my $dir = "sshdir";
763 my $port = "sshport";
764 my $tmout = "sshtmout";
765 my $path = "sshpath";
766 my $conf = "sshconf";
767 my $rebuild = "sshrebuild";
[348]768 if (($cmt eq "vm") || ($cmt eq "Script")) {
[320]769 $login = "vmlogin";
[322]770 $dir = "pbdefdir";
[320]771 $tmout = "vmtmout";
772 $rebuild = "vmrebuild";
773 # Specific VM
774 $host = "vmhost";
775 $port = "vmport";
776 } elsif ($cmt eq "ve") {
777 $login = "velogin";
[322]778 $dir = "pbdefdir";
[320]779 $tmout = "vetmout";
780 # Specific VE
781 $path = "vepath";
782 $conf = "veconf";
783 $rebuild = "verebuild";
784 }
[158]785 my $cmd = "";
[90]786
[353]787 my $ptr = pb_get_pkg();
[87]788 @pkgs = @$ptr;
789
[136]790 # Get the running distro to consider
[347]791 my ($odir,$over,$oarch) = (undef, undef, undef);
[320]792 if (defined $v) {
793 ($odir,$over,$oarch) = split(/-/,$v);
[118]794 }
795 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
[315]796 pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
[87]797
[353]798 # Get list of packages to build
[87]799 # Get content saved in cms2build
[353]800 my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
[87]801 $pkg = { } if (not defined $pkg);
802
[118]803 my $src = "";
[87]804 chdir "$ENV{'PBBUILDDIR'}";
805 foreach my $pbpkg (@pkgs) {
[88]806 my $vertag = $pkg->{$pbpkg};
[87]807 # get the version of the current package - maybe different
808 ($pbver,$pbtag) = split(/-/,$vertag);
809
[320]810 if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
[158]811 $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
[166]812 if ($cmd eq "") {
813 $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
814 } else {
815 $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
816 }
[118]817 }
818 }
[320]819 if (($cmt eq "vm") || ($cmt eq "ve")) {
[353]820 $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc";
[142]821 } elsif ($cmt eq "Script") {
822 $src="$src $ENV{'PBDESTDIR'}/pbscript";
[118]823 } elsif ($cmt eq "Packages") {
824 # Get package list from file made during build2pkg
[353]825 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[126]826 $src = <KEEP>;
[118]827 chomp($src);
828 close(KEEP);
829 if ($dtype eq "rpm") {
830 # Also make a pbscript to generate yum/urpmi bases
[108]831 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[118]832 } elsif ($dtype eq "deb") {
833 # Also make a pbscript to generate apt bases
834 # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
[90]835 }
[87]836 }
[320]837 # Remove potential leading spaces (cause problem with basename)
[132]838 $src =~ s/^ *//;
[129]839 my $basesrc = "";
[131]840 foreach my $i (split(/ +/,$src)) {
841 $basesrc .= " ".basename($i);
[130]842 }
[118]843
[320]844 pb_log(0,"Sources handled ($cmt): $src\n");
[355]845 pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf))."\n");
[320]846 my ($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf) = pb_conf_get($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf);
847 pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf))."\n");
848 # Not mandatory
849 my ($testver) = pb_conf_get_if("testver");
850
851 my $mac;
852 # Useless for VE
853 if ($cmt ne "ve") {
854 $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
855 # Overwrite account value if passed as parameter
856 $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
[355]857 pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
[320]858 }
859
[108]860 my $tdir;
[136]861 my $bdir;
[142]862 if (($cmt eq "Sources") || ($cmt eq "Script")) {
[108]863 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
[320]864 } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
865 $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
866 $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
[136]867 # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
868 $bdir =~ s|\$ENV.+\}/||;
[90]869 } elsif ($cmt eq "Packages") {
[108]870 $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
[337]871 if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
[289]872 # This is a test pkg => target dir is under test
873 $tdir .= "/test";
[291]874 }
[90]875 } else {
876 return;
[22]877 }
[239]878
[320]879 # Useless for VE
880 my $nport;
881 if ($cmt ne "ve") {
882 $nport = $sshport->{$ENV{'PBPROJ'}};
883 $nport = "$pbport" if (defined $pbport);
884 }
885
[136]886 # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
[132]887 $tdir =~ s|\$ENV.+\}/||;
888
[320]889 my $tm = $vtmout->{$ENV{'PBPROJ'}};
890
891 # ssh communication if not VE
[349]892 # should use a hash instead...
[320]893 my ($shcmd,$cpcmd,$cptarget,$cp2target);
894 if ($cmt ne "ve") {
[347]895 my $keyfile = pb_ssh_get(0);
896 $shcmd = "ssh -i $keyfile -q -p $nport $mac";
897 $cpcmd = "scp -i $keyfile -p -P $nport";
[320]898 $cptarget = "$mac:$tdir";
[351]899 if ($cmt eq "vm") {
900 $cp2target = "$mac:$bdir";
901 }
[320]902 } else {
903 my $tp = $vepath->{$ENV{'PBPROJ'}};
904 $shcmd = "sudo chroot $tp/$v /bin/su - $sshlogin->{$ENV{'PBPROJ'}} -c ";
905 $cpcmd = "cp -a ";
906 $cptarget = "$tp/$tdir";
907 $cp2target = "$tp/$bdir";
908 }
909
910 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");
911 pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
912 # For VE we need to change the owner manually - To be tested if needed
913 #if ($cmt eq "ve") {
914 #pb_system("cd $cptarget ; sudo chown -R $sshlogin->{$ENV{'PBPROJ'}} .","$cmt chown in $cptarget to $sshlogin->{$ENV{'PBPROJ'}}");
915 #}
916 pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $cptarget if needed");
917 if (($cmt eq "vm") || ($cmt eq "ve")) {
[128]918 # Get back info on pkg produced, compute their name and get them from the VM
[353]919 pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
920 open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[118]921 my $src = <KEEP>;
922 chomp($src);
923 close(KEEP);
[131]924 $src =~ s/^ *//;
[136]925 pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
[320]926 # Change pgben to make the next send2target happy
[143]927 my $made = "";
[353]928 open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
[136]929 foreach my $p (split(/ +/,$src)) {
[139]930 my $j = basename($p);
[320]931 pb_system("$cpcmd $cp2target/\'$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $cp2target");
[144]932 $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
[136]933 }
[143]934 print KEEP "$made\n";
[139]935 close(KEEP);
[320]936 pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
[355]937
938 # We want to send them to the ssh account so overwrite what has been done before
939 undef $pbaccount;
[357]940 pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
[355]941 pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
[320]942 if ((! $vmexist) && ($cmt eq "vm")) {
943 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)");
[142]944 }
[141]945 pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
[108]946 }
[9]947}
[16]948
[320]949sub pb_script2v {
[142]950 my $pbscript=shift;
[320]951 my $vtype=shift;
[141]952
953 # Prepare the script to be executed on the VM
954 # in $ENV{'PBDESTDIR'}/pbscript
[142]955 if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
956 copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
957 chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
958 }
[141]959
[320]960 my ($vm,$all) = pb_get_v($vtype);
961 my ($vmexist,$vmpid) = (undef,undef);
[142]962
[141]963 foreach my $v (@$vm) {
[320]964 # Launch the VM/VE
965 if ($vtype eq "vm") {
966 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
[141]967
[320]968 # Skip that VM if something went wrong
969 next if (($vmpid == 0) && ($vmexist ==0));
970 }
[274]971
[142]972 # Gather all required files to send them to the VM
[320]973 # and launch the build through pbscript
974 pb_send2target("Script","$v",$vmexist,$vmpid);
[169]975
[142]976 }
977}
978
[320]979sub pb_launchv {
980 my $vtype = shift;
981 my $v = shift;
982 my $create = shift || 0; # By default do not create a VM
[310]983
[320]984 die "No VM/VE defined, unable to launch" if (not defined $v);
985 # Keep only the first VM in case many were given
986 $v =~ s/,.*//;
[310]987
[320]988 # Which is our local arch ? (standardize on i386 for those platforms)
989 my $arch = `uname -m`;
990 chomp($arch);
991 $arch =~ s/i.86/i386/;
[310]992
[320]993 # Launch the VMs/VEs
994 if ($vtype eq "vm") {
995 die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
[310]996
[320]997 my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
998
999 my $vmtype = $ptr->{$ENV{'PBPROJ'}};
1000 if (not defined $ENV{'PBVMOPT'}) {
1001 $ENV{'PBVMOPT'} = "";
[310]1002 }
[320]1003 if (defined $vmopt->{$ENV{'PBPROJ'}}) {
1004 $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
1005 }
1006 my $nport = $vmport->{$ENV{'PBPROJ'}};
1007 $nport = "$pbport" if (defined $pbport);
1008
1009 my $cmd;
1010 my $vmcmd; # has to be used for pb_check_ps
1011 my $vmm; # has to be used for pb_check_ps
1012 if ($vmtype eq "qemu") {
1013 my $qemucmd32;
1014 my $qemucmd64;
1015 if ($arch eq "x86_64") {
1016 $qemucmd32 = "/usr/bin/qemu-system-i386";
1017 $qemucmd64 = "/usr/bin/qemu";
1018 } else {
1019 $qemucmd32 = "/usr/bin/qemu";
1020 $qemucmd64 = "/usr/bin/qemu-system-x86_64";
1021 }
1022 if ($v =~ /x86_64/) {
1023 $vmcmd = "$qemucmd64 -no-kqemu";
1024 } else {
1025 $vmcmd = "$qemucmd32";
1026 }
1027 $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
1028 if ($create != 0) {
1029 $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
1030 }
1031 $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
1032 } elsif ($vmtype eq "xen") {
1033 } elsif ($vmtype eq "vmware") {
[310]1034 } else {
[320]1035 die "VM of type $vmtype not supported. Report to the dev team";
[310]1036 }
[320]1037 my ($tmpcmd,$void) = split(/ +/,$cmd);
1038 my $vmexist = pb_check_ps($tmpcmd,$vmm);
1039 my $vmpid = 0;
1040 if (! $vmexist) {
1041 if ($create != 0) {
1042 if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
1043 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
1044 } elsif ($vmtype eq "vmware") {
1045 } else {
1046 }
1047 }
1048 if (! -f "$vmm") {
1049 pb_log(0,"Unable to find VM $vmm\n");
1050 } else {
1051 pb_system("$cmd &","Launching the VM $vmm");
1052 pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $v to come up");
1053 $vmpid = pb_check_ps($tmpcmd,$vmm);
[357]1054 pb_log(0,"VM $vmm launched (pid $vmpid)\n");
[320]1055 }
[310]1056 } else {
[320]1057 pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
[310]1058 }
[320]1059 return($vmexist,$vmpid);
1060 # VE here
[310]1061 } else {
[320]1062 # Get VE context
1063 my ($ptr,$vepath,$vetmout,$verebuild,$veconf) = pb_conf_get("vetype","vepath","vetmout","verebuild","veconf");
1064 my $vetype = $ptr->{$ENV{'PBPROJ'}};
[310]1065
[320]1066 # Get distro context
1067 my ($name,$ver,$darch) = split(/-/,$v);
1068 chomp($darch);
1069 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
[142]1070
[320]1071 if ($vetype eq "chroot") {
1072 # Architecture consistency
1073 if ($arch ne $darch) {
1074 die "Unable to launch a VE of architecture $darch on a $arch platform" if (not (($darch eq "x86_64") && ($arch =~ /i?86/)));
1075 }
[142]1076
[320]1077 if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($force == 1)) {
1078 # We have to rebuild the chroot
1079 if ($dtype eq "rpm") {
1080 pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
1081 # Once setup we need to install some packages, the pb account, ...
1082 pb_system("sudo /usr/sbin/mock --install --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
1083 #pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" --basedir=\"$vepath->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
1084 } elsif ($dtype eq "deb") {
1085 pb_system("","Creating the pbuilder VE");
1086 } elsif ($dtype eq "ebuild") {
1087 die "Please teach the dev team how to build gentoo chroot";
1088 } else {
1089 die "Unknown distribution type $dtype. Report to dev team";
1090 }
[310]1091 }
[320]1092 # Nothing more to do for VE. No real launch
[274]1093 } else {
[320]1094 die "VE of type $vetype not supported. Report to the dev team";
[262]1095 }
[141]1096 }
1097}
[142]1098
[320]1099sub pb_build2v {
[118]1100
[320]1101my $vtype = shift;
[142]1102
[320]1103# Prepare the script to be executed on the VM/VE
1104# in $ENV{'PBDESTDIR'}/pbscript
[353]1105#my ($ntp) = pb_conf_get($vtype."ntp");
1106#my $vntp = $ntp->{$ENV{'PBPROJ'}};
[118]1107
[320]1108open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
1109print SCRIPT "#!/bin/bash\n";
1110print SCRIPT "echo ... Execution needed\n";
1111print SCRIPT "# This is in directory delivery\n";
1112print SCRIPT "# Setup the variables required for building\n";
1113print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
1114print SCRIPT "# Preparation for pb\n";
1115print SCRIPT "mv .pbrc \$HOME\n";
1116print SCRIPT "cd ..\n";
1117# Force new date to be in the future compared to the date of the tar file by adding 1 minute
1118my @date=pb_get_date();
1119$date[1]++;
1120my $upddate = strftime("%m%d%H%M%Y", @date);
[353]1121#print SCRIPT "echo Setting up date on $vntp...\n";
[320]1122# Or use ntpdate if available TBC
1123print SCRIPT "sudo date $upddate\n";
[353]1124# Get list of packages to build and get some ENV vars as well
1125my $ptr = pb_get_pkg();
1126@pkgs = @$ptr;
1127my $p = join(' ',@pkgs) if (@pkgs);
1128print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
1129print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
[320]1130print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
1131print SCRIPT "# Build\n";
1132print SCRIPT "echo Building packages on $vtype...\n";
1133print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
1134close(SCRIPT);
1135chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
1136
1137my ($v,$all) = pb_get_v($vtype);
1138
1139# Send tar files when we do a global generation
1140pb_build2ssh() if ($all == 1);
1141
1142my ($vmexist,$vmpid) = (undef,undef);
1143
1144foreach my $v (@$v) {
1145 if ($vtype eq "vm") {
[142]1146 # Launch the VM
[357]1147 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
[118]1148
[274]1149 # Skip that VM if it something went wrong
1150 next if (($vmpid == 0) && ($vmexist == 0));
[118]1151 }
[320]1152 # Gather all required files to send them to the VM/VE
[347]1153 # and launch the build through pbscript
[357]1154 pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
[320]1155 pb_send2target($vtype,"$v",$vmexist,$vmpid);
[105]1156}
[320]1157}
[105]1158
[262]1159
[199]1160sub pb_newver {
1161
[204]1162 die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
[340]1163
1164 my ($scheme,$uri)=pb_cms_init($pbinit);
[358]1165 my ($pburl) = pb_conf_get("pburl");
1166 my ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
[340]1167
1168 if ($scheme !~ /^svn/) {
[199]1169 die "Only SVN is supported at the moment";
1170 }
[358]1171 my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
1172 die "You need to have no differences in $uri before creating a new version" if ($res != 0);
1173
1174 $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
1175 die "You need to have no differences in $pburl->{$ENV{'PBPROJ'}} before creating a new version" if ($res != 0);
1176
1177 # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
1178 # we want to get for the root of the new URL
1179
1180 my $tmp = $ENV{'PBROOTDIR'};
1181 $tmp =~ s|^$ENV{'PBCONFDIR'}||;
1182
1183 my $newurl = "$uri/".dirname($tmp)."/$newver";
1184 pb_log(2,"Copying $uri to $newurl\n");
1185 #pb_cms_copy($scheme,$uri,$newurl);
1186 pb_log(2,"Checkout $newurl to $ENV{'PBDIR'}/../$newver\n");
1187 #pb_cms_checkout($scheme,$newurl,"$ENV{'PBDIR'}/../$newver");
1188 my $oldver=basename($uri);
1189 open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
1190 open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
[208]1191 while(<FILE>) {
[209]1192 s/projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
[211]1193 print OUT $_;
[208]1194 }
1195 close(FILE);
[211]1196 close(OUT);
[358]1197 rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
1198 pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
1199 #pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver");
[199]1200}
1201
[293]1202#
[320]1203# Return the list of VMs/VEs we are working on
[105]1204# $all is a flag to know if we return all of them
1205# or only some (if all we publish also tar files in addition to pkgs
1206#
[320]1207sub pb_get_v {
[91]1208
[320]1209my $vtype = shift;
1210my @v;
[105]1211my $all = 0;
[320]1212my $vlist;
1213my $pbv = 'PBV';
[91]1214
[320]1215if ($vtype eq "vm") {
1216 $vlist = "vmlist";
1217} elsif ($vtype eq "ve") {
1218 $vlist = "velist";
1219}
1220# Get VM/VE list
1221if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
1222 my ($ptr) = pb_conf_get($vlist);
1223 $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
[105]1224 $all = 1;
[91]1225}
[320]1226pb_log(2,"$vtype: $ENV{$pbv}\n");
1227@v = split(/,/,$ENV{$pbv});
1228return(\@v,$all);
[91]1229}
1230
[320]1231# Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
1232# Needs to use root account to connect to the VM/VE
1233# pb will take your local public SSH key to access
[346]1234# the pb account in the VM later on if needed
1235sub pb_setup_v {
[320]1236
1237my $vtype = shift;
1238
[353]1239my ($vm,$all) = pb_get_v($vtype);
1240
[346]1241# Script generated
1242my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
[320]1243
[353]1244foreach my $v (@$vm) {
1245 # Name of the account to deal with for VM/VE
1246 # Do not use the one passed potentially with -a
1247 my ($pbac) = pb_conf_get($vtype."login");
[354]1248 my ($key,$zero0,$zero1,$zero2);
[357]1249 my ($vmexist,$vmpid);
[346]1250
[353]1251 if ($vtype eq "vm") {
1252 # Prepare the key to be used and transfered remotely
1253 my $keyfile = pb_ssh_get(1);
1254
1255 my ($vmhost,$vmport) = pb_conf_get("vmhost","vmport");
1256 my $nport = $vmport->{$ENV{'PBPROJ'}};
1257 $nport = "$pbport" if (defined $pbport);
[347]1258
[353]1259 # Launch the VM
[357]1260 ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
[347]1261
[353]1262 # Skip that VM if something went wrong
1263 return if (($vmpid == 0) && ($vmexist == 0));
1264
[354]1265 # Store the pub key part in a variable
1266 open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
1267 ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
1268 close(FILE);
1269
1270 $key = "\Q$zero1";
1271
[353]1272 pb_system("cat $keyfile.pub | ssh -q -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 will require the root password");
1273 # once this is done, we can do what we want on the VM remotely
1274 }
1275
1276 # Prepare the script to be executed on the VM/VE
1277 # in $ENV{'PBDESTDIR'}/setupv
1278
1279 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
1280 print SCRIPT << 'EOF';
[320]1281#!/usr/bin/perl -w
1282
[346]1283use strict;
1284use File::Copy;
1285
[354]1286EOF
1287 if ($vtype eq "vm") {
1288 print SCRIPT << 'EOF';
1289# Removes duplicate in .ssh/authorized_keys of our key if needed
1290#
1291my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
1292open(PBFILE,$file1) || die "Unable to open $file1";
1293open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
1294my $count = 0;
1295while (<PBFILE>) {
1296EOF
1297 print SCRIPT << "EOF";
1298 if (/ $key /) {
1299 \$count++;
1300 }
1301print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
1302}
1303close(PBFILE);
1304close(PBOUT);
1305rename("\$file1.new",\$file1);
1306chmod 0600,\$file1;
1307EOF
1308 }
1309 print SCRIPT << 'EOF';
1310
1311# Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
1312#
[346]1313my $file="/etc/passwd";
[320]1314open(PBFILE,$file) || die "Unable to open $file";
1315my $found = 0;
1316while (<PBFILE>) {
[346]1317EOF
[353]1318 print SCRIPT << "EOF";
1319 \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
[346]1320EOF
[353]1321 print SCRIPT << 'EOF';
[320]1322}
1323close(PBFILE);
1324
1325if ( $found == 0 ) {
1326 if ( ! -d "/home" ) {
1327 mkdir "/home";
1328 }
[346]1329EOF
[353]1330 print SCRIPT << "EOF";
1331system "groupadd $pbac->{$ENV{'PBPROJ'}}";
1332system "useradd $pbac->{$ENV{'PBPROJ'}} -g $pbac->{$ENV{'PBPROJ'}} -m -d /home/$pbac->{$ENV{'PBPROJ'}}";
[320]1333
[354]1334# allow ssh entry to build
1335#
[353]1336chdir "/home/$pbac->{$ENV{'PBPROJ'}}";
[320]1337mkdir ".ssh",0700;
[347]1338# Allow those accessing root to access the build account
[348]1339copy("\$ENV{'HOME'}/.ssh/authorized_keys",".ssh/authorized_keys");
[320]1340chmod 0600,".ssh/authorized_keys";
[353]1341system 'chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} .ssh';
[320]1342
[346]1343EOF
[353]1344 print SCRIPT << 'EOF';
[346]1345}
1346
[347]1347# No passwd for build account only keys
[320]1348$file="/etc/shadow";
1349open(PBFILE,$file) || die "Unable to open $file";
1350open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1351while (<PBFILE>) {
[346]1352EOF
[353]1353 print SCRIPT << "EOF";
1354 s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
1355 s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
[346]1356EOF
[353]1357 print SCRIPT << 'EOF';
[320]1358 print PBOUT $_;
1359}
1360close(PBFILE);
1361close(PBOUT);
1362rename("$file.new",$file);
1363chmod 0640,$file;
1364
1365# pb has to be added to portage group on gentoo
1366
[346]1367# Adapt sudoers
1368$file="/etc/sudoers";
1369open(PBFILE,$file) || die "Unable to open $file";
1370open(PBOUT,"> $file.new") || die "Unable to open $file.new";
1371while (<PBFILE>) {
1372EOF
[353]1373 print SCRIPT << "EOF";
1374 next if (/^$pbac->{$ENV{'PBPROJ'}} /);
[346]1375EOF
[353]1376 print SCRIPT << 'EOF';
[346]1377 s/Defaults[ \t]+requiretty//;
1378 print PBOUT $_;
1379}
1380close(PBFILE);
1381EOF
[353]1382 print SCRIPT << "EOF";
1383# This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
1384print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
[346]1385EOF
[353]1386 print SCRIPT << 'EOF';
[346]1387close(PBOUT);
1388rename("$file.new",$file);
1389chmod 0440,$file;
1390
1391EOF
[353]1392
1393 my $SCRIPT = \*SCRIPT;
1394
1395 pb_install_deps($SCRIPT);
1396
1397 print SCRIPT << 'EOF';
[346]1398# Suse wants sudoers as 640
1399if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {
1400 chmod 0640,$file;
1401}
1402
1403# Sync date
[353]1404#system "/usr/sbin/ntpdate ntp.pool.org";
[346]1405
[352]1406system "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-*";
[358]1407system "pb 2>&1 | head -5";
[357]1408EOF
1409 if ((! $vmexist) && ($vtype eq "vm")) {
1410 print SCRIPT << 'EOF';
[356]1411system "sudo /sbin/halt -p";
[346]1412EOF
[357]1413 }
[353]1414
1415 # Adds pb_distro_init from ProjectBuilder::Distribution
1416 foreach my $d (@INC) {
1417 my $f = "$d/ProjectBuilder/Distribution.pm";
1418 if (-f "$f") {
1419 open(PBD,"$f") || die "Unable to open $f";
1420 while (<PBD>) {
1421 next if (/^package/);
1422 next if (/^use Exporter/);
1423 next if (/^\@our /);
1424 print SCRIPT $_;
1425 }
1426 close(PBD);
1427 last;
[347]1428 }
1429 }
[353]1430 close(SCRIPT);
1431 chmod 0755,"$pbscript";
1432
1433 # That build script needs to be run as root
1434 $pbaccount = "root";
1435 pb_script2v($pbscript,$vtype);
[347]1436}
[353]1437return;
[346]1438}
1439
[347]1440sub pb_install_deps {
[346]1441
[348]1442my $SCRIPT = shift;
[346]1443
[348]1444print {$SCRIPT} << 'EOF';
[346]1445# We need to have that pb_distro_init function
[347]1446# Get it from Project-Builder::Distribution
[320]1447my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
1448print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
1449
1450# Get and install pb
[357]1451my $insdm = "rm -rf Date-Manip* ; wget http://search.cpan.org/CPAN/authors/id/S/SB/SBECK/Date-Manip-5.48.tar.gz ; tar xvfz Date-Manip-5.48.tar.gz ; cd Date-Manip* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf Date-Manip*";
1452my $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*";
1453my $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*";
1454my $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*";
1455
[320]1456if ( $ddir eq "fedora" ) {
1457 system "yum clean all";
[346]1458 #system "yum update -y";
[320]1459 my $arch=`uname -m`;
1460 my $opt = "";
1461 chomp($arch);
1462 if ($arch eq "x86_64") {
1463 $opt="--exclude=*.i?86";
1464 }
1465
[353]1466 system "yum -y $opt install rpm-build wget patch ntp sudo perl-DateManip perl-File-MimeInfo perl-ExtUtils-MakeMaker";
[357]1467 if ($dver eq 4) {
1468 system "$insmb";
1469 system "$insfm";
1470 system "$insfb";
1471 }
1472} elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || ($ddir eq "slackware")) {
[358]1473 # Suppose pkg are installed already as no online mirror available
[320]1474 system "rpm -e lsb 2>&1 > /dev/null";
[357]1475 system "$insdm";
[358]1476 system "$insmb";
1477 system "$insfm";
1478 system "$insfb";
[320]1479} elsif ($ddir eq "suse") {
1480 # New OpenSuSE
[358]1481 system "$insmb";
1482 system "$insfm";
1483 system "$insfb";
[320]1484 system "export TERM=linux ; liste=\"\" ; for i in make wget patch sudo perl-DateManip perl-File-HomeDir 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";
1485} elsif ( $dfam eq "md" ) {
[357]1486 system "urpmi.update -a ; urpmi --auto rpm-build wget sudo patch ntp-client perl-File-MimeInfo";
1487 if (($ddir eq "mandrake") && ($dver eq "10.1")) {
1488 system "$insdm";
1489 } else {
1490 system "urpmi --auto perl-DateManip";
1491 }
[320]1492} elsif ( $dfam eq "du" ) {
1493 if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
[346]1494 #system "apt-get update";
[358]1495 system "$insfb";
1496 system "$insfm";
1497 system "apt-get -y install wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libmodule-build-perl libdate-manip-perl";
[320]1498 } else {
[358]1499 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";
[320]1500 }
1501} elsif ( $dfam eq "gen" ) {
[358]1502 #system "emerge -u system ; emerge wget sudo ntp DateManip File-MimeInfo";
1503 system "emerge wget sudo ntp DateManip File-MimeInfo";
[320]1504} else {
1505 print "No pkg to install\n";
1506}
1507EOF
1508}
1509
[347]1510# Return the SSH key file to use
1511# Potentially create it if needed
1512
1513sub pb_ssh_get {
1514
1515my $create = shift || 0; # Do not create keys by default
1516
1517# Check the SSH environment
1518my $keyfile = undef;
1519
1520# We have specific keys by default
1521$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
[348]1522if (!(-e $keyfile) && ($create eq 1)) {
[347]1523 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
1524}
1525
1526$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
1527$keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
1528$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
1529die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
1530return($keyfile);
1531}
1532
1533
[145]1534# Returns the pid of a running VM command using a specific VM file
[142]1535sub pb_check_ps {
1536 my $vmcmd = shift;
1537 my $vmm = shift;
1538 my $vmexist = 0; # FALSE by default
1539
1540 open(PS, "ps auxhww|") || die "Unable to call ps";
1541 while (<PS>) {
1542 next if (! /$vmcmd/);
1543 next if (! /$vmm/);
1544 my ($void1, $void2);
1545 ($void1, $vmexist, $void2) = split(/ +/);
1546 last;
1547 }
1548 return($vmexist);
1549}
1550
1551
[77]1552sub pb_extract_build_files {
[25]1553
1554my $src=shift;
1555my $dir=shift;
[26]1556my $ddir=shift;
[28]1557my @files;
[25]1558
[188]1559if ($src =~ /tar\.gz$/) {
1560 pb_system("tar xfpz $src $dir","Extracting build files");
1561} elsif ($src =~ /tar\.bz2$/) {
1562 pb_system("tar xfpj $src $dir","Extracting build files");
1563} else {
1564 die "Unknown compression algorithm for $src";
1565}
[25]1566opendir(DIR,"$dir") || die "Unable to open directory $dir";
1567foreach my $f (readdir(DIR)) {
1568 next if ($f =~ /^\./);
[26]1569 move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
[315]1570 pb_log(2,"mv $dir/$f $ddir\n");
[28]1571 push @files,"$ddir/$f";
[25]1572}
1573closedir(DIR);
[26]1574# Not enough but still a first cleanup
[74]1575pb_rm_rf("$dir");
[28]1576return(@files);
[25]1577}
1578
[315]1579sub pb_list_bfiles {
1580
1581my $dir = shift;
1582my $pbpkg = shift;
1583my $bfiles = shift;
1584my $pkgfiles = shift;
1585my $supfiles = shift;
1586
1587opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
1588foreach my $f (readdir(BDIR)) {
1589 next if ($f =~ /^\./);
1590 $bfiles->{$f} = "$dir/$f";
[340]1591 $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
[315]1592 if (defined $supfiles->{$pbpkg}) {
1593 $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
1594 }
1595}
1596closedir(BDIR);
1597}
1598
[74]1599sub pb_syntax {
[21]1600
[331]1601my $exit_status = shift || -1;
1602my $verbose_level = shift || 0;
1603
1604my $filehandle = \*STDERR;
1605
1606$filehandle = \*STDOUT if ($exit_status == 0);
1607
1608pod2usage( { -message => "pb (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n",
1609 -exitval => $exit_status ,
1610 -verbose => $verbose_level,
1611 -output => $filehandle } );
[21]1612}
Note: See TracBrowser for help on using the repository browser.