1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Project Builder main application
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 | # Copyright B. Cornec 2007
|
---|
8 | # Provided under the GPL v2
|
---|
9 |
|
---|
10 | # Syntax: see at end
|
---|
11 |
|
---|
12 | use strict 'vars';
|
---|
13 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
14 | use Data::Dumper;
|
---|
15 | use English;
|
---|
16 | use File::Basename;
|
---|
17 | use File::Copy;
|
---|
18 | use File::stat;
|
---|
19 | use File::Temp qw(tempdir);
|
---|
20 | use File::Find;
|
---|
21 | use Time::localtime qw(localtime);
|
---|
22 | use POSIX qw(strftime);
|
---|
23 | use lib qw (lib);
|
---|
24 | use ProjectBuilder::Version;
|
---|
25 | use ProjectBuilder::Base;
|
---|
26 | use ProjectBuilder::Display;
|
---|
27 | use ProjectBuilder::Conf;
|
---|
28 | use ProjectBuilder::Distribution;
|
---|
29 | use ProjectBuilder::CMS;
|
---|
30 | use ProjectBuilder::Env;
|
---|
31 | use ProjectBuilder::Filter;
|
---|
32 | use ProjectBuilder::Changelog;
|
---|
33 | use Mail::Sendmail;
|
---|
34 |
|
---|
35 | # Global variables
|
---|
36 | my %opts; # CLI Options
|
---|
37 | my $action; # action to realize
|
---|
38 | my $test = "FALSE"; # Not used
|
---|
39 | my $pbforce = 0; # Force VE/VM rebuild
|
---|
40 | my $pbsnap = 0; # Do not use snapshot mode for VM/VE by default
|
---|
41 | my $option = ""; # Not used
|
---|
42 | my @pkgs; # list of packages
|
---|
43 | my $pbtag; # Global Tag variable
|
---|
44 | my $pbver; # Global Version variable
|
---|
45 | my $pbscript; # Name of the script
|
---|
46 | my %pbver; # per package
|
---|
47 | my %pbtag; # per package
|
---|
48 | my $pbrev; # Global REVISION variable
|
---|
49 | my $pbaccount; # Login to use to connect to the VM
|
---|
50 | my $pbport; # Port to use to connect to the VM
|
---|
51 | my $newver; # New version to create
|
---|
52 | my $iso = undef; # ISO image for the VM to create
|
---|
53 |
|
---|
54 | my @date = pb_get_date();
|
---|
55 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
56 |
|
---|
57 | =pod
|
---|
58 |
|
---|
59 | =head1 NAME
|
---|
60 |
|
---|
61 | pb, aka project-builder.org - builds packages for your projects
|
---|
62 |
|
---|
63 | =head1 DESCRIPTION
|
---|
64 |
|
---|
65 | pb helps you build various packages directly from your project sources.
|
---|
66 | Those sources could be handled by a CMS (Configuration Management System)
|
---|
67 | such as Subversion, CVS, Git, Mercurial... or being a simple reference to a compressed tar file.
|
---|
68 | It's based on a set of configuration files, a set of provided macros to help
|
---|
69 | you keeping build files as generic as possible. For example, a single .spec
|
---|
70 | file should be required to generate for all rpm based distributions, even
|
---|
71 | if you could also have multiple .spec files if required.
|
---|
72 |
|
---|
73 | =head1 SYNOPSIS
|
---|
74 |
|
---|
75 | pb [-vhSq][-r pbroot][-p project][[-s script -a account -P port][-m mach-1[,...]]][-i iso] <action> [<pkg1> ...]
|
---|
76 |
|
---|
77 | pb [--verbose][--help][--man][--quiet][--snapshot][--revision pbroot][--project project][[--script script --account account --port port][--machine mach-1[,...]]][--iso iso] <action> [<pkg1> ...]
|
---|
78 |
|
---|
79 | =head1 OPTIONS
|
---|
80 |
|
---|
81 | =over 4
|
---|
82 |
|
---|
83 | =item B<-v|--verbose>
|
---|
84 |
|
---|
85 | Print a brief help message and exits.
|
---|
86 |
|
---|
87 | =item B<-q|--quiet>
|
---|
88 |
|
---|
89 | Do not print any output.
|
---|
90 |
|
---|
91 | =item B<-h|--help>
|
---|
92 |
|
---|
93 | Print a brief help message and exits.
|
---|
94 |
|
---|
95 | =item B<-S|--snapshot>
|
---|
96 |
|
---|
97 | Use the snapshot mode of VMs or VEs
|
---|
98 |
|
---|
99 | =item B<--man>
|
---|
100 |
|
---|
101 | Prints the manual page and exits.
|
---|
102 |
|
---|
103 | =item B<-m|--machine machine1[,machine2,...]>
|
---|
104 |
|
---|
105 | Name of the Virtual Machines (VM) or Virtual Environments (VE) you want to build on (coma separated).
|
---|
106 | All if none precised (or use the env variable PBV).
|
---|
107 |
|
---|
108 | =item B<-s|--script script>
|
---|
109 |
|
---|
110 | Name of the script you want to execute on the related VMs or VEs.
|
---|
111 |
|
---|
112 | =item B<-i|--iso iso_image>
|
---|
113 |
|
---|
114 | Name of the ISO image of the distribution you want to install on the related VMs.
|
---|
115 |
|
---|
116 | =item B<-a|--account account>
|
---|
117 |
|
---|
118 | Name of the account to use to connect on the related VMs.
|
---|
119 |
|
---|
120 | =item B<-P|--port port_number>
|
---|
121 |
|
---|
122 | Port number to use to connect on the related VMs.\n";
|
---|
123 |
|
---|
124 | =item B<-p|--project project_name>
|
---|
125 |
|
---|
126 | Name of the project you're working on (or use the env variable PBPROJ)
|
---|
127 |
|
---|
128 | =item B<-r|--revision revision>
|
---|
129 |
|
---|
130 | Path Name of the project revision under the CMS (or use the env variable PBROOT)
|
---|
131 |
|
---|
132 | =item B<-V|--version new_version>
|
---|
133 |
|
---|
134 | New version of the project to create based on the current one.
|
---|
135 |
|
---|
136 | =back
|
---|
137 |
|
---|
138 | =head1 ARGUMENTS
|
---|
139 |
|
---|
140 | <action> can be:
|
---|
141 |
|
---|
142 | =over 4
|
---|
143 |
|
---|
144 | =item B<cms2build>
|
---|
145 |
|
---|
146 | Create tar files for the project under your CMS.
|
---|
147 | CMS supported are SVN, CVS and Mercurial
|
---|
148 | parameters are packages to build
|
---|
149 | if not using default list
|
---|
150 |
|
---|
151 | =item B<build2pkg>
|
---|
152 |
|
---|
153 | Create packages for your running distribution
|
---|
154 |
|
---|
155 | =item B<cms2pkg>
|
---|
156 |
|
---|
157 | cms2build + build2pkg
|
---|
158 |
|
---|
159 | =item B<build2ssh>
|
---|
160 |
|
---|
161 | Send the tar files to a SSH host
|
---|
162 |
|
---|
163 | =item B<cms2ssh>
|
---|
164 |
|
---|
165 | cms2build + build2ssh
|
---|
166 |
|
---|
167 | =item B<pkg2ssh>
|
---|
168 |
|
---|
169 | Send the packages built to a SSH host
|
---|
170 |
|
---|
171 | =item B<build2vm>
|
---|
172 |
|
---|
173 | Create packages in VMs, launching them if needed
|
---|
174 | and send those packages to a SSH host once built
|
---|
175 | VM type supported are QEMU
|
---|
176 |
|
---|
177 | =item B<build2ve>
|
---|
178 |
|
---|
179 | Create packages in VEs, creating it if needed
|
---|
180 | and send those packages to a SSH host once built
|
---|
181 |
|
---|
182 | =item B<cms2vm>
|
---|
183 |
|
---|
184 | cms2build + build2vm
|
---|
185 |
|
---|
186 | =item B<cms2ve>
|
---|
187 |
|
---|
188 | cms2build + build2ve
|
---|
189 |
|
---|
190 | =item B<launchvm>
|
---|
191 |
|
---|
192 | Launch one virtual machine
|
---|
193 |
|
---|
194 | =item B<launchve>
|
---|
195 |
|
---|
196 | Launch one virtual environment
|
---|
197 |
|
---|
198 | =item B<script2vm>
|
---|
199 |
|
---|
200 | Launch one virtual machine if needed
|
---|
201 | and executes a script on it
|
---|
202 |
|
---|
203 | =item B<script2ve>
|
---|
204 |
|
---|
205 | Execute a script in a virtual environment
|
---|
206 |
|
---|
207 | =item B<newvm>
|
---|
208 |
|
---|
209 | Create a new virtual machine
|
---|
210 |
|
---|
211 | =item B<newve>
|
---|
212 |
|
---|
213 | Create a new virtual environment
|
---|
214 |
|
---|
215 | =item B<setupvm>
|
---|
216 |
|
---|
217 | Setup a virtual machine for pb usage
|
---|
218 |
|
---|
219 | =item B<setupve>
|
---|
220 |
|
---|
221 | Setup a virtual environment for pb usage
|
---|
222 |
|
---|
223 | =item B<snapvm>
|
---|
224 |
|
---|
225 | Snapshot a virtual machine for pb usage
|
---|
226 |
|
---|
227 | =item B<snapve>
|
---|
228 |
|
---|
229 | Snapshot a virtual environment for pb usage
|
---|
230 |
|
---|
231 | =item B<test2pkg>
|
---|
232 |
|
---|
233 | Test a package locally
|
---|
234 |
|
---|
235 | =item B<test2vm>
|
---|
236 |
|
---|
237 | Test a package in a virtual machine
|
---|
238 |
|
---|
239 | =item B<test2ve>
|
---|
240 |
|
---|
241 | Test a package in a virtual environment
|
---|
242 |
|
---|
243 | =item B<newver>
|
---|
244 |
|
---|
245 | Create a new version of the project derived
|
---|
246 | from the current one
|
---|
247 |
|
---|
248 | =item B<newproj>
|
---|
249 |
|
---|
250 | Create a new project and a template set of
|
---|
251 | configuration files under pbconf
|
---|
252 |
|
---|
253 | =item B<announce>
|
---|
254 |
|
---|
255 | Announce the availability of the project through various means
|
---|
256 |
|
---|
257 | =item B<web2ssh>
|
---|
258 |
|
---|
259 | Deliver the Web site content to the target server using ssh.
|
---|
260 |
|
---|
261 | =item B<clean>
|
---|
262 |
|
---|
263 | Purge the build and delivery directories related to the current project
|
---|
264 |
|
---|
265 | =back
|
---|
266 |
|
---|
267 | <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).
|
---|
268 |
|
---|
269 | =head1 WEB SITES
|
---|
270 |
|
---|
271 | The 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/>.
|
---|
272 |
|
---|
273 | =head1 USER MAILING LIST
|
---|
274 |
|
---|
275 | None exists for the moment.
|
---|
276 |
|
---|
277 | =head1 CONFIGURATION FILES
|
---|
278 |
|
---|
279 | Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
|
---|
280 |
|
---|
281 | Here is an example of such a configuration file:
|
---|
282 |
|
---|
283 | #
|
---|
284 | # Define for each project the URL of its pbconf repository
|
---|
285 | # No default option allowed here as they need to be all different
|
---|
286 | #
|
---|
287 | # URL of the pbconf content
|
---|
288 | # This is the format of a classical URL with the extension of additional schema such as
|
---|
289 | # svn+ssh, cvs+ssh, ...
|
---|
290 | #
|
---|
291 | pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
|
---|
292 |
|
---|
293 | # This is normaly defined in the project's configuration file
|
---|
294 | # Url of the project
|
---|
295 | #
|
---|
296 | pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
|
---|
297 |
|
---|
298 | # All these URLs needs to be defined here as the are the entry point
|
---|
299 | # for how to build packages for the project
|
---|
300 | #
|
---|
301 | pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
|
---|
302 | pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
|
---|
303 | pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
|
---|
304 | pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
|
---|
305 |
|
---|
306 | # Under that dir will take place everything related to pb
|
---|
307 | # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
|
---|
308 | # to your VMs/chroot/...
|
---|
309 | # if not defined then /var/cache
|
---|
310 | pbdefdir default = $ENV{'HOME'}/project-builder
|
---|
311 | pbdefdir pb = $ENV{'HOME'}
|
---|
312 | pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
|
---|
313 | pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
|
---|
314 |
|
---|
315 | # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
|
---|
316 | # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
|
---|
317 | pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
|
---|
318 | pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
|
---|
319 |
|
---|
320 | # pbdir points to the directory where the CMS content of the pburl is checked out
|
---|
321 | # If not defined, pbdir is under pbdefdir/pbproj
|
---|
322 | # Only defined if we have access to the dev of the project
|
---|
323 | pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
|
---|
324 | pbdir mondorescue = $ENV{'HOME'}/mondo/svn
|
---|
325 |
|
---|
326 | # -daemonize doesn't work with qemu 0.8.2
|
---|
327 | vmopt default = -m 384
|
---|
328 |
|
---|
329 | =head1 AUTHORS
|
---|
330 |
|
---|
331 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
332 |
|
---|
333 | =head1 COPYRIGHT
|
---|
334 |
|
---|
335 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
336 | described in the file C<COPYING> included with the distribution.
|
---|
337 |
|
---|
338 | =cut
|
---|
339 |
|
---|
340 | # ---------------------------------------------------------------------------
|
---|
341 |
|
---|
342 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
343 | my $appname = "pb";
|
---|
344 |
|
---|
345 | # Initialize the syntax string
|
---|
346 |
|
---|
347 | pb_syntax_init("$appname (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
|
---|
348 |
|
---|
349 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
350 | "man" => \$opts{'man'},
|
---|
351 | "verbose|v+" => \$opts{'v'},
|
---|
352 | "snapshot|S" => \$opts{'S'},
|
---|
353 | "quiet|q" => \$opts{'q'},
|
---|
354 | "log-files|l=s" => \$opts{'l'},
|
---|
355 | "force|f" => \$opts{'f'},
|
---|
356 | "account|a=s" => \$opts{'a'},
|
---|
357 | "revision|r=s" => \$opts{'r'},
|
---|
358 | "script|s=s" => \$opts{'s'},
|
---|
359 | "machines|mock|m=s" => \$opts{'m'},
|
---|
360 | "port|P=i" => \$opts{'P'},
|
---|
361 | "project|p=s" => \$opts{'p'},
|
---|
362 | "iso|i=s" => \$opts{'i'},
|
---|
363 | "version|V=s" => \$opts{'V'},
|
---|
364 | ) || pb_syntax(-1,0);
|
---|
365 |
|
---|
366 | if (defined $opts{'h'}) {
|
---|
367 | pb_syntax(0,1);
|
---|
368 | }
|
---|
369 | if (defined $opts{'man'}) {
|
---|
370 | pb_syntax(0,2);
|
---|
371 | }
|
---|
372 | if (defined $opts{'v'}) {
|
---|
373 | $pbdebug = $opts{'v'};
|
---|
374 | }
|
---|
375 | if (defined $opts{'f'}) {
|
---|
376 | $pbforce=1;
|
---|
377 | }
|
---|
378 | if (defined $opts{'q'}) {
|
---|
379 | $pbdebug=-1;
|
---|
380 | }
|
---|
381 | if (defined $opts{'S'}) {
|
---|
382 | $pbsnap=1;
|
---|
383 | }
|
---|
384 | if (defined $opts{'l'}) {
|
---|
385 | open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
386 | $pbLOG = \*pbLOG;
|
---|
387 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
388 | }
|
---|
389 | pb_log_init($pbdebug, $pbLOG);
|
---|
390 | pb_display_init("text","");
|
---|
391 |
|
---|
392 | # Handle root of the project if defined
|
---|
393 | if (defined $opts{'r'}) {
|
---|
394 | $ENV{'PBROOTDIR'} = $opts{'r'};
|
---|
395 | }
|
---|
396 | # Handle virtual machines if any
|
---|
397 | if (defined $opts{'m'}) {
|
---|
398 | $ENV{'PBV'} = $opts{'m'};
|
---|
399 | }
|
---|
400 | if (defined $opts{'s'}) {
|
---|
401 | $pbscript = $opts{'s'};
|
---|
402 | }
|
---|
403 | if (defined $opts{'a'}) {
|
---|
404 | $pbaccount = $opts{'a'};
|
---|
405 | die "option -a requires a -s script option" if (not defined $pbscript);
|
---|
406 | }
|
---|
407 | if (defined $opts{'P'}) {
|
---|
408 | $pbport = $opts{'P'};
|
---|
409 | }
|
---|
410 | if (defined $opts{'V'}) {
|
---|
411 | $newver = $opts{'V'};
|
---|
412 | }
|
---|
413 | if (defined $opts{'i'}) {
|
---|
414 | $iso = $opts{'i'};
|
---|
415 | }
|
---|
416 |
|
---|
417 | # Get Action
|
---|
418 | $action = shift @ARGV;
|
---|
419 | die pb_syntax(-1,1) if (not defined $action);
|
---|
420 |
|
---|
421 | my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
|
---|
422 | my $pbinit = undef;
|
---|
423 | $pbinit = 1 if ($action =~ /^newproj$/);
|
---|
424 |
|
---|
425 | # Handles project name if any
|
---|
426 | # And get global params
|
---|
427 | ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action);
|
---|
428 |
|
---|
429 | #
|
---|
430 | # Check for command requirements
|
---|
431 | #
|
---|
432 | my ($req,$opt) = pb_conf_get_if("oscmd","oscmdopt");
|
---|
433 | my ($req2,$opt2) = (undef,undef);
|
---|
434 | $req2 = $req->{$appname} if (defined $req);
|
---|
435 | $opt2 = $opt->{$appname} if (defined $opt);
|
---|
436 | pb_check_requirements($req2,$opt2);
|
---|
437 |
|
---|
438 | pb_log(0,"Project: $ENV{'PBPROJ'}\n");
|
---|
439 | pb_log(0,"Action: $action\n");
|
---|
440 |
|
---|
441 | # Act depending on action
|
---|
442 | if ($action =~ /^cms2build$/) {
|
---|
443 | pb_cms2build();
|
---|
444 | } elsif ($action =~ /^build2pkg$/) {
|
---|
445 | pb_build2pkg();
|
---|
446 | } elsif ($action =~ /^cms2pkg$/) {
|
---|
447 | pb_cms2build();
|
---|
448 | pb_build2pkg();
|
---|
449 | } elsif ($action =~ /^build2ssh$/) {
|
---|
450 | pb_build2ssh();
|
---|
451 | } elsif ($action =~ /^cms2ssh$/) {
|
---|
452 | pb_cms2build();
|
---|
453 | pb_build2ssh();
|
---|
454 | } elsif ($action =~ /^pkg2ssh$/) {
|
---|
455 | pb_pkg2ssh();
|
---|
456 | } elsif ($action =~ /^build2ve$/) {
|
---|
457 | pb_build2v("ve","build");
|
---|
458 | } elsif ($action =~ /^build2vm$/) {
|
---|
459 | pb_build2v("vm","build");
|
---|
460 | } elsif ($action =~ /^cms2ve$/) {
|
---|
461 | pb_cms2build();
|
---|
462 | pb_build2v("ve","build");
|
---|
463 | } elsif ($action =~ /^cms2vm$/) {
|
---|
464 | pb_cms2build();
|
---|
465 | pb_build2v("vm","build");
|
---|
466 | } elsif ($action =~ /^launchvm$/) {
|
---|
467 | pb_launchv("vm",$ENV{'PBV'},0);
|
---|
468 | } elsif ($action =~ /^launchve$/) {
|
---|
469 | pb_launchv("ve",$ENV{'PBV'},0);
|
---|
470 | } elsif ($action =~ /^script2vm$/) {
|
---|
471 | pb_script2v($pbscript,"vm");
|
---|
472 | } elsif ($action =~ /^script2ve$/) {
|
---|
473 | pb_script2v($pbscript,"ve");
|
---|
474 | } elsif ($action =~ /^newver$/) {
|
---|
475 | pb_newver();
|
---|
476 | } elsif ($action =~ /^newve$/) {
|
---|
477 | pb_launchv("ve",$ENV{'PBV'},1);
|
---|
478 | } elsif ($action =~ /^newvm$/) {
|
---|
479 | pb_launchv("vm",$ENV{'PBV'},1);
|
---|
480 | pb_log(0, "Please ensure that sshd is running in your VM by default\n");
|
---|
481 | pb_log(0, "and that it allows remote root login (PermitRootLogin yes in /etc/ssh/sshd_config)\n");
|
---|
482 | pb_log(0, "Also ensure that network is up, firewalling correctly configured, and perl and scp/ssh installed\n");
|
---|
483 | } elsif ($action =~ /^setupve$/) {
|
---|
484 | pb_setup2v("ve");
|
---|
485 | } elsif ($action =~ /^setupvm$/) {
|
---|
486 | pb_setup2v("vm");
|
---|
487 | } elsif ($action =~ /^snapve$/) {
|
---|
488 | pb_snap2v("ve");
|
---|
489 | } elsif ($action =~ /^snapvm$/) {
|
---|
490 | pb_snap2v("vm");
|
---|
491 | } elsif ($action =~ /^test2pkg$/) {
|
---|
492 | pb_test2pkg();
|
---|
493 | } elsif ($action =~ /^test2ve$/) {
|
---|
494 | pb_build2v("ve","test");
|
---|
495 | } elsif ($action =~ /^test2vm$/) {
|
---|
496 | pb_build2v("vm","test");
|
---|
497 | } elsif ($action =~ /^newproj$/) {
|
---|
498 | # Nothing to do - already done in pb_env_init
|
---|
499 | } elsif ($action =~ /^clean$/) {
|
---|
500 | pb_clean();
|
---|
501 | } elsif ($action =~ /^announce$/) {
|
---|
502 | # For announce only. Require avoids the systematic load of these modules
|
---|
503 | require DBI;
|
---|
504 | require DBD::SQLite;
|
---|
505 |
|
---|
506 | pb_announce();
|
---|
507 | } elsif ($action =~ /^web2ssh$/) {
|
---|
508 | require DBI;
|
---|
509 | require DBD::SQLite;
|
---|
510 |
|
---|
511 | pb_cms2build("Web");
|
---|
512 | pb_send2target("Web");
|
---|
513 | } else {
|
---|
514 | pb_log(0,"\'$action\' is not available\n");
|
---|
515 | pb_syntax(-2,1);
|
---|
516 | }
|
---|
517 |
|
---|
518 | sub pb_cms2build {
|
---|
519 |
|
---|
520 | my $param = shift || undef;
|
---|
521 |
|
---|
522 | my $pkg;
|
---|
523 | my @pkgs;
|
---|
524 | my $webdir;
|
---|
525 |
|
---|
526 | my %pkgs;
|
---|
527 | my %pb; # Structure to store conf info
|
---|
528 |
|
---|
529 | # If Website, then pkg is only the website
|
---|
530 | if ((defined $param) && ($param eq "Web")) {
|
---|
531 | ($webdir) = pb_conf_get("webdir");
|
---|
532 | pb_log(2,"webdir: ".Dumper($webdir)."\n");
|
---|
533 | $pkgs[0] = $webdir->{$ENV{'PBPROJ'}};
|
---|
534 | $extpkgdir = $webdir;
|
---|
535 | pb_log(0,"Package: $pkgs[0]\n");
|
---|
536 | } else {
|
---|
537 | $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
|
---|
538 | @pkgs = @$pkg;
|
---|
539 | }
|
---|
540 |
|
---|
541 | my ($scheme, $uri) = pb_cms_init($pbinit);
|
---|
542 |
|
---|
543 | # We need 2 lines here
|
---|
544 | my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
|
---|
545 | my @pt = pb_conf_get_if("vmlist","velist");
|
---|
546 |
|
---|
547 | # declare packager and repo for filtering
|
---|
548 | # TODO: Is pbrepo needed so early in the process ?
|
---|
549 | my ($tmp1, $tmp2) = pb_conf_get("pbpackager","pbrepo");
|
---|
550 | $ENV{'PBPACKAGER'} = $tmp1->{$ENV{'PBPROJ'}};
|
---|
551 | $ENV{'PBREPO'} = $tmp2->{$ENV{'PBPROJ'}};
|
---|
552 |
|
---|
553 | foreach my $pbpkg (@pkgs) {
|
---|
554 | $ENV{'PBPKG'} = $pbpkg;
|
---|
555 |
|
---|
556 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
557 | $pbver = $pkgv->{$pbpkg};
|
---|
558 | } else {
|
---|
559 | $pbver = $ENV{'PBPROJVER'};
|
---|
560 | }
|
---|
561 | # If it's a test version, then tag == 0.date
|
---|
562 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
563 | $pbtag = "0.".strftime("%Y%m%d%H%M%S", @date);
|
---|
564 | $ENV{'PBPROJTAG'} = $pbtag;
|
---|
565 | } elsif ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
566 | $pbtag = $pkgt->{$pbpkg};
|
---|
567 | } else {
|
---|
568 | $pbtag = $ENV{'PBPROJTAG'};
|
---|
569 | }
|
---|
570 |
|
---|
571 | $pbrev = $ENV{'PBREVISION'};
|
---|
572 | pb_log(0,"\n");
|
---|
573 | pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
|
---|
574 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
575 |
|
---|
576 | # Clean up dest if necessary. The export will recreate it
|
---|
577 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
|
---|
578 | pb_rm_rf($dest) if (-d $dest);
|
---|
579 |
|
---|
580 | # Export CMS tree for the concerned package to dest
|
---|
581 | # And generate some additional files
|
---|
582 | $OUTPUT_AUTOFLUSH=1;
|
---|
583 |
|
---|
584 | # computes in which dir we have to work
|
---|
585 | my $dir = $defpkgdir->{$pbpkg};
|
---|
586 | $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
|
---|
587 | $dir = $webdir->{$ENV{'PBPROJ'}} if ((defined $param) && ($param eq "Web"));
|
---|
588 | pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
|
---|
589 |
|
---|
590 | # Exporting content from CMS
|
---|
591 | my $preserve = pb_cms_export($uri,"$ENV{'PBDIR'}/$dir",$dest);
|
---|
592 |
|
---|
593 | # Generated fake content for test versions to speed up stuff
|
---|
594 | my $chglog;
|
---|
595 |
|
---|
596 | # Get project info on authors and log file
|
---|
597 | $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
|
---|
598 | $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
|
---|
599 | $chglog = undef if (! -f $chglog);
|
---|
600 |
|
---|
601 | my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
|
---|
602 | $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
|
---|
603 | $authors = "/dev/null" if (! -f $authors);
|
---|
604 |
|
---|
605 | # Extract cms log history and store it
|
---|
606 | if ((defined $chglog) && (! -f "$dest/NEWS")) {
|
---|
607 | pb_log(2,"Generating NEWS file from $chglog\n");
|
---|
608 | copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
|
---|
609 | }
|
---|
610 | pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
|
---|
611 |
|
---|
612 | my %build;
|
---|
613 | # We want to at least build for the underlying distro
|
---|
614 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $arch) = pb_distro_init();
|
---|
615 | my $tmpl = "$ddir-$dver-$arch,";
|
---|
616 | my %patches;
|
---|
617 |
|
---|
618 | # Get list of distributions for which I need to generate build files
|
---|
619 | if (defined $pt[0]->{$ENV{'PBPROJ'}}) {
|
---|
620 | $tmpl .= $pt[0]->{$ENV{'PBPROJ'}};
|
---|
621 | }
|
---|
622 | if (defined $pt[1]->{$ENV{'PBPROJ'}}) {
|
---|
623 | # the 2 lists needs to be grouped with a ',' separating them
|
---|
624 | if ($tmpl ne "") {
|
---|
625 | $tmpl .= ",";
|
---|
626 | }
|
---|
627 | $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
|
---|
628 | }
|
---|
629 |
|
---|
630 | # Setup %pb structure to allow filtering later on, on files using that structure
|
---|
631 | $pb{'tag'} = $pbtag;
|
---|
632 | $pb{'rev'} = $pbrev;
|
---|
633 | $pb{'ver'} = $pbver;
|
---|
634 | $pb{'pkg'} = $pbpkg;
|
---|
635 | $pb{'date'} = $pbdate;
|
---|
636 | $pb{'defpkgdir'} = $defpkgdir;
|
---|
637 | $pb{'extpkgdir'} = $extpkgdir;
|
---|
638 | $pb{'chglog'} = $chglog;
|
---|
639 | $pb{'packager'} = $ENV{'PBPACKAGER'};
|
---|
640 | $pb{'proj'} = $ENV{'PBPROJ'};
|
---|
641 | $pb{'repo'} = $ENV{'PBREPO'};
|
---|
642 | $pb{'patches'} = \%patches;
|
---|
643 | pb_log(2,"DEBUG: pb: ".Dumper(%pb)."\n");
|
---|
644 |
|
---|
645 | # Do not do that for website
|
---|
646 | if ((not defined $param) || ($param ne "Web")) {
|
---|
647 | pb_log(0,"Build files are being generated for ...\n");
|
---|
648 | my %virt;
|
---|
649 | # De-duplicate similar VM and VE
|
---|
650 | foreach my $d (split(/,/,$tmpl)) {
|
---|
651 | # skip ill-formatted vms (name-ver-arch)
|
---|
652 | next if ($d !~ /-/);
|
---|
653 | $virt{$d} = $d;
|
---|
654 | }
|
---|
655 |
|
---|
656 | foreach my $d (keys %virt) {
|
---|
657 | my ($name,$ver,$arch) = split(/-/,$d);
|
---|
658 | pb_log(0,"Bad format for $d") if ((not defined $name) || (not defined $ver) || (not defined $arch)) ;
|
---|
659 | chomp($arch);
|
---|
660 | my ($ddir, $dver, $dfam);
|
---|
661 | ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'os'}, $pb{'suf'}, $pb{'upd'}, $pb{'arch'}) = pb_distro_init($name,$ver,$arch);
|
---|
662 | pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
|
---|
663 | pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
|
---|
664 |
|
---|
665 | # We need to compute the real name of the package
|
---|
666 | my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pb{'dtype'});
|
---|
667 | $pb{'realpkg'} = $pbrealpkg;
|
---|
668 | pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $ddir-$dver\n") if ($pbrealpkg ne $pbpkg);
|
---|
669 |
|
---|
670 | # Filter build files from the less precise up to the most with overloading
|
---|
671 | # Filter all files found, keeping the name, and generating in dest
|
---|
672 |
|
---|
673 | # Find all build files first relatively to PBROOTDIR
|
---|
674 | # Find also all specific files referenced in the .pb conf file
|
---|
675 | my %bfiles = ();
|
---|
676 | my %pkgfiles = ();
|
---|
677 | $build{"$ddir-$dver-$arch"} = "yes";
|
---|
678 |
|
---|
679 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
|
---|
680 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
681 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
|
---|
682 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
683 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
|
---|
684 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
685 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
|
---|
686 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
687 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
|
---|
688 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
689 | } else {
|
---|
690 | $build{"$ddir-$dver-$arch"} = "no";
|
---|
691 | next;
|
---|
692 | }
|
---|
693 | pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
|
---|
694 |
|
---|
695 | # Get all filters to apply
|
---|
696 | my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
|
---|
697 |
|
---|
698 | # Prepare local patches for this distro - They are always applied first - May be a problem one day
|
---|
699 | foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
|
---|
700 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
|
---|
701 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
|
---|
702 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$pb{'dtype'}$/));
|
---|
703 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$pb{'dtype'}$/);
|
---|
704 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
|
---|
705 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
|
---|
706 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
|
---|
707 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
|
---|
708 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
|
---|
709 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
|
---|
710 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
|
---|
711 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
|
---|
712 | }
|
---|
713 |
|
---|
714 | # Prepare also remote patches to be included - Applied after the local ones
|
---|
715 | foreach my $p ("all","$pb{'dtype'}","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
|
---|
716 | my $f = "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch.$p";
|
---|
717 | next if (not -f $f);
|
---|
718 | if (not open(PATCH,$f)) {
|
---|
719 | pb_display("Unable to open existing external patch file content $f\n");
|
---|
720 | next;
|
---|
721 | }
|
---|
722 | while (<PATCH>) {
|
---|
723 | chomp();
|
---|
724 | $patches{"$ddir-$dver-$arch"} .= "," if (defined $patches{"$ddir-$dver-$arch"});
|
---|
725 | $patches{"$ddir-$dver-$arch"} .= "$_";
|
---|
726 | }
|
---|
727 | close(PATCH);
|
---|
728 | }
|
---|
729 | pb_log(2,"DEBUG: pb->patches: ".Dumper($pb{'patches'})."\n");
|
---|
730 |
|
---|
731 | # Apply now all the filters on all the files concerned
|
---|
732 | # destination dir depends on the type of file
|
---|
733 | if (defined $ptr) {
|
---|
734 | # For patch support
|
---|
735 | $pb{'tuple'} = "$ddir-$dver-$arch";
|
---|
736 | foreach my $f (values %bfiles,values %pkgfiles) {
|
---|
737 | pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
|
---|
738 | }
|
---|
739 | }
|
---|
740 | }
|
---|
741 | my @found;
|
---|
742 | my @notfound;
|
---|
743 | foreach my $b (keys %build) {
|
---|
744 | push @found,$b if ($build{$b} =~ /yes/);
|
---|
745 | push @notfound,$b if ($build{$b} =~ /no/);
|
---|
746 | }
|
---|
747 | pb_log(0," ... ".join(',',sort(@found))."\n");
|
---|
748 | pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
|
---|
749 | pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
|
---|
750 | }
|
---|
751 |
|
---|
752 | # Get the generic filter (all.pbf) and
|
---|
753 | # apply those to the non-build files including those
|
---|
754 | # generated by pbinit if applicable
|
---|
755 |
|
---|
756 | # Get only all.pbf filter
|
---|
757 | my $ptr = pb_get_filters($pbpkg);
|
---|
758 |
|
---|
759 | my $liste ="";
|
---|
760 | if (defined $filteredfiles->{$pbpkg}) {
|
---|
761 | foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
|
---|
762 | pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
|
---|
763 | $liste = "$f $liste";
|
---|
764 | }
|
---|
765 | }
|
---|
766 | pb_log(2,"Files ".$liste."have been filtered\n");
|
---|
767 |
|
---|
768 | # Do not do that for website
|
---|
769 | if ((not defined $param) || ($param ne "Web")) {
|
---|
770 | my %tmp;
|
---|
771 | # Filter potential patches (local + remote)
|
---|
772 | pb_log(0,"Delivering and compressing patches ");
|
---|
773 | foreach my $v (keys %patches) {
|
---|
774 | pb_mkdir_p("$dest/pbconf/$v/pbpatch");
|
---|
775 | foreach my $pf (split(/,/,$patches{$v})) {
|
---|
776 | my $pp = basename($pf);
|
---|
777 | pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
|
---|
778 | pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
|
---|
779 | pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
|
---|
780 | $tmp{$pf} = "";
|
---|
781 | }
|
---|
782 | }
|
---|
783 | foreach my $v (keys %tmp) {
|
---|
784 | pb_log(0,"$v ");
|
---|
785 | }
|
---|
786 | pb_log(0,"\n");
|
---|
787 | } else {
|
---|
788 | # Instead call News generation
|
---|
789 | pb_web_news2html($dest);
|
---|
790 | # And create an empty pbconf
|
---|
791 | pb_mkdir_p("$dest/pbconf");
|
---|
792 | # And prepare the pbscript to execute remotely
|
---|
793 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
794 | print SCRIPT "#!/bin/bash\n";
|
---|
795 | print SCRIPT "#set -x\n";
|
---|
796 | print SCRIPT "echo ... Extracting Website content\n";
|
---|
797 | print SCRIPT "find . -type f | grep -Ev '^./$pbpkg-$pbver.tar.gz|^./pbscript' | xargs rm -f non-existent\n";
|
---|
798 | print SCRIPT "find * -type d -depth | xargs rmdir 2> /dev/null \n";
|
---|
799 | print SCRIPT "tar xfz $pbpkg-$pbver.tar.gz\n";
|
---|
800 | print SCRIPT "mv $pbpkg-$pbver/* .\n";
|
---|
801 | print SCRIPT "rm -f $pbpkg-$pbver.tar.gz\n";
|
---|
802 | print SCRIPT "rmdir $pbpkg-$pbver\n";
|
---|
803 | close(SCRIPT);
|
---|
804 | }
|
---|
805 |
|
---|
806 | # Prepare the dest directory for archive
|
---|
807 | if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
|
---|
808 | pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
|
---|
809 | chmod 0755,"$ENV{'PBTMP'}/pbinit";
|
---|
810 | pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
|
---|
811 | }
|
---|
812 |
|
---|
813 | # Do we have additional script to run to prepare the environement for the project ?
|
---|
814 | # Then include it in the pbconf delivery
|
---|
815 | foreach my $pbvf (<$ENV{'PBROOTDIR'}/pbv*.pre>,<$ENV{'PBROOTDIR'}/pbv*.post>, <$ENV{'PBROOTDIR'}/pbtest*>) {
|
---|
816 | if (-x "$pbvf") {
|
---|
817 | my $target = "$ENV{'PBDESTDIR'}/".basename($pbvf);
|
---|
818 | pb_filter_file("$pbvf",$ptr,$target,\%pb);
|
---|
819 | chmod 0755,"$target";
|
---|
820 | }
|
---|
821 | }
|
---|
822 |
|
---|
823 | # Archive dest dir
|
---|
824 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
825 | if (defined $preserve) {
|
---|
826 | # In that case we want to preserve the original tar file for checksum purposes
|
---|
827 | # The one created is btw equivalent in that case to this one
|
---|
828 | # Maybe check basename of both to be sure they are the same ?
|
---|
829 | pb_log(0,"Preserving original tar file ");
|
---|
830 | move("$preserve","$pbpkg-$pbver.tar.gz");
|
---|
831 | } else {
|
---|
832 | # Possibility to look at PBSRC to guess more the filename
|
---|
833 | pb_system("tar cfz $pbpkg-$pbver.tar.gz --exclude=$pbpkg-$pbver/pbconf $pbpkg-$pbver","Creating $pbpkg tar files compressed");
|
---|
834 | }
|
---|
835 | pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
|
---|
836 | pb_system("tar cfz $pbpkg-$pbver.pbconf.tar.gz $pbpkg-$pbver/pbconf","Creating pbconf tar files compressed");
|
---|
837 | pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz\n");
|
---|
838 |
|
---|
839 | # Keep track of version-tag per pkg
|
---|
840 | $pkgs{$pbpkg} = "$pbver-$pbtag";
|
---|
841 |
|
---|
842 | # Final cleanup
|
---|
843 | pb_rm_rf($dest) if (-d $dest);
|
---|
844 | }
|
---|
845 |
|
---|
846 | # Keep track of per package version
|
---|
847 | pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
|
---|
848 | open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
|
---|
849 | foreach my $pbpkg (keys %pkgs) {
|
---|
850 | print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
|
---|
851 | }
|
---|
852 | close(PKG);
|
---|
853 |
|
---|
854 | # Keep track of what is generated by default
|
---|
855 | # We need to store the dir and info on version-tag
|
---|
856 | # Base our content on the existing .pb file
|
---|
857 | copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
|
---|
858 | open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
|
---|
859 | print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
|
---|
860 | print LAST "projver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
|
---|
861 | print LAST "projtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
|
---|
862 | print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
|
---|
863 | close(LAST);
|
---|
864 | }
|
---|
865 |
|
---|
866 | sub pb_test2pkg {
|
---|
867 | # Get the running distro to test on
|
---|
868 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $arch) = pb_distro_init();
|
---|
869 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch))."\n");
|
---|
870 |
|
---|
871 | # Get list of packages to test
|
---|
872 | # Get content saved in cms2build
|
---|
873 | my $ptr = pb_get_pkg();
|
---|
874 | @pkgs = @$ptr;
|
---|
875 |
|
---|
876 | # Additional potential repo
|
---|
877 | pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
|
---|
878 | foreach my $pbpkg (@pkgs) {
|
---|
879 | # We need to install the package to test, and deps brought with it
|
---|
880 | pb_distro_installdeps(undef,$dtype,$pbupd,$pbpkg);
|
---|
881 | pb_system("$ENV{'PBDESTDIR'}/pbtest","Launching test for $pbpkg","verbose");
|
---|
882 | }
|
---|
883 | }
|
---|
884 |
|
---|
885 | sub pb_build2pkg {
|
---|
886 |
|
---|
887 | # Get the running distro to build on
|
---|
888 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $arch) = pb_distro_init();
|
---|
889 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch))."\n");
|
---|
890 |
|
---|
891 | # Get list of packages to build
|
---|
892 | my $ptr = pb_get_pkg();
|
---|
893 | @pkgs = @$ptr;
|
---|
894 |
|
---|
895 | # Get content saved in cms2build
|
---|
896 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
897 | $pkg = { } if (not defined $pkg);
|
---|
898 |
|
---|
899 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
900 | my $made = ""; # pkgs made during build
|
---|
901 | foreach my $pbpkg (@pkgs) {
|
---|
902 | my $vertag = $pkg->{$pbpkg};
|
---|
903 | # get the version of the current package - maybe different
|
---|
904 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
905 |
|
---|
906 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
907 | my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
|
---|
908 | pb_log(2,"Source file: $src\n");
|
---|
909 | pb_log(2,"Pbconf file: $src2\n");
|
---|
910 |
|
---|
911 | pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
|
---|
912 | if ($dtype eq "rpm") {
|
---|
913 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
914 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
915 | 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";
|
---|
916 | }
|
---|
917 | }
|
---|
918 |
|
---|
919 | # Remove in case a previous link/file was there
|
---|
920 | unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
|
---|
921 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
922 | # We need to first extract the spec file
|
---|
923 | my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$ENV{'PBBUILDDIR'}/SPECS","spec");
|
---|
924 |
|
---|
925 | # We need to handle potential patches to upstream sources
|
---|
926 | pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
|
---|
927 |
|
---|
928 | pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
|
---|
929 | # set LANGUAGE to check for correct log messages
|
---|
930 | $ENV{'LANGUAGE'}="C";
|
---|
931 | # Older Redhat use _target_platform in %configure incorrectly
|
---|
932 | my $specialdef = "";
|
---|
933 | if (($ddir eq "redhat") || (($ddir eq "rhel") && ($dver eq "2.1"))) {
|
---|
934 | $specialdef = "--define \'_target_platform \"\"\'";
|
---|
935 | }
|
---|
936 |
|
---|
937 | # If needed we may add repository to the build env
|
---|
938 | pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
|
---|
939 | foreach my $f (@specfile) {
|
---|
940 | if ($f =~ /\.spec$/) {
|
---|
941 | pb_distro_installdeps($f,$dtype,$pbupd);
|
---|
942 | pb_system("rpmbuild $specialdef --define \'packager $ENV{'PBPACKAGER'}\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
|
---|
943 | last;
|
---|
944 | }
|
---|
945 | }
|
---|
946 | # Get the name of the generated packages
|
---|
947 | open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
|
---|
948 | while (<LOG>) {
|
---|
949 | chomp($_);
|
---|
950 | next if ($_ !~ /^Wrote:/);
|
---|
951 | s|.*/([S]*RPMS.*)|$1|;
|
---|
952 | $made .=" $_";
|
---|
953 | }
|
---|
954 | close(LOG);
|
---|
955 |
|
---|
956 | } elsif ($dtype eq "deb") {
|
---|
957 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
958 | pb_system("tar xfz $src","Extracting sources");
|
---|
959 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
960 |
|
---|
961 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
962 | pb_rm_rf("debian");
|
---|
963 | symlink "pbconf/$ddir-$dver-$arch","debian" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
|
---|
964 | chmod 0755,"debian/rules";
|
---|
965 |
|
---|
966 | pb_distro_setuprepo($ddir,$dver,$arch,$dtype);
|
---|
967 | pb_distro_installdeps("debian/control",$dtype,$pbupd);
|
---|
968 | pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
|
---|
969 | # Get the name of the generated packages
|
---|
970 | open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
|
---|
971 | while (<LOG>) {
|
---|
972 | chomp();
|
---|
973 | my $tmp = $_;
|
---|
974 | next if ($tmp !~ /^dpkg-deb.*:/);
|
---|
975 | $tmp =~ s|.*../(.*)_(.*).deb.*|$1|;
|
---|
976 | $made="$made $tmp.dsc $tmp.tar.gz $tmp"."_*.deb $tmp"."_*.changes";
|
---|
977 | }
|
---|
978 | close(LOG);
|
---|
979 | } elsif ($dtype eq "ebuild") {
|
---|
980 | my @ebuildfile;
|
---|
981 | # For gentoo we need to take pb as subsystem name
|
---|
982 | # We put every apps here under sys-apps. hope it's correct
|
---|
983 | # We use pb's home dir in order to have a single OVERLAY line
|
---|
984 | my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
|
---|
985 | pb_mkdir_p($tmpd) if (! -d "$tmpd");
|
---|
986 | pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
|
---|
987 |
|
---|
988 | # We need to first extract the ebuild file
|
---|
989 | @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$tmpd","ebuild");
|
---|
990 |
|
---|
991 | # Prepare the build env for gentoo
|
---|
992 | my $found = 0;
|
---|
993 | my $pbbd = $ENV{'HOME'};
|
---|
994 | $pbbd =~ s|/|\\/|g;
|
---|
995 | if (-r "/etc/make.conf") {
|
---|
996 | open(MAKE,"/etc/make.conf");
|
---|
997 | while (<MAKE>) {
|
---|
998 | $found = 1 if (/$pbbd\/portage/);
|
---|
999 | }
|
---|
1000 | close(MAKE);
|
---|
1001 | }
|
---|
1002 | if ($found == 0) {
|
---|
1003 | pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
|
---|
1004 | }
|
---|
1005 | #$found = 0;
|
---|
1006 | #if (-r "/etc/portage/package.keywords") {
|
---|
1007 | #open(KEYW,"/etc/portage/package.keywords");
|
---|
1008 | #while (<KEYW>) {
|
---|
1009 | #$found = 1 if (/portage\/pb/);
|
---|
1010 | #}
|
---|
1011 | #close(KEYW);
|
---|
1012 | #}
|
---|
1013 | #if ($found == 0) {
|
---|
1014 | #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
|
---|
1015 | #}
|
---|
1016 |
|
---|
1017 | # Build
|
---|
1018 | foreach my $f (@ebuildfile) {
|
---|
1019 | if ($f =~ /\.ebuild$/) {
|
---|
1020 | pb_distro_installdeps($f,$dtype,$pbupd);
|
---|
1021 | move($f,"$tmpd/$pbpkg-$pbver.ebuild");
|
---|
1022 | pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
|
---|
1023 | # Now move it where pb expects it
|
---|
1024 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
|
---|
1025 | move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-$pbtag.ebuild");
|
---|
1026 | }
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-$pbtag.ebuild";
|
---|
1030 | } elsif ($dtype eq "tgz") {
|
---|
1031 | # Slackware family
|
---|
1032 | $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
|
---|
1033 |
|
---|
1034 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
1035 | pb_system("tar xfz $src","Extracting sources");
|
---|
1036 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
1037 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
1038 | symlink "pbconf/$ddir-$dver-$arch","install" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
|
---|
1039 | if (-x "install/pbslack") {
|
---|
1040 | pb_distro_installdeps("./install/pbslack",$dtype,$pbupd);
|
---|
1041 | pb_system("./install/pbslack","Building software");
|
---|
1042 | pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
|
---|
1043 | }
|
---|
1044 | } elsif ($dtype eq "pkg") {
|
---|
1045 | # Solaris
|
---|
1046 | $made="$made $pbpkg-$pbver-$pbtag.pkg.gz";
|
---|
1047 | my $pkgdestdir="$ENV{'PBBUILDDIR'}/install";
|
---|
1048 |
|
---|
1049 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
1050 | # Will host resulting packages
|
---|
1051 | pb_mkdir_p("$dtype");
|
---|
1052 | pb_mkdir_p("$pkgdestdir/delivery");
|
---|
1053 | pb_system("tar xfz $src","Extracting sources under $ENV{'PBBUILDDIR'}");
|
---|
1054 | pb_system("tar xfz $src2","Extracting pbconf under $ENV{'PBBUILDDIR'}");
|
---|
1055 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
1056 | if (-f "pbconf/$ddir-$dver-$arch/pbbuild") {
|
---|
1057 | chmod 0755,"pbconf/$ddir-$dver-$arch/pbbuild";
|
---|
1058 | # pkginfo file is mandatory
|
---|
1059 | die "Unable to find pkginfo file in pbconf/$ddir-$dver-$arch" if (! -f "pbconf/$ddir-$dver-$arch/pkginfo");
|
---|
1060 | # Build
|
---|
1061 | pb_system("pbconf/$ddir-$dver-$arch/pbbuild $pkgdestdir/delivery","Building software and installing under $pkgdestdir/delivery");
|
---|
1062 | # Copy complementary files
|
---|
1063 | if (-f "pbconf/$ddir-$dver-$arch/prototype") {
|
---|
1064 | copy("pbconf/$ddir-$dver-$arch/prototype", $pkgdestdir)
|
---|
1065 | } else {
|
---|
1066 | # No prototype provided, calculating it
|
---|
1067 | open(PROTO,"> $pkgdestdir/prototype") || die "Unable to create prototype file";
|
---|
1068 | print PROTO "i pkginfo\n";
|
---|
1069 | print PROTO "i depend\n" if (-f "pbconf/$ddir-$dver-$arch/depend");
|
---|
1070 | $ENV{'PBSOLDESTDIR'} = "$pkgdestdir/delivery";
|
---|
1071 | find(\&create_solaris_prototype, "$pkgdestdir/delivery");
|
---|
1072 | }
|
---|
1073 | copy("pbconf/$ddir-$dver-$arch/depend", $pkgdestdir) if (-f "pbconf/$ddir-$dver-$arch/depend");
|
---|
1074 | copy("pbconf/$ddir-$dver-$arch/pkginfo", $pkgdestdir);
|
---|
1075 | pb_system("cd $pkgdestdir/delivery ; pkgmk -o -f ../prototype -r $pkgdestdir/delivery -d $ENV{'PBBUILDDIR'}/$dtype","Packaging $pbpkg","verbose");
|
---|
1076 | pb_system("cd $ENV{'PBBUILDDIR'}/$dtype ; echo \"\" | pkgtrans -o -n -s $ENV{'PBBUILDDIR'}/$dtype $ENV{'PBBUILDDIR'}/$pbpkg-$pbver-$pbtag.pkg all","Transforming $pbpkg","verbose");
|
---|
1077 | pb_system("cd $ENV{'PBBUILDDIR'} ; gzip -9f $pbpkg-$pbver-$pbtag.pkg","Compressing $pbpkg-$pbver-$pbtag.pkg","verbose");
|
---|
1078 | } else {
|
---|
1079 | pb_log(0,"No pbconf/$ddir-$dver-$arch/pbbuild file found for $pbpkg-$pbver in \n");
|
---|
1080 | }
|
---|
1081 | chdir ".." || die "Unable to chdir to parent dir";
|
---|
1082 | pb_system("rm -rf $pbpkg-$pbver $ENV{'PBBUILDDIR'}/$dtype $pkgdestdir", "Cleanup");
|
---|
1083 | } else {
|
---|
1084 | die "Unknown dtype format $dtype";
|
---|
1085 | }
|
---|
1086 | }
|
---|
1087 | # Packages check if needed
|
---|
1088 | if ($dtype eq "rpm") {
|
---|
1089 | if (-f "/usr/bin/rpmlint") {
|
---|
1090 | pb_system("rpmlint $made","Checking validity of rpms with rpmlint","verbose");
|
---|
1091 | } else {
|
---|
1092 | pb_log(0,"rpm packages generated: $made\n");
|
---|
1093 | }
|
---|
1094 | } elsif ($dtype eq "deb") {
|
---|
1095 | my $made2 = "";
|
---|
1096 | foreach my $f (split(/ /,$made)) {
|
---|
1097 | $made2 .= "../$f " if ($f =~ /\.changes$/);
|
---|
1098 | }
|
---|
1099 | if (-f "/usr/bin/lintian") {
|
---|
1100 | pb_system("lintian $made2","Checking validity of debs with lintian","verbose");
|
---|
1101 | } else {
|
---|
1102 | pb_log(0,"deb packages generated: $made2\n");
|
---|
1103 | }
|
---|
1104 | } else {
|
---|
1105 | pb_log(0,"No check done for $dtype yet\n");
|
---|
1106 | pb_log(0,"Packages generated: $made\n");
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | # Keep track of what is generated so that we can get them back from VMs
|
---|
1110 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
1111 | print KEEP "$made\n";
|
---|
1112 | close(KEEP);
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | sub create_solaris_prototype {
|
---|
1116 |
|
---|
1117 | my $uidgid = "bin bin";
|
---|
1118 | my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
|
---|
1119 |
|
---|
1120 | return if ($_ =~ /^$pkgdestdir$/);
|
---|
1121 | if (-d $_) {
|
---|
1122 | my $n = $File::Find::name;
|
---|
1123 | $n =~ s~$pkgdestdir/~~;
|
---|
1124 | print PROTO "d none $n 0755 $uidgid\n";
|
---|
1125 | } elsif (-x $_) {
|
---|
1126 | my $n = $File::Find::name;
|
---|
1127 | $n =~ s~$pkgdestdir/~~;
|
---|
1128 | print PROTO "f none $n 0755 $uidgid\n";
|
---|
1129 | } elsif (-f $_) {
|
---|
1130 | my $n = $File::Find::name;
|
---|
1131 | $n =~ s~$pkgdestdir/~~;
|
---|
1132 | print PROTO "f none $n 0644 $uidgid\n";
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | sub pb_build2ssh {
|
---|
1137 | pb_send2target("Sources");
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | sub pb_pkg2ssh {
|
---|
1141 | pb_send2target("Packages");
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | # By default deliver to the the public site hosting the
|
---|
1145 | # ftp structure (or whatever) or a VM/VE
|
---|
1146 | sub pb_send2target {
|
---|
1147 |
|
---|
1148 | my $cmt = shift;
|
---|
1149 | my $v = shift || undef;
|
---|
1150 | my $vmexist = shift || 0; # 0 is FALSE
|
---|
1151 | my $vmpid = shift || 0; # 0 is FALSE
|
---|
1152 | my $snapme = shift || 0; # 0 is FALSE
|
---|
1153 |
|
---|
1154 | pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
|
---|
1155 | my $host = "sshhost";
|
---|
1156 | my $login = "sshlogin";
|
---|
1157 | my $dir = "sshdir";
|
---|
1158 | my $port = "sshport";
|
---|
1159 | my $conf = "sshconf";
|
---|
1160 | my $tmout = undef;
|
---|
1161 | my $path = undef;
|
---|
1162 | if ($cmt =~ /^VM/) {
|
---|
1163 | $login = "vmlogin";
|
---|
1164 | $dir = "pbdefdir";
|
---|
1165 | # Specific VM
|
---|
1166 | $tmout = "vmtmout";
|
---|
1167 | $path = "vmpath";
|
---|
1168 | $host = "vmhost";
|
---|
1169 | $port = "vmport";
|
---|
1170 | } elsif ($cmt =~ /^VE/) {
|
---|
1171 | $login = "velogin";
|
---|
1172 | $dir = "pbdefdir";
|
---|
1173 | # Specific VE
|
---|
1174 | $path = "vepath";
|
---|
1175 | $conf = "rbsconf";
|
---|
1176 | } elsif ($cmt eq "Web") {
|
---|
1177 | $host = "websshhost";
|
---|
1178 | $login = "websshlogin";
|
---|
1179 | $dir = "websshdir";
|
---|
1180 | $port = "websshport";
|
---|
1181 | }
|
---|
1182 | my $cmd = "";
|
---|
1183 | my $src = "";
|
---|
1184 | my ($odir,$over,$oarch) = (undef, undef, undef);
|
---|
1185 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf);
|
---|
1186 |
|
---|
1187 | if ($cmt ne "Announce") {
|
---|
1188 | # Get list of packages to build
|
---|
1189 | my $ptr = pb_get_pkg();
|
---|
1190 | @pkgs = @$ptr;
|
---|
1191 |
|
---|
1192 | # Get the running distro to consider
|
---|
1193 | if (defined $v) {
|
---|
1194 | ($odir,$over,$oarch) = split(/-/,$v);
|
---|
1195 | }
|
---|
1196 | ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($odir,$over,$oarch);
|
---|
1197 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
|
---|
1198 |
|
---|
1199 | # Get list of packages to build
|
---|
1200 | # Get content saved in cms2build
|
---|
1201 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
1202 | $pkg = { } if (not defined $pkg);
|
---|
1203 |
|
---|
1204 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
1205 | foreach my $pbpkg (@pkgs) {
|
---|
1206 | my $vertag = $pkg->{$pbpkg};
|
---|
1207 | # get the version of the current package - maybe different
|
---|
1208 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
1209 |
|
---|
1210 | if (($cmt eq "Sources") || ($cmt =~ /V[EM]build/)) {
|
---|
1211 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
|
---|
1212 | if ($cmd eq "") {
|
---|
1213 | $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
1214 | } else {
|
---|
1215 | $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
1216 | }
|
---|
1217 | } elsif ($cmt eq "Web") {
|
---|
1218 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 | # Adds conf file for availability of conf elements
|
---|
1222 | pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
|
---|
1223 | }
|
---|
1224 |
|
---|
1225 | if ($cmt =~ /V[EM]build/) {
|
---|
1226 | $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
|
---|
1227 | } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) {
|
---|
1228 | $src="$src $ENV{'PBDESTDIR'}/pbscript";
|
---|
1229 | } elsif ($cmt =~ /V[EM]test/) {
|
---|
1230 | $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript $ENV{'PBDESTDIR'}/pbtest";
|
---|
1231 | } elsif ($cmt eq "Announce") {
|
---|
1232 | $src="$src $ENV{'PBTMP'}/pbscript";
|
---|
1233 | } elsif ($cmt eq "Packages") {
|
---|
1234 | # Get package list from file made during build2pkg
|
---|
1235 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
1236 | $src = <KEEP>;
|
---|
1237 | chomp($src);
|
---|
1238 | close(KEEP);
|
---|
1239 | $src="$src $ENV{'PBBUILDDIR'}/pbscript";
|
---|
1240 | }
|
---|
1241 | # Remove potential leading spaces (cause problem with basename)
|
---|
1242 | $src =~ s/^ *//;
|
---|
1243 | my $basesrc = "";
|
---|
1244 | foreach my $i (split(/ +/,$src)) {
|
---|
1245 | $basesrc .= " ".basename($i);
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 | pb_log(0,"Sources handled ($cmt): $src\n");
|
---|
1249 | pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$path,$conf))."\n");
|
---|
1250 | my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
|
---|
1251 | # Not mandatory...
|
---|
1252 | my ($rbsconf,$testver,$delivery) = pb_conf_get_if($conf,"testver","delivery");
|
---|
1253 | my ($vtmout,$vepath);
|
---|
1254 | # ...Except those in virtual context
|
---|
1255 | if ($cmt =~ /^VE/) {
|
---|
1256 | ($vepath) = pb_conf_get($path);
|
---|
1257 | }
|
---|
1258 | if ($cmt =~ /^VM/) {
|
---|
1259 | ($vtmout) = pb_conf_get($tmout);
|
---|
1260 | }
|
---|
1261 | pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vepath,$rbsconf))."\n");
|
---|
1262 |
|
---|
1263 | my $mac;
|
---|
1264 | if ($cmt !~ /^VE/) {
|
---|
1265 | $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
|
---|
1266 | # Overwrite account value if passed as parameter
|
---|
1267 | $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
|
---|
1268 | pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
|
---|
1269 | } else {
|
---|
1270 | # VE
|
---|
1271 | # Overwrite account value if passed as parameter (typically for setup2ve)
|
---|
1272 | $mac = $sshlogin->{$ENV{'PBPROJ'}};
|
---|
1273 | $mac = $pbaccount if (defined $pbaccount);
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 | my $tdir;
|
---|
1277 | my $bdir;
|
---|
1278 | if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/)) {
|
---|
1279 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery/src";
|
---|
1280 | } elsif (($cmt =~ /V[EM]build/) || ($cmt =~ /V[EM]test/)) {
|
---|
1281 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
|
---|
1282 | $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
|
---|
1283 | # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
|
---|
1284 | $bdir =~ s|\$ENV.+\}/||;
|
---|
1285 | } elsif ($cmt eq "Announce") {
|
---|
1286 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery";
|
---|
1287 | } elsif ($cmt eq "Web") {
|
---|
1288 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery";
|
---|
1289 | } elsif ($cmt eq "Packages") {
|
---|
1290 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$delivery/$ddir/$dver";
|
---|
1291 |
|
---|
1292 | my $repodir = $tdir;
|
---|
1293 | $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
|
---|
1294 |
|
---|
1295 | my ($pbrepo) = pb_conf_get("pbrepo");
|
---|
1296 |
|
---|
1297 | # Repository management
|
---|
1298 | open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
|
---|
1299 | if ($dtype eq "rpm") {
|
---|
1300 | # Also make a pbscript to generate yum/urpmi bases
|
---|
1301 | print PBS << "EOF";
|
---|
1302 | #!/bin/bash
|
---|
1303 | # Prepare a script to ease yum setup
|
---|
1304 | cat > $ENV{'PBPROJ'}.repo << EOT
|
---|
1305 | [$ENV{'PBPROJ'}]
|
---|
1306 | name=$ddir $dver - $ENV{'PBPROJ'} Vanilla Packages
|
---|
1307 | baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
|
---|
1308 | enabled=1
|
---|
1309 | gpgcheck=0
|
---|
1310 | EOT
|
---|
1311 | chmod 644 $ENV{'PBPROJ'}.repo
|
---|
1312 |
|
---|
1313 | # Clean up old repo content
|
---|
1314 | rm -rf headers/ repodata/
|
---|
1315 | # Create yum repo
|
---|
1316 | yum-arch .
|
---|
1317 | # Create repodata
|
---|
1318 | createrepo .
|
---|
1319 | EOF
|
---|
1320 | if ($dfam eq "md") {
|
---|
1321 | # For Mandriva add urpmi management
|
---|
1322 | print PBS << "EOF";
|
---|
1323 | # Prepare a script to ease urpmi setup
|
---|
1324 | cat > $ENV{'PBPROJ'}.addmedia << EOT
|
---|
1325 | urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with media_info/hdlist.cz
|
---|
1326 | EOT
|
---|
1327 | chmod 755 $ENV{'PBPROJ'}.addmedia
|
---|
1328 |
|
---|
1329 | # Clean up old repo content
|
---|
1330 | rm -f hdlist.cz synthesis.hdlist.cz
|
---|
1331 | # Create urpmi repo
|
---|
1332 | genhdlist2 --clean .
|
---|
1333 | if [ \$\? -ne 0 ]; then
|
---|
1334 | genhdlist .
|
---|
1335 | fi
|
---|
1336 | EOF
|
---|
1337 | }
|
---|
1338 | if ($ddir eq "fedora") {
|
---|
1339 | # Extract the spec file to please Fedora maintainers :-(
|
---|
1340 | print PBS << "EOF";
|
---|
1341 | for p in $basesrc; do
|
---|
1342 | echo \$p | grep -q 'src.rpm'
|
---|
1343 | if [ \$\? -eq 0 ]; then
|
---|
1344 | rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
|
---|
1345 | fi
|
---|
1346 | done
|
---|
1347 | EOF
|
---|
1348 | }
|
---|
1349 | } elsif ($dtype eq "deb") {
|
---|
1350 | # Also make a pbscript to generate apt bases
|
---|
1351 | # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
|
---|
1352 | my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
|
---|
1353 | print PBS << "EOF";
|
---|
1354 | #!/bin/bash
|
---|
1355 | # Prepare a script to ease apt setup
|
---|
1356 | cat > $ENV{'PBPROJ'}.sources.list << EOT
|
---|
1357 | deb $rpd $dver contrib
|
---|
1358 | deb-src $rpd $dver contrib
|
---|
1359 | EOT
|
---|
1360 | chmod 644 $ENV{'PBPROJ'}.sources.list
|
---|
1361 |
|
---|
1362 | # Prepare a script to create apt info file
|
---|
1363 | (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)
|
---|
1364 | #(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)
|
---|
1365 | EOF
|
---|
1366 | } elsif ($dtype eq "ebuild") {
|
---|
1367 | # make a pbscript to generate links to latest version
|
---|
1368 | print PBS << "EOF";
|
---|
1369 | #!/bin/bash
|
---|
1370 | # Prepare a script to create correct links
|
---|
1371 | for p in $src; do
|
---|
1372 | echo \$p | grep -q '.ebuild'
|
---|
1373 | if [ \$\? -eq 0 ]; then
|
---|
1374 | j=`basename \$p`
|
---|
1375 | pp=`echo \$j | cut -d'-' -f1`
|
---|
1376 | ln -sf \$j \$pp.ebuild
|
---|
1377 | fi
|
---|
1378 | done
|
---|
1379 | EOF
|
---|
1380 | }
|
---|
1381 | close(PBS);
|
---|
1382 | chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
|
---|
1383 | } else {
|
---|
1384 | return;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | # Useless for VE
|
---|
1388 | my $nport;
|
---|
1389 | if ($cmt !~ /^VE/) {
|
---|
1390 | $nport = $sshport->{$ENV{'PBPROJ'}};
|
---|
1391 | $nport = "$pbport" if (defined $pbport);
|
---|
1392 | }
|
---|
1393 |
|
---|
1394 | # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
|
---|
1395 | $tdir =~ s|\$ENV.+\}/||;
|
---|
1396 |
|
---|
1397 | my $tm = undef;
|
---|
1398 | if ($cmt =~ /^VM/) {
|
---|
1399 | $tm = $vtmout->{$ENV{'PBPROJ'}};
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | # ssh communication if not VE
|
---|
1403 | # should use a hash instead...
|
---|
1404 | my ($shcmd,$cpcmd,$cptarget,$cp2target);
|
---|
1405 | if ($cmt !~ /^VE/) {
|
---|
1406 | my $keyfile = pb_ssh_get(0);
|
---|
1407 | $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
|
---|
1408 | $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
|
---|
1409 | $cptarget = "$mac:$tdir";
|
---|
1410 | if ($cmt =~ /^VMbuild/) {
|
---|
1411 | $cp2target = "$mac:$bdir";
|
---|
1412 | }
|
---|
1413 | } else {
|
---|
1414 | my $tp = $vepath->{$ENV{'PBPROJ'}};
|
---|
1415 | ($odir,$over,$oarch) = split(/-/,$v);
|
---|
1416 | my $tpdir = "$tp/$odir/$over/$oarch";
|
---|
1417 | my ($ptr) = pb_conf_get("vetype");
|
---|
1418 | my $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
1419 | if ($vetype eq "chroot") {
|
---|
1420 | $shcmd = "sudo chroot $tpdir /bin/su - $mac -c ";
|
---|
1421 | } elsif ($vetype eq "schroot") {
|
---|
1422 | $shcmd = "schroot $tp -u $mac -- ";
|
---|
1423 | }
|
---|
1424 | $cpcmd = "sudo cp -r ";
|
---|
1425 | # We need to get the home dir of the target account to deliver in the right place
|
---|
1426 | open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd";
|
---|
1427 | my $homedir = "";
|
---|
1428 | while (<PASS>) {
|
---|
1429 | my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
|
---|
1430 | $homedir = $c6 if ($c1 =~ /^$mac$/);
|
---|
1431 | pb_log(3,"Homedir: $homedir - account: $c6\n");
|
---|
1432 | }
|
---|
1433 | close(PASS);
|
---|
1434 | $cptarget = "$tpdir/$homedir/$tdir";
|
---|
1435 | if ($cmt eq "VEbuild") {
|
---|
1436 | $cp2target = "$tpdir/$homedir/$bdir";
|
---|
1437 | }
|
---|
1438 | pb_log(2,"On VE using $cptarget as target dir to copy to\n");
|
---|
1439 | }
|
---|
1440 |
|
---|
1441 | my $logres = "";
|
---|
1442 | # Do not touch when just announcing
|
---|
1443 | if ($cmt ne "Announce") {
|
---|
1444 | 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");
|
---|
1445 | } else {
|
---|
1446 | $logres = "> ";
|
---|
1447 | }
|
---|
1448 | pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
|
---|
1449 |
|
---|
1450 | # For VE we need to change the owner manually
|
---|
1451 | if ($cmt =~ /^VE/) {
|
---|
1452 | pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 | pb_system("$shcmd \"echo \'cd $tdir ; if [ -x pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
|
---|
1456 | if ($cmt =~ /^V[EM]build/) {
|
---|
1457 | # Get back info on pkg produced, compute their name and get them from the VM
|
---|
1458 | pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
|
---|
1459 | # For VE we need to change the owner manually
|
---|
1460 | if ($cmt eq "VEbuild") {
|
---|
1461 | pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID");
|
---|
1462 | }
|
---|
1463 | # return here to avoid breaking the load on VMs/VEs in case of a bad one
|
---|
1464 | if (not -f "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") {
|
---|
1465 | pb_log(0,"Problem with VM $v on $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}");
|
---|
1466 | return;
|
---|
1467 | }
|
---|
1468 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
1469 | my $src = <KEEP>;
|
---|
1470 | chomp($src);
|
---|
1471 | close(KEEP);
|
---|
1472 | $src =~ s/^ *//;
|
---|
1473 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
|
---|
1474 | # Change pgben to make the next send2target happy
|
---|
1475 | my $made = "";
|
---|
1476 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
1477 | foreach my $p (split(/ +/,$src)) {
|
---|
1478 | my $j = basename($p);
|
---|
1479 | # For VM we don't want shell expansion to hapen locally but remotely
|
---|
1480 | my $delim = '\'';
|
---|
1481 | if ($cmt =~ /^VEbuild/) {
|
---|
1482 | # For VE we need to support shell expansion locally
|
---|
1483 | $delim = "";
|
---|
1484 | }
|
---|
1485 | pb_system("$cpcmd $cp2target/$delim$p$delim $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Recovery of package $j in $ENV{'PBBUILDDIR'}/$odir/$over");
|
---|
1486 | $made="$made $odir/$over/$j"; # if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
|
---|
1487 | }
|
---|
1488 | print KEEP "$made\n";
|
---|
1489 | close(KEEP);
|
---|
1490 | pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
|
---|
1491 |
|
---|
1492 | # Sign packages locally
|
---|
1493 | if ($dtype eq "rpm") {
|
---|
1494 | #pb_system("rpm --addsign --define \'_signature gpg\' --define \'__gpg_sign_cmd /usr/bin/gpg --batch --no-verbose --no-armor --no-secmem-warning -u \"$ENV{'PBPACKAGER'}\" -sbo %{__signature_filename} %{__plaintext_filename} --use-agent\' $made","Signing RPM packages packages");
|
---|
1495 | } elsif ($dtype eq "deb") {
|
---|
1496 | #pb_system("debsign $made","Signing DEB packages");
|
---|
1497 | } else {
|
---|
1498 | pb_log(0,"I don't know yet how to sign packages for type $dtype.\nPlease give feedback to dev team\n");
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | # We want to send them to the ssh account so overwrite what has been done before
|
---|
1502 | undef $pbaccount;
|
---|
1503 | pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
1504 | pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
|
---|
1505 | pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
|
---|
1506 | }
|
---|
1507 | pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
1508 | if ((! $vmexist) && ($cmt =~ /^VM/)) {
|
---|
1509 | # If in setupvm then takes a snapshot just before halting
|
---|
1510 | if ($snapme != 0) {
|
---|
1511 | my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype");
|
---|
1512 | # For monitoring control
|
---|
1513 | if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) {
|
---|
1514 | require Net::Telnet;
|
---|
1515 | my $t = new Net::Telnet (Timeout => 120, Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor";
|
---|
1516 | # move to monitor mode
|
---|
1517 | my @lines = $t->cmd("c");
|
---|
1518 | # Create a snapshot named pb
|
---|
1519 | @lines = $t->cmd("savevm pb");
|
---|
1520 | # Write the new status in the VM
|
---|
1521 | @lines = $t->cmd("commit all");
|
---|
1522 | # End
|
---|
1523 | @lines = $t->cmd("quit");
|
---|
1524 | }
|
---|
1525 | }
|
---|
1526 | my $hoption = "-p";
|
---|
1527 | # Solaris doesn't support -h
|
---|
1528 | $hoption = "" if ($dtype eq "pkg");
|
---|
1529 | pb_system("$shcmd \"sudo /sbin/halt $hoption \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
|
---|
1530 | }
|
---|
1531 | if (($cmt =~ /^VE/) && ($snapme != 0)) {
|
---|
1532 | ($odir,$over,$oarch) = split(/-/,$v);
|
---|
1533 | my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$odir/$over/$oarch";
|
---|
1534 | pb_system("sudo tar cz -f $vepath->{$ENV{'PBPROJ'}}/$odir-$over-$oarch.tar.gz -C $tpdir .","Creating a snapshot of $tpdir");
|
---|
1535 | }
|
---|
1536 | }
|
---|
1537 |
|
---|
1538 | sub pb_script2v {
|
---|
1539 | my $pbscript=shift;
|
---|
1540 | my $vtype=shift;
|
---|
1541 | my $pbforce=shift || 0; # Force stop of VM. Default not
|
---|
1542 | my $vm1=shift || undef; # Only that VM to treat
|
---|
1543 | my $snapme=shift || 0; # Do we have to create a snapshot
|
---|
1544 | my $vm;
|
---|
1545 | my $all;
|
---|
1546 |
|
---|
1547 | pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce,".Dumper($vm1).",$snapme)\n");
|
---|
1548 | # Prepare the script to be executed on the VM
|
---|
1549 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
1550 | if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
|
---|
1551 | copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
1552 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
1553 | }
|
---|
1554 |
|
---|
1555 | if (not defined $vm1) {
|
---|
1556 | ($vm,$all) = pb_get2v($vtype);
|
---|
1557 | } else {
|
---|
1558 | @$vm = ($vm1);
|
---|
1559 | }
|
---|
1560 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
1561 |
|
---|
1562 | foreach my $v (@$vm) {
|
---|
1563 | # Launch VM/VE
|
---|
1564 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme,$pbsnap);
|
---|
1565 |
|
---|
1566 | if ($vtype eq "vm") {
|
---|
1567 | pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
1568 |
|
---|
1569 | # Skip that VM if something went wrong
|
---|
1570 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
1571 |
|
---|
1572 | # If force stopping the VM then reset vmexist
|
---|
1573 | if ($pbforce == 1) {
|
---|
1574 | $vmpid = $vmexist;
|
---|
1575 | $vmexist = 0;
|
---|
1576 | }
|
---|
1577 | } else {
|
---|
1578 | #VE
|
---|
1579 | $vmexist = 0;
|
---|
1580 | $vmpid = 0;
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | # Gather all required files to send them to the VM
|
---|
1584 | # and launch the build through pbscript
|
---|
1585 | pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
1586 | pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme);
|
---|
1587 |
|
---|
1588 | }
|
---|
1589 | }
|
---|
1590 |
|
---|
1591 | sub pb_launchv {
|
---|
1592 | my $vtype = shift;
|
---|
1593 | my $v = shift;
|
---|
1594 | my $create = shift || 0; # By default do not create a VM/VE
|
---|
1595 | my $snapme = shift || 0; # By default do not snap a VM/VE
|
---|
1596 | my $usesnap = shift || 1; # By default study the usage of the snapshot feature of VM/VE
|
---|
1597 |
|
---|
1598 | # If creation or snapshot creation mode, no snapshot usable
|
---|
1599 | if (($create == 1) || ($snapme == 1)) {
|
---|
1600 | $usesnap = 0;
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create,$snapme,$usesnap)\n");
|
---|
1604 | die "No VM/VE defined, unable to launch" if (not defined $v);
|
---|
1605 | # Keep only the first VM in case many were given
|
---|
1606 | $v =~ s/,.*//;
|
---|
1607 |
|
---|
1608 | my $arch = pb_get_arch();
|
---|
1609 |
|
---|
1610 | # Launch the VMs/VEs
|
---|
1611 | if ($vtype eq "vm") {
|
---|
1612 | die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
|
---|
1613 |
|
---|
1614 | # TODO: vmmonport should be optional
|
---|
1615 | my ($ptr,$vmpath,$vmport,$vmsize,$vmmonport) = pb_conf_get("vmtype","vmpath","vmport","vmsize","vmmonport");
|
---|
1616 | my ($vmopt,$vmtmout,$vmsnap) = pb_conf_get_if("vmopt","vmtmout","vmsnap");
|
---|
1617 |
|
---|
1618 | my $vmtype = $ptr->{$ENV{'PBPROJ'}};
|
---|
1619 | if (not defined $ENV{'PBVMOPT'}) {
|
---|
1620 | $ENV{'PBVMOPT'} = "";
|
---|
1621 | }
|
---|
1622 | # Save the current status for later restoration
|
---|
1623 | $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
|
---|
1624 | # Set a default timeout of 2 minutes
|
---|
1625 | if (not defined $ENV{'PBVMTMOUT'}) {
|
---|
1626 | $ENV{'PBVMTMOUT'} = "120";
|
---|
1627 | }
|
---|
1628 | if (defined $vmopt->{$v}) {
|
---|
1629 | $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
|
---|
1630 | } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
|
---|
1631 | $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
|
---|
1632 | }
|
---|
1633 |
|
---|
1634 | # Are we allowed to use snapshot feature
|
---|
1635 | if ($usesnap == 1) {
|
---|
1636 | if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) {
|
---|
1637 | $ENV{'PBVMOPT'} .= "-snapshot ";
|
---|
1638 | } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
1639 | $ENV{'PBVMOPT'} .= "-snapshot ";
|
---|
1640 | } elsif ($pbsnap eq 1) {
|
---|
1641 | $ENV{'PBVMOPT'} .= "-snapshot ";
|
---|
1642 | }
|
---|
1643 | }
|
---|
1644 | if ($snapme != 0) {
|
---|
1645 | if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
|
---|
1646 | # Configure the monitoring to automize the creation of the 'pb' snapshot
|
---|
1647 | $ENV{'PBVMOPT'} .= "-serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait ";
|
---|
1648 | # In that case no snapshot call needed
|
---|
1649 | $ENV{'PBVMOPT'} =~ s/-snapshot //;
|
---|
1650 | }
|
---|
1651 | }
|
---|
1652 | if (defined $vmtmout->{$v}) {
|
---|
1653 | $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
|
---|
1654 | } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
|
---|
1655 | $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
|
---|
1656 | }
|
---|
1657 | my $nport = $vmport->{$ENV{'PBPROJ'}};
|
---|
1658 | $nport = "$pbport" if (defined $pbport);
|
---|
1659 |
|
---|
1660 | my $cmd;
|
---|
1661 | my $vmcmd; # has to be used for pb_check_ps
|
---|
1662 | my $vmm; # has to be used for pb_check_ps
|
---|
1663 | if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
|
---|
1664 | my $qemucmd32;
|
---|
1665 | my $qemucmd64;
|
---|
1666 | if ($arch eq "x86_64") {
|
---|
1667 | $qemucmd32 = "/usr/bin/qemu-system-i386";
|
---|
1668 | $qemucmd64 = "/usr/bin/qemu";
|
---|
1669 | } else {
|
---|
1670 | $qemucmd32 = "/usr/bin/qemu";
|
---|
1671 | $qemucmd64 = "/usr/bin/qemu-system-x86_64";
|
---|
1672 | }
|
---|
1673 | if ($v =~ /x86_64/) {
|
---|
1674 | $vmcmd = "$qemucmd64";
|
---|
1675 | } else {
|
---|
1676 | $vmcmd = "$qemucmd32";
|
---|
1677 | }
|
---|
1678 | if ($vmtype eq "kvm") {
|
---|
1679 | $vmcmd = "/usr/bin/kvm";
|
---|
1680 | }
|
---|
1681 | $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
|
---|
1682 | if (($create != 0) || (defined $iso)) {
|
---|
1683 | $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
|
---|
1684 | }
|
---|
1685 | # Always redirect the network and always try to use a 'pb' snapshot
|
---|
1686 | $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 -loadvm pb $vmm"
|
---|
1687 | } elsif ($vmtype eq "xen") {
|
---|
1688 | } elsif ($vmtype eq "vmware") {
|
---|
1689 | } else {
|
---|
1690 | die "VM of type $vmtype not supported. Report to the dev team";
|
---|
1691 | }
|
---|
1692 | # Restore the ENV VAR Value
|
---|
1693 | $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
|
---|
1694 |
|
---|
1695 | my ($tmpcmd,$void) = split(/ +/,$cmd);
|
---|
1696 | my $vmexist = pb_check_ps($tmpcmd,$vmm);
|
---|
1697 | my $vmpid = 0;
|
---|
1698 | if (! $vmexist) {
|
---|
1699 | if ($create != 0) {
|
---|
1700 | die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
|
---|
1701 | if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
|
---|
1702 | pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
|
---|
1703 | } elsif ($vmtype eq "vmware") {
|
---|
1704 | } else {
|
---|
1705 | }
|
---|
1706 | }
|
---|
1707 | if (! -f "$vmm") {
|
---|
1708 | pb_log(0,"Unable to find VM $vmm\n");
|
---|
1709 | } else {
|
---|
1710 | pb_system("$cmd &","Launching the VM $vmm");
|
---|
1711 | pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
|
---|
1712 | $vmpid = pb_check_ps($tmpcmd,$vmm);
|
---|
1713 | pb_log(0,"VM $vmm launched (pid $vmpid)\n");
|
---|
1714 | }
|
---|
1715 | } else {
|
---|
1716 | pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
|
---|
1717 | }
|
---|
1718 | pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
|
---|
1719 | return($vmexist,$vmpid);
|
---|
1720 | # VE here
|
---|
1721 | } else {
|
---|
1722 | # Get distro context
|
---|
1723 | my ($name,$ver,$darch) = split(/-/,$v);
|
---|
1724 | chomp($darch);
|
---|
1725 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
|
---|
1726 |
|
---|
1727 | # Get VE context
|
---|
1728 | my ($ptr,$vepath) = pb_conf_get("vetype","vepath");
|
---|
1729 | my $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
1730 |
|
---|
1731 | # We can probably only get those params now we have the distro context
|
---|
1732 | my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv");
|
---|
1733 |
|
---|
1734 | # We need to avoid umask propagation to the VE
|
---|
1735 | umask 0022;
|
---|
1736 |
|
---|
1737 | if (($vetype eq "chroot") || ($vetype eq "schroot")) {
|
---|
1738 | # Architecture consistency
|
---|
1739 | if ($arch ne $darch) {
|
---|
1740 | die "Unable to launch a VE of architecture $darch on a $arch platform" if (($darch eq "x86_64") && ($arch =~ /i?86/));
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
|
---|
1744 | if (($create != 0) || ((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) {
|
---|
1745 | my ($rbsopt1) = pb_conf_get_if("rbsopt");
|
---|
1746 |
|
---|
1747 | # We have to rebuild the chroot
|
---|
1748 | if ($dtype eq "rpm") {
|
---|
1749 |
|
---|
1750 | # Which tool is used
|
---|
1751 | my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}};
|
---|
1752 |
|
---|
1753 | # Get potential rbs option
|
---|
1754 | my $rbsopt = "";
|
---|
1755 | if (defined $rbsopt1) {
|
---|
1756 | if (defined $rbsopt1->{$verpmstyle}) {
|
---|
1757 | $rbsopt = $rbsopt1->{$verpmstyle};
|
---|
1758 | } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
|
---|
1759 | $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
|
---|
1760 | } else {
|
---|
1761 | $rbsopt = "";
|
---|
1762 | }
|
---|
1763 | }
|
---|
1764 |
|
---|
1765 | my $postinstall = pb_get_postinstall($ddir,$dver,$darch,$rbspi,$verpmstyle);
|
---|
1766 | if ($verpmstyle eq "rinse") {
|
---|
1767 | # Need to reshape the mirrors generated with local before-post-install script
|
---|
1768 | my $b4post = "--before-post-install ";
|
---|
1769 | my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbsb4pi);
|
---|
1770 | if ($postparam eq "") {
|
---|
1771 | $b4post = "";
|
---|
1772 | } else {
|
---|
1773 | $b4post .= $postparam;
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | # Need to reshape the package list for pb
|
---|
1777 | my $addpkgs;
|
---|
1778 | $postparam = "";
|
---|
1779 | $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
|
---|
1780 | if ($postparam eq "") {
|
---|
1781 | $addpkgs = "";
|
---|
1782 | } else {
|
---|
1783 | my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
|
---|
1784 | open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
|
---|
1785 | foreach my $p (split(/,/,$postparam)) {
|
---|
1786 | print PKG "$p\n";
|
---|
1787 | }
|
---|
1788 | close(PKG);
|
---|
1789 | $addpkgs = "--add-pkg-list $pkgfile";
|
---|
1790 | }
|
---|
1791 |
|
---|
1792 | my $rinseverb = "";
|
---|
1793 | $rinseverb = "--verbose" if ($pbdebug gt 0);
|
---|
1794 | my ($rbsconf) = pb_conf_get("rbsconf");
|
---|
1795 |
|
---|
1796 | pb_system("sudo /usr/sbin/rinse --directory \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" --arch \"$darch\" --distribution \"$ddir-$dver\" --config \"$rbsconf->{$ENV{'PBPROJ'}}\" $b4post $postinstall $rbsopt $addpkgs $rinseverb","Creating the rinse VE for $ddir-$dver ($darch)", "verbose");
|
---|
1797 | } elsif ($verpmstyle eq "rpmbootstrap") {
|
---|
1798 | my $rbsverb = "";
|
---|
1799 | foreach my $i (1..$pbdebug) {
|
---|
1800 | $rbsverb .= " -v";
|
---|
1801 | }
|
---|
1802 | my $addpkgs = "";
|
---|
1803 | my $postparam = "";
|
---|
1804 | $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
|
---|
1805 | if ($postparam eq "") {
|
---|
1806 | $addpkgs = "";
|
---|
1807 | } else {
|
---|
1808 | $addpkgs = "-a $postparam";
|
---|
1809 | }
|
---|
1810 | pb_system("sudo /usr/bin/rpmbootstrap $rbsopt $postinstall $addpkgs $ddir-$dver-$darch $rbsverb","Creating the rpmbootstrap VE for $ddir-$dver ($darch)", "verbose");
|
---|
1811 | } elsif ($verpmstyle eq "mock") {
|
---|
1812 | my ($rbsconf) = pb_conf_get("rbsconf");
|
---|
1813 | pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v $rbsopt","Creating the mock VE for $ddir-$dver ($darch)");
|
---|
1814 | # Once setup we need to install some packages, the pb account, ...
|
---|
1815 | pb_system("sudo /usr/sbin/mock --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
|
---|
1816 | } else {
|
---|
1817 | die "Unknown verpmtype type $verpmstyle. Report to dev team";
|
---|
1818 | }
|
---|
1819 | } elsif ($dtype eq "deb") {
|
---|
1820 | my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
|
---|
1821 |
|
---|
1822 | my $codename = pb_distro_get_param($ddir,$dver,$darch,$oscodename);
|
---|
1823 | my $postparam = "";
|
---|
1824 | my $addpkgs;
|
---|
1825 | $postparam .= pb_distro_get_param($ddir,$dver,$darch,$osmindep);
|
---|
1826 | if ($postparam eq "") {
|
---|
1827 | $addpkgs = "";
|
---|
1828 | } else {
|
---|
1829 | $addpkgs = "--include $postparam";
|
---|
1830 | }
|
---|
1831 | my $debmir = "";
|
---|
1832 | $debmir .= pb_distro_get_param($ddir,$dver,$darch,$rbsmirrorsrv);
|
---|
1833 |
|
---|
1834 | # Get potential rbs option
|
---|
1835 | my $rbsopt = "";
|
---|
1836 | if (defined $rbsopt1) {
|
---|
1837 | if (defined $rbsopt1->{$vedebstyle}) {
|
---|
1838 | $rbsopt = $rbsopt1->{$vedebstyle};
|
---|
1839 | } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
|
---|
1840 | $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
|
---|
1841 | } else {
|
---|
1842 | $rbsopt = "";
|
---|
1843 | }
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | # debootstrap works with amd64 not x86_64
|
---|
1847 | my $debarch = $darch;
|
---|
1848 | $debarch = "amd64" if ($darch eq "x86_64");
|
---|
1849 | if ($vedebstyle eq "debootstrap") {
|
---|
1850 | my $dbsverb = "";
|
---|
1851 | $dbsverb = "--verbose" if ($pbdebug gt 0);
|
---|
1852 |
|
---|
1853 | # Some perl modules are in Universe on Ubuntu
|
---|
1854 | $rbsopt .= " --components=main,universe" if ($ddir eq "ubuntu");
|
---|
1855 |
|
---|
1856 | pb_system("sudo /usr/sbin/debootstrap $dbsverb $rbsopt --arch=$debarch $addpkgs $codename \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" $debmir","Creating the debootstrap VE for $ddir-$dver ($darch)", "verbose");
|
---|
1857 | # debootstrap doesn't create an /etc/hosts file
|
---|
1858 | if (! -f "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts" ) {
|
---|
1859 | pb_system("sudo cp /etc/hosts $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch/etc/hosts");
|
---|
1860 | }
|
---|
1861 | } else {
|
---|
1862 | die "Unknown vedebtype type $vedebstyle. Report to dev team";
|
---|
1863 | }
|
---|
1864 | } elsif ($dtype eq "ebuild") {
|
---|
1865 | die "Please teach the dev team how to build gentoo chroot";
|
---|
1866 | } else {
|
---|
1867 | die "Unknown distribution type $dtype. Report to dev team";
|
---|
1868 | }
|
---|
1869 | }
|
---|
1870 | # Fix modes to allow access to the VE for pb user
|
---|
1871 | pb_system("sudo chmod 755 $vepath->{$ENV{'PBPROJ'}}/$ddir $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch","Fixing permissions");
|
---|
1872 |
|
---|
1873 | # Test if an existing snapshot exists and use it if appropriate
|
---|
1874 | # And also use it of no local extracted VE is present
|
---|
1875 | if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
|
---|
1876 | (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) ||
|
---|
1877 | ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i)) ||
|
---|
1878 | ($pbsnap eq 1) ||
|
---|
1879 | (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch"))) {
|
---|
1880 | pb_system("sudo rm -rf $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch ; sudo mkdir -p $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch ; sudo tar xz -C $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Extracting snapshot of $ddir-$dver-$darch.tar.gz under $vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch");
|
---|
1881 | }
|
---|
1882 | # Nothing more to do for VE. No real launch
|
---|
1883 | } else {
|
---|
1884 | die "VE of type $vetype not supported. Report to the dev team";
|
---|
1885 | }
|
---|
1886 | }
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | # Return string for date synchro
|
---|
1890 | sub pb_date2v {
|
---|
1891 |
|
---|
1892 | my $vtype = shift;
|
---|
1893 | my $v = shift;
|
---|
1894 |
|
---|
1895 | my ($ntp) = pb_conf_get_if($vtype."ntp");
|
---|
1896 | my $vntp = $ntp->{$ENV{'PBPROJ'}} if (defined $ntp);
|
---|
1897 | my $ntpline;
|
---|
1898 |
|
---|
1899 | if (defined $vntp) {
|
---|
1900 | my ($ntpcmd) = pb_conf_get($vtype."ntpcmd");
|
---|
1901 | my $vntpcmd;
|
---|
1902 | if (defined $ntpcmd->{$v}) {
|
---|
1903 | $vntpcmd = $ntpcmd->{$v};
|
---|
1904 | } elsif (defined $ntpcmd->{$ENV{'PBPROJ'}}) {
|
---|
1905 | $vntpcmd = $ntpcmd->{$ENV{'PBPROJ'}};
|
---|
1906 | } else {
|
---|
1907 | $vntpcmd = "/bin/true";
|
---|
1908 | }
|
---|
1909 | $ntpline = "sudo $vntpcmd $vntp";
|
---|
1910 | } else {
|
---|
1911 | $ntpline = undef;
|
---|
1912 | }
|
---|
1913 | # Force new date to be in the future compared to the date
|
---|
1914 | # of the host by adding 1 minute
|
---|
1915 | my @date=pb_get_date();
|
---|
1916 | $date[1]++;
|
---|
1917 | my $upddate = strftime("%m%d%H%M%Y", @date);
|
---|
1918 | my $dateline = "sudo date $upddate";
|
---|
1919 | return($ntpline,$dateline);
|
---|
1920 | }
|
---|
1921 |
|
---|
1922 | sub pb_build2v {
|
---|
1923 |
|
---|
1924 | my $vtype = shift;
|
---|
1925 | my $action = shift || "build";
|
---|
1926 |
|
---|
1927 | my ($v,$all) = pb_get2v($vtype);
|
---|
1928 |
|
---|
1929 | # Send tar files when we do a global generation
|
---|
1930 | pb_build2ssh() if (($all == 1) && ($action eq "build"));
|
---|
1931 |
|
---|
1932 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
1933 |
|
---|
1934 | foreach my $v (@$v) {
|
---|
1935 | # Prepare the script to be executed on the VM/VE
|
---|
1936 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
1937 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
1938 | print SCRIPT "#!/bin/bash\n";
|
---|
1939 |
|
---|
1940 | # Transmit the verbosity level to the virtual env/mach.
|
---|
1941 | my $verbose = "";
|
---|
1942 | my $i = 0; # minimal debug level
|
---|
1943 | while ($i lt $pbdebug) {
|
---|
1944 | $verbose .= "-v ";
|
---|
1945 | $i++;
|
---|
1946 | }
|
---|
1947 | # Activate script verbosity if at least 2 for pbdebug
|
---|
1948 | print SCRIPT "set -x\n" if ($i gt 1);
|
---|
1949 | # Quiet if asked to be so on the original system
|
---|
1950 | $verbose = "-q" if ($pbdebug eq -1);
|
---|
1951 |
|
---|
1952 | print SCRIPT "echo ... Execution needed\n";
|
---|
1953 | print SCRIPT "# This is in directory delivery\n";
|
---|
1954 | print SCRIPT "# Setup the variables required for building\n";
|
---|
1955 | print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
|
---|
1956 |
|
---|
1957 | if ($action eq "build") {
|
---|
1958 | print SCRIPT "# Preparation for pb\n";
|
---|
1959 | print SCRIPT "mv .pbrc \$HOME\n";
|
---|
1960 | print SCRIPT "cd ..\n";
|
---|
1961 | }
|
---|
1962 |
|
---|
1963 | # VE needs a good /proc
|
---|
1964 | if ($vtype eq "ve") {
|
---|
1965 | print SCRIPT "sudo mount -t proc /proc /proc\n";
|
---|
1966 | }
|
---|
1967 |
|
---|
1968 | my ($ntpline,$dateline) = pb_date2v($vtype,$v);
|
---|
1969 | print SCRIPT "# Time sync\n";
|
---|
1970 | print SCRIPT "echo 'setting up date with '";
|
---|
1971 | if (defined $ntpline) {
|
---|
1972 | print SCRIPT "echo $ntpline\n";
|
---|
1973 | print SCRIPT "$ntpline\n";
|
---|
1974 | } else {
|
---|
1975 | print SCRIPT "echo $dateline\n";
|
---|
1976 | print SCRIPT "$dateline\n";
|
---|
1977 | }
|
---|
1978 | # Use potential local proxy declaration in case we need it to download repo, pkgs, ...
|
---|
1979 | if (defined $ENV{'http_proxy'}) {
|
---|
1980 | print SCRIPT "export http_proxy=\"$ENV{'http_proxy'}\"\n";
|
---|
1981 | }
|
---|
1982 |
|
---|
1983 | if (defined $ENV{'ftp_proxy'}) {
|
---|
1984 | print SCRIPT "export ftp_proxy=\"$ENV{'ftp_proxy'}\"\n";
|
---|
1985 | }
|
---|
1986 |
|
---|
1987 | # Get list of packages to build/test and get some ENV vars as well
|
---|
1988 | my $ptr = pb_get_pkg();
|
---|
1989 | @pkgs = @$ptr;
|
---|
1990 | my $p = join(' ',@pkgs) if (@pkgs);
|
---|
1991 | print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
|
---|
1992 | print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
|
---|
1993 | print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
|
---|
1994 |
|
---|
1995 | # We may need to do some other tasks before building. Read a script here to finish setup
|
---|
1996 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
|
---|
1997 | print SCRIPT "# Special pre-instructions to be launched\n";
|
---|
1998 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
|
---|
2002 | print SCRIPT "# Special pre-$action instructions to be launched\n";
|
---|
2003 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
|
---|
2004 | }
|
---|
2005 |
|
---|
2006 | print SCRIPT "# $action\n";
|
---|
2007 | print SCRIPT "echo $action"."ing packages on $vtype...\n";
|
---|
2008 |
|
---|
2009 | if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
|
---|
2010 | die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
|
---|
2011 | }
|
---|
2012 | print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
|
---|
2013 |
|
---|
2014 | if ($vtype eq "ve") {
|
---|
2015 | print SCRIPT "sudo umount /proc\n";
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | # We may need to do some other tasks after building. Read a script here to exit properly
|
---|
2019 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
|
---|
2020 | print SCRIPT "# Special post-$action instructions to be launched\n";
|
---|
2021 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
|
---|
2022 | }
|
---|
2023 |
|
---|
2024 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
|
---|
2025 | print SCRIPT "# Special post-instructions to be launched\n";
|
---|
2026 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
|
---|
2027 | }
|
---|
2028 |
|
---|
2029 | close(SCRIPT);
|
---|
2030 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
2031 |
|
---|
2032 | # Launch the VM/VE
|
---|
2033 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
2034 |
|
---|
2035 | if ($vtype eq "vm") {
|
---|
2036 | # Skip that VM if it something went wrong
|
---|
2037 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
2038 | } else {
|
---|
2039 | # VE
|
---|
2040 | $vmexist = 0;
|
---|
2041 | $vmpid = 0;
|
---|
2042 | }
|
---|
2043 | # Gather all required files to send them to the VM/VE
|
---|
2044 | # and launch the build through pbscript
|
---|
2045 | pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
|
---|
2046 | pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
|
---|
2047 | }
|
---|
2048 | }
|
---|
2049 |
|
---|
2050 |
|
---|
2051 | sub pb_clean {
|
---|
2052 |
|
---|
2053 | my $sleep=10;
|
---|
2054 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
2055 | die "Unable to get env var PBBUILDDIR" if (not defined $ENV{'PBBUILDDIR'});
|
---|
2056 | pb_log(0,"We will now wait $sleep s before removing both directories\n$ENV{'PBDESTDIR'} and $ENV{'PBBUILDDIR'}.\nPlease break me if this is wrong\n");
|
---|
2057 | sleep $sleep;
|
---|
2058 | pb_rm_rf($ENV{'PBDESTDIR'});
|
---|
2059 | pb_rm_rf($ENV{'PBBUILDDIR'});
|
---|
2060 | }
|
---|
2061 |
|
---|
2062 | sub pb_newver {
|
---|
2063 |
|
---|
2064 | die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
|
---|
2065 |
|
---|
2066 | # Need this call for PBDIR
|
---|
2067 | my ($scheme2,$uri) = pb_cms_init($pbinit);
|
---|
2068 |
|
---|
2069 | my ($pbconf,$pburl) = pb_conf_get("pbconfurl","pburl");
|
---|
2070 | $uri = $pbconf->{$ENV{'PBPROJ'}};
|
---|
2071 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
2072 |
|
---|
2073 | # Checking CMS repositories status
|
---|
2074 | ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
|
---|
2075 |
|
---|
2076 | if ($scheme !~ /^svn/) {
|
---|
2077 | die "Only SVN is supported at the moment";
|
---|
2078 | }
|
---|
2079 |
|
---|
2080 | my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
|
---|
2081 | die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
|
---|
2082 |
|
---|
2083 | $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
|
---|
2084 | die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
|
---|
2085 |
|
---|
2086 | # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
|
---|
2087 | # we want to get for the root of the new URL
|
---|
2088 |
|
---|
2089 | my $tmp = $ENV{'PBROOTDIR'};
|
---|
2090 | $tmp =~ s|^$ENV{'PBCONFDIR'}||;
|
---|
2091 |
|
---|
2092 | my $newurl = "$uri/".dirname($tmp)."/$newver";
|
---|
2093 | # Should probably use projver in the old file
|
---|
2094 | my $oldver= basename($tmp);
|
---|
2095 |
|
---|
2096 | # Duplicate and extract project-builder part
|
---|
2097 | pb_log(2,"Copying $uri/$tmp to $newurl\n");
|
---|
2098 | pb_cms_copy($scheme,"$uri/$tmp",$newurl);
|
---|
2099 | pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
|
---|
2100 | pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
|
---|
2101 |
|
---|
2102 | # Duplicate and extract project
|
---|
2103 | my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/".dirname($tmp)."/$newver";
|
---|
2104 |
|
---|
2105 | pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$tmp to $newurl2\n");
|
---|
2106 | pb_cms_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$tmp",$newurl2);
|
---|
2107 | pb_log(2,"Checkout $newurl2 to $ENV{'PBDIR'}/../$newver\n");
|
---|
2108 | pb_cms_up($scheme2,"$ENV{'PBDIR'}/..");
|
---|
2109 |
|
---|
2110 | # Update the .pb file
|
---|
2111 | open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
|
---|
2112 | open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
|
---|
2113 | while(<FILE>) {
|
---|
2114 | s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
|
---|
2115 | 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/);
|
---|
2116 | pb_log(0,"Commenting testver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
|
---|
2117 | s/^testver/#testver/;
|
---|
2118 | print OUT $_;
|
---|
2119 | pb_log(0,"Please check delivery ($_) in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^delivery/);
|
---|
2120 | }
|
---|
2121 | close(FILE);
|
---|
2122 | close(OUT);
|
---|
2123 | rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
|
---|
2124 |
|
---|
2125 | # Checking pbcl files
|
---|
2126 | foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
|
---|
2127 | # Compute new pbcl file
|
---|
2128 | my $f2 = $f;
|
---|
2129 | $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBROOTDIR'}/../$newver/|;
|
---|
2130 | open(PBCL,$f) || die "Unable to open $f";
|
---|
2131 | my $foundnew = 0;
|
---|
2132 | while (<PBCL>) {
|
---|
2133 | $foundnew = 1 if (/^$newver \(/);
|
---|
2134 | }
|
---|
2135 | close(PBCL);
|
---|
2136 | open(OUT,"> $f2") || die "Unable to write to $f2: $!";
|
---|
2137 | open(PBCL,$f) || die "Unable to open $f";
|
---|
2138 | while (<PBCL>) {
|
---|
2139 | print OUT "$_" if (not /^$oldver \(/);
|
---|
2140 | if ((/^$oldver \(/) && ($foundnew == 0)) {
|
---|
2141 | print OUT "$newver ($pbdate)\n";
|
---|
2142 | print OUT "- TBD\n";
|
---|
2143 | print OUT "\n";
|
---|
2144 | pb_log(0,"WARNING: version $newver not found in $f so added to $f2...\n") if ($foundnew == 0);
|
---|
2145 | }
|
---|
2146 | }
|
---|
2147 | close(OUT);
|
---|
2148 | close(PBCL);
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 | pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
|
---|
2152 | pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 | #
|
---|
2156 | # Return the list of VMs/VEs we are working on
|
---|
2157 | # $all is a flag to know if we return all of them
|
---|
2158 | # or only some (if all we publish also tar files in addition to pkgs
|
---|
2159 | #
|
---|
2160 | sub pb_get2v {
|
---|
2161 |
|
---|
2162 | my $vtype = shift;
|
---|
2163 | my @v;
|
---|
2164 | my $all = 0;
|
---|
2165 | my $vlist;
|
---|
2166 | my $pbv = 'PBV';
|
---|
2167 |
|
---|
2168 | if ($vtype eq "vm") {
|
---|
2169 | $vlist = "vmlist";
|
---|
2170 | } elsif ($vtype eq "ve") {
|
---|
2171 | $vlist = "velist";
|
---|
2172 | }
|
---|
2173 | # Get VM/VE list
|
---|
2174 | if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
|
---|
2175 | my ($ptr) = pb_conf_get($vlist);
|
---|
2176 | $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
|
---|
2177 | $all = 1;
|
---|
2178 | }
|
---|
2179 | pb_log(2,"$vtype: $ENV{$pbv}\n");
|
---|
2180 | @v = split(/,/,$ENV{$pbv});
|
---|
2181 | return(\@v,$all);
|
---|
2182 | }
|
---|
2183 |
|
---|
2184 | # Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
|
---|
2185 | # Needs to use root account to connect to the VM/VE
|
---|
2186 | # pb will take your local public SSH key to access
|
---|
2187 | # the pb account in the VM later on if needed
|
---|
2188 | sub pb_setup2v {
|
---|
2189 |
|
---|
2190 | my $vtype = shift;
|
---|
2191 |
|
---|
2192 | my ($vm,$all) = pb_get2v($vtype);
|
---|
2193 |
|
---|
2194 | # Script generated
|
---|
2195 | my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
|
---|
2196 |
|
---|
2197 | foreach my $v (@$vm) {
|
---|
2198 | # Deal with date sync.
|
---|
2199 | my ($ntpline,$dateline) = pb_date2v($vtype,$v);
|
---|
2200 |
|
---|
2201 | # Get distro context
|
---|
2202 | my ($name,$ver,$darch) = split(/-/,$v);
|
---|
2203 | chomp($darch);
|
---|
2204 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd) = pb_distro_init($name,$ver,$darch);
|
---|
2205 |
|
---|
2206 | # Name of the account to deal with for VM/VE
|
---|
2207 | # Do not use the one passed potentially with -a
|
---|
2208 | my ($pbac) = pb_conf_get($vtype."login");
|
---|
2209 | my ($key,$zero0,$zero1,$zero2);
|
---|
2210 | my ($vmexist,$vmpid);
|
---|
2211 |
|
---|
2212 | # Prepare the script to be executed on the VM/VE
|
---|
2213 | # in $ENV{'PBDESTDIR'}/setupv
|
---|
2214 | open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
|
---|
2215 |
|
---|
2216 | print SCRIPT << 'EOF';
|
---|
2217 | #!/usr/bin/perl -w
|
---|
2218 |
|
---|
2219 | use strict;
|
---|
2220 | use File::Copy;
|
---|
2221 |
|
---|
2222 | # We should not need in this script more functions than what is provided
|
---|
2223 | # by Base and Distribution to avoid problems at exec time.
|
---|
2224 | # They are appended at the end.
|
---|
2225 |
|
---|
2226 | our $pbdebug;
|
---|
2227 | our $pbLOG;
|
---|
2228 | our $pbsynmsg = "pbscript";
|
---|
2229 | our $pbdisplaytype = "text";
|
---|
2230 | our $pblocale = "";
|
---|
2231 | pb_log_init($pbdebug, $pbLOG);
|
---|
2232 | pb_temp_init();
|
---|
2233 |
|
---|
2234 | EOF
|
---|
2235 |
|
---|
2236 | # Launch the VM/VE - Usage of snapshot disabled
|
---|
2237 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,0,0);
|
---|
2238 |
|
---|
2239 | if ($vtype eq "vm") {
|
---|
2240 | # Prepare the key to be used and transfered remotely
|
---|
2241 | my $keyfile = pb_ssh_get(1);
|
---|
2242 |
|
---|
2243 | my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
|
---|
2244 | my $nport = $vmport->{$ENV{'PBPROJ'}};
|
---|
2245 | $nport = "$pbport" if (defined $pbport);
|
---|
2246 |
|
---|
2247 | # Skip that VM if something went wrong
|
---|
2248 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
2249 |
|
---|
2250 | # Store the pub key part in a variable
|
---|
2251 | open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
|
---|
2252 | ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
|
---|
2253 | close(FILE);
|
---|
2254 |
|
---|
2255 | $key = "\Q$zero1";
|
---|
2256 |
|
---|
2257 | 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 ; if [ -x /usr/bin/chcon ]; then /usr/bin/chcon -Rt home_ssh_t .ssh 2> /dev/null; fi\"","Copying local keys to $vtype. This may require the root password");
|
---|
2258 | # once this is done, we can do what we want on the VM remotely
|
---|
2259 | } elsif ($vtype eq "ve") {
|
---|
2260 | print SCRIPT << "EOF";
|
---|
2261 | # For VE we need a good null dev
|
---|
2262 | pb_system("rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null");
|
---|
2263 | EOF
|
---|
2264 | print SCRIPT << "EOF";
|
---|
2265 | # For VE we first need to mount some FS
|
---|
2266 | pb_system("mount -t proc /proc /proc");
|
---|
2267 |
|
---|
2268 | EOF
|
---|
2269 | }
|
---|
2270 |
|
---|
2271 | if ($vtype eq "vm") {
|
---|
2272 | print SCRIPT << 'EOF';
|
---|
2273 | # Removes duplicate in .ssh/authorized_keys of our key if needed
|
---|
2274 | #
|
---|
2275 | my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
|
---|
2276 | open(PBFILE,$file1) || die "Unable to open $file1";
|
---|
2277 | open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
|
---|
2278 | my $count = 0;
|
---|
2279 | while (<PBFILE>) {
|
---|
2280 |
|
---|
2281 | EOF
|
---|
2282 | print SCRIPT << "EOF";
|
---|
2283 | if (/ $key /) {
|
---|
2284 | \$count++;
|
---|
2285 | }
|
---|
2286 | print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
|
---|
2287 | }
|
---|
2288 | close(PBFILE);
|
---|
2289 | close(PBOUT);
|
---|
2290 | rename("\$file1.new",\$file1);
|
---|
2291 | chmod 0600,\$file1;
|
---|
2292 |
|
---|
2293 | # Sync date
|
---|
2294 | EOF
|
---|
2295 | if (defined $ntpline) {
|
---|
2296 | print SCRIPT "pb_system(\"$ntpline\");\n";
|
---|
2297 | } else {
|
---|
2298 | print SCRIPT "pb_system(\"$dateline\");\n";
|
---|
2299 | }
|
---|
2300 | }
|
---|
2301 | print SCRIPT << 'EOF';
|
---|
2302 |
|
---|
2303 | # Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
|
---|
2304 | #
|
---|
2305 | my $file="/etc/passwd";
|
---|
2306 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
2307 | my $found = 0;
|
---|
2308 | while (<PBFILE>) {
|
---|
2309 | EOF
|
---|
2310 | print SCRIPT << "EOF";
|
---|
2311 | \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
|
---|
2312 | EOF
|
---|
2313 |
|
---|
2314 | my $home = "/home";
|
---|
2315 | # Solaris doesn't like that we use /home
|
---|
2316 | $home = "/export/home" if ($dtype eq "pkg");
|
---|
2317 |
|
---|
2318 | print SCRIPT << "EOF";
|
---|
2319 | }
|
---|
2320 | close(PBFILE);
|
---|
2321 |
|
---|
2322 | if ( \$found == 0 ) {
|
---|
2323 | if ( ! -d "$home" ) {
|
---|
2324 | pb_mkdir_p("$home");
|
---|
2325 | }
|
---|
2326 | EOF
|
---|
2327 | print SCRIPT << "EOF";
|
---|
2328 | pb_system("/usr/sbin/groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
|
---|
2329 | pb_system("/usr/sbin/useradd -g $pbac->{$ENV{'PBPROJ'}} -m -d $home/$pbac->{$ENV{'PBPROJ'}} $pbac->{$ENV{'PBPROJ'}}","Adding user $pbac->{$ENV{'PBPROJ'}} (group $pbac->{$ENV{'PBPROJ'}} - home $home/$pbac->{$ENV{'PBPROJ'}})");
|
---|
2330 | }
|
---|
2331 | EOF
|
---|
2332 |
|
---|
2333 | # Copy the content of our local conf file to the VM/VE
|
---|
2334 | my $content = pb_get_content(pb_distro_conffile());
|
---|
2335 | print SCRIPT << "EOF";
|
---|
2336 | #
|
---|
2337 | # Create a temporary local conf file for distribution support
|
---|
2338 | # This is created here before its use later. Its place is hardcoded, so no choice for the path
|
---|
2339 | #
|
---|
2340 | my \$tempconf = pb_distro_conffile();
|
---|
2341 | pb_mkdir_p(dirname(\$tempconf));
|
---|
2342 | open(CONF,"> \$tempconf") || die "Unable to create \$tempconf";
|
---|
2343 | print CONF q{$content};
|
---|
2344 | close(CONF);
|
---|
2345 | EOF
|
---|
2346 |
|
---|
2347 | if ($vtype eq "vm") {
|
---|
2348 | print SCRIPT << "EOF";
|
---|
2349 | # allow ssh entry to build
|
---|
2350 | #
|
---|
2351 | mkdir "$home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
|
---|
2352 | # Allow those accessing root to access the build account
|
---|
2353 | copy("\$ENV{'HOME'}/.ssh/authorized_keys","$home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
|
---|
2354 | chmod 0600,".ssh/authorized_keys";
|
---|
2355 | pb_system("chown -R $pbac->{$ENV{'PBPROJ'}}:$pbac->{$ENV{'PBPROJ'}} $home/$pbac->{$ENV{'PBPROJ'}}","Finish setting up the account env for $pbac->{$ENV{'PBPROJ'}}");
|
---|
2356 |
|
---|
2357 | EOF
|
---|
2358 | }
|
---|
2359 | print SCRIPT << 'EOF';
|
---|
2360 | # No passwd for build account only keys
|
---|
2361 | $file="/etc/shadow";
|
---|
2362 | if (-f $file) {
|
---|
2363 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
2364 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
2365 | while (<PBFILE>) {
|
---|
2366 | EOF
|
---|
2367 | print SCRIPT << "EOF";
|
---|
2368 | s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
|
---|
2369 | s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
|
---|
2370 | s/^$pbac->{$ENV{'PBPROJ'}}:\\*LK\\*:/$pbac->{$ENV{'PBPROJ'}}:NP:/; #Solaris e.g.
|
---|
2371 | EOF
|
---|
2372 | print SCRIPT << 'EOF';
|
---|
2373 | print PBOUT $_;
|
---|
2374 | }
|
---|
2375 | close(PBFILE);
|
---|
2376 | close(PBOUT);
|
---|
2377 | rename("$file.new",$file);
|
---|
2378 | chmod 0640,$file;
|
---|
2379 | }
|
---|
2380 |
|
---|
2381 | # Keep the VM in text mode
|
---|
2382 | $file="/etc/inittab";
|
---|
2383 | if (-f $file) {
|
---|
2384 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
2385 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
2386 | while (<PBFILE>) {
|
---|
2387 | s/^(..):5:initdefault:$/$1:3:initdefault:/;
|
---|
2388 | print PBOUT $_;
|
---|
2389 | }
|
---|
2390 | close(PBFILE);
|
---|
2391 | close(PBOUT);
|
---|
2392 | rename("$file.new",$file);
|
---|
2393 | chmod 0640,$file;
|
---|
2394 | }
|
---|
2395 |
|
---|
2396 | # pb has to be added to portage group on gentoo
|
---|
2397 |
|
---|
2398 | # We need to have that pb_distro_init function
|
---|
2399 | # Get it from Project-Builder::Distribution
|
---|
2400 | # And we now need the conf file required for this to work created above
|
---|
2401 |
|
---|
2402 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf, $pbupd, $darch) = pb_distro_init();
|
---|
2403 | print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $darch))."\n";
|
---|
2404 |
|
---|
2405 | # Adapt sudoers
|
---|
2406 | # sudo is not default on Solaris and needs to be installed first
|
---|
2407 | # from http://www.sunfreeware.com/programlistsparc10.html#sudo
|
---|
2408 | if ($dtype eq "pkg") {
|
---|
2409 | $file="/usr/local/etc/sudoers";
|
---|
2410 | } else {
|
---|
2411 | $file="/etc/sudoers";
|
---|
2412 | }
|
---|
2413 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
2414 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
2415 | while (<PBFILE>) {
|
---|
2416 | EOF
|
---|
2417 | print SCRIPT << "EOF";
|
---|
2418 | next if (/^$pbac->{$ENV{'PBPROJ'}} /);
|
---|
2419 | EOF
|
---|
2420 | print SCRIPT << 'EOF';
|
---|
2421 | s/Defaults[ \t]+requiretty//;
|
---|
2422 | print PBOUT $_;
|
---|
2423 | }
|
---|
2424 | close(PBFILE);
|
---|
2425 | EOF
|
---|
2426 | print SCRIPT << "EOF";
|
---|
2427 | # Some distro force requiretty at compile time, so disable here
|
---|
2428 | print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} !requiretty\n";
|
---|
2429 | print PBOUT "Defaults:root !requiretty\n";
|
---|
2430 | # This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
|
---|
2431 | print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} env_keep += \\\"http_proxy ftp_proxy\\\"\n";
|
---|
2432 | print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
|
---|
2433 | EOF
|
---|
2434 | print SCRIPT << 'EOF';
|
---|
2435 | close(PBOUT);
|
---|
2436 | rename("$file.new",$file);
|
---|
2437 | chmod 0440,$file;
|
---|
2438 |
|
---|
2439 | EOF
|
---|
2440 |
|
---|
2441 | # We may need a proxy configuration. Get it from the local env
|
---|
2442 |
|
---|
2443 | if (defined $ENV{'http_proxy'}) {
|
---|
2444 | print SCRIPT "\$ENV\{'http_proxy'\}=\"$ENV{'http_proxy'}\";\n";
|
---|
2445 | }
|
---|
2446 |
|
---|
2447 | if (defined $ENV{'ftp_proxy'}) {
|
---|
2448 | print SCRIPT "\$ENV\{'ftp_proxy'\}=\"$ENV{'ftp_proxy'}\";\n";
|
---|
2449 | }
|
---|
2450 |
|
---|
2451 | print SCRIPT << 'EOF';
|
---|
2452 |
|
---|
2453 | my ($ospkgdep,$osperldep,$osperlver) = pb_conf_get_if("ospkgdep","osperldep","osperlver");
|
---|
2454 |
|
---|
2455 | # First install all required packages
|
---|
2456 | pb_system("yum clean all","Cleaning yum env") if (($ddir eq "fedora") || ($ddir eq "asianux") || ($ddir eq "rhel"));
|
---|
2457 | my $pkgdep = pb_distro_get_param($ddir,$dver,$darch,$ospkgdep,$dfam,$dtype);
|
---|
2458 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,join(' ',split(/,/,$pkgdep))));
|
---|
2459 |
|
---|
2460 | # Then install manually the missing perl modules
|
---|
2461 | my $perldep = pb_distro_get_param($ddir,$dver,$darch,$osperldep,$dfam,$dtype);
|
---|
2462 | foreach my $m (split(/,/,$perldep)) {
|
---|
2463 | # Skip empty deps
|
---|
2464 | next if ($m =~ /^\s*$/);
|
---|
2465 | my $dir = $m;
|
---|
2466 | $dir =~ s/-.*//;
|
---|
2467 | pb_system("echo \"rm -rf $m* ; wget http://search.cpan.org/CPAN/modules/by-module/$dir/$m-$osperlver->{$m}.tar.gz ; gzip -cd $m-$osperlver->{$m}.tar.gz | tar xf - ; cd $m* ; if [ -f Build.PL ]; then perl Build.PL; ./Build ; ./Build install ; else perl Makefile.PL; make ; make install ; fi; cd .. ; rm -rf $m*\" | bash" ,"Installing perl module $m-$osperlver->{$m}");
|
---|
2468 | }
|
---|
2469 |
|
---|
2470 | # Suse wants sudoers as 640
|
---|
2471 | if ((($ddir eq "sles") && (($dver =~ /10/) || ($dver =~ /9/))) || (($ddir eq "opensuse") && ($dver =~ /10.[012]/))) {
|
---|
2472 | chmod 0640,$file;
|
---|
2473 | }
|
---|
2474 |
|
---|
2475 | pb_system("rm -rf ProjectBuilder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/ProjectBuilder-latest.tar.gz ; gzip -cd ProjectBuilder-latest.tar.gz | tar xf - ; cd ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf ProjectBuilder-* ; rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; gzip -cd project-builder-latest.tar.gz | tar xf - ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf project-builder-* ;","Building Project-Builder");
|
---|
2476 | pb_system("pb 2>&1 | head -5",undef,"verbose");
|
---|
2477 | EOF
|
---|
2478 | if ($vtype eq "ve") {
|
---|
2479 | print SCRIPT << 'EOF';
|
---|
2480 | # For VE we need to umount some FS at the end
|
---|
2481 |
|
---|
2482 | pb_system("umount /proc");
|
---|
2483 |
|
---|
2484 | # Create a basic network file if not already there
|
---|
2485 |
|
---|
2486 | my $nf="/etc/sysconfig/network";
|
---|
2487 | if ((! -f $nf) && ($dtype eq "rpm")) {
|
---|
2488 | open(NF,"> $nf") || die "Unable to create $nf";
|
---|
2489 | print NF "NETWORKING=yes\n";
|
---|
2490 | print NF "HOSTNAME=localhost\n";
|
---|
2491 | close(NF);
|
---|
2492 | }
|
---|
2493 | chmod 0755,$nf;
|
---|
2494 | EOF
|
---|
2495 | }
|
---|
2496 |
|
---|
2497 | # Adds pb_distro_init and all functions needed from ProjectBuilder::Distribution and Base
|
---|
2498 | foreach my $d (@INC) {
|
---|
2499 | my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm","$d/ProjectBuilder/Conf.pm");
|
---|
2500 | foreach my $f (@f) {
|
---|
2501 | if (-f "$f") {
|
---|
2502 | open(PBD,"$f") || die "Unable to open $f";
|
---|
2503 | while (<PBD>) {
|
---|
2504 | next if (/^package/);
|
---|
2505 | next if (/^use Exporter/);
|
---|
2506 | next if (/^use ProjectBuilder::/);
|
---|
2507 | next if (/^our /);
|
---|
2508 | print SCRIPT $_;
|
---|
2509 | }
|
---|
2510 | close(PBD);
|
---|
2511 | }
|
---|
2512 | }
|
---|
2513 | }
|
---|
2514 | close(SCRIPT);
|
---|
2515 | chmod 0755,"$pbscript";
|
---|
2516 |
|
---|
2517 | # That build script needs to be run as root and force stop of VM at end
|
---|
2518 | $pbaccount = "root";
|
---|
2519 |
|
---|
2520 | # Force shutdown of VM exept if it was already launched
|
---|
2521 | my $pbforce = 0;
|
---|
2522 | if ((! $vmexist) && ($vtype eq "vm")) {
|
---|
2523 | $pbforce = 1;
|
---|
2524 | }
|
---|
2525 |
|
---|
2526 | pb_script2v($pbscript,$vtype,$pbforce,$v);
|
---|
2527 | }
|
---|
2528 | return;
|
---|
2529 | }
|
---|
2530 |
|
---|
2531 | # Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
|
---|
2532 | sub pb_snap2v {
|
---|
2533 |
|
---|
2534 | my $vtype = shift;
|
---|
2535 |
|
---|
2536 | my ($vm,$all) = pb_get2v($vtype);
|
---|
2537 |
|
---|
2538 | # Script generated
|
---|
2539 | my $pbscript = "$ENV{'PBDESTDIR'}/snapv";
|
---|
2540 |
|
---|
2541 | my ($pbac) = pb_conf_get($vtype."login");
|
---|
2542 |
|
---|
2543 | foreach my $v (@$vm) {
|
---|
2544 | # Get distro context
|
---|
2545 | my ($name,$ver,$darch) = split(/-/,$v);
|
---|
2546 | chomp($darch);
|
---|
2547 | my ($ddir, $dver, $dfam, $dtype, $dos, $pbsuf) = pb_distro_init($name,$ver,$darch);
|
---|
2548 | my ($vepath) = pb_conf_get("vepath");
|
---|
2549 |
|
---|
2550 | # Test if an existing snapshot exists and remove it if there is a VE
|
---|
2551 | if ((-f "$vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz") &&
|
---|
2552 | (! -d "$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch")) {
|
---|
2553 | pb_system("sudo rm -f $vepath->{$ENV{'PBPROJ'}}/$ddir-$dver-$darch.tar.gz","Removing previous snapshot $ddir-$dver-$darch.tar.gz");
|
---|
2554 | }
|
---|
2555 |
|
---|
2556 | # Name of the account to deal with for VM/VE
|
---|
2557 | # Do not use the one passed potentially with -a
|
---|
2558 | my ($vmexist,$vmpid);
|
---|
2559 |
|
---|
2560 | # Prepare the script to be executed on the VM/VE
|
---|
2561 | # in $ENV{'PBDESTDIR'}/setupv
|
---|
2562 | open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
|
---|
2563 |
|
---|
2564 | print SCRIPT << 'EOF';
|
---|
2565 | #!/bin/bash
|
---|
2566 | sleep 2
|
---|
2567 | EOF
|
---|
2568 | close(SCRIPT);
|
---|
2569 | chmod 0755,"$pbscript";
|
---|
2570 |
|
---|
2571 | # Force shutdown of VM/VE
|
---|
2572 | # Force snapshot of VM/VE
|
---|
2573 | pb_script2v($pbscript,$vtype,1,$v,1);
|
---|
2574 | }
|
---|
2575 | return;
|
---|
2576 | }
|
---|
2577 |
|
---|
2578 | sub pb_announce {
|
---|
2579 |
|
---|
2580 | # Get all required parameters
|
---|
2581 | my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
|
---|
2582 | my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
|
---|
2583 | my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
|
---|
2584 | my @pkgs = @$pkg;
|
---|
2585 | my %pkgs;
|
---|
2586 | my $first = 0;
|
---|
2587 |
|
---|
2588 | # Command to find packages on repo
|
---|
2589 | my $findstr = "find . ";
|
---|
2590 | # Generated announce files
|
---|
2591 | my @files;
|
---|
2592 |
|
---|
2593 | foreach my $pbpkg (@pkgs) {
|
---|
2594 | if ($first != 0) {
|
---|
2595 | $findstr .= "-o ";
|
---|
2596 | }
|
---|
2597 | $first++;
|
---|
2598 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
2599 | $pbver = $pkgv->{$pbpkg};
|
---|
2600 | } else {
|
---|
2601 | $pbver = $ENV{'PBPROJVER'};
|
---|
2602 | }
|
---|
2603 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
2604 | $pbtag = $pkgt->{$pbpkg};
|
---|
2605 | } else {
|
---|
2606 | $pbtag = $ENV{'PBPROJTAG'};
|
---|
2607 | }
|
---|
2608 |
|
---|
2609 | # TODO: use virtual/real names here now
|
---|
2610 | $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver\.ebuild\' ";
|
---|
2611 |
|
---|
2612 | my $chglog;
|
---|
2613 |
|
---|
2614 | # Get project info on log file and generate tmp files used later on
|
---|
2615 | pb_cms_init($pbinit);
|
---|
2616 | $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
|
---|
2617 | $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
|
---|
2618 | $chglog = undef if (! -f $chglog);
|
---|
2619 |
|
---|
2620 | open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
|
---|
2621 | my %pb;
|
---|
2622 | $pb{'dtype'} = "announce";
|
---|
2623 | $pb{'realpkg'} = $pbpkg;
|
---|
2624 | $pb{'ver'} = $pbver;
|
---|
2625 | $pb{'tag'} = $pbtag;
|
---|
2626 | $pb{'suf'} = "N/A"; # Should not be empty even if unused
|
---|
2627 | $pb{'date'} = $pbdate;
|
---|
2628 | $pb{'chglog'} = $chglog;
|
---|
2629 | $pb{'packager'} = $pbpackager;
|
---|
2630 | $pb{'proj'} = $ENV{'PBPROJ'};
|
---|
2631 | $pb{'repo'} = $pbrepo;
|
---|
2632 | pb_changelog(\%pb,\*OUT,"yes");
|
---|
2633 | close(OUT);
|
---|
2634 | push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
|
---|
2635 | }
|
---|
2636 | $findstr .= " | grep -Ev \'src.rpm\'";
|
---|
2637 |
|
---|
2638 | # Prepare the command to run and execute it
|
---|
2639 | open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
|
---|
2640 | print PBS "$findstr\n";
|
---|
2641 | close(PBS);
|
---|
2642 | chmod 0755,"$ENV{'PBTMP'}/pbscript";
|
---|
2643 | pb_send2target("Announce");
|
---|
2644 |
|
---|
2645 | # Get subject line
|
---|
2646 | my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
|
---|
2647 | pb_log(0,"Please enter the title of your announce\n");
|
---|
2648 | pb_log(0,"(By default: $sl)\n");
|
---|
2649 | my $sl2 = <STDIN>;
|
---|
2650 | $sl = $sl2 if ($sl2 !~ /^$/);
|
---|
2651 |
|
---|
2652 | # Prepare a template of announce
|
---|
2653 | open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
|
---|
2654 | print ANN << "EOF";
|
---|
2655 | $sl</p>
|
---|
2656 |
|
---|
2657 | <p>The project team is happy to announce the availability of a newest version of $ENV{'PBPROJ'} $ENV{'PBPROJVER'}. Enjoy it as usual!</p>
|
---|
2658 | <p>
|
---|
2659 | Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
|
---|
2660 | </p>
|
---|
2661 | <p>
|
---|
2662 | EOF
|
---|
2663 | open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
|
---|
2664 | my $col = 2;
|
---|
2665 | my $i = 1;
|
---|
2666 | print ANN << 'EOF';
|
---|
2667 | <TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
|
---|
2668 | <TR>
|
---|
2669 | EOF
|
---|
2670 | while (<LOG>) {
|
---|
2671 | print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
|
---|
2672 | $i++;
|
---|
2673 | if ($i > $col) {
|
---|
2674 | print ANN "</TR>\n<TR>";
|
---|
2675 | $i = 1;
|
---|
2676 | }
|
---|
2677 | }
|
---|
2678 | close(LOG);
|
---|
2679 | print ANN << "EOF";
|
---|
2680 | </TR>
|
---|
2681 | </TABLE>
|
---|
2682 | </p>
|
---|
2683 |
|
---|
2684 | <p>As usual source packages are also available in the same directory.</p>
|
---|
2685 |
|
---|
2686 | <p>
|
---|
2687 | Changes are :
|
---|
2688 | </p>
|
---|
2689 | <p>
|
---|
2690 | EOF
|
---|
2691 | # Get each package changelog content
|
---|
2692 | foreach my $f (sort(@files)) {
|
---|
2693 | open(IN,"$f") || die "Unable to read $f:$!";
|
---|
2694 | while (<IN>) {
|
---|
2695 | print ANN $_;
|
---|
2696 | }
|
---|
2697 | close(IN);
|
---|
2698 | print ANN "</p><p>\n";
|
---|
2699 | }
|
---|
2700 | print ANN "</p>\n";
|
---|
2701 | close(ANN);
|
---|
2702 |
|
---|
2703 | # Allow for modification
|
---|
2704 | my $editor = "vi";
|
---|
2705 | $editor = $ENV{'EDITOR'} if (defined $ENV{'EDITOR'});
|
---|
2706 | pb_system("$editor $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
|
---|
2707 |
|
---|
2708 | # Store it in DB for external usage (Web pages generation)
|
---|
2709 | my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
|
---|
2710 |
|
---|
2711 | my $precmd = "";
|
---|
2712 | if (! -f $db) {
|
---|
2713 | $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
|
---|
2714 | }
|
---|
2715 |
|
---|
2716 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
2717 | { RaiseError => 1, AutoCommit => 1 })
|
---|
2718 | || die "Unable to connect to $db";
|
---|
2719 |
|
---|
2720 | if ($precmd ne "") {
|
---|
2721 | my $sth = $dbh->prepare(qq{$precmd})
|
---|
2722 | || die "Unable to create table into $db";
|
---|
2723 | $sth->execute();
|
---|
2724 | }
|
---|
2725 |
|
---|
2726 | # To read whole file
|
---|
2727 | local $/;
|
---|
2728 | open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
|
---|
2729 | my $announce = <ANN>;
|
---|
2730 | close(ANN);
|
---|
2731 |
|
---|
2732 | pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
|
---|
2733 | my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
|
---|
2734 | || die "Unable to insert into $db";
|
---|
2735 | $sth->execute($pbdate, $announce);
|
---|
2736 | $sth->finish();
|
---|
2737 | $dbh->disconnect;
|
---|
2738 |
|
---|
2739 | # Then deliver it on the Web
|
---|
2740 | # $TOOLHOME/livwww www
|
---|
2741 |
|
---|
2742 | # Mail it to project's ML
|
---|
2743 | open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
|
---|
2744 | print ML << 'EOF';
|
---|
2745 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
|
---|
2746 |
|
---|
2747 | <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
|
---|
2748 | <head>
|
---|
2749 | </head>
|
---|
2750 | <body>
|
---|
2751 | <p>
|
---|
2752 | EOF
|
---|
2753 | open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
|
---|
2754 | while(<ANN>) {
|
---|
2755 | print ML $_;
|
---|
2756 | }
|
---|
2757 | print ML << 'EOF';
|
---|
2758 | </body>
|
---|
2759 | </html>
|
---|
2760 | EOF
|
---|
2761 | close(ML);
|
---|
2762 |
|
---|
2763 | # To read whole file
|
---|
2764 | local $/;
|
---|
2765 | open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
|
---|
2766 | my $msg = <ANN>;
|
---|
2767 | close(ANN);
|
---|
2768 |
|
---|
2769 | # Preparation of headers
|
---|
2770 |
|
---|
2771 | my %mail = (
|
---|
2772 | To => $pbml->{$ENV{'PBPROJ'}},
|
---|
2773 | From => $pbpackager->{$ENV{'PBPROJ'}},
|
---|
2774 | Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
|
---|
2775 | Body => $msg,
|
---|
2776 | Subject => "[ANNOUNCE] $sl",
|
---|
2777 | );
|
---|
2778 |
|
---|
2779 | # Send mail
|
---|
2780 | sendmail(%mail) or die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
|
---|
2781 | }
|
---|
2782 |
|
---|
2783 | #
|
---|
2784 | # Creates a set of HTML file containing the news for the project
|
---|
2785 | # based on what has been generated by the pb_announce function
|
---|
2786 | #
|
---|
2787 | sub pb_web_news2html {
|
---|
2788 |
|
---|
2789 | my $dest = shift || $ENV{'PBTMP'};
|
---|
2790 |
|
---|
2791 | # Get all required parameters
|
---|
2792 | my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
|
---|
2793 |
|
---|
2794 | # DB of announces for external usage (Web pages generation)
|
---|
2795 | my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
|
---|
2796 |
|
---|
2797 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
2798 | { RaiseError => 1, AutoCommit => 1 })
|
---|
2799 | || die "Unable to connect to $db";
|
---|
2800 | # For date handling
|
---|
2801 | $ENV{LANGUAGE}="C";
|
---|
2802 | my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
|
---|
2803 | my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
|
---|
2804 | pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
|
---|
2805 | my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
|
---|
2806 | my %news;
|
---|
2807 | $news{"cy"} = ""; # current year's news
|
---|
2808 | $news{"ly"} = ""; # last year news
|
---|
2809 | $news{"py"} = ""; # previous years news
|
---|
2810 | $news{"fp"} = ""; # first page news
|
---|
2811 | my $cpt = 4; # how many news for first page
|
---|
2812 | # Extract info from DB
|
---|
2813 | foreach my $row (@$all) {
|
---|
2814 | my ($id, $date, $announce) = @$row;
|
---|
2815 | $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
|
---|
2816 | $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
|
---|
2817 | $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
|
---|
2818 | $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
|
---|
2819 | $cpt--;
|
---|
2820 | }
|
---|
2821 | pb_log(1,"news{fp}: ".$news{"fp"}."\n");
|
---|
2822 | $dbh->disconnect;
|
---|
2823 |
|
---|
2824 | # Generate the HTML content
|
---|
2825 | foreach my $pref (keys %news) {
|
---|
2826 | open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
|
---|
2827 | print NEWS "$news{$pref}";
|
---|
2828 | close(NEWS);
|
---|
2829 | }
|
---|
2830 | }
|
---|
2831 |
|
---|
2832 |
|
---|
2833 | # Return the SSH key file to use
|
---|
2834 | # Potentially create it if needed
|
---|
2835 |
|
---|
2836 | sub pb_ssh_get {
|
---|
2837 |
|
---|
2838 | my $create = shift || 0; # Do not create keys by default
|
---|
2839 |
|
---|
2840 | # Check the SSH environment
|
---|
2841 | my $keyfile = undef;
|
---|
2842 |
|
---|
2843 | # We have specific keys by default
|
---|
2844 | $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
|
---|
2845 | if (!(-e $keyfile) && ($create eq 1)) {
|
---|
2846 | pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
|
---|
2847 | }
|
---|
2848 |
|
---|
2849 | $keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
|
---|
2850 | $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
|
---|
2851 | $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
|
---|
2852 | die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
|
---|
2853 | return($keyfile);
|
---|
2854 | }
|
---|
2855 |
|
---|
2856 |
|
---|
2857 | # Returns the pid of a running VM command using a specific VM file
|
---|
2858 | sub pb_check_ps {
|
---|
2859 | my $vmcmd = shift;
|
---|
2860 | my $vmm = shift;
|
---|
2861 | my $vmexist = 0; # FALSE by default
|
---|
2862 |
|
---|
2863 | open(PS, "ps auxhww|") || die "Unable to call ps";
|
---|
2864 | while (<PS>) {
|
---|
2865 | next if (! /$vmcmd/);
|
---|
2866 | next if (! /$vmm/);
|
---|
2867 | my ($void1, $void2);
|
---|
2868 | ($void1, $vmexist, $void2) = split(/ +/);
|
---|
2869 | last;
|
---|
2870 | }
|
---|
2871 | return($vmexist);
|
---|
2872 | }
|
---|
2873 |
|
---|
2874 |
|
---|
2875 | sub pb_extract_build_files {
|
---|
2876 |
|
---|
2877 | my $src=shift;
|
---|
2878 | my $dir=shift;
|
---|
2879 | my $ddir=shift;
|
---|
2880 | my $mandatory=shift || "spec";
|
---|
2881 | my @files;
|
---|
2882 |
|
---|
2883 | my $flag = "mayfail" if ($mandatory eq "patch");
|
---|
2884 | my $res;
|
---|
2885 |
|
---|
2886 | if ($src =~ /tar\.gz$/) {
|
---|
2887 | $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
|
---|
2888 | } elsif ($src =~ /tar\.bz2$/) {
|
---|
2889 | $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
|
---|
2890 | } else {
|
---|
2891 | die "Unknown compression algorithm for $src";
|
---|
2892 | }
|
---|
2893 | # If not mandatory return now
|
---|
2894 | return() if (($res != 0) and ($mandatory eq "patch"));
|
---|
2895 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
2896 | foreach my $f (readdir(DIR)) {
|
---|
2897 | next if ($f =~ /^\./);
|
---|
2898 | # Skip potential patch dir
|
---|
2899 | next if ($f =~ /^pbpatch/);
|
---|
2900 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
2901 | pb_log(2,"mv $dir/$f $ddir\n");
|
---|
2902 | push @files,"$ddir/$f";
|
---|
2903 | }
|
---|
2904 | closedir(DIR);
|
---|
2905 | # Not enough but still a first cleanup
|
---|
2906 | pb_rm_rf("$dir");
|
---|
2907 | return(@files);
|
---|
2908 | }
|
---|
2909 |
|
---|
2910 | sub pb_list_bfiles {
|
---|
2911 |
|
---|
2912 | my $dir = shift;
|
---|
2913 | my $pbpkg = shift;
|
---|
2914 | my $bfiles = shift;
|
---|
2915 | my $pkgfiles = shift;
|
---|
2916 | my $supfiles = shift;
|
---|
2917 |
|
---|
2918 | opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
|
---|
2919 | foreach my $f (readdir(BDIR)) {
|
---|
2920 | next if ($f =~ /^\./);
|
---|
2921 | $bfiles->{$f} = "$dir/$f";
|
---|
2922 | $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
|
---|
2923 | if (defined $supfiles->{$pbpkg}) {
|
---|
2924 | $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
|
---|
2925 | }
|
---|
2926 | }
|
---|
2927 | closedir(BDIR);
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 |
|
---|
2931 | #
|
---|
2932 | # Return the list of packages we are working on in a non CMS action
|
---|
2933 | #
|
---|
2934 | sub pb_get_pkg {
|
---|
2935 |
|
---|
2936 | my @pkgs = ();
|
---|
2937 |
|
---|
2938 | my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
2939 | @pkgs = keys %$var;
|
---|
2940 |
|
---|
2941 | pb_log(0,"Packages: ".join(',',@pkgs)."\n");
|
---|
2942 | return(\@pkgs);
|
---|
2943 | }
|
---|
2944 |
|
---|
2945 | #
|
---|
2946 | # Return the postinstall line if needed
|
---|
2947 | #
|
---|
2948 |
|
---|
2949 | sub pb_get_postinstall {
|
---|
2950 |
|
---|
2951 | my $ddir = shift;
|
---|
2952 | my $dver = shift;
|
---|
2953 | my $darch = shift;
|
---|
2954 | my $rbspi = shift;
|
---|
2955 | my $vestyle = shift;
|
---|
2956 | my $post = "";
|
---|
2957 |
|
---|
2958 | # Do we have a local post-install script
|
---|
2959 | if ($vestyle eq "rinse") {
|
---|
2960 | $post = "--post-install ";
|
---|
2961 | } elsif ($vestyle eq "rpmbootstrap") {
|
---|
2962 | $post = "-s ";
|
---|
2963 | }
|
---|
2964 |
|
---|
2965 | my $postparam = pb_distro_get_param($ddir,$dver,$darch,$rbspi);
|
---|
2966 | if ($postparam eq "") {
|
---|
2967 | $post = "";
|
---|
2968 | } else {
|
---|
2969 | $post .= $postparam;
|
---|
2970 | }
|
---|
2971 | return($post);
|
---|
2972 | }
|
---|
2973 |
|
---|
2974 | 1;
|
---|