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