[5] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Project Builder main application
|
---|
| 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
[1248] | 7 | # Copyright B. Cornec 2007-2011
|
---|
[5] | 8 | # Provided under the GPL v2
|
---|
| 9 |
|
---|
[22] | 10 | # Syntax: see at end
|
---|
[9] | 11 |
|
---|
[18] | 12 | use strict 'vars';
|
---|
[1107] | 13 |
|
---|
| 14 | # The modules mentioned here are required by pb when used both
|
---|
[1176] | 15 | # locally or inside a VE/VM/RM
|
---|
[1107] | 16 | # Additional required modules only used locally are called with a require
|
---|
| 17 | # in their respective section
|
---|
[331] | 18 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
[9] | 19 | use Data::Dumper;
|
---|
| 20 | use English;
|
---|
[16] | 21 | use File::Basename;
|
---|
[26] | 22 | use File::Copy;
|
---|
[395] | 23 | use File::stat;
|
---|
| 24 | use File::Temp qw(tempdir);
|
---|
[872] | 25 | use File::Find;
|
---|
[547] | 26 | use Time::localtime qw(localtime);
|
---|
[13] | 27 | use POSIX qw(strftime);
|
---|
[17] | 28 | use lib qw (lib);
|
---|
[329] | 29 | use ProjectBuilder::Version;
|
---|
[318] | 30 | use ProjectBuilder::Base;
|
---|
[512] | 31 | use ProjectBuilder::Display;
|
---|
[405] | 32 | use ProjectBuilder::Conf;
|
---|
| 33 | use ProjectBuilder::Distribution;
|
---|
[1469] | 34 | use ProjectBuilder::VCS;
|
---|
[405] | 35 | use ProjectBuilder::CMS;
|
---|
[416] | 36 | use ProjectBuilder::Env;
|
---|
[405] | 37 | use ProjectBuilder::Filter;
|
---|
[473] | 38 | use ProjectBuilder::Changelog;
|
---|
[1348] | 39 | use ProjectBuilder::VE;
|
---|
[473] | 40 |
|
---|
[397] | 41 | # Global variables
|
---|
[5] | 42 | my %opts; # CLI Options
|
---|
[9] | 43 | my $action; # action to realize
|
---|
[320] | 44 | my $test = "FALSE"; # Not used
|
---|
[748] | 45 | my $pbforce = 0; # Force VE/VM rebuild
|
---|
[968] | 46 | my $pbsnap = 0; # Do not use snapshot mode for VM/VE by default
|
---|
[1425] | 47 | my $pbkeep = 0; # keep temporary directory at the end
|
---|
[320] | 48 | my $option = ""; # Not used
|
---|
| 49 | my @pkgs; # list of packages
|
---|
[95] | 50 | my $pbtag; # Global Tag variable
|
---|
| 51 | my $pbver; # Global Version variable
|
---|
[141] | 52 | my $pbscript; # Name of the script
|
---|
[77] | 53 | my %pbver; # per package
|
---|
| 54 | my %pbtag; # per package
|
---|
[53] | 55 | my $pbrev; # Global REVISION variable
|
---|
[1176] | 56 | my $pbaccount; # Login to use to connect to the VM/RM
|
---|
[1401] | 57 | my $pbtarget = undef; # Target os-ver-arch you want to build for
|
---|
[1176] | 58 | my $pbport; # Port to use to connect to the VM/RM
|
---|
[199] | 59 | my $newver; # New version to create
|
---|
[792] | 60 | my $iso = undef; # ISO image for the VM to create
|
---|
[5] | 61 |
|
---|
[320] | 62 | my @date = pb_get_date();
|
---|
| 63 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
[5] | 64 |
|
---|
[331] | 65 | =pod
|
---|
| 66 |
|
---|
| 67 | =head1 NAME
|
---|
| 68 |
|
---|
| 69 | pb, aka project-builder.org - builds packages for your projects
|
---|
| 70 |
|
---|
| 71 | =head1 DESCRIPTION
|
---|
| 72 |
|
---|
| 73 | pb helps you build various packages directly from your project sources.
|
---|
| 74 | Those sources could be handled by a CMS (Configuration Management System)
|
---|
[748] | 75 | such as Subversion, CVS, Git, Mercurial... or being a simple reference to a compressed tar file.
|
---|
[331] | 76 | It's based on a set of configuration files, a set of provided macros to help
|
---|
| 77 | you keeping build files as generic as possible. For example, a single .spec
|
---|
| 78 | file should be required to generate for all rpm based distributions, even
|
---|
| 79 | if you could also have multiple .spec files if required.
|
---|
| 80 |
|
---|
| 81 | =head1 SYNOPSIS
|
---|
| 82 |
|
---|
[1401] | 83 | pb [-vhSq][-r pbroot][-p project][[-s script -a account -P port][-t [os-ver-arch]][-m os-ver-arch[,...]]][-g][-i iso] <action> [<pkg1> ...]
|
---|
[331] | 84 |
|
---|
[1401] | 85 | pb [--verbose][--help][--man][--quiet][--snapshot][--revision pbroot][--project project][[--script script --account account --port port][--target [os-ver-arch]][--machine os-ver-arch[,...]]][--nographic][--iso iso][--rebuild] <action> [<pkg1> ...]
|
---|
[331] | 86 |
|
---|
| 87 | =head1 OPTIONS
|
---|
| 88 |
|
---|
| 89 | =over 4
|
---|
| 90 |
|
---|
| 91 | =item B<-v|--verbose>
|
---|
| 92 |
|
---|
| 93 | Print a brief help message and exits.
|
---|
| 94 |
|
---|
| 95 | =item B<-q|--quiet>
|
---|
| 96 |
|
---|
| 97 | Do not print any output.
|
---|
| 98 |
|
---|
| 99 | =item B<-h|--help>
|
---|
| 100 |
|
---|
| 101 | Print a brief help message and exits.
|
---|
| 102 |
|
---|
[748] | 103 | =item B<-S|--snapshot>
|
---|
| 104 |
|
---|
| 105 | Use the snapshot mode of VMs or VEs
|
---|
| 106 |
|
---|
[331] | 107 | =item B<--man>
|
---|
| 108 |
|
---|
| 109 | Prints the manual page and exits.
|
---|
| 110 |
|
---|
[1120] | 111 | =item B<-t|--target os-ver-arch>
|
---|
[331] | 112 |
|
---|
[1120] | 113 | Name of the target system you want to build for.
|
---|
| 114 | All if none precised.
|
---|
| 115 |
|
---|
| 116 | =item B<-m|--machine os-ver-arch[,os-ver-arch,...]>
|
---|
| 117 |
|
---|
[1176] | 118 | Name of the Virtual Machines (VM), Virtual Environments (VE) or Remote Machines (RM)
|
---|
| 119 | you want to build on (coma separated).
|
---|
[331] | 120 | All if none precised (or use the env variable PBV).
|
---|
| 121 |
|
---|
| 122 | =item B<-s|--script script>
|
---|
| 123 |
|
---|
[1176] | 124 | Name of the script you want to execute on the related VMs/VEs/RMs.
|
---|
[331] | 125 |
|
---|
[1158] | 126 | =item B<-g|--nographic>
|
---|
[1124] | 127 |
|
---|
| 128 | Do not launch VMs in graphical mode.
|
---|
| 129 |
|
---|
[331] | 130 | =item B<-i|--iso iso_image>
|
---|
| 131 |
|
---|
| 132 | Name of the ISO image of the distribution you want to install on the related VMs.
|
---|
| 133 |
|
---|
| 134 | =item B<-a|--account account>
|
---|
| 135 |
|
---|
[1176] | 136 | Name of the account to use to connect on the related VMs/RMs.
|
---|
[331] | 137 |
|
---|
| 138 | =item B<-P|--port port_number>
|
---|
| 139 |
|
---|
[1176] | 140 | Port number to use to connect on the related VMs/RMs.";
|
---|
[331] | 141 |
|
---|
| 142 | =item B<-p|--project project_name>
|
---|
| 143 |
|
---|
| 144 | Name of the project you're working on (or use the env variable PBPROJ)
|
---|
| 145 |
|
---|
| 146 | =item B<-r|--revision revision>
|
---|
| 147 |
|
---|
| 148 | Path Name of the project revision under the CMS (or use the env variable PBROOT)
|
---|
| 149 |
|
---|
| 150 | =item B<-V|--version new_version>
|
---|
| 151 |
|
---|
| 152 | New version of the project to create based on the current one.
|
---|
| 153 |
|
---|
[1425] | 154 | =item B<-k|--keep>
|
---|
| 155 |
|
---|
| 156 | Keep the temporary dir where files have been created in or der to help debug
|
---|
| 157 |
|
---|
[1386] | 158 | =item B<--rebuild>
|
---|
| 159 |
|
---|
| 160 | Only valid with the checkssh action, it alllows to automatically relaunch the build of the failed packages
|
---|
| 161 |
|
---|
[331] | 162 | =back
|
---|
| 163 |
|
---|
| 164 | =head1 ARGUMENTS
|
---|
| 165 |
|
---|
| 166 | <action> can be:
|
---|
| 167 |
|
---|
| 168 | =over 4
|
---|
| 169 |
|
---|
[1097] | 170 | =item B<sbx2build>
|
---|
| 171 |
|
---|
| 172 | Create tar files for the project under your CMS.
|
---|
| 173 | Current state of the exported content is taken.
|
---|
| 174 | CMS supported are SVN, SVK, CVS, Git and Mercurial
|
---|
| 175 | parameters are packages to build
|
---|
| 176 | if not using default list
|
---|
| 177 |
|
---|
[331] | 178 | =item B<cms2build>
|
---|
| 179 |
|
---|
| 180 | Create tar files for the project under your CMS.
|
---|
[1097] | 181 | Current state of the CMS is taken.
|
---|
| 182 | CMS supported are SVN, SVK, CVS, Git and Mercurial
|
---|
[331] | 183 | parameters are packages to build
|
---|
| 184 | if not using default list
|
---|
| 185 |
|
---|
| 186 | =item B<build2pkg>
|
---|
| 187 |
|
---|
| 188 | Create packages for your running distribution
|
---|
| 189 |
|
---|
| 190 | =item B<cms2pkg>
|
---|
| 191 |
|
---|
| 192 | cms2build + build2pkg
|
---|
| 193 |
|
---|
[1097] | 194 | =item B<sbx2pkg>
|
---|
| 195 |
|
---|
| 196 | sbx2build + build2pkg
|
---|
| 197 |
|
---|
[331] | 198 | =item B<build2ssh>
|
---|
| 199 |
|
---|
| 200 | Send the tar files to a SSH host
|
---|
| 201 |
|
---|
[1097] | 202 | =item B<sbx2ssh>
|
---|
| 203 |
|
---|
| 204 | sbx2build + build2ssh
|
---|
| 205 |
|
---|
[331] | 206 | =item B<cms2ssh>
|
---|
| 207 |
|
---|
| 208 | cms2build + build2ssh
|
---|
| 209 |
|
---|
| 210 | =item B<pkg2ssh>
|
---|
| 211 |
|
---|
| 212 | Send the packages built to a SSH host
|
---|
| 213 |
|
---|
| 214 | =item B<build2vm>
|
---|
| 215 |
|
---|
| 216 | Create packages in VMs, launching them if needed
|
---|
| 217 | and send those packages to a SSH host once built
|
---|
[1176] | 218 | VM type supported are QEMU and KVM
|
---|
[331] | 219 |
|
---|
| 220 | =item B<build2ve>
|
---|
| 221 |
|
---|
| 222 | Create packages in VEs, creating it if needed
|
---|
| 223 | and send those packages to a SSH host once built
|
---|
| 224 |
|
---|
[1176] | 225 | =item B<build2rm>
|
---|
| 226 |
|
---|
| 227 | Create packages in RMs, which should pre-exist,
|
---|
| 228 | and send those packages to a SSH host once built
|
---|
| 229 | RM means Remote Machine, and could be a physical or Virtual one.
|
---|
| 230 | This is one buildfarm integration for pb.
|
---|
| 231 |
|
---|
[1097] | 232 | =item B<sbx2vm>
|
---|
| 233 |
|
---|
| 234 | sbx2build + build2vm
|
---|
| 235 |
|
---|
| 236 | =item B<sbx2ve>
|
---|
| 237 |
|
---|
| 238 | sbx2build + build2ve
|
---|
| 239 |
|
---|
[1176] | 240 | =item B<sbx2rm>
|
---|
| 241 |
|
---|
| 242 | sbx2build + build2rm
|
---|
| 243 |
|
---|
[331] | 244 | =item B<cms2vm>
|
---|
| 245 |
|
---|
| 246 | cms2build + build2vm
|
---|
| 247 |
|
---|
| 248 | =item B<cms2ve>
|
---|
| 249 |
|
---|
| 250 | cms2build + build2ve
|
---|
| 251 |
|
---|
[1176] | 252 | =item B<cms2rm>
|
---|
| 253 |
|
---|
| 254 | cms2build + build2rm
|
---|
| 255 |
|
---|
[331] | 256 | =item B<launchvm>
|
---|
| 257 |
|
---|
| 258 | Launch one virtual machine
|
---|
| 259 |
|
---|
| 260 | =item B<launchve>
|
---|
| 261 |
|
---|
| 262 | Launch one virtual environment
|
---|
| 263 |
|
---|
| 264 | =item B<script2vm>
|
---|
| 265 |
|
---|
| 266 | Launch one virtual machine if needed
|
---|
| 267 | and executes a script on it
|
---|
| 268 |
|
---|
| 269 | =item B<script2ve>
|
---|
| 270 |
|
---|
| 271 | Execute a script in a virtual environment
|
---|
| 272 |
|
---|
[1176] | 273 | =item B<script2rm>
|
---|
| 274 |
|
---|
| 275 | Execute a script on a remote machine
|
---|
| 276 |
|
---|
[331] | 277 | =item B<newvm>
|
---|
| 278 |
|
---|
| 279 | Create a new virtual machine
|
---|
| 280 |
|
---|
| 281 | =item B<newve>
|
---|
| 282 |
|
---|
| 283 | Create a new virtual environment
|
---|
| 284 |
|
---|
[346] | 285 | =item B<setupvm>
|
---|
| 286 |
|
---|
| 287 | Setup a virtual machine for pb usage
|
---|
| 288 |
|
---|
| 289 | =item B<setupve>
|
---|
| 290 |
|
---|
| 291 | Setup a virtual environment for pb usage
|
---|
| 292 |
|
---|
[1176] | 293 | =item B<setuprm>
|
---|
| 294 |
|
---|
| 295 | Setup a remote machine for pb usage
|
---|
| 296 |
|
---|
[1140] | 297 | =item B<sbx2setupvm>
|
---|
| 298 |
|
---|
| 299 | Setup a virtual machine for pb usage using the sandbox version of pb instead of the latest stable
|
---|
| 300 | Reserved to dev team.
|
---|
| 301 |
|
---|
| 302 | =item B<sbx2setupve>
|
---|
| 303 |
|
---|
| 304 | Setup a virtual environment for pb usage using the sandbox version of pb instead of the latest stable
|
---|
| 305 | Reserved to dev team.
|
---|
| 306 |
|
---|
[1176] | 307 | =item B<sbx2setuprm>
|
---|
| 308 |
|
---|
| 309 | Setup a remote machine for pb usage using the sandbox version of pb instead of the latest stable
|
---|
| 310 | Reserved to dev team.
|
---|
| 311 |
|
---|
[748] | 312 | =item B<snapvm>
|
---|
| 313 |
|
---|
| 314 | Snapshot a virtual machine for pb usage
|
---|
| 315 |
|
---|
| 316 | =item B<snapve>
|
---|
| 317 |
|
---|
| 318 | Snapshot a virtual environment for pb usage
|
---|
| 319 |
|
---|
[1111] | 320 | =item B<updatevm>
|
---|
| 321 |
|
---|
| 322 | Update the distribution in the virtual machine
|
---|
| 323 |
|
---|
| 324 | =item B<updateve>
|
---|
| 325 |
|
---|
| 326 | Update the distribution in the virtual environment
|
---|
| 327 |
|
---|
[1176] | 328 | =item B<updaterm>
|
---|
| 329 |
|
---|
| 330 | Update the distribution in the remote machine
|
---|
| 331 |
|
---|
[783] | 332 | =item B<test2pkg>
|
---|
| 333 |
|
---|
| 334 | Test a package locally
|
---|
| 335 |
|
---|
[772] | 336 | =item B<test2vm>
|
---|
| 337 |
|
---|
| 338 | Test a package in a virtual machine
|
---|
| 339 |
|
---|
| 340 | =item B<test2ve>
|
---|
| 341 |
|
---|
| 342 | Test a package in a virtual environment
|
---|
| 343 |
|
---|
[1176] | 344 | =item B<test2rm>
|
---|
| 345 |
|
---|
| 346 | Test a package in a remote machine
|
---|
| 347 |
|
---|
[1386] | 348 | =item B<checkssh>
|
---|
| 349 |
|
---|
| 350 | Check the delivery of the packages on the repository
|
---|
| 351 |
|
---|
[331] | 352 | =item B<newver>
|
---|
| 353 |
|
---|
| 354 | Create a new version of the project derived
|
---|
| 355 | from the current one
|
---|
| 356 |
|
---|
| 357 | =item B<newproj>
|
---|
| 358 |
|
---|
| 359 | Create a new project and a template set of
|
---|
| 360 | configuration files under pbconf
|
---|
| 361 |
|
---|
[471] | 362 | =item B<announce>
|
---|
| 363 |
|
---|
| 364 | Announce the availability of the project through various means
|
---|
| 365 |
|
---|
[1117] | 366 | =item B<sbx2webssh>
|
---|
[557] | 367 |
|
---|
[1117] | 368 | Create tar files for the website under your CMS.
|
---|
| 369 | Current state of the exported content is taken.
|
---|
| 370 | Deliver the content to the target server using ssh from the exported dir.
|
---|
[557] | 371 |
|
---|
[1117] | 372 | =item B<cms2webssh>
|
---|
| 373 |
|
---|
| 374 | Create tar files for the website from your CMS.
|
---|
| 375 | Deliver the content to the target server using ssh from the DVCS.
|
---|
| 376 |
|
---|
| 377 | =item B<sbx2webpkg>
|
---|
| 378 |
|
---|
| 379 | Create tar files for the website under your CMS.
|
---|
| 380 | Current state of the exported content is taken.
|
---|
| 381 |
|
---|
| 382 | =item B<cms2webpkg>
|
---|
| 383 |
|
---|
| 384 | Create tar files for the website under your CMS.
|
---|
| 385 |
|
---|
[739] | 386 | =item B<clean>
|
---|
| 387 |
|
---|
| 388 | Purge the build and delivery directories related to the current project
|
---|
| 389 |
|
---|
[1392] | 390 | =item B<cleanssh>
|
---|
| 391 |
|
---|
| 392 | Purge the ssh server of its packages (only for testver and test packages)
|
---|
| 393 |
|
---|
| 394 | =back
|
---|
| 395 |
|
---|
[331] | 396 | <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).
|
---|
| 397 |
|
---|
| 398 | =head1 WEB SITES
|
---|
| 399 |
|
---|
| 400 | 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/>.
|
---|
| 401 |
|
---|
| 402 | =head1 USER MAILING LIST
|
---|
| 403 |
|
---|
| 404 | None exists for the moment.
|
---|
| 405 |
|
---|
| 406 | =head1 CONFIGURATION FILES
|
---|
| 407 |
|
---|
| 408 | Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
|
---|
| 409 |
|
---|
| 410 | Here is an example of such a configuration file:
|
---|
| 411 |
|
---|
| 412 | #
|
---|
| 413 | # Define for each project the URL of its pbconf repository
|
---|
| 414 | # No default option allowed here as they need to be all different
|
---|
| 415 | #
|
---|
| 416 | # URL of the pbconf content
|
---|
| 417 | # This is the format of a classical URL with the extension of additional schema such as
|
---|
| 418 | # svn+ssh, cvs+ssh, ...
|
---|
| 419 | #
|
---|
| 420 | pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
|
---|
| 421 |
|
---|
| 422 | # This is normaly defined in the project's configuration file
|
---|
| 423 | # Url of the project
|
---|
| 424 | #
|
---|
| 425 | pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
|
---|
| 426 |
|
---|
| 427 | # All these URLs needs to be defined here as the are the entry point
|
---|
| 428 | # for how to build packages for the project
|
---|
| 429 | #
|
---|
| 430 | pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
|
---|
| 431 | pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
|
---|
| 432 | pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
|
---|
| 433 | pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
|
---|
| 434 |
|
---|
| 435 | # Under that dir will take place everything related to pb
|
---|
| 436 | # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
|
---|
| 437 | # to your VMs/chroot/...
|
---|
| 438 | # if not defined then /var/cache
|
---|
| 439 | pbdefdir default = $ENV{'HOME'}/project-builder
|
---|
| 440 | pbdefdir pb = $ENV{'HOME'}
|
---|
| 441 | pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
|
---|
| 442 | pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
|
---|
| 443 |
|
---|
| 444 | # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
|
---|
| 445 | # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
|
---|
| 446 | pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
|
---|
| 447 | pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
|
---|
| 448 |
|
---|
| 449 | # pbdir points to the directory where the CMS content of the pburl is checked out
|
---|
| 450 | # If not defined, pbdir is under pbdefdir/pbproj
|
---|
| 451 | # Only defined if we have access to the dev of the project
|
---|
| 452 | pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
|
---|
| 453 | pbdir mondorescue = $ENV{'HOME'}/mondo/svn
|
---|
| 454 |
|
---|
| 455 | # -daemonize doesn't work with qemu 0.8.2
|
---|
| 456 | vmopt default = -m 384
|
---|
| 457 |
|
---|
| 458 | =head1 AUTHORS
|
---|
| 459 |
|
---|
| 460 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 461 |
|
---|
| 462 | =head1 COPYRIGHT
|
---|
| 463 |
|
---|
| 464 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 465 | described in the file C<COPYING> included with the distribution.
|
---|
| 466 |
|
---|
| 467 | =cut
|
---|
| 468 |
|
---|
| 469 | # ---------------------------------------------------------------------------
|
---|
| 470 |
|
---|
[75] | 471 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
[974] | 472 | my $appname = "pb";
|
---|
[331] | 473 |
|
---|
[397] | 474 | # Initialize the syntax string
|
---|
| 475 |
|
---|
[974] | 476 | pb_syntax_init("$appname (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
|
---|
[397] | 477 |
|
---|
[331] | 478 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
| 479 | "man" => \$opts{'man'},
|
---|
| 480 | "verbose|v+" => \$opts{'v'},
|
---|
[748] | 481 | "snapshot|S" => \$opts{'S'},
|
---|
[331] | 482 | "quiet|q" => \$opts{'q'},
|
---|
| 483 | "log-files|l=s" => \$opts{'l'},
|
---|
| 484 | "force|f" => \$opts{'f'},
|
---|
| 485 | "account|a=s" => \$opts{'a'},
|
---|
| 486 | "revision|r=s" => \$opts{'r'},
|
---|
| 487 | "script|s=s" => \$opts{'s'},
|
---|
| 488 | "machines|mock|m=s" => \$opts{'m'},
|
---|
[1401] | 489 | "target|t:s" => \$opts{'t'},
|
---|
[1158] | 490 | "nographic|g" => \$opts{'g'},
|
---|
[331] | 491 | "port|P=i" => \$opts{'P'},
|
---|
| 492 | "project|p=s" => \$opts{'p'},
|
---|
[1386] | 493 | "rebuild" => \$opts{'rebuild'},
|
---|
[331] | 494 | "iso|i=s" => \$opts{'i'},
|
---|
[815] | 495 | "version|V=s" => \$opts{'V'},
|
---|
[1425] | 496 | "keep|k" => \$opts{'k'},
|
---|
[331] | 497 | ) || pb_syntax(-1,0);
|
---|
| 498 |
|
---|
[21] | 499 | if (defined $opts{'h'}) {
|
---|
[331] | 500 | pb_syntax(0,1);
|
---|
[21] | 501 | }
|
---|
[331] | 502 | if (defined $opts{'man'}) {
|
---|
| 503 | pb_syntax(0,2);
|
---|
| 504 | }
|
---|
[21] | 505 | if (defined $opts{'v'}) {
|
---|
[495] | 506 | $pbdebug = $opts{'v'};
|
---|
[21] | 507 | }
|
---|
[320] | 508 | if (defined $opts{'f'}) {
|
---|
[748] | 509 | $pbforce=1;
|
---|
[320] | 510 | }
|
---|
[21] | 511 | if (defined $opts{'q'}) {
|
---|
[495] | 512 | $pbdebug=-1;
|
---|
[21] | 513 | }
|
---|
[748] | 514 | if (defined $opts{'S'}) {
|
---|
| 515 | $pbsnap=1;
|
---|
| 516 | }
|
---|
[1425] | 517 | if (defined $opts{'k'}) {
|
---|
| 518 | $pbkeep=1;
|
---|
| 519 | }
|
---|
[22] | 520 | if (defined $opts{'l'}) {
|
---|
[495] | 521 | open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
| 522 | $pbLOG = \*pbLOG;
|
---|
| 523 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
[22] | 524 | }
|
---|
[495] | 525 | pb_log_init($pbdebug, $pbLOG);
|
---|
| 526 | pb_display_init("text","");
|
---|
[315] | 527 |
|
---|
[67] | 528 | # Handle root of the project if defined
|
---|
| 529 | if (defined $opts{'r'}) {
|
---|
[340] | 530 | $ENV{'PBROOTDIR'} = $opts{'r'};
|
---|
[67] | 531 | }
|
---|
[91] | 532 | # Handle virtual machines if any
|
---|
| 533 | if (defined $opts{'m'}) {
|
---|
[320] | 534 | $ENV{'PBV'} = $opts{'m'};
|
---|
[91] | 535 | }
|
---|
[141] | 536 | if (defined $opts{'s'}) {
|
---|
| 537 | $pbscript = $opts{'s'};
|
---|
| 538 | }
|
---|
[152] | 539 | if (defined $opts{'a'}) {
|
---|
| 540 | $pbaccount = $opts{'a'};
|
---|
[347] | 541 | die "option -a requires a -s script option" if (not defined $pbscript);
|
---|
[152] | 542 | }
|
---|
[162] | 543 | if (defined $opts{'P'}) {
|
---|
| 544 | $pbport = $opts{'P'};
|
---|
| 545 | }
|
---|
[199] | 546 | if (defined $opts{'V'}) {
|
---|
| 547 | $newver = $opts{'V'};
|
---|
| 548 | }
|
---|
[262] | 549 | if (defined $opts{'i'}) {
|
---|
| 550 | $iso = $opts{'i'};
|
---|
| 551 | }
|
---|
[1120] | 552 | if (defined $opts{'t'}) {
|
---|
| 553 | $pbtarget = $opts{'t'};
|
---|
| 554 | }
|
---|
[108] | 555 |
|
---|
| 556 | # Get Action
|
---|
| 557 | $action = shift @ARGV;
|
---|
[331] | 558 | die pb_syntax(-1,1) if (not defined $action);
|
---|
[108] | 559 |
|
---|
[314] | 560 | my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
|
---|
[273] | 561 | my $pbinit = undef;
|
---|
| 562 | $pbinit = 1 if ($action =~ /^newproj$/);
|
---|
[108] | 563 |
|
---|
[59] | 564 | # Handles project name if any
|
---|
[108] | 565 | # And get global params
|
---|
[1425] | 566 | ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir) = pb_env_init($opts{'p'},$pbinit,$action,$pbkeep);
|
---|
[59] | 567 |
|
---|
[982] | 568 | #
|
---|
| 569 | # Check for command requirements
|
---|
| 570 | #
|
---|
[1126] | 571 | my ($req,$opt,$pbpara) = pb_conf_get_if("oscmd","oscmdopt","pbparallel");
|
---|
[1128] | 572 | pb_check_requirements($req,$opt,$appname);
|
---|
[982] | 573 |
|
---|
[1125] | 574 | #
|
---|
| 575 | # Check if we can launch some actions in // with Parallel::ForkManager
|
---|
| 576 | #
|
---|
[1126] | 577 | my $pbparallel = $pbpara->{$appname} if (defined $pbpara);
|
---|
| 578 | if (not defined $pbparallel) {
|
---|
| 579 | eval
|
---|
| 580 | {
|
---|
| 581 | require Sys::CPU;
|
---|
| 582 | Sys::CPU->import();
|
---|
| 583 | };
|
---|
| 584 | if ($@) {
|
---|
| 585 | # Sys::CPU not found, defaulting to 1
|
---|
[1153] | 586 | pb_log(1,"ADVISE: Install Sys::CPU to benefit from automatic parallelism optimization.\nOr use pbparallel in your pb.conf file\nOnly 1 process at a time for the moment\n");
|
---|
[1126] | 587 | $pbparallel = 1;
|
---|
| 588 | } else {
|
---|
| 589 | # Using the number of cores
|
---|
| 590 | $pbparallel = Sys::CPU::cpu_count();
|
---|
[1153] | 591 | pb_log(1,"Using parallel mode with $pbparallel processes\n");
|
---|
[1126] | 592 | }
|
---|
| 593 | }
|
---|
| 594 |
|
---|
[1125] | 595 | eval
|
---|
| 596 | {
|
---|
| 597 | require Parallel::ForkManager;
|
---|
| 598 | Parallel::ForkManager->import();
|
---|
| 599 | };
|
---|
| 600 | # Parallel::ForkManager not found so no // actions
|
---|
| 601 | if ($@) {
|
---|
| 602 | $pbparallel = undef;
|
---|
[1153] | 603 | pb_log(1,"ADVISE: Install Parallel::ForkManager to benefit from automatic parallelism optimization.\nOnly 1 process at a time for the moment\n");
|
---|
[1125] | 604 | }
|
---|
| 605 |
|
---|
[315] | 606 | pb_log(0,"Project: $ENV{'PBPROJ'}\n");
|
---|
| 607 | pb_log(0,"Action: $action\n");
|
---|
[9] | 608 |
|
---|
| 609 | # Act depending on action
|
---|
| 610 | if ($action =~ /^cms2build$/) {
|
---|
[1097] | 611 | pb_cms2build("CMS");
|
---|
| 612 | } elsif ($action =~ /^sbx2build$/) {
|
---|
| 613 | pb_cms2build("SandBox");
|
---|
[77] | 614 | } elsif ($action =~ /^build2pkg$/) {
|
---|
| 615 | pb_build2pkg();
|
---|
| 616 | } elsif ($action =~ /^cms2pkg$/) {
|
---|
[1097] | 617 | pb_cms2build("CMS");
|
---|
[77] | 618 | pb_build2pkg();
|
---|
[1097] | 619 | } elsif ($action =~ /^sbx2pkg$/) {
|
---|
| 620 | pb_cms2build("SandBox");
|
---|
| 621 | pb_build2pkg();
|
---|
[88] | 622 | } elsif ($action =~ /^build2ssh$/) {
|
---|
| 623 | pb_build2ssh();
|
---|
[220] | 624 | } elsif ($action =~ /^cms2ssh$/) {
|
---|
[1097] | 625 | pb_cms2build("CMS");
|
---|
[220] | 626 | pb_build2ssh();
|
---|
[1102] | 627 | } elsif ($action =~ /^sbx2ssh$/) {
|
---|
[1097] | 628 | pb_cms2build("SandBox");
|
---|
| 629 | pb_build2ssh();
|
---|
[88] | 630 | } elsif ($action =~ /^pkg2ssh$/) {
|
---|
| 631 | pb_pkg2ssh();
|
---|
[1176] | 632 | } elsif ($action =~ /^build2rm$/) {
|
---|
| 633 | pb_build2v("rm","build");
|
---|
[320] | 634 | } elsif ($action =~ /^build2ve$/) {
|
---|
[772] | 635 | pb_build2v("ve","build");
|
---|
[91] | 636 | } elsif ($action =~ /^build2vm$/) {
|
---|
[772] | 637 | pb_build2v("vm","build");
|
---|
[1176] | 638 | } elsif ($action =~ /^cms2rm$/) {
|
---|
| 639 | pb_cms2build("CMS");
|
---|
| 640 | pb_build2v("rm","build");
|
---|
[320] | 641 | } elsif ($action =~ /^cms2ve$/) {
|
---|
[1097] | 642 | pb_cms2build("CMS");
|
---|
[772] | 643 | pb_build2v("ve","build");
|
---|
[1176] | 644 | } elsif ($action =~ /^sbx2rm$/) {
|
---|
| 645 | pb_cms2build("SandBox");
|
---|
| 646 | pb_build2v("rm","build");
|
---|
[1097] | 647 | } elsif ($action =~ /^sbx2ve$/) {
|
---|
| 648 | pb_cms2build("SandBox");
|
---|
| 649 | pb_build2v("ve","build");
|
---|
[91] | 650 | } elsif ($action =~ /^cms2vm$/) {
|
---|
[1097] | 651 | pb_cms2build("CMS");
|
---|
[772] | 652 | pb_build2v("vm","build");
|
---|
[1097] | 653 | } elsif ($action =~ /^sbx2vm$/) {
|
---|
| 654 | pb_cms2build("SandBox");
|
---|
| 655 | pb_build2v("vm","build");
|
---|
[141] | 656 | } elsif ($action =~ /^launchvm$/) {
|
---|
[320] | 657 | pb_launchv("vm",$ENV{'PBV'},0);
|
---|
| 658 | } elsif ($action =~ /^launchve$/) {
|
---|
| 659 | pb_launchv("ve",$ENV{'PBV'},0);
|
---|
[142] | 660 | } elsif ($action =~ /^script2vm$/) {
|
---|
[320] | 661 | pb_script2v($pbscript,"vm");
|
---|
| 662 | } elsif ($action =~ /^script2ve$/) {
|
---|
| 663 | pb_script2v($pbscript,"ve");
|
---|
[1176] | 664 | } elsif ($action =~ /^script2rm$/) {
|
---|
| 665 | pb_script2v($pbscript,"rm");
|
---|
[199] | 666 | } elsif ($action =~ /^newver$/) {
|
---|
| 667 | pb_newver();
|
---|
[320] | 668 | } elsif ($action =~ /^newve$/) {
|
---|
| 669 | pb_launchv("ve",$ENV{'PBV'},1);
|
---|
[262] | 670 | } elsif ($action =~ /^newvm$/) {
|
---|
[320] | 671 | pb_launchv("vm",$ENV{'PBV'},1);
|
---|
[909] | 672 | pb_log(0, "Please ensure that sshd is running in your VM by default\n");
|
---|
| 673 | pb_log(0, "and that it allows remote root login (PermitRootLogin yes in /etc/ssh/sshd_config)\n");
|
---|
[1105] | 674 | pb_log(0, "Also ensure that network is up, firewalling correctly configured\n");
|
---|
| 675 | pb_log(0, "and perl, sudo, ntpdate and scp/ssh installed\n");
|
---|
[1072] | 676 | pb_log(0, "You should then be able to login with ssh -p VMPORT root\@localhost (if VM started with pb)\n");
|
---|
[1176] | 677 | } elsif ($action =~ /^setuprm$/) {
|
---|
| 678 | pb_setup2v("rm");
|
---|
[346] | 679 | } elsif ($action =~ /^setupve$/) {
|
---|
[772] | 680 | pb_setup2v("ve");
|
---|
[346] | 681 | } elsif ($action =~ /^setupvm$/) {
|
---|
[772] | 682 | pb_setup2v("vm");
|
---|
[1176] | 683 | } elsif ($action =~ /^sbx2setuprm$/) {
|
---|
| 684 | die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
|
---|
| 685 | pb_cms2build("SandBox");
|
---|
| 686 | pb_setup2v("rm","SandBox");
|
---|
[1140] | 687 | } elsif ($action =~ /^sbx2setupve$/) {
|
---|
| 688 | die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
|
---|
| 689 | pb_cms2build("SandBox");
|
---|
| 690 | pb_setup2v("ve","SandBox");
|
---|
| 691 | } elsif ($action =~ /^sbx2setupvm$/) {
|
---|
| 692 | die "This feature is limited to the pb project" if ($ENV{'PBPROJ'} ne $appname);
|
---|
| 693 | pb_cms2build("SandBox");
|
---|
| 694 | pb_setup2v("vm","SandBox");
|
---|
[1176] | 695 | } elsif ($action =~ /^updaterm$/) {
|
---|
| 696 | pb_update2v("rm");
|
---|
[1111] | 697 | } elsif ($action =~ /^updateve$/) {
|
---|
| 698 | pb_update2v("ve");
|
---|
| 699 | } elsif ($action =~ /^updatevm$/) {
|
---|
| 700 | pb_update2v("vm");
|
---|
[748] | 701 | } elsif ($action =~ /^snapve$/) {
|
---|
[772] | 702 | pb_snap2v("ve");
|
---|
[748] | 703 | } elsif ($action =~ /^snapvm$/) {
|
---|
[772] | 704 | pb_snap2v("vm");
|
---|
[783] | 705 | } elsif ($action =~ /^test2pkg$/) {
|
---|
| 706 | pb_test2pkg();
|
---|
[1176] | 707 | } elsif ($action =~ /^test2rm$/) {
|
---|
| 708 | pb_build2v("rm","test");
|
---|
[772] | 709 | } elsif ($action =~ /^test2ve$/) {
|
---|
| 710 | pb_build2v("ve","test");
|
---|
| 711 | } elsif ($action =~ /^test2vm$/) {
|
---|
| 712 | pb_build2v("vm","test");
|
---|
[273] | 713 | } elsif ($action =~ /^newproj$/) {
|
---|
| 714 | # Nothing to do - already done in pb_env_init
|
---|
[106] | 715 | } elsif ($action =~ /^clean$/) {
|
---|
[739] | 716 | pb_clean();
|
---|
[471] | 717 | } elsif ($action =~ /^announce$/) {
|
---|
[498] | 718 | # For announce only. Require avoids the systematic load of these modules
|
---|
| 719 | require DBI;
|
---|
[557] | 720 | require DBD::SQLite;
|
---|
[498] | 721 |
|
---|
[1386] | 722 | pb_announce("Announce");
|
---|
[1392] | 723 | } elsif ($action =~ /^cleanssh$/) {
|
---|
| 724 | pb_announce("Clean");
|
---|
[1386] | 725 | } elsif ($action =~ /^checkssh$/) {
|
---|
| 726 | pb_announce("Check");
|
---|
[1117] | 727 | } elsif ($action =~ /^sbx2webpkg$/) {
|
---|
[547] | 728 | require DBI;
|
---|
[557] | 729 | require DBD::SQLite;
|
---|
[547] | 730 |
|
---|
[1117] | 731 | pb_cms2build("SandBox","Web");
|
---|
| 732 | } elsif ($action =~ /^sbx2webssh$/) {
|
---|
| 733 | require DBI;
|
---|
| 734 | require DBD::SQLite;
|
---|
| 735 |
|
---|
| 736 | pb_cms2build("SandBox","Web");
|
---|
[556] | 737 | pb_send2target("Web");
|
---|
[1117] | 738 | } elsif ($action =~ /^cms2webpkg$/) {
|
---|
| 739 | require DBI;
|
---|
| 740 | require DBD::SQLite;
|
---|
| 741 |
|
---|
| 742 | pb_cms2build("CMS","Web");
|
---|
| 743 | } elsif ($action =~ /^cms2webssh$/) {
|
---|
| 744 | require DBI;
|
---|
| 745 | require DBD::SQLite;
|
---|
| 746 |
|
---|
| 747 | pb_cms2build("CMS","Web");
|
---|
| 748 | pb_send2target("Web");
|
---|
[77] | 749 | } else {
|
---|
[315] | 750 | pb_log(0,"\'$action\' is not available\n");
|
---|
[331] | 751 | pb_syntax(-2,1);
|
---|
[77] | 752 | }
|
---|
| 753 |
|
---|
| 754 | sub pb_cms2build {
|
---|
| 755 |
|
---|
[556] | 756 | my $param = shift || undef;
|
---|
[1117] | 757 | my $web = shift || undef;
|
---|
[556] | 758 |
|
---|
| 759 | my $pkg;
|
---|
| 760 | my @pkgs;
|
---|
[557] | 761 | my $webdir;
|
---|
[556] | 762 |
|
---|
[557] | 763 | my %pkgs;
|
---|
[1186] | 764 | my $pb; # Structure to store conf info
|
---|
[557] | 765 |
|
---|
[1117] | 766 | die "pb_cms2build requires a parameter: SandBox or CMS" if (not defined $param);
|
---|
[1097] | 767 |
|
---|
[556] | 768 | # If Website, then pkg is only the website
|
---|
[1117] | 769 | if (defined $web) {
|
---|
[557] | 770 | ($webdir) = pb_conf_get("webdir");
|
---|
| 771 | pb_log(2,"webdir: ".Dumper($webdir)."\n");
|
---|
| 772 | $pkgs[0] = $webdir->{$ENV{'PBPROJ'}};
|
---|
[556] | 773 | $extpkgdir = $webdir;
|
---|
[557] | 774 | pb_log(0,"Package: $pkgs[0]\n");
|
---|
[556] | 775 | } else {
|
---|
| 776 | $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
|
---|
| 777 | @pkgs = @$pkg;
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[1097] | 780 | my ($scheme, $uri) = pb_cms_init($pbinit,$param);
|
---|
[331] | 781 |
|
---|
[898] | 782 | # We need 2 lines here
|
---|
| 783 | my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
|
---|
[174] | 784 |
|
---|
[429] | 785 | # declare packager and repo for filtering
|
---|
| 786 | my ($tmp1, $tmp2) = pb_conf_get("pbpackager","pbrepo");
|
---|
| 787 | $ENV{'PBPACKAGER'} = $tmp1->{$ENV{'PBPROJ'}};
|
---|
| 788 | $ENV{'PBREPO'} = $tmp2->{$ENV{'PBPROJ'}};
|
---|
[1203] | 789 | my ($delivery) = pb_conf_get_if("delivery");
|
---|
| 790 | $delivery->{$ENV{'PBPROJ'}} = "" if (not defined $delivery->{$ENV{'PBPROJ'}});
|
---|
[174] | 791 |
|
---|
[1432] | 792 | # If we deal with a test dir, we want to keep the date in tar file and dir name
|
---|
| 793 | my $pbextdir = "";
|
---|
| 794 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
| 795 | $pbextdir = strftime("%Y%m%d%H%M%S", @date);
|
---|
| 796 | }
|
---|
| 797 |
|
---|
[27] | 798 | foreach my $pbpkg (@pkgs) {
|
---|
[115] | 799 | $ENV{'PBPKG'} = $pbpkg;
|
---|
[728] | 800 |
|
---|
[98] | 801 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
| 802 | $pbver = $pkgv->{$pbpkg};
|
---|
[9] | 803 | } else {
|
---|
[353] | 804 | $pbver = $ENV{'PBPROJVER'};
|
---|
[9] | 805 | }
|
---|
[1432] | 806 | # If it's a test version, then tag == 0
|
---|
[897] | 807 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
[1432] | 808 | $pbtag = "0";
|
---|
[728] | 809 | $ENV{'PBPROJTAG'} = $pbtag;
|
---|
| 810 | } elsif ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
[98] | 811 | $pbtag = $pkgt->{$pbpkg};
|
---|
[9] | 812 | } else {
|
---|
[353] | 813 | $pbtag = $ENV{'PBPROJTAG'};
|
---|
[9] | 814 | }
|
---|
[95] | 815 |
|
---|
[16] | 816 | $pbrev = $ENV{'PBREVISION'};
|
---|
[319] | 817 | pb_log(0,"\n");
|
---|
| 818 | pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
|
---|
[9] | 819 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
[539] | 820 |
|
---|
[1432] | 821 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir";
|
---|
[1173] | 822 | # Create the structure if needed
|
---|
| 823 | pb_mkdir_p($dest);
|
---|
[16] | 824 | # Clean up dest if necessary. The export will recreate it
|
---|
[74] | 825 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 826 |
|
---|
| 827 | # Export CMS tree for the concerned package to dest
|
---|
| 828 | # And generate some additional files
|
---|
| 829 | $OUTPUT_AUTOFLUSH=1;
|
---|
[29] | 830 |
|
---|
[9] | 831 | # computes in which dir we have to work
|
---|
[113] | 832 | my $dir = $defpkgdir->{$pbpkg};
|
---|
| 833 | $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
|
---|
[1117] | 834 | $dir = $webdir->{$ENV{'PBPROJ'}} if (defined $web);
|
---|
| 835 | die "Variable \$dir not defined. Please report to dev team with log of a verbose run and this info ".Dumper($webdir) if (not defined $dir);
|
---|
[1260] | 836 | pb_log(2,"def:".Dumper($defpkgdir)."ext: ".Dumper($extpkgdir)."dir: $dir\n");
|
---|
[9] | 837 |
|
---|
[537] | 838 | # Exporting content from CMS
|
---|
[1097] | 839 | my $sourcedir = undef;
|
---|
| 840 | my $sourceuri = $uri;
|
---|
| 841 | if ($param eq "SandBox") {
|
---|
| 842 | # Point to the local instance
|
---|
| 843 | $sourcedir = "$ENV{'PBDIR'}/$dir";
|
---|
| 844 | } else {
|
---|
| 845 | # Get it from a subdir of the URI with same version as localy but different root
|
---|
[1174] | 846 | # Only if using a real CMS
|
---|
| 847 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
| 848 | if (($scheme !~ /^file/) && ($scheme !~ /^(ht|f)tp/)) {
|
---|
| 849 | $sourceuri = "$ENV{'PBDIR'}/$dir";
|
---|
[1260] | 850 | $sourceuri =~ s|^$ENV{'PBPROJDIR'}/|$uri/|;
|
---|
[1174] | 851 | }
|
---|
[1097] | 852 | }
|
---|
[1469] | 853 | my $preserve = pb_vcs_export($sourceuri,$sourcedir,$dest);
|
---|
[315] | 854 |
|
---|
[435] | 855 | # Generated fake content for test versions to speed up stuff
|
---|
| 856 | my $chglog;
|
---|
[285] | 857 |
|
---|
[448] | 858 | # Get project info on authors and log file
|
---|
[1185] | 859 | # TODO: Make it CMS aware
|
---|
[448] | 860 | $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
|
---|
| 861 | $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
|
---|
| 862 | $chglog = undef if (! -f $chglog);
|
---|
[285] | 863 |
|
---|
[1185] | 864 | # TODO: Make it CMS aware
|
---|
[448] | 865 | my $authors = "$ENV{'PBROOTDIR'}/$pbpkg/pbauthors";
|
---|
| 866 | $authors = "$ENV{'PBROOTDIR'}/pbauthors" if (! -f $authors);
|
---|
| 867 | $authors = "/dev/null" if (! -f $authors);
|
---|
[435] | 868 |
|
---|
[448] | 869 | # Extract cms log history and store it
|
---|
| 870 | if ((defined $chglog) && (! -f "$dest/NEWS")) {
|
---|
| 871 | pb_log(2,"Generating NEWS file from $chglog\n");
|
---|
| 872 | copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
|
---|
[285] | 873 | }
|
---|
[448] | 874 | pb_cms_log($scheme,"$ENV{'PBDIR'}/$dir",$dest,$chglog,$authors,$testver);
|
---|
[29] | 875 |
|
---|
[21] | 876 | my %build;
|
---|
[865] | 877 | # We want to at least build for the underlying distro
|
---|
[1120] | 878 | # except if a target was given, in which case we only build for it
|
---|
[1401] | 879 | # if -t was passed without target then build for the native distro.
|
---|
[1177] | 880 | my $pbos = pb_distro_get_context($pbtarget);
|
---|
[1282] | 881 | my $tmpl = pb_get_distros($pbos,$pbtarget);
|
---|
[1120] | 882 |
|
---|
[1186] | 883 | # Setup $pb structure to allow filtering later on, on files using that structure
|
---|
| 884 | $pb->{'tag'} = $pbtag;
|
---|
| 885 | $pb->{'rev'} = $pbrev;
|
---|
| 886 | $pb->{'ver'} = $pbver;
|
---|
| 887 | $pb->{'pkg'} = $pbpkg;
|
---|
[1192] | 888 | $pb->{'suf'} = $pbos->{'suffix'};
|
---|
[1186] | 889 | $pb->{'realpkg'} = $pbpkg;
|
---|
| 890 | $pb->{'date'} = $pbdate;
|
---|
| 891 | $pb->{'defpkgdir'} = $defpkgdir;
|
---|
| 892 | $pb->{'extpkgdir'} = $extpkgdir;
|
---|
| 893 | $pb->{'chglog'} = $chglog;
|
---|
[1432] | 894 | $pb->{'extdir'} = $pbextdir;
|
---|
[1186] | 895 | $pb->{'packager'} = $ENV{'PBPACKAGER'};
|
---|
| 896 | $pb->{'proj'} = $ENV{'PBPROJ'};
|
---|
[1200] | 897 | $pb->{'repo'} = "$ENV{'PBREPO'}/$delivery->{$ENV{'PBPROJ'}}";
|
---|
[1186] | 898 | $pb->{'patches'} = ();
|
---|
| 899 | $pb->{'sources'} = ();
|
---|
[556] | 900 |
|
---|
[1185] | 901 | my $tmpd = "$ENV{'PBTMP'}/cms.$$";
|
---|
| 902 | pb_mkdir_p($tmpd) if (defined $pbparallel);
|
---|
| 903 |
|
---|
| 904 | # Get only all.pbf filter at this stage for pbinit
|
---|
| 905 | my $ptr = pb_get_filters($pbpkg);
|
---|
| 906 |
|
---|
[556] | 907 | # Do not do that for website
|
---|
[1117] | 908 | if (not defined $web) {
|
---|
[665] | 909 | my %virt;
|
---|
[1176] | 910 | # De-duplicate similar VM/VE/RM
|
---|
[556] | 911 | foreach my $d (split(/,/,$tmpl)) {
|
---|
[766] | 912 | # skip ill-formatted vms (name-ver-arch)
|
---|
| 913 | next if ($d !~ /-/);
|
---|
[665] | 914 | $virt{$d} = $d;
|
---|
| 915 | }
|
---|
| 916 |
|
---|
[1125] | 917 | # Try to use // processing here
|
---|
[1350] | 918 | my $pm = new Parallel::ForkManager($pbparallel) if (defined $pbparallel);
|
---|
[1125] | 919 |
|
---|
[1189] | 920 | pb_log(0,"Preparing delivery ...\n");
|
---|
[1177] | 921 | foreach my $v (keys %virt) {
|
---|
[1125] | 922 | $pm->start and next if (defined $pbparallel);
|
---|
[1177] | 923 |
|
---|
| 924 | # Distro context
|
---|
| 925 | my $pbos = pb_distro_get_context($v);
|
---|
[1207] | 926 |
|
---|
[1186] | 927 | $pb->{'pbos'} = $pbos;
|
---|
[1189] | 928 | $pb->{'suf'} = $pbos->{'suffix'};
|
---|
[1186] | 929 | pb_log(3,"DEBUG: pb: ".Dumper($pb)."\n");
|
---|
[1185] | 930 |
|
---|
| 931 | # Get all filters to apply
|
---|
[1192] | 932 | $ptr = pb_get_filters($pbpkg,$pbos);
|
---|
[1185] | 933 |
|
---|
[556] | 934 | pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
|
---|
| 935 |
|
---|
| 936 | # We need to compute the real name of the package
|
---|
[1177] | 937 | my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pbos->{'type'});
|
---|
[1186] | 938 | $pb->{'realpkg'} = $pbrealpkg;
|
---|
[1177] | 939 | pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $pbos->{'name'}-$pbos->{'version'}\n") if ($pbrealpkg ne $pbpkg);
|
---|
[556] | 940 |
|
---|
| 941 | # Filter build files from the less precise up to the most with overloading
|
---|
| 942 | # Filter all files found, keeping the name, and generating in dest
|
---|
| 943 |
|
---|
| 944 | # Find all build files first relatively to PBROOTDIR
|
---|
| 945 | # Find also all specific files referenced in the .pb conf file
|
---|
| 946 | my %bfiles = ();
|
---|
| 947 | my %pkgfiles = ();
|
---|
[1185] | 948 | # Used in Filter.pm by pb_filter_file
|
---|
| 949 |
|
---|
[1363] | 950 | $build{$v} = "no";
|
---|
[1185] | 951 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'os'}") {
|
---|
| 952 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'os'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[1363] | 953 | $build{$v} = "yes";
|
---|
| 954 | }
|
---|
| 955 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'type'}") {
|
---|
[1177] | 956 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'type'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[1363] | 957 | $build{$v} = "yes";
|
---|
| 958 | }
|
---|
| 959 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'family'}") {
|
---|
[1177] | 960 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'family'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[1363] | 961 | $build{$v} = "yes";
|
---|
| 962 | }
|
---|
| 963 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}") {
|
---|
[1177] | 964 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[1363] | 965 | $build{$v} = "yes";
|
---|
| 966 | }
|
---|
| 967 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}") {
|
---|
[1177] | 968 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[1363] | 969 | $build{$v} = "yes";
|
---|
| 970 | }
|
---|
| 971 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") {
|
---|
[1177] | 972 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[1363] | 973 | $build{$v} = "yes";
|
---|
[500] | 974 | }
|
---|
[1186] | 975 | pb_log(2,"DEBUG($v) bfiles: ".Dumper(\%bfiles)."\n");
|
---|
[556] | 976 |
|
---|
[1185] | 977 | if ($build{$v} ne "no") {
|
---|
| 978 | # Apply now all the filters on all the files concerned
|
---|
| 979 | # destination dir depends on the type of file
|
---|
[556] | 980 | # For patch support
|
---|
[1185] | 981 | # TODO: Make it CMS aware
|
---|
[1186] | 982 | $pb->{'patches'} = pb_list_sfiles("$ENV{'PBROOTDIR'}/$pbpkg/pbpatch", $pb->{'patches'}, $pbos, "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch");
|
---|
| 983 | pb_log(2,"DEBUG($v) patches: ".Dumper($pb->{'patches'})."\n");
|
---|
[1185] | 984 | # TODO: Make it CMS aware
|
---|
[1186] | 985 | $pb->{'sources'} = pb_list_sfiles("$ENV{'PBROOTDIR'}/$pbpkg/pbsrc", $pb->{'sources'}, $pbos, "$ENV{'PBROOTDIR'}/$pbpkg/pbextsrc");
|
---|
| 986 | pb_log(2,"DEBUG($v) sources: ".Dumper($pb->{'sources'})."\n");
|
---|
[1185] | 987 |
|
---|
[1186] | 988 | if (defined $pb->{'patches'}->{$v}) {
|
---|
[1185] | 989 | # Filter potential patches (local + remote)
|
---|
| 990 | pb_mkdir_p("$dest/pbconf/$v/pbpatch");
|
---|
[1367] | 991 | # If Debian based distribution, then prepare what will be done at build time
|
---|
| 992 | my ($patchcmd,$patchopt);
|
---|
| 993 | if ($pbos->{'type'} eq "deb") {
|
---|
| 994 | ($patchcmd,$patchopt) = pb_distro_get_param($pbos,pb_conf_get_if("ospatchcmd","ospatchopt"));
|
---|
| 995 | open(SCRIPT,"> $dest/pbconf/$v/pbpatch/pbapplypatch") || die "Unable to create $dest/pbconf/$v/pbpatch/pbapplypatch";
|
---|
| 996 | print SCRIPT "#!/bin/bash\n";
|
---|
| 997 | print SCRIPT "set -x\n" if ($pbdebug gt 1);
|
---|
| 998 | }
|
---|
[1186] | 999 | foreach my $pf (split(/,/,$pb->{'patches'}->{$v})) {
|
---|
[1185] | 1000 | my $pp = basename($pf);
|
---|
[1469] | 1001 | pb_vcs_export($pf,undef,"$dest/pbconf/$v/pbpatch");
|
---|
[1186] | 1002 | pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",$pb);
|
---|
[1185] | 1003 | pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
|
---|
[1367] | 1004 | if ($pbos->{'type'} eq "deb") {
|
---|
| 1005 | # If Debian based distribution, then prepare what will be done at build time
|
---|
| 1006 | # by applying the patches that will be available under the debian/patches dir
|
---|
| 1007 | print SCRIPT "$patchcmd $patchopt \< debian/patches/$pp\n";
|
---|
| 1008 | }
|
---|
[1185] | 1009 | }
|
---|
[1367] | 1010 | if ($pbos->{'type'} eq "deb") {
|
---|
| 1011 | close(SCRIPT);
|
---|
| 1012 | chmod 0755,"$dest/pbconf/$v/pbpatch/pbapplypatch";
|
---|
| 1013 | }
|
---|
| 1014 | #pb_system("cat $dest/pbconf/$v/pbpatch/pbapplypatch","APPLY","verbose");
|
---|
[1185] | 1015 | }
|
---|
[1186] | 1016 | if (defined $pb->{'sources'}->{$v}) {
|
---|
[1185] | 1017 | pb_mkdir_p("$dest/pbconf/$v/pbsrc");
|
---|
[1186] | 1018 | foreach my $pf (split(/,/,$pb->{'sources'}->{$v})) {
|
---|
[1185] | 1019 | my $pp = basename($pf);
|
---|
[1469] | 1020 | pb_vcs_export($pf,undef,"$dest/pbconf/$v/pbsrc");
|
---|
[1186] | 1021 | pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbsrc/$pp",$pb);
|
---|
[1185] | 1022 | }
|
---|
| 1023 | }
|
---|
[1186] | 1024 | # Filter build files at the end, as they depend on patches and sources
|
---|
[1363] | 1025 | foreach my $f (keys %bfiles) {
|
---|
| 1026 | pb_filter_file("$ENV{'PBROOTDIR'}/$bfiles{$f}",$ptr,"$dest/pbconf/$v/$f",$pb);
|
---|
[1186] | 1027 | }
|
---|
[1363] | 1028 | foreach my $f (keys %pkgfiles) {
|
---|
| 1029 | pb_filter_file("$ENV{'PBROOTDIR'}/$pkgfiles{$f}",$ptr,"$dest/pbconf/$v/$f",$pb);
|
---|
| 1030 | }
|
---|
[556] | 1031 | }
|
---|
[1130] | 1032 |
|
---|
[1185] | 1033 | if (defined $pbparallel) {
|
---|
| 1034 | # Communicate results back to parent
|
---|
| 1035 | my $str = "";
|
---|
| 1036 | $str .= "build $v = $build{$v}\n" if (defined $build{$v});
|
---|
[1186] | 1037 | $str .= "patches $v = $pb->{'patches'}->{$v}\n" if (defined $pb->{'patches'}->{$v});
|
---|
| 1038 | $str .= "sources $v = $pb->{'sources'}->{$v}\n" if (defined $pb->{'sources'}->{$v});
|
---|
[1185] | 1039 | pb_set_content("$tmpd/$$","$str");
|
---|
| 1040 | $pm->finish;
|
---|
| 1041 | }
|
---|
[15] | 1042 | }
|
---|
[1185] | 1043 | # In the parent, we need to get the result from the children
|
---|
[1125] | 1044 | $pm->wait_all_children if (defined $pbparallel);
|
---|
[1185] | 1045 | my $made = "";
|
---|
| 1046 | my %h = ();
|
---|
| 1047 | my %tmp;
|
---|
[1186] | 1048 | my %tmp2;
|
---|
[1185] | 1049 | my $pt;
|
---|
| 1050 | my $k;
|
---|
| 1051 |
|
---|
| 1052 | foreach $k (<$tmpd/*>) {
|
---|
| 1053 | $made .= pb_get_content($k);
|
---|
[556] | 1054 | }
|
---|
[1185] | 1055 | pb_rm_rf($tmpd);
|
---|
| 1056 | pb_log(3,"MADE:\n$made");
|
---|
[500] | 1057 |
|
---|
[1185] | 1058 | # Rebuild local hashes
|
---|
| 1059 | foreach $k (split(/\n/,$made)) {
|
---|
| 1060 | if ($k =~ /^\s*([A-z0-9-_]+)\s+([[A-z0-9-_.]+)\s*=\s*(.+)$/) {
|
---|
| 1061 | $h{$1}->{$2}=$3;
|
---|
| 1062 | }
|
---|
| 1063 | }
|
---|
[1186] | 1064 | pb_log(2,"HASH: ".Dumper(%h));
|
---|
[236] | 1065 |
|
---|
[1185] | 1066 | # Patches
|
---|
| 1067 | pb_log(0,"Delivered and compressed patches ");
|
---|
| 1068 | $pt = $h{'patches'};
|
---|
[1186] | 1069 | foreach $k (keys %$pt) {
|
---|
| 1070 | foreach my $v1 (split(/,/,$pt->{$k})) {
|
---|
| 1071 | $tmp{$v1} = "";
|
---|
| 1072 | }
|
---|
[1185] | 1073 | }
|
---|
[1186] | 1074 | if (keys %tmp) {
|
---|
| 1075 | foreach $k (keys %tmp) {
|
---|
| 1076 | pb_log(0,"$k ");
|
---|
| 1077 | }
|
---|
| 1078 | } else {
|
---|
| 1079 | pb_log(0,"N/A");
|
---|
[1185] | 1080 | }
|
---|
| 1081 | pb_log(0,"\n");
|
---|
[236] | 1082 |
|
---|
[1185] | 1083 | # Sources
|
---|
| 1084 | pb_log(0,"Delivered additional sources ");
|
---|
| 1085 | $pt = $h{'sources'};
|
---|
[1186] | 1086 | foreach $k (keys %$pt) {
|
---|
| 1087 | foreach my $v1 (split(/,/,$pt->{$k})) {
|
---|
| 1088 | $tmp2{$v1} = "";
|
---|
| 1089 | }
|
---|
[236] | 1090 | }
|
---|
[1186] | 1091 | if (keys %tmp2) {
|
---|
| 1092 | foreach $k (keys %tmp2) {
|
---|
| 1093 | pb_log(0,"$k ");
|
---|
| 1094 | }
|
---|
| 1095 | } else {
|
---|
| 1096 | pb_log(0,"N/A");
|
---|
[1185] | 1097 | }
|
---|
| 1098 | pb_log(0,"\n");
|
---|
[236] | 1099 |
|
---|
[1185] | 1100 | # Build files
|
---|
| 1101 | my @found;
|
---|
| 1102 | my @notfound;
|
---|
| 1103 | $pt = $h{'build'};
|
---|
| 1104 | foreach my $b (keys %$pt) {
|
---|
| 1105 | push @found,$b if ($pt->{$b} =~ /yes/);
|
---|
| 1106 | push @notfound,$b if ($pt->{$b} =~ /no/);
|
---|
| 1107 | }
|
---|
| 1108 | pb_log(0,"Build files have been generated for ... ".join(',',sort(@found))."\n") if (@found);
|
---|
| 1109 | pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
|
---|
| 1110 |
|
---|
[556] | 1111 | } else {
|
---|
| 1112 | # Instead call News generation
|
---|
| 1113 | pb_web_news2html($dest);
|
---|
[559] | 1114 | # And create an empty pbconf
|
---|
| 1115 | pb_mkdir_p("$dest/pbconf");
|
---|
[560] | 1116 | # And prepare the pbscript to execute remotely
|
---|
[1138] | 1117 | open(SCRIPT,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
|
---|
[560] | 1118 | print SCRIPT "#!/bin/bash\n";
|
---|
| 1119 | print SCRIPT "#set -x\n";
|
---|
| 1120 | print SCRIPT "echo ... Extracting Website content\n";
|
---|
[1461] | 1121 | print SCRIPT "find . -type f | grep -Ev '^./$pbpkg-$pbver$pbextdir.tar.gz|^./pbscript' | xargs rm -f non-existent\n";
|
---|
[560] | 1122 | print SCRIPT "find * -type d -depth | xargs rmdir 2> /dev/null \n";
|
---|
[1461] | 1123 | print SCRIPT "tar xfz $pbpkg-$pbver$pbextdir.tar.gz\n";
|
---|
| 1124 | print SCRIPT "mv $pbpkg-$pbver$pbextdir/* .\n";
|
---|
| 1125 | print SCRIPT "rm -f $pbpkg-$pbver$pbextdir.tar.gz\n";
|
---|
| 1126 | print SCRIPT "rmdir $pbpkg-$pbver$pbextdir\n";
|
---|
[1484] | 1127 | print SCRIPT "find . -type f -print0 | xargs -0 chmod 644\n";
|
---|
| 1128 | print SCRIPT "find . -type d -print0 | xargs -0 chmod 755\n";
|
---|
[560] | 1129 | close(SCRIPT);
|
---|
[1165] | 1130 | chmod 0755,"$ENV{'PBTMP'}/pbscript";
|
---|
[499] | 1131 | }
|
---|
| 1132 |
|
---|
[1259] | 1133 | # Apply filters to the non-build files
|
---|
| 1134 | my $liste ="";
|
---|
| 1135 | if (defined $filteredfiles->{$pbpkg}) {
|
---|
| 1136 | foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
|
---|
| 1137 | pb_filter_file_inplace($ptr,"$dest/$f",$pb);
|
---|
| 1138 | $liste = "$f $liste";
|
---|
| 1139 | }
|
---|
| 1140 | }
|
---|
| 1141 | pb_log(2,"Files ".$liste."have been filtered\n");
|
---|
| 1142 |
|
---|
| 1143 | # TODO: Make it CMS aware
|
---|
| 1144 | # Execute the pbinit script if any
|
---|
| 1145 | if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
|
---|
| 1146 | pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$pb);
|
---|
| 1147 | chmod 0755,"$ENV{'PBTMP'}/pbinit";
|
---|
| 1148 | pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit under $dest","verbose");
|
---|
| 1149 | }
|
---|
| 1150 |
|
---|
| 1151 | # Do we have additional script to run to prepare the environement for the project ?
|
---|
| 1152 | # Then include it in the pbconf delivery
|
---|
| 1153 | foreach my $pbvf (<$ENV{'PBROOTDIR'}/pbv*.pre>,<$ENV{'PBROOTDIR'}/pbv*.post>, <$ENV{'PBROOTDIR'}/pbtest*>) {
|
---|
| 1154 | if (-x "$pbvf") {
|
---|
| 1155 | my $target = "$ENV{'PBDESTDIR'}/".basename($pbvf);
|
---|
| 1156 | pb_filter_file("$pbvf",$ptr,$target,$pb);
|
---|
| 1157 | chmod 0755,"$target";
|
---|
| 1158 | }
|
---|
| 1159 | }
|
---|
| 1160 |
|
---|
[265] | 1161 | # Prepare the dest directory for archive
|
---|
[69] | 1162 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
[537] | 1163 | if (defined $preserve) {
|
---|
| 1164 | # In that case we want to preserve the original tar file for checksum purposes
|
---|
| 1165 | # The one created is btw equivalent in that case to this one
|
---|
| 1166 | # Maybe check basename of both to be sure they are the same ?
|
---|
| 1167 | pb_log(0,"Preserving original tar file ");
|
---|
[1432] | 1168 | move("$preserve","$pbpkg-$pbver$pbextdir.tar.gz");
|
---|
[537] | 1169 | } else {
|
---|
| 1170 | # Possibility to look at PBSRC to guess more the filename
|
---|
[1432] | 1171 | pb_system("tar cfz $pbpkg-$pbver$pbextdir.tar.gz --exclude=$pbpkg-$pbver$pbextdir/pbconf $pbpkg-$pbver$pbextdir","Creating $pbpkg tar files compressed");
|
---|
[537] | 1172 | }
|
---|
[1432] | 1173 | pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz\n");
|
---|
| 1174 | pb_system("tar cfz $pbpkg-$pbver$pbextdir.pbconf.tar.gz $pbpkg-$pbver$pbextdir/pbconf","Creating pbconf tar files compressed");
|
---|
| 1175 | pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.pbconf.tar.gz\n");
|
---|
[83] | 1176 |
|
---|
[357] | 1177 | # Keep track of version-tag per pkg
|
---|
| 1178 | $pkgs{$pbpkg} = "$pbver-$pbtag";
|
---|
[83] | 1179 |
|
---|
[288] | 1180 | # Final cleanup
|
---|
| 1181 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 1182 | }
|
---|
[357] | 1183 |
|
---|
| 1184 | # Keep track of per package version
|
---|
| 1185 | pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
|
---|
| 1186 | open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
|
---|
[539] | 1187 | foreach my $pbpkg (keys %pkgs) {
|
---|
[357] | 1188 | print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
|
---|
| 1189 | }
|
---|
| 1190 | close(PKG);
|
---|
| 1191 |
|
---|
| 1192 | # Keep track of what is generated by default
|
---|
| 1193 | # We need to store the dir and info on version-tag
|
---|
| 1194 | # Base our content on the existing .pb file
|
---|
| 1195 | copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
|
---|
| 1196 | open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
|
---|
| 1197 | print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
|
---|
[702] | 1198 | print LAST "projver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
|
---|
| 1199 | print LAST "projtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
|
---|
[357] | 1200 | print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
|
---|
[1432] | 1201 | print LAST "pbextdir $ENV{'PBPROJ'} = $pbextdir\n";
|
---|
[357] | 1202 | close(LAST);
|
---|
[77] | 1203 | }
|
---|
[22] | 1204 |
|
---|
[772] | 1205 | sub pb_test2pkg {
|
---|
| 1206 | # Get the running distro to test on
|
---|
[1177] | 1207 | my $pbos = pb_distro_get_context();
|
---|
[772] | 1208 |
|
---|
| 1209 | # Get list of packages to test
|
---|
| 1210 | # Get content saved in cms2build
|
---|
| 1211 | my $ptr = pb_get_pkg();
|
---|
| 1212 | @pkgs = @$ptr;
|
---|
| 1213 |
|
---|
| 1214 | # Additional potential repo
|
---|
[1177] | 1215 | pb_distro_setuprepo($pbos);
|
---|
[772] | 1216 | foreach my $pbpkg (@pkgs) {
|
---|
| 1217 | # We need to install the package to test, and deps brought with it
|
---|
[1177] | 1218 | pb_distro_installdeps(undef,$pbos,$pbpkg);
|
---|
[772] | 1219 | pb_system("$ENV{'PBDESTDIR'}/pbtest","Launching test for $pbpkg","verbose");
|
---|
| 1220 | }
|
---|
| 1221 | }
|
---|
| 1222 |
|
---|
[77] | 1223 | sub pb_build2pkg {
|
---|
| 1224 |
|
---|
[22] | 1225 | # Get the running distro to build on
|
---|
[1177] | 1226 | my $pbos = pb_distro_get_context();
|
---|
[22] | 1227 |
|
---|
[1137] | 1228 | # If needed we may add repository to the build env
|
---|
[1177] | 1229 | pb_distro_setuprepo($pbos);
|
---|
[1137] | 1230 |
|
---|
[353] | 1231 | # Get list of packages to build
|
---|
| 1232 | my $ptr = pb_get_pkg();
|
---|
| 1233 | @pkgs = @$ptr;
|
---|
| 1234 |
|
---|
[898] | 1235 | # Get content saved in cms2build
|
---|
[353] | 1236 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
[83] | 1237 | $pkg = { } if (not defined $pkg);
|
---|
[1432] | 1238 | my $pbextdir = pb_get_extdir();
|
---|
[83] | 1239 |
|
---|
[1212] | 1240 | pb_mkdir_p("$ENV{'PBBUILDDIR'}") if (! -d "$ENV{'PBBUILDDIR'}");
|
---|
[1208] | 1241 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
[126] | 1242 | my $made = ""; # pkgs made during build
|
---|
[1176] | 1243 | my $pm;
|
---|
| 1244 | $pm = new Parallel::ForkManager($pbparallel) if (defined $pbparallel);
|
---|
[1137] | 1245 |
|
---|
| 1246 | # We need to communicate info back from the children if parallel so prepare a dir for that
|
---|
| 1247 | my $tmpd = "$ENV{'PBTMP'}/build.$$";
|
---|
| 1248 | pb_mkdir_p($tmpd) if (defined $pbparallel);
|
---|
| 1249 |
|
---|
[27] | 1250 | foreach my $pbpkg (@pkgs) {
|
---|
[1137] | 1251 | $pm->start and next if (defined $pbparallel);
|
---|
| 1252 |
|
---|
[88] | 1253 | my $vertag = $pkg->{$pbpkg};
|
---|
[1459] | 1254 | pb_log(2,"Vertag: $vertag\n");
|
---|
[77] | 1255 | # get the version of the current package - maybe different
|
---|
| 1256 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 1257 |
|
---|
[1432] | 1258 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz";
|
---|
| 1259 | my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.pbconf.tar.gz";
|
---|
[315] | 1260 | pb_log(2,"Source file: $src\n");
|
---|
[493] | 1261 | pb_log(2,"Pbconf file: $src2\n");
|
---|
[25] | 1262 |
|
---|
[315] | 1263 | pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
|
---|
[1177] | 1264 | if ($pbos->{'type'} eq "rpm") {
|
---|
[25] | 1265 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
[28] | 1266 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
[1212] | 1267 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$d");
|
---|
[28] | 1268 | }
|
---|
[25] | 1269 | }
|
---|
| 1270 |
|
---|
[315] | 1271 | # Remove in case a previous link/file was there
|
---|
[301] | 1272 | unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
|
---|
[188] | 1273 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
[25] | 1274 | # We need to first extract the spec file
|
---|
[1432] | 1275 | my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/","$ENV{'PBBUILDDIR'}/SPECS","spec");
|
---|
[25] | 1276 |
|
---|
[493] | 1277 | # We need to handle potential patches to upstream sources
|
---|
[1432] | 1278 | pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
|
---|
[493] | 1279 |
|
---|
[1219] | 1280 | # We need to handle potential additional sources to upstream sources
|
---|
[1432] | 1281 | pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbsrc/","$ENV{'PBBUILDDIR'}/SOURCES","src");
|
---|
[1219] | 1282 |
|
---|
[315] | 1283 | pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
|
---|
[25] | 1284 | # set LANGUAGE to check for correct log messages
|
---|
| 1285 | $ENV{'LANGUAGE'}="C";
|
---|
[459] | 1286 | # Older Redhat use _target_platform in %configure incorrectly
|
---|
| 1287 | my $specialdef = "";
|
---|
[1177] | 1288 | if (($pbos->{'name'} eq "redhat") || (($pbos->{'name'} eq "rhel") && ($pbos->{'version'} eq "2.1"))) {
|
---|
[459] | 1289 | $specialdef = "--define \'_target_platform \"\"\'";
|
---|
| 1290 | }
|
---|
[702] | 1291 |
|
---|
[28] | 1292 | foreach my $f (@specfile) {
|
---|
| 1293 | if ($f =~ /\.spec$/) {
|
---|
[1137] | 1294 | # This could cause an issue in // mode
|
---|
[1177] | 1295 | pb_distro_installdeps($f,$pbos);
|
---|
[1085] | 1296 | pb_system("rpmbuild $specialdef --define \"packager $ENV{'PBPACKAGER'}\" --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
|
---|
[28] | 1297 | last;
|
---|
| 1298 | }
|
---|
| 1299 | }
|
---|
[540] | 1300 | # Get the name of the generated packages
|
---|
[1137] | 1301 | open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to open $ENV{'PBTMP'}/system.$$.log";
|
---|
[540] | 1302 | while (<LOG>) {
|
---|
[572] | 1303 | chomp($_);
|
---|
[540] | 1304 | next if ($_ !~ /^Wrote:/);
|
---|
| 1305 | s|.*/([S]*RPMS.*)|$1|;
|
---|
[572] | 1306 | $made .=" $_";
|
---|
[540] | 1307 | }
|
---|
[541] | 1308 | close(LOG);
|
---|
[540] | 1309 |
|
---|
[1177] | 1310 | } elsif ($pbos->{'type'} eq "deb") {
|
---|
[274] | 1311 | pb_system("tar xfz $src","Extracting sources");
|
---|
[493] | 1312 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
[149] | 1313 |
|
---|
[1432] | 1314 | chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
|
---|
[310] | 1315 | pb_rm_rf("debian");
|
---|
[1177] | 1316 | symlink "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}","debian" || die "Unable to symlink to pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[199] | 1317 | chmod 0755,"debian/rules";
|
---|
[544] | 1318 |
|
---|
[1359] | 1319 | # We need to handle potential patches to upstream sources
|
---|
[1363] | 1320 | pb_mkdir_p("debian/patches");
|
---|
[1432] | 1321 | my @f = pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbpatch/","debian/patches","patch");
|
---|
[1363] | 1322 |
|
---|
[1367] | 1323 | # By default we use format 1.0 - Cf man dpkg-source
|
---|
| 1324 | my $debsrcfmt = "1.0";
|
---|
| 1325 | my $debsrcfile = "debian/source/format";
|
---|
| 1326 | if (-f $debsrcfile) {
|
---|
| 1327 | $debsrcfmt = pb_get_content($debsrcfile);
|
---|
| 1328 | }
|
---|
| 1329 |
|
---|
| 1330 | if ($debsrcfmt =~ /^3.*quilt/) {
|
---|
| 1331 | # If we use quilt to manage patches, we then setup the env correctly
|
---|
| 1332 | # as per http://pkg-perl.alioth.debian.org/howto/quilt.html
|
---|
| 1333 | # Generate Debian patch series for quilt
|
---|
| 1334 | open(SERIE,"> debian/patches/series") || die "Unable to write in debian/patches/series";
|
---|
| 1335 | $ENV{'QUILT_PATCHES'}="debian/patches";
|
---|
| 1336 | } else {
|
---|
| 1337 | # If we use dpatch to manage patches, we then setup the 00list file as well
|
---|
| 1338 | open(SERIE,"> debian/patches/00list") || die "Unable to write in debian/patches/00list";
|
---|
| 1339 | }
|
---|
[1363] | 1340 | foreach my $f (sort @f) {
|
---|
[1367] | 1341 | # Skip the script made to apply the patches to the Debian tree
|
---|
| 1342 | next if ($f =~ /pbapplypatch/);
|
---|
| 1343 | # We also need to uncompress them
|
---|
| 1344 | pb_system("gzip -d $f","","quiet");
|
---|
| 1345 | $f =~ s/\.gz$//;
|
---|
[1359] | 1346 | print SERIE "$f\n";
|
---|
| 1347 | }
|
---|
| 1348 | close(SERIE);
|
---|
[1367] | 1349 | if (@f) {
|
---|
[1432] | 1350 | # We have patches...
|
---|
| 1351 | if ($debsrcfmt =~ /^1.*/) {
|
---|
| 1352 | # In that case we need to apply the patches ourselves locally
|
---|
| 1353 | pb_system("cat debian/patches/pbapplypatch","APPLY","verbose");
|
---|
| 1354 | pb_system("debian/patches/pbapplypatch","Applying patches to $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} tree");
|
---|
| 1355 | }
|
---|
| 1356 | # ...so modify the name of files to be Debian compliant
|
---|
| 1357 | move("../$src","../$pbpkg-$pbver$pbextdir.orig.tar.gz");
|
---|
[1367] | 1358 | }
|
---|
[1359] | 1359 |
|
---|
| 1360 | # We need to handle potential additional sources to upstream sources
|
---|
[1432] | 1361 | #pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbsrc/","$ENV{'PBBUILDDIR'}/debian","src");
|
---|
[1359] | 1362 |
|
---|
[1177] | 1363 | pb_distro_installdeps("debian/control",$pbos);
|
---|
[544] | 1364 | pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
|
---|
| 1365 | # Get the name of the generated packages
|
---|
[1137] | 1366 | open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to open $ENV{'PBTMP'}/system.$$.log";
|
---|
[544] | 1367 | while (<LOG>) {
|
---|
| 1368 | chomp();
|
---|
| 1369 | my $tmp = $_;
|
---|
[567] | 1370 | next if ($tmp !~ /^dpkg-deb.*:/);
|
---|
[1234] | 1371 | $tmp =~ s|.*\.\./(.*)_(.*).deb.*|$1|;
|
---|
[544] | 1372 | $made="$made $tmp.dsc $tmp.tar.gz $tmp"."_*.deb $tmp"."_*.changes";
|
---|
[448] | 1373 | }
|
---|
[544] | 1374 | close(LOG);
|
---|
[1234] | 1375 | chdir ".." || die "Unable to chdir to parent dir";
|
---|
[1424] | 1376 | pb_rm_rf("$pbpkg-$pbver");
|
---|
[1177] | 1377 | } elsif ($pbos->{'type'} eq "ebuild") {
|
---|
[149] | 1378 | my @ebuildfile;
|
---|
| 1379 | # For gentoo we need to take pb as subsystem name
|
---|
[295] | 1380 | # We put every apps here under sys-apps. hope it's correct
|
---|
[435] | 1381 | # We use pb's home dir in order to have a single OVERLAY line
|
---|
[1185] | 1382 | my $tmpe = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
|
---|
| 1383 | pb_mkdir_p($tmpe) if (! -d "$tmpe");
|
---|
[295] | 1384 | pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
|
---|
[149] | 1385 |
|
---|
[295] | 1386 | # We need to first extract the ebuild file
|
---|
[1432] | 1387 | @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/","$tmpe","ebuild");
|
---|
[149] | 1388 |
|
---|
| 1389 | # Prepare the build env for gentoo
|
---|
| 1390 | my $found = 0;
|
---|
[295] | 1391 | my $pbbd = $ENV{'HOME'};
|
---|
[150] | 1392 | $pbbd =~ s|/|\\/|g;
|
---|
[295] | 1393 | if (-r "/etc/make.conf") {
|
---|
| 1394 | open(MAKE,"/etc/make.conf");
|
---|
| 1395 | while (<MAKE>) {
|
---|
| 1396 | $found = 1 if (/$pbbd\/portage/);
|
---|
| 1397 | }
|
---|
| 1398 | close(MAKE);
|
---|
[149] | 1399 | }
|
---|
| 1400 | if ($found == 0) {
|
---|
[295] | 1401 | pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
|
---|
[149] | 1402 | }
|
---|
[295] | 1403 | #$found = 0;
|
---|
| 1404 | #if (-r "/etc/portage/package.keywords") {
|
---|
| 1405 | #open(KEYW,"/etc/portage/package.keywords");
|
---|
| 1406 | #while (<KEYW>) {
|
---|
| 1407 | #$found = 1 if (/portage\/pb/);
|
---|
| 1408 | #}
|
---|
| 1409 | #close(KEYW);
|
---|
| 1410 | #}
|
---|
| 1411 | #if ($found == 0) {
|
---|
| 1412 | #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
|
---|
| 1413 | #}
|
---|
[149] | 1414 |
|
---|
| 1415 | # Build
|
---|
| 1416 | foreach my $f (@ebuildfile) {
|
---|
| 1417 | if ($f =~ /\.ebuild$/) {
|
---|
[1177] | 1418 | pb_distro_installdeps($f,$pbos);
|
---|
[1185] | 1419 | move($f,"$tmpe/$pbpkg-$pbver.ebuild");
|
---|
| 1420 | pb_system("cd $tmpe ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
|
---|
[295] | 1421 | # Now move it where pb expects it
|
---|
| 1422 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
|
---|
[1432] | 1423 | if ($pbtag eq 0) {
|
---|
| 1424 | # This is assumed to be a test version
|
---|
| 1425 | my $nver = substr($pbver,0,-14);
|
---|
| 1426 | my $ntag = substr($pbver,-14);
|
---|
| 1427 | my $ebtg = "portage/pb/sys-apps/$pbpkg/$pbpkg-$nver"."_p$ntag.ebuild";
|
---|
| 1428 | move("$tmpe/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/$ebtg");
|
---|
| 1429 | $made="$made $ebtg";
|
---|
[1174] | 1430 | } else {
|
---|
[1432] | 1431 | my $ebtg = "portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver-r$pbtag.ebuild";
|
---|
| 1432 | move("$tmpe/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/$ebtg");
|
---|
| 1433 | $made="$made $ebtg";
|
---|
[1174] | 1434 | }
|
---|
[149] | 1435 | }
|
---|
| 1436 | }
|
---|
| 1437 |
|
---|
[1177] | 1438 | } elsif ($pbos->{'type'} eq "tgz") {
|
---|
[437] | 1439 | # Slackware family
|
---|
[435] | 1440 | $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
|
---|
| 1441 |
|
---|
| 1442 | pb_system("tar xfz $src","Extracting sources");
|
---|
[493] | 1443 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
[1432] | 1444 | chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
|
---|
[1177] | 1445 | symlink "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}","install" || die "Unable to symlink to pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[435] | 1446 | if (-x "install/pbslack") {
|
---|
[1177] | 1447 | pb_distro_installdeps("./install/pbslack",$pbos);
|
---|
[872] | 1448 | pb_system("./install/pbslack","Building software");
|
---|
[529] | 1449 | pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
|
---|
[435] | 1450 | }
|
---|
[1234] | 1451 | chdir ".." || die "Unable to chdir to parent dir";
|
---|
[1432] | 1452 | pb_rm_rf("$pbpkg-$pbver$pbextdir");
|
---|
[1177] | 1453 | } elsif ($pbos->{'type'} eq "pkg") {
|
---|
[872] | 1454 | # Solaris
|
---|
[916] | 1455 | $made="$made $pbpkg-$pbver-$pbtag.pkg.gz";
|
---|
[873] | 1456 | my $pkgdestdir="$ENV{'PBBUILDDIR'}/install";
|
---|
[872] | 1457 |
|
---|
| 1458 | # Will host resulting packages
|
---|
[1177] | 1459 | pb_mkdir_p("$pbos->{'type'}");
|
---|
[878] | 1460 | pb_mkdir_p("$pkgdestdir/delivery");
|
---|
[873] | 1461 | pb_system("tar xfz $src","Extracting sources under $ENV{'PBBUILDDIR'}");
|
---|
| 1462 | pb_system("tar xfz $src2","Extracting pbconf under $ENV{'PBBUILDDIR'}");
|
---|
[1242] | 1463 | # We need to handle potential patches to upstream sources
|
---|
[1432] | 1464 | pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbpatch/","$ENV{'PBBUILDDIR'}","patch");
|
---|
[1242] | 1465 |
|
---|
| 1466 | # We need to handle potential additional sources to upstream sources
|
---|
[1432] | 1467 | pb_extract_build_files($src2,"$pbpkg-$pbver$pbextdir/pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbsrc/","$ENV{'PBBUILDDIR'}","src");
|
---|
[1242] | 1468 |
|
---|
[1432] | 1469 | chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
|
---|
[1177] | 1470 | if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild") {
|
---|
| 1471 | chmod 0755,"pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild";
|
---|
[872] | 1472 | # pkginfo file is mandatory
|
---|
[1177] | 1473 | die "Unable to find pkginfo file in pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}" if (! -f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pkginfo");
|
---|
[872] | 1474 | # Build
|
---|
[1177] | 1475 | pb_system("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild $pkgdestdir/delivery","Building software and installing under $pkgdestdir/delivery");
|
---|
[872] | 1476 | # Copy complementary files
|
---|
[1177] | 1477 | if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/prototype") {
|
---|
| 1478 | copy("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/prototype", $pkgdestdir)
|
---|
[872] | 1479 | } else {
|
---|
| 1480 | # No prototype provided, calculating it
|
---|
[878] | 1481 | open(PROTO,"> $pkgdestdir/prototype") || die "Unable to create prototype file";
|
---|
[872] | 1482 | print PROTO "i pkginfo\n";
|
---|
[1177] | 1483 | print PROTO "i depend\n" if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/depend");
|
---|
[879] | 1484 | $ENV{'PBSOLDESTDIR'} = "$pkgdestdir/delivery";
|
---|
| 1485 | find(\&create_solaris_prototype, "$pkgdestdir/delivery");
|
---|
[872] | 1486 | }
|
---|
[1177] | 1487 | copy("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/depend", $pkgdestdir) if (-f "pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/depend");
|
---|
| 1488 | copy("pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pkginfo", $pkgdestdir);
|
---|
| 1489 | pb_system("cd $pkgdestdir/delivery ; pkgmk -o -f ../prototype -r $pkgdestdir/delivery -d $ENV{'PBBUILDDIR'}/$pbos->{'type'}","Packaging $pbpkg","verbose");
|
---|
| 1490 | pb_system("cd $ENV{'PBBUILDDIR'}/$pbos->{'type'} ; echo \"\" | pkgtrans -o -n -s $ENV{'PBBUILDDIR'}/$pbos->{'type'} $ENV{'PBBUILDDIR'}/$pbpkg-$pbver-$pbtag.pkg all","Transforming $pbpkg","verbose");
|
---|
[916] | 1491 | pb_system("cd $ENV{'PBBUILDDIR'} ; gzip -9f $pbpkg-$pbver-$pbtag.pkg","Compressing $pbpkg-$pbver-$pbtag.pkg","verbose");
|
---|
[913] | 1492 | } else {
|
---|
[1177] | 1493 | pb_log(0,"No pbconf/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}/pbbuild file found for $pbpkg-$pbver in \n");
|
---|
[872] | 1494 | }
|
---|
[874] | 1495 | chdir ".." || die "Unable to chdir to parent dir";
|
---|
[1432] | 1496 | pb_rm_rf("$pbpkg-$pbver$pbextdir","$ENV{'PBBUILDDIR'}/$pbos->{'type'}","$pkgdestdir");
|
---|
[1177] | 1497 | } elsif ($pbos->{'type'} eq "hpux") {
|
---|
[1174] | 1498 | # HP-UX
|
---|
| 1499 | pb_system("tar xfz $src","Extracting sources");
|
---|
| 1500 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
| 1501 |
|
---|
[1432] | 1502 | chdir "$pbpkg-$pbver$pbextdir" || die "Unable to chdir to $pbpkg-$pbver$pbextdir";
|
---|
[1174] | 1503 | pb_system("buildpackage ","Building package","verbose");
|
---|
| 1504 | # Get the name of the generated packages
|
---|
| 1505 | open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to open $ENV{'PBTMP'}/system.$$.log";
|
---|
| 1506 | while (<LOG>) {
|
---|
| 1507 | chomp();
|
---|
| 1508 | my $tmp = $_;
|
---|
| 1509 | next if ($tmp !~ /^SD BUILD.*:/);
|
---|
| 1510 | $tmp =~ s|.*../(.*)_(.*).sd.*|$1|;
|
---|
[1279] | 1511 | $made = "$made $tmp"."_*.sd";
|
---|
[1174] | 1512 | }
|
---|
| 1513 | close(LOG);
|
---|
| 1514 | $made="$made $pbpkg-$pbver-$pbtag.sd";
|
---|
| 1515 |
|
---|
[1234] | 1516 | chdir ".." || die "Unable to chdir to parent dir";
|
---|
[1432] | 1517 | pb_rm_rf("$pbpkg-$pbver$pbextdir");
|
---|
[87] | 1518 | } else {
|
---|
[1177] | 1519 | die "Unknown OS type format $pbos->{'type'}";
|
---|
[87] | 1520 | }
|
---|
[1137] | 1521 | if (defined $pbparallel) {
|
---|
| 1522 | # Communicate results back to parent
|
---|
| 1523 | pb_set_content("$tmpd/$$",$made);
|
---|
| 1524 | $pm->finish;
|
---|
| 1525 | }
|
---|
[87] | 1526 | }
|
---|
[1137] | 1527 | if (defined $pbparallel) {
|
---|
| 1528 | # In the parent, we need to get the result from the children
|
---|
| 1529 | $pm->wait_all_children;
|
---|
| 1530 | foreach my $f (<$tmpd/*>) {
|
---|
| 1531 | $made .= " ".pb_get_content($f);
|
---|
| 1532 | }
|
---|
| 1533 | pb_rm_rf($tmpd);
|
---|
| 1534 | }
|
---|
| 1535 |
|
---|
[1278] | 1536 | # Sign packages
|
---|
| 1537 | pb_sign_pkgs($pbos,$made);
|
---|
| 1538 |
|
---|
[1109] | 1539 | # Find the appropriate check cmd/opts
|
---|
[1177] | 1540 | my ($chkcmd,$chkopt) = pb_distro_get_param($pbos,pb_conf_get_if("oschkcmd","oschkopt"));
|
---|
[1109] | 1541 |
|
---|
[541] | 1542 | # Packages check if needed
|
---|
[1177] | 1543 | if ($pbos->{'type'} eq "rpm") {
|
---|
| 1544 | if ((defined $chkcmd) && (-x $chkcmd)) {
|
---|
| 1545 | my $cmd = "$chkcmd";
|
---|
| 1546 | $cmd .= " $chkopt" if (defined $chkopt);
|
---|
| 1547 | $cmd .= " $made";
|
---|
| 1548 | pb_system("$cmd","Checking validity of rpms with $chkcmd","verbose");
|
---|
[541] | 1549 | }
|
---|
[1098] | 1550 | my $rpms ="";
|
---|
| 1551 | my $srpms ="";
|
---|
| 1552 | foreach my $f (split(/ /,$made)) {
|
---|
| 1553 | $rpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^RPMS\//);
|
---|
| 1554 | $srpms .= "$ENV{'PBBUILDDIR'}/$f " if ($f =~ /^SRPMS\//);
|
---|
| 1555 | }
|
---|
| 1556 | pb_log(0,"SRPM packages generated: $srpms\n");
|
---|
| 1557 | pb_log(0,"RPM packages generated: $rpms\n");
|
---|
[1177] | 1558 | } elsif ($pbos->{'type'} eq "deb") {
|
---|
[572] | 1559 | my $made2 = "";
|
---|
[971] | 1560 | foreach my $f (split(/ /,$made)) {
|
---|
[1234] | 1561 | $made2 .= "$f " if ($f =~ /\.deb$/);
|
---|
[971] | 1562 | }
|
---|
[1109] | 1563 | if (-x $chkcmd) {
|
---|
| 1564 | pb_system("$chkcmd $chkopt $made2","Checking validity of debs with $chkcmd","verbose");
|
---|
[541] | 1565 | }
|
---|
[1234] | 1566 | pb_log(0,"deb packages generated: $made2\n");
|
---|
[541] | 1567 | } else {
|
---|
[1177] | 1568 | pb_log(0,"No check done for $pbos->{'type'} yet\n");
|
---|
[572] | 1569 | pb_log(0,"Packages generated: $made\n");
|
---|
[541] | 1570 | }
|
---|
| 1571 |
|
---|
[1176] | 1572 | # Keep track of what is generated so that we can get them back from VMs/RMs
|
---|
[1189] | 1573 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[118] | 1574 | print KEEP "$made\n";
|
---|
| 1575 | close(KEEP);
|
---|
[87] | 1576 | }
|
---|
| 1577 |
|
---|
[874] | 1578 | sub create_solaris_prototype {
|
---|
[872] | 1579 |
|
---|
[873] | 1580 | my $uidgid = "bin bin";
|
---|
[877] | 1581 | my $pkgdestdir = $ENV{'PBSOLDESTDIR'};
|
---|
[872] | 1582 |
|
---|
[878] | 1583 | return if ($_ =~ /^$pkgdestdir$/);
|
---|
[875] | 1584 | if (-d $_) {
|
---|
| 1585 | my $n = $File::Find::name;
|
---|
| 1586 | $n =~ s~$pkgdestdir/~~;
|
---|
| 1587 | print PROTO "d none $n 0755 $uidgid\n";
|
---|
[877] | 1588 | } elsif (-x $_) {
|
---|
[875] | 1589 | my $n = $File::Find::name;
|
---|
| 1590 | $n =~ s~$pkgdestdir/~~;
|
---|
| 1591 | print PROTO "f none $n 0755 $uidgid\n";
|
---|
[872] | 1592 | } elsif (-f $_) {
|
---|
[875] | 1593 | my $n = $File::Find::name;
|
---|
| 1594 | $n =~ s~$pkgdestdir/~~;
|
---|
| 1595 | print PROTO "f none $n 0644 $uidgid\n";
|
---|
[872] | 1596 | }
|
---|
| 1597 | }
|
---|
| 1598 |
|
---|
[88] | 1599 | sub pb_build2ssh {
|
---|
[320] | 1600 | pb_send2target("Sources");
|
---|
[1374] | 1601 | pb_send2target("CPAN");
|
---|
[90] | 1602 | }
|
---|
[87] | 1603 |
|
---|
[90] | 1604 | sub pb_pkg2ssh {
|
---|
[320] | 1605 | pb_send2target("Packages");
|
---|
[90] | 1606 | }
|
---|
| 1607 |
|
---|
[108] | 1608 | # By default deliver to the the public site hosting the
|
---|
[1176] | 1609 | # ftp structure (or whatever) or a VM/VE/RM
|
---|
[320] | 1610 | sub pb_send2target {
|
---|
[90] | 1611 |
|
---|
| 1612 | my $cmt = shift;
|
---|
[320] | 1613 | my $v = shift || undef;
|
---|
[142] | 1614 | my $vmexist = shift || 0; # 0 is FALSE
|
---|
[200] | 1615 | my $vmpid = shift || 0; # 0 is FALSE
|
---|
[748] | 1616 | my $snapme = shift || 0; # 0 is FALSE
|
---|
[320] | 1617 |
|
---|
[444] | 1618 | pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
|
---|
[320] | 1619 | my $host = "sshhost";
|
---|
| 1620 | my $login = "sshlogin";
|
---|
| 1621 | my $dir = "sshdir";
|
---|
| 1622 | my $port = "sshport";
|
---|
| 1623 | my $conf = "sshconf";
|
---|
[883] | 1624 | my $tmout = undef;
|
---|
| 1625 | my $path = undef;
|
---|
[772] | 1626 | if ($cmt =~ /^VM/) {
|
---|
[320] | 1627 | $login = "vmlogin";
|
---|
[322] | 1628 | $dir = "pbdefdir";
|
---|
[320] | 1629 | # Specific VM
|
---|
[883] | 1630 | $tmout = "vmtmout";
|
---|
| 1631 | $path = "vmpath";
|
---|
[320] | 1632 | $host = "vmhost";
|
---|
| 1633 | $port = "vmport";
|
---|
[1176] | 1634 | } elsif ($cmt =~ /^RM/) {
|
---|
| 1635 | $login = "rmlogin";
|
---|
| 1636 | $dir = "pbdefdir";
|
---|
| 1637 | # Specific RM
|
---|
| 1638 | $tmout = "rmtmout";
|
---|
| 1639 | $path = "rmpath";
|
---|
| 1640 | $host = "rmhost";
|
---|
| 1641 | $port = "rmport";
|
---|
[772] | 1642 | } elsif ($cmt =~ /^VE/) {
|
---|
[320] | 1643 | $login = "velogin";
|
---|
[322] | 1644 | $dir = "pbdefdir";
|
---|
[320] | 1645 | # Specific VE
|
---|
| 1646 | $path = "vepath";
|
---|
[986] | 1647 | $conf = "rbsconf";
|
---|
[556] | 1648 | } elsif ($cmt eq "Web") {
|
---|
| 1649 | $host = "websshhost";
|
---|
| 1650 | $login = "websshlogin";
|
---|
| 1651 | $dir = "websshdir";
|
---|
| 1652 | $port = "websshport";
|
---|
[1374] | 1653 | } elsif ($cmt eq "CPAN") {
|
---|
| 1654 | $host = "cpanpause";
|
---|
| 1655 | $login = "";
|
---|
| 1656 | $dir = "cpandir";
|
---|
| 1657 | $port = "";
|
---|
[320] | 1658 | }
|
---|
[158] | 1659 | my $cmd = "";
|
---|
[471] | 1660 | my $src = "";
|
---|
[1374] | 1661 | my $cpanpkg = 0;
|
---|
[1177] | 1662 | my $pbos;
|
---|
[90] | 1663 |
|
---|
[1432] | 1664 | my $pbextdir = pb_get_extdir();
|
---|
| 1665 |
|
---|
[471] | 1666 | if ($cmt ne "Announce") {
|
---|
[898] | 1667 | # Get list of packages to build
|
---|
[471] | 1668 | my $ptr = pb_get_pkg();
|
---|
| 1669 | @pkgs = @$ptr;
|
---|
[87] | 1670 |
|
---|
[471] | 1671 | # Get the running distro to consider
|
---|
[1177] | 1672 | $pbos = pb_distro_get_context($v);
|
---|
[87] | 1673 |
|
---|
[471] | 1674 | # Get content saved in cms2build
|
---|
| 1675 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
| 1676 | $pkg = { } if (not defined $pkg);
|
---|
[87] | 1677 |
|
---|
[1212] | 1678 | pb_mkdir_p("$ENV{'PBBUILDDIR'}") if (! -d "$ENV{'PBBUILDDIR'}");
|
---|
[1208] | 1679 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
[471] | 1680 | foreach my $pbpkg (@pkgs) {
|
---|
| 1681 | my $vertag = $pkg->{$pbpkg};
|
---|
| 1682 | # get the version of the current package - maybe different
|
---|
[1459] | 1683 | pb_log(2,"Vertag: $vertag\n");
|
---|
[471] | 1684 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
[87] | 1685 |
|
---|
[1179] | 1686 | if (($cmt eq "Sources") || ($cmt =~ /(V[EM]|RM)build/)) {
|
---|
[1432] | 1687 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.pbconf.tar.gz";
|
---|
[471] | 1688 | if ($cmd eq "") {
|
---|
[1432] | 1689 | $cmd = "ln -sf $pbpkg-$pbver$pbextdir.tar.gz $pbpkg-latest.tar.gz";
|
---|
[471] | 1690 | } else {
|
---|
[1432] | 1691 | $cmd = "$cmd ; ln -sf $pbpkg-$pbver$pbextdir.tar.gz $pbpkg-latest.tar.gz";
|
---|
[471] | 1692 | }
|
---|
[560] | 1693 | } elsif ($cmt eq "Web") {
|
---|
[1432] | 1694 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver$pbextdir.tar.gz"
|
---|
[166] | 1695 | }
|
---|
[1374] | 1696 |
|
---|
| 1697 | # Do we have one perl package
|
---|
| 1698 | my @nametype = pb_conf_get_if("namingtype");
|
---|
| 1699 | my $type = $nametype[0]->{$pbpkg};
|
---|
| 1700 | if ((defined $type) && ($type eq "perl")) {
|
---|
| 1701 | $cpanpkg = 1;
|
---|
| 1702 | }
|
---|
[118] | 1703 | }
|
---|
[471] | 1704 | # Adds conf file for availability of conf elements
|
---|
| 1705 | pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
|
---|
[118] | 1706 | }
|
---|
[1374] | 1707 | my ($rbsconf,$testver,$delivery) = pb_conf_get_if($conf,"testver","delivery");
|
---|
| 1708 | if ($cmt =~ /CPAN/) {
|
---|
| 1709 | # Do not deliver on Pause if this is a test version
|
---|
[1384] | 1710 | return if (not defined $testver);
|
---|
[1374] | 1711 | return if ($testver =~ /true/);
|
---|
| 1712 | # Do not deliver on Pause if this is not a perl package
|
---|
| 1713 | return if ($cpanpkg == 0);
|
---|
| 1714 | }
|
---|
[417] | 1715 |
|
---|
[1176] | 1716 | if ($cmt =~ /(V[EM]|RM)build/) {
|
---|
[1138] | 1717 | $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript.$$";
|
---|
[1176] | 1718 | } elsif ($cmt =~ /(V[EM]|RM)Script/) {
|
---|
[1138] | 1719 | $src="$src $ENV{'PBDESTDIR'}/pbscript.$$";
|
---|
[1176] | 1720 | } elsif ($cmt =~ /(V[EM]|RM)test/) {
|
---|
[1138] | 1721 | $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";
|
---|
[1374] | 1722 | } elsif (($cmt eq "Announce") || ($cmt eq "Web") || ($cmt eq "CPAN")) {
|
---|
[471] | 1723 | $src="$src $ENV{'PBTMP'}/pbscript";
|
---|
[118] | 1724 | } elsif ($cmt eq "Packages") {
|
---|
| 1725 | # Get package list from file made during build2pkg
|
---|
[1189] | 1726 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[126] | 1727 | $src = <KEEP>;
|
---|
[118] | 1728 | chomp($src);
|
---|
| 1729 | close(KEEP);
|
---|
[1279] | 1730 | $src = "$src $ENV{'PBBUILDDIR'}/pbscript.$$";
|
---|
[87] | 1731 | }
|
---|
[1374] | 1732 | if (($cmt eq "Sources") || ($cmt eq "Packages") || ($cmt eq "CPAN")) {
|
---|
[1279] | 1733 | my ($pbpackager) = pb_conf_get("pbpackager");
|
---|
| 1734 | $ENV{'PBPACKAGER'} = $pbpackager->{$ENV{'PBPROJ'}};
|
---|
| 1735 | pb_log(0,"Exporting public key for $ENV{'PBPACKAGER'}\n");
|
---|
| 1736 | # Using pb_system is not working due to redirection below
|
---|
| 1737 | system("gpg --export -a \'$ENV{'PBPACKAGER'}\' > $ENV{'PBDESTDIR'}/$ENV{'PBPROJ'}.pubkey");
|
---|
| 1738 | chmod 0644,"$ENV{'PBDESTDIR'}/$ENV{'PBPROJ'}.pubkey";
|
---|
| 1739 | $src = "$src $ENV{'PBDESTDIR'}/$ENV{'PBPROJ'}.pubkey";
|
---|
| 1740 | }
|
---|
[320] | 1741 | # Remove potential leading spaces (cause problem with basename)
|
---|
[132] | 1742 | $src =~ s/^ *//;
|
---|
[129] | 1743 | my $basesrc = "";
|
---|
[131] | 1744 | foreach my $i (split(/ +/,$src)) {
|
---|
| 1745 | $basesrc .= " ".basename($i);
|
---|
[130] | 1746 | }
|
---|
[118] | 1747 |
|
---|
[320] | 1748 | pb_log(0,"Sources handled ($cmt): $src\n");
|
---|
[987] | 1749 | pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$path,$conf))."\n");
|
---|
[883] | 1750 | my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
|
---|
| 1751 | # Not mandatory...
|
---|
[1102] | 1752 | $delivery->{$ENV{'PBPROJ'}} = "" if (not defined $delivery->{$ENV{'PBPROJ'}});
|
---|
[883] | 1753 | my ($vtmout,$vepath);
|
---|
| 1754 | # ...Except those in virtual context
|
---|
| 1755 | if ($cmt =~ /^VE/) {
|
---|
| 1756 | ($vepath) = pb_conf_get($path);
|
---|
| 1757 | }
|
---|
[1176] | 1758 | if ($cmt =~ /^(V|R)M/) {
|
---|
[1218] | 1759 | $vtmout = pb_distro_get_param($pbos,pb_conf_get_if($tmout));
|
---|
[883] | 1760 | }
|
---|
[1216] | 1761 | my $remhost = $sshhost->{$ENV{'PBPROJ'}};
|
---|
| 1762 | my $remdir = $sshdir->{$ENV{'PBPROJ'}};
|
---|
| 1763 | if ($cmt =~ /^V[EM]|RM/) {
|
---|
| 1764 | # In that case our real host is in the xxhost with the OS as key, not project as above
|
---|
| 1765 | $remhost = pb_distro_get_param($pbos,$sshhost);
|
---|
[1176] | 1766 | }
|
---|
[1217] | 1767 | pb_log(2,"ssh: ".Dumper(($remhost,$sshlogin,$remdir,$sshport,$vepath,$rbsconf))."\n");
|
---|
| 1768 | pb_log(2,"ssh: ".Dumper($vtmout)."\n") if (defined $vtmout);
|
---|
[320] | 1769 |
|
---|
| 1770 | my $mac;
|
---|
[772] | 1771 | if ($cmt !~ /^VE/) {
|
---|
[1216] | 1772 | $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$remhost";
|
---|
[320] | 1773 | # Overwrite account value if passed as parameter
|
---|
[1216] | 1774 | $mac = "$pbaccount\@$remhost" if (defined $pbaccount);
|
---|
[355] | 1775 | pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
|
---|
[681] | 1776 | } else {
|
---|
| 1777 | # VE
|
---|
[1138] | 1778 | # Overwrite account value if passed as parameter (typically for setup2v)
|
---|
[681] | 1779 | $mac = $sshlogin->{$ENV{'PBPROJ'}};
|
---|
| 1780 | $mac = $pbaccount if (defined $pbaccount);
|
---|
[320] | 1781 | }
|
---|
| 1782 |
|
---|
[108] | 1783 | my $tdir;
|
---|
[136] | 1784 | my $bdir;
|
---|
[1176] | 1785 | if (($cmt eq "Sources") || ($cmt =~ /(V[EM]|RM)Script/)) {
|
---|
[1216] | 1786 | $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}/src";
|
---|
[1374] | 1787 | } elsif ($cmt eq "CPAN") {
|
---|
| 1788 | $tdir = "$remdir";
|
---|
[1176] | 1789 | } elsif ($cmt =~ /(V[EM]|RM)(build|test)/) {
|
---|
[1216] | 1790 | $tdir = $remdir."/$ENV{'PBPROJ'}/delivery";
|
---|
| 1791 | $bdir = $remdir."/$ENV{'PBPROJ'}/build";
|
---|
[136] | 1792 | # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
|
---|
| 1793 | $bdir =~ s|\$ENV.+\}/||;
|
---|
[471] | 1794 | } elsif ($cmt eq "Announce") {
|
---|
[1216] | 1795 | $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}";
|
---|
[556] | 1796 | } elsif ($cmt eq "Web") {
|
---|
[1216] | 1797 | $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}";
|
---|
[90] | 1798 | } elsif ($cmt eq "Packages") {
|
---|
[1192] | 1799 | if (($pbos->{'type'} eq "rpm") || ($pbos->{'type'} eq "pkg") || ($pbos->{'type'} eq "hpux") || ($pbos->{'type'} eq "tgz")) {
|
---|
| 1800 | # put packages under an arch subdir
|
---|
[1216] | 1801 | $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
|
---|
[1192] | 1802 | } elsif (($pbos->{'type'} eq "deb") || ($pbos->{'type'} eq "ebuild")) {
|
---|
| 1803 | # No need for an arch subdir
|
---|
[1216] | 1804 | $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}";
|
---|
[1192] | 1805 | } else {
|
---|
| 1806 | die "Please teach the dev team where to deliver ($pbos->{'type'} type of packages\n";
|
---|
| 1807 | }
|
---|
[429] | 1808 |
|
---|
| 1809 | my $repodir = $tdir;
|
---|
[1216] | 1810 | $repodir =~ s|^$remdir/||;
|
---|
[429] | 1811 |
|
---|
| 1812 | my ($pbrepo) = pb_conf_get("pbrepo");
|
---|
| 1813 |
|
---|
| 1814 | # Repository management
|
---|
[1189] | 1815 | open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript.$$") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript.$$";
|
---|
[1177] | 1816 | if ($pbos->{'type'} eq "rpm") {
|
---|
[1276] | 1817 | my $pbsha = pb_distro_get_param($pbos,pb_conf_get("ossha"));
|
---|
[429] | 1818 | # Also make a pbscript to generate yum/urpmi bases
|
---|
| 1819 | print PBS << "EOF";
|
---|
[433] | 1820 | #!/bin/bash
|
---|
[429] | 1821 | # Prepare a script to ease yum setup
|
---|
[1298] | 1822 | EOF
|
---|
| 1823 | print PBS "set -x\n" if ($pbdebug gt 1);
|
---|
| 1824 | print PBS << "EOF";
|
---|
[429] | 1825 | cat > $ENV{'PBPROJ'}.repo << EOT
|
---|
| 1826 | [$ENV{'PBPROJ'}]
|
---|
[1177] | 1827 | name=$pbos->{'name'} $pbos->{'version'} $pbos->{'arch'} - $ENV{'PBPROJ'} Vanilla Packages
|
---|
[433] | 1828 | baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
|
---|
[429] | 1829 | enabled=1
|
---|
[1289] | 1830 | gpgcheck=1
|
---|
[1335] | 1831 | gpgkey=$pbrepo->{$ENV{'PBPROJ'}}/$repodir/$ENV{'PBPROJ'}.pubkey
|
---|
[429] | 1832 | EOT
|
---|
| 1833 | chmod 644 $ENV{'PBPROJ'}.repo
|
---|
| 1834 |
|
---|
| 1835 | # Clean up old repo content
|
---|
| 1836 | rm -rf headers/ repodata/
|
---|
| 1837 | # Create yum repo
|
---|
[1102] | 1838 | if [ -x /usr/bin/yum-arch ]; then
|
---|
| 1839 | yum-arch .
|
---|
| 1840 | fi
|
---|
[429] | 1841 | # Create repodata
|
---|
[1276] | 1842 | createrepo -s $pbsha .
|
---|
[1365] | 1843 | # Link to the key
|
---|
[1409] | 1844 | (cd repodata ; ln -sf ../$ENV{'PBPROJ'}.pubkey repomd.xml.key)
|
---|
[1365] | 1845 | # sign the repomd (at least useful for SLES - which requires a local key)
|
---|
| 1846 | # gpg -a --detach-sign repodata/repomd.xml
|
---|
| 1847 | # SLES also looks for media.1/info.txt
|
---|
[429] | 1848 | EOF
|
---|
[1177] | 1849 | if ($pbos->{'family'} eq "md") {
|
---|
[429] | 1850 | # For Mandriva add urpmi management
|
---|
| 1851 | print PBS << "EOF";
|
---|
| 1852 | # Prepare a script to ease urpmi setup
|
---|
| 1853 | cat > $ENV{'PBPROJ'}.addmedia << EOT
|
---|
[1003] | 1854 | urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with media_info/hdlist.cz
|
---|
[429] | 1855 | EOT
|
---|
| 1856 | chmod 755 $ENV{'PBPROJ'}.addmedia
|
---|
| 1857 |
|
---|
| 1858 | # Clean up old repo content
|
---|
[437] | 1859 | rm -f hdlist.cz synthesis.hdlist.cz
|
---|
[429] | 1860 | # Create urpmi repo
|
---|
[1002] | 1861 | genhdlist2 --clean .
|
---|
| 1862 | if [ \$\? -ne 0 ]; then
|
---|
| 1863 | genhdlist .
|
---|
| 1864 | fi
|
---|
[429] | 1865 | EOF
|
---|
| 1866 | }
|
---|
[1177] | 1867 | if ($pbos->{'name'} eq "fedora") {
|
---|
[484] | 1868 | # Extract the spec file to please Fedora maintainers :-(
|
---|
| 1869 | print PBS << "EOF";
|
---|
| 1870 | for p in $basesrc; do
|
---|
| 1871 | echo \$p | grep -q 'src.rpm'
|
---|
| 1872 | if [ \$\? -eq 0 ]; then
|
---|
| 1873 | rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
|
---|
| 1874 | fi
|
---|
| 1875 | done
|
---|
| 1876 | EOF
|
---|
| 1877 | }
|
---|
[1177] | 1878 | if ($pbos->{'family'} eq "novell") {
|
---|
[1089] | 1879 | # Add ymp scripts for one-click install on SuSE
|
---|
| 1880 | print PBS << "EOF";
|
---|
| 1881 | # Prepare a script to ease SuSE one-click install
|
---|
[1090] | 1882 | # Cf: http://de.opensuse.org/1-Klick-Installation/ISV
|
---|
| 1883 | #
|
---|
[1089] | 1884 | cat > $ENV{'PBPROJ'}.ymp << EOT
|
---|
[1096] | 1885 | <?xml version="1.0" encoding="utf-8"?>
|
---|
| 1886 | <!-- vim: set sw=2 ts=2 ai et: -->
|
---|
[1089] | 1887 | <metapackage xmlns:os="http://opensuse.org/Standards/One_Click_Install" xmlns="http://opensuse.org/Standards/One_Click_Install">
|
---|
| 1888 | <group><!-- The group of software, typically one for project-builder.org -->
|
---|
| 1889 | <name>$ENV{'PBPROJ'} Bundle</name> <!-- Name of the software group -->
|
---|
| 1890 | <summary>Software bundle for the $ENV{'PBPROJ'} project</summary> <!--This message is shown to the user and should describe the whole bundle -->
|
---|
[1095] | 1891 | <description>This is the summary of the $ENV{'PBPROJ'} Project
|
---|
[1089] | 1892 |
|
---|
[1095] | 1893 | Details are available on a per package basis below
|
---|
| 1894 |
|
---|
[1089] | 1895 | </description><!--This is also shown to the user -->
|
---|
| 1896 | <remainSubscribed>false</remainSubscribed> <!-- Don't know what it mean -->
|
---|
| 1897 | <repositories><!-- List of needed repositories -->
|
---|
| 1898 | <repository>
|
---|
| 1899 | <name>$ENV{'PBPROJ'} Repository</name> <!-- Name of the repository -->
|
---|
| 1900 | <summary>This repository contains the $ENV{'PBPROJ'} project packages.</summary> <!-- Summary of the repository -->
|
---|
| 1901 | <description>This repository contains the $ENV{'PBPROJ'} project packages.</description><!-- This description is shown to the user -->
|
---|
| 1902 | <url>$pbrepo->{$ENV{'PBPROJ'}}/$repodir</url><!--URL of repository, which is added -->
|
---|
| 1903 | </repository>
|
---|
| 1904 | </repositories>
|
---|
| 1905 | <software><!-- A List of packages, which should be added through the one-click-installation -->
|
---|
| 1906 | EOT
|
---|
| 1907 | for p in $basesrc; do
|
---|
| 1908 | sum=`rpm -q --qf '%{SUMMARY}' \$p`
|
---|
[1096] | 1909 | name=`rpm -q --qf '%{NAME}' \$p`
|
---|
[1089] | 1910 | desc=`rpm -q --qf '%{description}' \$p`
|
---|
| 1911 | cat >> $ENV{'PBPROJ'}.ymp << EOT
|
---|
| 1912 | <item>
|
---|
[1096] | 1913 | <name>\$name</name><!-- Name of the package, is shown to the user and used to identify the package at the repository -->
|
---|
[1089] | 1914 | <summary>\$sum</summary> <!-- Summary of the package -->
|
---|
| 1915 | <description>\$desc</description> <!-- Description, is shown to the user -->
|
---|
| 1916 | </item>
|
---|
| 1917 | EOT
|
---|
| 1918 | done
|
---|
| 1919 | cat >> $ENV{'PBPROJ'}.ymp << EOT
|
---|
| 1920 | </software>
|
---|
| 1921 | </group>
|
---|
| 1922 | </metapackage>
|
---|
| 1923 | EOT
|
---|
| 1924 | chmod 644 $ENV{'PBPROJ'}.ymp
|
---|
| 1925 | EOF
|
---|
| 1926 | }
|
---|
[1177] | 1927 | } elsif ($pbos->{'type'} eq "deb") {
|
---|
[429] | 1928 | # Also make a pbscript to generate apt bases
|
---|
[460] | 1929 | # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
|
---|
[1246] | 1930 | # This dirname removes ver
|
---|
[1283] | 1931 | my $debarch = $pbos->{'arch'};
|
---|
[1287] | 1932 | $debarch = "amd64" if ($pbos->{'arch'} eq "x86_64");
|
---|
[465] | 1933 | my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
|
---|
[1357] | 1934 | # Remove extra . in path to fix #522
|
---|
| 1935 | $rpd =~ s|/./|/|g;
|
---|
[460] | 1936 | print PBS << "EOF";
|
---|
[465] | 1937 | #!/bin/bash
|
---|
| 1938 | # Prepare a script to ease apt setup
|
---|
| 1939 | cat > $ENV{'PBPROJ'}.sources.list << EOT
|
---|
[1177] | 1940 | deb $rpd $pbos->{'version'} contrib
|
---|
| 1941 | deb-src $rpd $pbos->{'version'} contrib
|
---|
[460] | 1942 | EOT
|
---|
[465] | 1943 | chmod 644 $ENV{'PBPROJ'}.sources.list
|
---|
[460] | 1944 |
|
---|
[1112] | 1945 | # Up two levels to deal with the dist dir cross versions
|
---|
[1192] | 1946 | cd ..
|
---|
[1275] | 1947 | mkdir -p dists/$pbos->{'version'}/contrib/binary-$debarch dists/$pbos->{'version'}/contrib/source
|
---|
[1112] | 1948 |
|
---|
[460] | 1949 | # Prepare a script to create apt info file
|
---|
[1192] | 1950 | # Reuse twice after
|
---|
[1112] | 1951 | TMPD=`mktemp -d /tmp/pb.XXXXXXXXXX` || exit 1
|
---|
| 1952 | mkdir -p \$TMPD
|
---|
| 1953 | cat > \$TMPD/Release << EOT
|
---|
| 1954 | Archive: unstable
|
---|
| 1955 | Component: contrib
|
---|
| 1956 | Origin: $ENV{'PBPROJ'}
|
---|
| 1957 | Label: $ENV{'PBPROJ'} dev repository $pbrepo->{$ENV{'PBPROJ'}}
|
---|
| 1958 | EOT
|
---|
| 1959 |
|
---|
[1275] | 1960 | echo "Creating Packages metadata ($pbos->{'arch'} aka $debarch)"
|
---|
| 1961 | dpkg-scanpackages -a$debarch $pbos->{'version'} /dev/null | gzip -c9 > dists/$pbos->{'version'}/contrib/binary-$debarch/Packages.gz
|
---|
| 1962 | dpkg-scanpackages -a$debarch $pbos->{'version'} /dev/null | bzip2 -c9 > dists/$pbos->{'version'}/contrib/binary-$debarch/Packages.bz2
|
---|
[1192] | 1963 | echo "Creating Contents metadata"
|
---|
| 1964 | apt-ftparchive contents $pbos->{'version'} | gzip -c9 > dists/$pbos->{'version'}/Contents.gz
|
---|
[1275] | 1965 | echo "Creating Release metadata ($pbos->{'arch'} aka $debarch)"
|
---|
| 1966 | cat \$TMPD/Release > dists/$pbos->{'version'}/contrib/binary-$debarch/Release
|
---|
[1279] | 1967 | echo "Architecture: $debarch" >> dists/$pbos->{'version'}/contrib/binary-$debarch/Release
|
---|
[1112] | 1968 | echo "Creating Source metadata"
|
---|
[1192] | 1969 | dpkg-scansources $pbos->{'version'} /dev/null | gzip -c9 > dists/$pbos->{'version'}/contrib/source/Sources.gz
|
---|
[1177] | 1970 | cat \$TMPD/Release > dists/$pbos->{'version'}/contrib/source/Release
|
---|
| 1971 | echo "Architecture: Source" >> dists/$pbos->{'version'}/contrib/source/Release
|
---|
[1112] | 1972 | echo "Creating Release metadata"
|
---|
[1388] | 1973 | # Signing that file would be useful but uneasy as gpg keys are not there
|
---|
| 1974 | # Cf: http://wiki.debian.org/SecureApt
|
---|
| 1975 | # Same as for repomd
|
---|
[1177] | 1976 | apt-ftparchive release dists/$pbos->{'version'} > dists/$pbos->{'version'}/Release
|
---|
[1112] | 1977 | rm -rf \$TMPD
|
---|
[460] | 1978 | EOF
|
---|
[1177] | 1979 | } elsif ($pbos->{'type'} eq "ebuild") {
|
---|
[586] | 1980 | # make a pbscript to generate links to latest version
|
---|
| 1981 | print PBS << "EOF";
|
---|
| 1982 | #!/bin/bash
|
---|
| 1983 | # Prepare a script to create correct links
|
---|
| 1984 | for p in $src; do
|
---|
| 1985 | echo \$p | grep -q '.ebuild'
|
---|
| 1986 | if [ \$\? -eq 0 ]; then
|
---|
| 1987 | j=`basename \$p`
|
---|
| 1988 | pp=`echo \$j | cut -d'-' -f1`
|
---|
| 1989 | ln -sf \$j \$pp.ebuild
|
---|
| 1990 | fi
|
---|
| 1991 | done
|
---|
| 1992 | EOF
|
---|
[429] | 1993 | }
|
---|
| 1994 | close(PBS);
|
---|
[1189] | 1995 | chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript.$$";
|
---|
[90] | 1996 | } else {
|
---|
| 1997 | return;
|
---|
[22] | 1998 | }
|
---|
[239] | 1999 |
|
---|
[1143] | 2000 | # Useless for VE
|
---|
[1179] | 2001 | my $nport = pb_get_port($sshport,$pbos,$cmt) if ($cmt !~ /^VE/);
|
---|
[320] | 2002 |
|
---|
[136] | 2003 | # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
|
---|
[132] | 2004 | $tdir =~ s|\$ENV.+\}/||;
|
---|
| 2005 |
|
---|
[1217] | 2006 | my $tm = "";
|
---|
[1176] | 2007 | if ($cmt =~ /^(V|R)M/) {
|
---|
[1218] | 2008 | $tm = "sleep $vtmout" if (defined $vtmout);
|
---|
[883] | 2009 | }
|
---|
[320] | 2010 |
|
---|
[1374] | 2011 | # ssh communication if not VE or CPAN
|
---|
[349] | 2012 | # should use a hash instead...
|
---|
[320] | 2013 | my ($shcmd,$cpcmd,$cptarget,$cp2target);
|
---|
[1374] | 2014 | if ($cmt =~ /^VE/) {
|
---|
[320] | 2015 | my $tp = $vepath->{$ENV{'PBPROJ'}};
|
---|
[1179] | 2016 | my $tpdir = "$tp/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
|
---|
[681] | 2017 | my ($ptr) = pb_conf_get("vetype");
|
---|
| 2018 | my $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
| 2019 | if ($vetype eq "chroot") {
|
---|
[1179] | 2020 | $shcmd = "sudo /usr/sbin/chroot $tpdir /bin/su - $mac -c ";
|
---|
[681] | 2021 | } elsif ($vetype eq "schroot") {
|
---|
| 2022 | $shcmd = "schroot $tp -u $mac -- ";
|
---|
| 2023 | }
|
---|
[1179] | 2024 | $cpcmd = "sudo /bin/cp -r ";
|
---|
[681] | 2025 | # We need to get the home dir of the target account to deliver in the right place
|
---|
| 2026 | open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd";
|
---|
| 2027 | my $homedir = "";
|
---|
| 2028 | while (<PASS>) {
|
---|
| 2029 | my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
|
---|
| 2030 | $homedir = $c6 if ($c1 =~ /^$mac$/);
|
---|
| 2031 | pb_log(3,"Homedir: $homedir - account: $c6\n");
|
---|
| 2032 | }
|
---|
| 2033 | close(PASS);
|
---|
| 2034 | $cptarget = "$tpdir/$homedir/$tdir";
|
---|
[773] | 2035 | if ($cmt eq "VEbuild") {
|
---|
[681] | 2036 | $cp2target = "$tpdir/$homedir/$bdir";
|
---|
| 2037 | }
|
---|
| 2038 | pb_log(2,"On VE using $cptarget as target dir to copy to\n");
|
---|
[1374] | 2039 | } elsif ($cmt =~ /^CPAN/) {
|
---|
[1382] | 2040 | my $ftpput = pb_check_req("ncftpput",1);
|
---|
| 2041 | my $ftpget = pb_check_req("wget",1);
|
---|
[1374] | 2042 | my ($cpanuser,$cpanpasswd) = pb_conf_get("cpanuser","cpanpasswd");
|
---|
| 2043 | my ($cpansubdir) = pb_conf_get_if("cpansubdir");
|
---|
| 2044 | $shcmd = "$ftpget --post-data \'HIDDENNAME=".$cpanuser;
|
---|
| 2045 | $shcmd .= "&user=".$cpanuser;
|
---|
| 2046 | $shcmd .= "&password=".$cpanpasswd;
|
---|
| 2047 | $shcmd .= "&SUBMIT_pause99_add_uri_upload=\"Upload the checked files\"";
|
---|
| 2048 | $shcmd .= "&pause99_add_uri_subdirtext=".$cpansubdir if (defined $cpansubdir);
|
---|
| 2049 | foreach my $s (split(/ /,$src)) {
|
---|
| 2050 | $shcmd .= "&pause99_add_uri_upload=".basename($s);
|
---|
| 2051 | }
|
---|
| 2052 | $shcmd .= "'";
|
---|
| 2053 | $cpcmd = "$ftpput $host $dir";
|
---|
| 2054 | $cptarget = "CPAN";
|
---|
| 2055 | } else {
|
---|
| 2056 | my $keyfile = pb_ssh_get(0);
|
---|
[1382] | 2057 | my $sshcmd = pb_check_req("ssh",1);
|
---|
| 2058 | my $scpcmd = pb_check_req("scp",1);
|
---|
[1374] | 2059 | $shcmd = "$sshcmd -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
|
---|
| 2060 | $cpcmd = "$scpcmd -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
|
---|
| 2061 | $cptarget = "$mac:$tdir";
|
---|
| 2062 | if ($cmt =~ /^(V|R)Mbuild/) {
|
---|
| 2063 | $cp2target = "$mac:$bdir";
|
---|
| 2064 | }
|
---|
[320] | 2065 | }
|
---|
[1374] | 2066 |
|
---|
[471] | 2067 | my $logres = "";
|
---|
| 2068 | # Do not touch when just announcing
|
---|
[1374] | 2069 | if (($cmt ne "Announce") && ($cmt ne "CPAN")) {
|
---|
[908] | 2070 | 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");
|
---|
[471] | 2071 | } else {
|
---|
| 2072 | $logres = "> ";
|
---|
| 2073 | }
|
---|
[320] | 2074 | pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
|
---|
[444] | 2075 |
|
---|
[681] | 2076 | # For VE we need to change the owner manually
|
---|
[772] | 2077 | if ($cmt =~ /^VE/) {
|
---|
[681] | 2078 | pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
|
---|
| 2079 | }
|
---|
| 2080 |
|
---|
[1140] | 2081 | # Use the right script name depending on context
|
---|
| 2082 | my $pbscript;
|
---|
[1189] | 2083 | if (($cmt =~ /^(V[EM]|RM)/) || ($cmt =~ /Packages/)){
|
---|
[1140] | 2084 | $pbscript = "pbscript.$$";
|
---|
| 2085 | } else {
|
---|
| 2086 | $pbscript = "pbscript";
|
---|
| 2087 | }
|
---|
| 2088 |
|
---|
[1374] | 2089 | # It's already ready for CPAN
|
---|
[1383] | 2090 | my $shcmdbase = $shcmd;
|
---|
[1374] | 2091 | if ($cmt !~ /^CPAN/) {
|
---|
[1383] | 2092 | $shcmd .= " \"echo \'cd $tdir ; if [ -x $pbscript ]; then ./$pbscript; fi ; rm -f ./$pbscript\' | bash\"";
|
---|
[1374] | 2093 | }
|
---|
[1386] | 2094 | my $cmdverb = "verbose";
|
---|
[1388] | 2095 | if (($cmt eq "Announce") || ($cmt eq "CPAN")) {
|
---|
[1386] | 2096 | $cmdverb = undef;
|
---|
| 2097 | }
|
---|
| 2098 | pb_system("$shcmd","Executing pbscript on $cptarget if needed",$cmdverb);
|
---|
[1176] | 2099 | if ($cmt =~ /^(V[EM]|RM)build/) {
|
---|
| 2100 | # Get back info on pkg produced, compute their name and get them from the VM/RM
|
---|
[1189] | 2101 | pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$ 2> /dev/null","Get package names in $cp2target");
|
---|
[681] | 2102 | # For VE we need to change the owner manually
|
---|
[772] | 2103 | if ($cmt eq "VEbuild") {
|
---|
[1138] | 2104 | pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$","Adapt owner in $tdir to $UID");
|
---|
[681] | 2105 | }
|
---|
[1138] | 2106 | if (not -f "$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$") {
|
---|
[1176] | 2107 | pb_log(0,"Problem with VM/RM $v on $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$");
|
---|
[1156] | 2108 | } else {
|
---|
| 2109 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$";
|
---|
| 2110 | my $src = <KEEP>;
|
---|
| 2111 | chomp($src);
|
---|
| 2112 | close(KEEP);
|
---|
| 2113 | unlink("$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.$$");
|
---|
[1138] | 2114 |
|
---|
[1156] | 2115 | $src =~ s/^ *//;
|
---|
[1179] | 2116 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
|
---|
[1156] | 2117 | # Change pgben to make the next send2target happy
|
---|
| 2118 | my $made = "";
|
---|
| 2119 |
|
---|
[1176] | 2120 | # For VM/RM we don't want shell expansion to hapen locally but remotely
|
---|
[1156] | 2121 | my $delim = '\'';
|
---|
| 2122 | if ($cmt =~ /^VEbuild/) {
|
---|
| 2123 | # For VE we need to support shell expansion locally
|
---|
| 2124 | $delim = "";
|
---|
| 2125 | }
|
---|
[1138] | 2126 |
|
---|
[1189] | 2127 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}-$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
[1156] | 2128 | foreach my $p (split(/ +/,$src)) {
|
---|
| 2129 | my $j = basename($p);
|
---|
[1179] | 2130 | pb_system("$cpcmd $cp2target/$delim$p$delim $ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} 2> /dev/null","Recovery of package $j in $ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
|
---|
| 2131 | $made="$made $pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/$j"; # if (($pbos->{'type'} ne "rpm") || ($j !~ /.src.rpm$/));
|
---|
[1156] | 2132 | }
|
---|
| 2133 | print KEEP "$made\n";
|
---|
| 2134 | close(KEEP);
|
---|
[1383] | 2135 | pb_system("$shcmdbase \"rm -rf $tdir $bdir\"","$cmt cleanup");
|
---|
[1138] | 2136 |
|
---|
[1156] | 2137 | # Sign packages locally
|
---|
[1278] | 2138 | pb_sign_pkgs($pbos,$made);
|
---|
[1156] | 2139 |
|
---|
| 2140 | # We want to send them to the ssh account so overwrite what has been done before
|
---|
| 2141 | undef $pbaccount;
|
---|
| 2142 | pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[1179] | 2143 | pb_send2target("Packages",$pbos->{'name'}."-".$pbos->{'version'}."-".$pbos->{'arch'},$vmexist,$vmpid);
|
---|
| 2144 | pb_rm_rf("$ENV{'PBBUILDDIR'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
|
---|
[623] | 2145 | }
|
---|
[108] | 2146 | }
|
---|
[1425] | 2147 | unlink("$ENV{'PBDESTDIR'}/pbscript.$$") if ((($cmt =~ /^(V[ME]|RM)/) || ($cmt =~ /Packages/)) && ($pbkeep eq 0));
|
---|
[1139] | 2148 |
|
---|
[442] | 2149 | pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[772] | 2150 | if ((! $vmexist) && ($cmt =~ /^VM/)) {
|
---|
[748] | 2151 | # If in setupvm then takes a snapshot just before halting
|
---|
| 2152 | if ($snapme != 0) {
|
---|
| 2153 | my ($vmmonport,$vmtype) = pb_conf_get("vmmonport","vmtype");
|
---|
| 2154 | # For monitoring control
|
---|
| 2155 | if ((($vmtype->{$ENV{'PBPROJ'}}) eq "kvm") || (($vmtype->{$ENV{'PBPROJ'}}) eq "qemu")) {
|
---|
[1153] | 2156 | eval
|
---|
| 2157 | {
|
---|
[804] | 2158 | require Net::Telnet;
|
---|
[1153] | 2159 | Net::Telnet->import();
|
---|
| 2160 | };
|
---|
| 2161 | if ($@) {
|
---|
| 2162 | # Net::Telnet not found
|
---|
| 2163 | pb_log(1,"ADVISE: Install Net::Telnet to benefit from monitoring control and snapshot feature.\nWARNING: No snapshot created");
|
---|
| 2164 | } else {
|
---|
| 2165 | my $t = new Net::Telnet (Timeout => 120, Host => "localhost", Port => $vmmonport->{$ENV{'PBPROJ'}}) || die "Unable to dialog on the monitor";
|
---|
| 2166 | # move to monitor mode
|
---|
| 2167 | my @lines = $t->cmd("c");
|
---|
| 2168 | # Create a snapshot named pb
|
---|
| 2169 | @lines = $t->cmd("savevm pb");
|
---|
| 2170 | # Write the new status in the VM
|
---|
| 2171 | @lines = $t->cmd("commit all");
|
---|
| 2172 | # End
|
---|
| 2173 | @lines = $t->cmd("quit");
|
---|
| 2174 | }
|
---|
[748] | 2175 | }
|
---|
| 2176 | }
|
---|
[914] | 2177 | my $hoption = "-p";
|
---|
[1197] | 2178 | my $hpath = pb_distro_get_param($pbos,pb_conf_get("ospathcmd-halt"));
|
---|
[1194] | 2179 | # Solaris doesn't support -p of halt
|
---|
[1177] | 2180 | if ($pbos->{'type'} eq "pkg") {
|
---|
[1091] | 2181 | $hoption = "" ;
|
---|
| 2182 | }
|
---|
[1383] | 2183 | pb_system("$shcmdbase \"sudo $hpath $hoption \"; $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
|
---|
[442] | 2184 | }
|
---|
[772] | 2185 | if (($cmt =~ /^VE/) && ($snapme != 0)) {
|
---|
[1179] | 2186 | my $tpdir = "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}";
|
---|
| 2187 | pb_system("sudo tar cz -C $tpdir -f $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz .","Creating a snapshot of $tpdir");
|
---|
[752] | 2188 | }
|
---|
[9] | 2189 | }
|
---|
[16] | 2190 |
|
---|
[320] | 2191 | sub pb_script2v {
|
---|
[142] | 2192 | my $pbscript=shift;
|
---|
[320] | 2193 | my $vtype=shift;
|
---|
[1138] | 2194 | my $pbforce=shift || 0; # Force stop of VM. Default not.
|
---|
[1176] | 2195 | my $vm1=shift || undef; # Only that VM/VE/RM to treat. Default all.
|
---|
[1138] | 2196 | my $snapme=shift || 0; # Do we have to create a snapshot. Default not.
|
---|
[442] | 2197 | my $vm;
|
---|
| 2198 | my $all;
|
---|
[141] | 2199 |
|
---|
[767] | 2200 | pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$pbforce,".Dumper($vm1).",$snapme)\n");
|
---|
[1176] | 2201 | # Prepare the script to be executed on the VM/VE/RM
|
---|
[1138] | 2202 | # in $ENV{'PBDESTDIR'}/pbscript.$$
|
---|
| 2203 | if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript.$$")) {
|
---|
| 2204 | copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript.$$") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript.$$";
|
---|
| 2205 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript.$$";
|
---|
[142] | 2206 | }
|
---|
[141] | 2207 |
|
---|
[442] | 2208 | if (not defined $vm1) {
|
---|
[772] | 2209 | ($vm,$all) = pb_get2v($vtype);
|
---|
[442] | 2210 | } else {
|
---|
| 2211 | @$vm = ($vm1);
|
---|
| 2212 | }
|
---|
[320] | 2213 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
[142] | 2214 |
|
---|
[141] | 2215 | foreach my $v (@$vm) {
|
---|
[968] | 2216 | # Launch VM/VE
|
---|
| 2217 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,$snapme,$pbsnap);
|
---|
[755] | 2218 |
|
---|
[320] | 2219 | if ($vtype eq "vm") {
|
---|
[442] | 2220 | pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[141] | 2221 |
|
---|
[1176] | 2222 | # Skip that VM/RM if something went wrong
|
---|
[442] | 2223 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
| 2224 |
|
---|
| 2225 | # If force stopping the VM then reset vmexist
|
---|
[748] | 2226 | if ($pbforce == 1) {
|
---|
[442] | 2227 | $vmpid = $vmexist;
|
---|
| 2228 | $vmexist = 0;
|
---|
| 2229 | }
|
---|
[670] | 2230 | } else {
|
---|
| 2231 | #VE
|
---|
| 2232 | $vmexist = 0;
|
---|
| 2233 | $vmpid = 0;
|
---|
[320] | 2234 | }
|
---|
[274] | 2235 |
|
---|
[1176] | 2236 | # Gather all required files to send them to the VM/VE/RM
|
---|
[320] | 2237 | # and launch the build through pbscript
|
---|
[442] | 2238 | pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[748] | 2239 | pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid,$snapme);
|
---|
[169] | 2240 |
|
---|
[142] | 2241 | }
|
---|
| 2242 | }
|
---|
| 2243 |
|
---|
[320] | 2244 | sub pb_launchv {
|
---|
| 2245 | my $vtype = shift;
|
---|
| 2246 | my $v = shift;
|
---|
[1176] | 2247 | my $create = shift || 0; # By default do not create a VM/VE/RM
|
---|
| 2248 | my $snapme = shift || 0; # By default do not snap a VM/VE/RM
|
---|
[1349] | 2249 | my $usesnap = shift || 1; # By default study the usage of the snapshot feature of VM/VE/RM
|
---|
[310] | 2250 |
|
---|
[773] | 2251 | # If creation or snapshot creation mode, no snapshot usable
|
---|
| 2252 | if (($create == 1) || ($snapme == 1)) {
|
---|
| 2253 | $usesnap = 0;
|
---|
| 2254 | }
|
---|
| 2255 |
|
---|
| 2256 | pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create,$snapme,$usesnap)\n");
|
---|
[1176] | 2257 | die "No VM/VE/RM defined, unable to launch" if (not defined $v);
|
---|
[320] | 2258 | # Keep only the first VM in case many were given
|
---|
| 2259 | $v =~ s/,.*//;
|
---|
[310] | 2260 |
|
---|
[1179] | 2261 | my $pbos = pb_distro_get_context($v);
|
---|
[1348] | 2262 |
|
---|
[320] | 2263 | # Launch the VMs/VEs
|
---|
| 2264 | if ($vtype eq "vm") {
|
---|
| 2265 | die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
|
---|
[310] | 2266 |
|
---|
[940] | 2267 | # TODO: vmmonport should be optional
|
---|
[1249] | 2268 | my ($ptr,$ptr2,$vmpath,$vmport,$vms,$vmmonport) = pb_conf_get("vmtype","vmcmd","vmpath","vmport","vmsize","vmmonport");
|
---|
[1322] | 2269 | my ($vmopt,$vmmm,$vmtmout,$vmsnap,$vmbuildtm) = pb_conf_get_if("vmopt","vmmem","vmtmout","vmsnap","vmbuildtm");
|
---|
[1249] | 2270 | my $vmsize = pb_distro_get_param($pbos,$vms);
|
---|
[320] | 2271 |
|
---|
| 2272 | my $vmtype = $ptr->{$ENV{'PBPROJ'}};
|
---|
[1072] | 2273 | my $vmcmd = $ptr2->{$ENV{'PBPROJ'}};
|
---|
[1124] | 2274 |
|
---|
| 2275 | if (defined $opts{'g'}) {
|
---|
| 2276 | if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
|
---|
[1158] | 2277 | $ENV{'PBVMOPT'} = "--nographic";
|
---|
[1124] | 2278 | }
|
---|
| 2279 | }
|
---|
[320] | 2280 | if (not defined $ENV{'PBVMOPT'}) {
|
---|
| 2281 | $ENV{'PBVMOPT'} = "";
|
---|
[310] | 2282 | }
|
---|
[639] | 2283 | # Save the current status for later restoration
|
---|
| 2284 | $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
|
---|
[483] | 2285 | # Set a default timeout of 2 minutes
|
---|
| 2286 | if (not defined $ENV{'PBVMTMOUT'}) {
|
---|
| 2287 | $ENV{'PBVMTMOUT'} = "120";
|
---|
| 2288 | }
|
---|
| 2289 | if (defined $vmopt->{$v}) {
|
---|
| 2290 | $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
|
---|
| 2291 | } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
|
---|
[320] | 2292 | $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
|
---|
| 2293 | }
|
---|
[773] | 2294 |
|
---|
[1143] | 2295 | # How much memory to allocate for VMs
|
---|
[1322] | 2296 | my $vmmem = pb_distro_get_param($pbos,$vmmm);
|
---|
| 2297 | if (defined $vmmem) {
|
---|
| 2298 | $ENV{'PBVMOPT'} .= " -m $vmmem";
|
---|
[1143] | 2299 | }
|
---|
| 2300 |
|
---|
[773] | 2301 | # Are we allowed to use snapshot feature
|
---|
| 2302 | if ($usesnap == 1) {
|
---|
[748] | 2303 | if ((defined $vmsnap->{$v}) && ($vmsnap->{$v} =~ /true/i)) {
|
---|
[1070] | 2304 | $ENV{'PBVMOPT'} .= " -snapshot";
|
---|
[748] | 2305 | } elsif ((defined $vmsnap->{$ENV{'PBPROJ'}}) && ($vmsnap->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
[1070] | 2306 | $ENV{'PBVMOPT'} .= " -snapshot";
|
---|
[748] | 2307 | } elsif ($pbsnap eq 1) {
|
---|
[1070] | 2308 | $ENV{'PBVMOPT'} .= " -snapshot";
|
---|
[748] | 2309 | }
|
---|
[767] | 2310 | }
|
---|
| 2311 | if ($snapme != 0) {
|
---|
[748] | 2312 | if (($vmtype eq "kvm") || ($vmtype eq "qemu")) {
|
---|
[1138] | 2313 | # Configure the monitoring to automate the creation of the 'pb' snapshot
|
---|
[1070] | 2314 | $ENV{'PBVMOPT'} .= " -serial mon:telnet::$vmmonport->{$ENV{'PBPROJ'}},server,nowait";
|
---|
[773] | 2315 | # In that case no snapshot call needed
|
---|
[1070] | 2316 | $ENV{'PBVMOPT'} =~ s/ -snapshot//;
|
---|
[748] | 2317 | }
|
---|
| 2318 | }
|
---|
[483] | 2319 | if (defined $vmtmout->{$v}) {
|
---|
| 2320 | $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
|
---|
| 2321 | } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
|
---|
| 2322 | $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
|
---|
| 2323 | }
|
---|
[1179] | 2324 | my $nport = pb_get_port($vmport,$pbos,$vtype);
|
---|
[320] | 2325 |
|
---|
| 2326 | my $cmd;
|
---|
| 2327 | my $vmm; # has to be used for pb_check_ps
|
---|
[677] | 2328 | if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
|
---|
| 2329 | $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
|
---|
[792] | 2330 | if (($create != 0) || (defined $iso)) {
|
---|
[677] | 2331 | $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
|
---|
[320] | 2332 | }
|
---|
[748] | 2333 | # Always redirect the network and always try to use a 'pb' snapshot
|
---|
[1340] | 2334 | #$cmd = "$vmcmd $ENV{'PBVMOPT'} -net user,hostfwd=tcp:$nport:10.0.2.15:22 -loadvm pb $vmm"
|
---|
[1381] | 2335 | $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
|
---|
[320] | 2336 | } elsif ($vmtype eq "xen") {
|
---|
| 2337 | } elsif ($vmtype eq "vmware") {
|
---|
[310] | 2338 | } else {
|
---|
[320] | 2339 | die "VM of type $vmtype not supported. Report to the dev team";
|
---|
[310] | 2340 | }
|
---|
[639] | 2341 | # Restore the ENV VAR Value
|
---|
[641] | 2342 | $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
|
---|
[639] | 2343 |
|
---|
[320] | 2344 | my ($tmpcmd,$void) = split(/ +/,$cmd);
|
---|
| 2345 | my $vmexist = pb_check_ps($tmpcmd,$vmm);
|
---|
| 2346 | my $vmpid = 0;
|
---|
| 2347 | if (! $vmexist) {
|
---|
| 2348 | if ($create != 0) {
|
---|
[653] | 2349 | die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
|
---|
[677] | 2350 | if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
|
---|
[1127] | 2351 | my $command = pb_check_req("qemu-img",0);
|
---|
[1249] | 2352 | pb_system("$command create -f qcow2 $vmm $vmsize","Creating the QEMU VM");
|
---|
[320] | 2353 | } elsif ($vmtype eq "vmware") {
|
---|
| 2354 | } else {
|
---|
| 2355 | }
|
---|
| 2356 | }
|
---|
| 2357 | if (! -f "$vmm") {
|
---|
| 2358 | pb_log(0,"Unable to find VM $vmm\n");
|
---|
| 2359 | } else {
|
---|
[1153] | 2360 | # Is the SSH port free? if not kill the existing process using it after a build timeout period
|
---|
| 2361 | my $vmssh = pb_check_ps($tmpcmd,"tcp:$nport:10.0.2.15:22");
|
---|
| 2362 | if ($vmssh) {
|
---|
| 2363 | my $buildtm = $ENV{'PBVMTMOUT'};
|
---|
| 2364 | if (defined $vmbuildtm->{$v}) {
|
---|
| 2365 | $buildtm = $vmbuildtm->{$v};
|
---|
| 2366 | } elsif (defined $vmbuildtm->{$ENV{'PBPROJ'}}) {
|
---|
| 2367 | $buildtm = $vmbuildtm->{$ENV{'PBPROJ'}};
|
---|
| 2368 | }
|
---|
| 2369 |
|
---|
| 2370 | sleep $buildtm;
|
---|
| 2371 | pb_log(0,"WARNING: Killing the process ($vmssh) using port $nport (previous failed VM ?)\n");
|
---|
| 2372 | kill 15,$vmssh;
|
---|
[1154] | 2373 | # Let it time to exit
|
---|
| 2374 | sleep 5;
|
---|
[1153] | 2375 | }
|
---|
[320] | 2376 | pb_system("$cmd &","Launching the VM $vmm");
|
---|
[1153] | 2377 | # Using system allows to kill it externaly if needed
|
---|
[483] | 2378 | pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
|
---|
[320] | 2379 | $vmpid = pb_check_ps($tmpcmd,$vmm);
|
---|
[357] | 2380 | pb_log(0,"VM $vmm launched (pid $vmpid)\n");
|
---|
[320] | 2381 | }
|
---|
[310] | 2382 | } else {
|
---|
[320] | 2383 | pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
|
---|
[310] | 2384 | }
|
---|
[442] | 2385 | pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
|
---|
[320] | 2386 | return($vmexist,$vmpid);
|
---|
[1176] | 2387 | } elsif ($vtype eq "ve") {
|
---|
[1360] | 2388 | # Force the creation of the VE and no snapshot usable
|
---|
[1388] | 2389 | pb_ve_launch($v,$create,$usesnap);
|
---|
[1176] | 2390 | } else {
|
---|
| 2391 | # RM here
|
---|
| 2392 | # Get distro context
|
---|
[1177] | 2393 | my $pbos = pb_distro_get_context($v);
|
---|
[1176] | 2394 |
|
---|
| 2395 | # Get RM context
|
---|
| 2396 | my ($ptr,$rmpath) = pb_conf_get("rmtype","rmpath");
|
---|
| 2397 |
|
---|
| 2398 | # Nothing more to do for RM. No real launch
|
---|
| 2399 | # For the moment we support the RM is already running
|
---|
| 2400 | # For ProLiant may be able to power them on if needed later on as an example.
|
---|
[141] | 2401 | }
|
---|
| 2402 | }
|
---|
[142] | 2403 |
|
---|
[639] | 2404 | # Return string for date synchro
|
---|
[772] | 2405 | sub pb_date2v {
|
---|
[639] | 2406 |
|
---|
| 2407 | my $vtype = shift;
|
---|
[1216] | 2408 | my $pbos = shift;
|
---|
[639] | 2409 |
|
---|
[986] | 2410 | my ($ntp) = pb_conf_get_if($vtype."ntp");
|
---|
| 2411 | my $vntp = $ntp->{$ENV{'PBPROJ'}} if (defined $ntp);
|
---|
[1221] | 2412 | my $ntpline = undef;
|
---|
[639] | 2413 |
|
---|
| 2414 | if (defined $vntp) {
|
---|
[1221] | 2415 | # ntp command depends on pbos
|
---|
| 2416 | my $vntpcmd = pb_distro_get_param($pbos,pb_conf_get($vtype."ntpcmd"));
|
---|
[652] | 2417 | $ntpline = "sudo $vntpcmd $vntp";
|
---|
[639] | 2418 | }
|
---|
| 2419 | # Force new date to be in the future compared to the date
|
---|
| 2420 | # of the host by adding 1 minute
|
---|
| 2421 | my @date=pb_get_date();
|
---|
| 2422 | $date[1]++;
|
---|
| 2423 | my $upddate = strftime("%m%d%H%M%Y", @date);
|
---|
[1179] | 2424 | my $dateline = "sudo /bin/date $upddate";
|
---|
[1190] | 2425 | if (defined $ntpline) {
|
---|
| 2426 | return($ntpline);
|
---|
| 2427 | } else {
|
---|
| 2428 | return($dateline);
|
---|
[639] | 2429 | }
|
---|
[1190] | 2430 | }
|
---|
[639] | 2431 |
|
---|
[320] | 2432 | sub pb_build2v {
|
---|
[118] | 2433 |
|
---|
[320] | 2434 | my $vtype = shift;
|
---|
[772] | 2435 | my $action = shift || "build";
|
---|
[142] | 2436 |
|
---|
[772] | 2437 | my ($v,$all) = pb_get2v($vtype);
|
---|
[320] | 2438 |
|
---|
| 2439 | # Send tar files when we do a global generation
|
---|
[772] | 2440 | pb_build2ssh() if (($all == 1) && ($action eq "build"));
|
---|
[320] | 2441 |
|
---|
[1143] | 2442 | # Adapt // mode to memory size
|
---|
| 2443 | $pbparallel = pb_set_parallel($vtype);
|
---|
| 2444 |
|
---|
[320] | 2445 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
[1176] | 2446 | my $pm;
|
---|
| 2447 | if (defined $pbparallel) {
|
---|
| 2448 | $pm = new Parallel::ForkManager($pbparallel);
|
---|
[320] | 2449 |
|
---|
[1176] | 2450 | # Set which port the VM/RM will use to communicate
|
---|
| 2451 | $pm->run_on_start(\&pb_set_port);
|
---|
| 2452 | }
|
---|
[1143] | 2453 |
|
---|
| 2454 | my $counter = 0;
|
---|
[320] | 2455 | foreach my $v (@$v) {
|
---|
[1143] | 2456 | $counter++;
|
---|
[1153] | 2457 | # Modulo 2 * pbparallel (to avoid synchronization problems)
|
---|
[1176] | 2458 | $counter = 1 if ((defined $pbparallel) && ($counter > 2 * $pbparallel));
|
---|
[1143] | 2459 | $pm->start($counter) and next if (defined $pbparallel);
|
---|
[1176] | 2460 | # Prepare the script to be executed on the VM/VE/RM
|
---|
[1138] | 2461 | # in $ENV{'PBDESTDIR'}/pbscript.$$
|
---|
| 2462 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript.$$") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript.$$";
|
---|
[652] | 2463 | print SCRIPT "#!/bin/bash\n";
|
---|
[721] | 2464 |
|
---|
| 2465 | # Transmit the verbosity level to the virtual env/mach.
|
---|
| 2466 | my $verbose = "";
|
---|
| 2467 | my $i = 0; # minimal debug level
|
---|
| 2468 | while ($i lt $pbdebug) {
|
---|
| 2469 | $verbose .= "-v ";
|
---|
| 2470 | $i++;
|
---|
| 2471 | }
|
---|
| 2472 | # Activate script verbosity if at least 2 for pbdebug
|
---|
| 2473 | print SCRIPT "set -x\n" if ($i gt 1);
|
---|
| 2474 | # Quiet if asked to be so on the original system
|
---|
| 2475 | $verbose = "-q" if ($pbdebug eq -1);
|
---|
| 2476 |
|
---|
[652] | 2477 | print SCRIPT "echo ... Execution needed\n";
|
---|
| 2478 | print SCRIPT "# This is in directory delivery\n";
|
---|
| 2479 | print SCRIPT "# Setup the variables required for building\n";
|
---|
| 2480 | print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
|
---|
[686] | 2481 |
|
---|
[772] | 2482 | if ($action eq "build") {
|
---|
| 2483 | print SCRIPT "# Preparation for pb\n";
|
---|
| 2484 | print SCRIPT "mv .pbrc \$HOME\n";
|
---|
| 2485 | print SCRIPT "cd ..\n";
|
---|
| 2486 | }
|
---|
| 2487 |
|
---|
[686] | 2488 | # VE needs a good /proc
|
---|
[687] | 2489 | if ($vtype eq "ve") {
|
---|
[1179] | 2490 | print SCRIPT "sudo /bin/mount -t proc /proc /proc\n";
|
---|
[686] | 2491 | }
|
---|
[652] | 2492 |
|
---|
[1216] | 2493 | # Get distro context
|
---|
| 2494 | my $pbos = pb_distro_get_context($v);
|
---|
| 2495 |
|
---|
| 2496 | my $ntpline = pb_date2v($vtype,$pbos);
|
---|
[652] | 2497 | print SCRIPT "# Time sync\n";
|
---|
[725] | 2498 | print SCRIPT "echo 'setting up date with '";
|
---|
[1190] | 2499 | print SCRIPT "echo $ntpline\n";
|
---|
| 2500 | print SCRIPT "$ntpline\n";
|
---|
[721] | 2501 | # Use potential local proxy declaration in case we need it to download repo, pkgs, ...
|
---|
| 2502 | if (defined $ENV{'http_proxy'}) {
|
---|
| 2503 | print SCRIPT "export http_proxy=\"$ENV{'http_proxy'}\"\n";
|
---|
| 2504 | }
|
---|
[652] | 2505 |
|
---|
[721] | 2506 | if (defined $ENV{'ftp_proxy'}) {
|
---|
| 2507 | print SCRIPT "export ftp_proxy=\"$ENV{'ftp_proxy'}\"\n";
|
---|
[652] | 2508 | }
|
---|
| 2509 |
|
---|
[772] | 2510 | # Get list of packages to build/test and get some ENV vars as well
|
---|
| 2511 | my $ptr = pb_get_pkg();
|
---|
| 2512 | @pkgs = @$ptr;
|
---|
| 2513 | my $p = join(' ',@pkgs) if (@pkgs);
|
---|
| 2514 | print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
|
---|
| 2515 | print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
|
---|
| 2516 | print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
|
---|
[721] | 2517 |
|
---|
| 2518 | # We may need to do some other tasks before building. Read a script here to finish setup
|
---|
[772] | 2519 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".pre") {
|
---|
| 2520 | print SCRIPT "# Special pre-instructions to be launched\n";
|
---|
| 2521 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".pre");
|
---|
[721] | 2522 | }
|
---|
| 2523 |
|
---|
[772] | 2524 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre") {
|
---|
| 2525 | print SCRIPT "# Special pre-$action instructions to be launched\n";
|
---|
| 2526 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.pre");
|
---|
| 2527 | }
|
---|
| 2528 |
|
---|
| 2529 | print SCRIPT "# $action\n";
|
---|
| 2530 | print SCRIPT "echo $action"."ing packages on $vtype...\n";
|
---|
| 2531 |
|
---|
| 2532 | if (($action eq "test") && (! -x "$ENV{'PBDESTDIR'}/pbtest")) {
|
---|
| 2533 | die "No test script ($ENV{'PBDESTDIR'}/pbtest) found when in test mode. Aborting ...";
|
---|
| 2534 | }
|
---|
| 2535 | print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} $action"."2pkg $p\n";
|
---|
| 2536 |
|
---|
[687] | 2537 | if ($vtype eq "ve") {
|
---|
[1179] | 2538 | print SCRIPT "sudo /bin/umount /proc\n";
|
---|
[686] | 2539 | }
|
---|
[721] | 2540 |
|
---|
| 2541 | # We may need to do some other tasks after building. Read a script here to exit properly
|
---|
[772] | 2542 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype"."$action.post") {
|
---|
| 2543 | print SCRIPT "# Special post-$action instructions to be launched\n";
|
---|
| 2544 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype"."$action.post");
|
---|
[721] | 2545 | }
|
---|
| 2546 |
|
---|
[772] | 2547 | if (-x "$ENV{'PBDESTDIR'}/pb$vtype".".post") {
|
---|
| 2548 | print SCRIPT "# Special post-instructions to be launched\n";
|
---|
| 2549 | print SCRIPT pb_get_content("$ENV{'PBDESTDIR'}/pb$vtype".".post");
|
---|
| 2550 | }
|
---|
| 2551 |
|
---|
[652] | 2552 | close(SCRIPT);
|
---|
[1138] | 2553 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript.$$";
|
---|
[652] | 2554 |
|
---|
[1176] | 2555 | # Launch the VM/VE/RM
|
---|
[755] | 2556 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
| 2557 |
|
---|
[1139] | 2558 |
|
---|
[320] | 2559 | if ($vtype eq "vm") {
|
---|
[1143] | 2560 | # Skip that VM if something went wrong
|
---|
[1139] | 2561 | if (($vmpid == 0) && ($vmexist == 0)) {
|
---|
| 2562 | $pm->finish if (defined $pbparallel);
|
---|
| 2563 | next;
|
---|
| 2564 | }
|
---|
[658] | 2565 | } else {
|
---|
[1176] | 2566 | # VE/RM
|
---|
[658] | 2567 | $vmexist = 0;
|
---|
| 2568 | $vmpid = 0;
|
---|
[118] | 2569 | }
|
---|
[320] | 2570 | # Gather all required files to send them to the VM/VE
|
---|
[347] | 2571 | # and launch the build through pbscript
|
---|
[357] | 2572 | pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
|
---|
[772] | 2573 | pb_send2target(uc($vtype).$action,"$v",$vmexist,$vmpid);
|
---|
[1139] | 2574 | $pm->finish if (defined $pbparallel);
|
---|
[105] | 2575 | }
|
---|
[1176] | 2576 | $pm->wait_all_children if (defined $pbparallel);
|
---|
[320] | 2577 | }
|
---|
[105] | 2578 |
|
---|
[262] | 2579 |
|
---|
[739] | 2580 | sub pb_clean {
|
---|
| 2581 |
|
---|
| 2582 | my $sleep=10;
|
---|
| 2583 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
| 2584 | die "Unable to get env var PBBUILDDIR" if (not defined $ENV{'PBBUILDDIR'});
|
---|
| 2585 | 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");
|
---|
| 2586 | sleep $sleep;
|
---|
| 2587 | pb_rm_rf($ENV{'PBDESTDIR'});
|
---|
| 2588 | pb_rm_rf($ENV{'PBBUILDDIR'});
|
---|
| 2589 | }
|
---|
| 2590 |
|
---|
[199] | 2591 | sub pb_newver {
|
---|
| 2592 |
|
---|
[204] | 2593 | die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
|
---|
[340] | 2594 |
|
---|
[366] | 2595 | # Need this call for PBDIR
|
---|
| 2596 | my ($scheme2,$uri) = pb_cms_init($pbinit);
|
---|
[361] | 2597 |
|
---|
[898] | 2598 | my ($pbconf,$pburl) = pb_conf_get("pbconfurl","pburl");
|
---|
[366] | 2599 | $uri = $pbconf->{$ENV{'PBPROJ'}};
|
---|
| 2600 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
| 2601 |
|
---|
[361] | 2602 | # Checking CMS repositories status
|
---|
[366] | 2603 | ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
|
---|
[340] | 2604 |
|
---|
| 2605 | if ($scheme !~ /^svn/) {
|
---|
[199] | 2606 | die "Only SVN is supported at the moment";
|
---|
| 2607 | }
|
---|
[483] | 2608 |
|
---|
[1469] | 2609 | my $res = pb_vcs_isdiff($scheme,$ENV{'PBROOTDIR'});
|
---|
[361] | 2610 | die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
|
---|
[358] | 2611 |
|
---|
[1469] | 2612 | $res = pb_vcs_isdiff($scheme2,$ENV{'PBDIR'});
|
---|
[361] | 2613 | die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
|
---|
[358] | 2614 |
|
---|
| 2615 | # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
|
---|
| 2616 | # we want to get for the root of the new URL
|
---|
| 2617 |
|
---|
[1381] | 2618 | my $oldver = $ENV{'PBROOTDIR'};
|
---|
| 2619 | $oldver =~ s|^$ENV{'PBCONFDIR'}||;
|
---|
[358] | 2620 |
|
---|
[1381] | 2621 | pb_log(2, "PBCONFDIR: $ENV{'PBCONFDIR'}\nPBROOTDIR: $ENV{'PBROOTDIR'}\n");
|
---|
| 2622 |
|
---|
| 2623 | my $newurl = "$uri/$newver";
|
---|
[366] | 2624 | # Should probably use projver in the old file
|
---|
[1381] | 2625 | my $oldvertxt= basename($oldver);
|
---|
| 2626 | my $newvertxt = basename($newver);
|
---|
[361] | 2627 |
|
---|
[366] | 2628 | # Duplicate and extract project-builder part
|
---|
[1381] | 2629 | pb_log(2,"Copying $uri/$oldver to $newurl\n");
|
---|
[1469] | 2630 | pb_vcs_copy($scheme,"$uri/$oldver",$newurl);
|
---|
[1381] | 2631 | pb_log(2,"Checkout $newurl to $ENV{'PBCONFDIR'}/$newver\n");
|
---|
[1469] | 2632 | pb_vcs_up($scheme,"$ENV{'PBCONFDIR'}");
|
---|
[361] | 2633 |
|
---|
[366] | 2634 | # Duplicate and extract project
|
---|
[1381] | 2635 | my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/$newver";
|
---|
[366] | 2636 |
|
---|
[1381] | 2637 | pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$oldver to $newurl2\n");
|
---|
[1469] | 2638 | pb_vcs_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$oldver",$newurl2);
|
---|
[366] | 2639 |
|
---|
[1381] | 2640 | my $tmp = $ENV{'PBDIR'};
|
---|
| 2641 | $tmp =~ s|$oldver$||;
|
---|
| 2642 | pb_log(2,"Checkout $newurl2 to $tmp/$newver\n");
|
---|
[1469] | 2643 | pb_vcs_up($scheme2,"$tmp");
|
---|
[1381] | 2644 |
|
---|
[361] | 2645 | # Update the .pb file
|
---|
[1381] | 2646 | open(FILE,"$ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb";
|
---|
| 2647 | open(OUT,"> $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb.new";
|
---|
[208] | 2648 | while(<FILE>) {
|
---|
[1420] | 2649 | if (/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldvertxt$/) {
|
---|
| 2650 | s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldvertxt$/projver $ENV{'PBPROJ'} = $newvertxt/;
|
---|
[1381] | 2651 | pb_log(0,"Changing projver from $oldvertxt to $newvertxt in $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb\n");
|
---|
| 2652 | }
|
---|
| 2653 | if (/^testver/) {
|
---|
| 2654 | s/^testver/#testver/;
|
---|
| 2655 | pb_log(0,"Commenting testver in $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
|
---|
| 2656 | }
|
---|
| 2657 | if (/^delivery/) {
|
---|
[1420] | 2658 | my $txt = $_;
|
---|
| 2659 | chomp($txt);
|
---|
| 2660 | pb_log(0,"Please check delivery ($txt) in $ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb\n");
|
---|
[1381] | 2661 | }
|
---|
[211] | 2662 | print OUT $_;
|
---|
[208] | 2663 | }
|
---|
| 2664 | close(FILE);
|
---|
[211] | 2665 | close(OUT);
|
---|
[1381] | 2666 | rename("$ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBCONFDIR'}/$newver/$ENV{'PBPROJ'}.pb");
|
---|
[363] | 2667 |
|
---|
[479] | 2668 | # Checking pbcl files
|
---|
| 2669 | foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
|
---|
[590] | 2670 | # Compute new pbcl file
|
---|
| 2671 | my $f2 = $f;
|
---|
[1381] | 2672 | $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBCONFDIR'}/$newver/|;
|
---|
[479] | 2673 | open(PBCL,$f) || die "Unable to open $f";
|
---|
| 2674 | my $foundnew = 0;
|
---|
| 2675 | while (<PBCL>) {
|
---|
[1381] | 2676 | $foundnew = 1 if (/^$newvertxt \(/);
|
---|
[479] | 2677 | }
|
---|
| 2678 | close(PBCL);
|
---|
[590] | 2679 | open(OUT,"> $f2") || die "Unable to write to $f2: $!";
|
---|
[479] | 2680 | open(PBCL,$f) || die "Unable to open $f";
|
---|
| 2681 | while (<PBCL>) {
|
---|
[1381] | 2682 | print OUT "$_" if (not /^$oldvertxt \(/);
|
---|
| 2683 | if ((/^$oldvertxt \(/) && ($foundnew == 0)) {
|
---|
| 2684 | print OUT "$newvertxt ($pbdate)\n";
|
---|
[479] | 2685 | print OUT "- TBD\n";
|
---|
| 2686 | print OUT "\n";
|
---|
[1381] | 2687 | pb_log(0,"WARNING: version $newvertxt not found in $f so added to $f2...\n") if ($foundnew == 0);
|
---|
[479] | 2688 | }
|
---|
| 2689 | }
|
---|
| 2690 | close(OUT);
|
---|
| 2691 | close(PBCL);
|
---|
| 2692 | }
|
---|
| 2693 |
|
---|
[1381] | 2694 | pb_log(2,"Checkin $ENV{'PBCONFDIR'}/$newver\n");
|
---|
| 2695 | pb_cms_checkin($scheme,"$ENV{'PBCONFDIR'}/$newver",undef);
|
---|
[199] | 2696 | }
|
---|
| 2697 |
|
---|
[293] | 2698 | #
|
---|
[1176] | 2699 | # Return the list of VMs/VEs/RMs we are working on
|
---|
[105] | 2700 | # $all is a flag to know if we return all of them
|
---|
| 2701 | # or only some (if all we publish also tar files in addition to pkgs
|
---|
| 2702 | #
|
---|
[772] | 2703 | sub pb_get2v {
|
---|
[91] | 2704 |
|
---|
[320] | 2705 | my $vtype = shift;
|
---|
| 2706 | my @v;
|
---|
[105] | 2707 | my $all = 0;
|
---|
[320] | 2708 | my $pbv = 'PBV';
|
---|
[1176] | 2709 | my $vlist = $vtype."list";
|
---|
[91] | 2710 |
|
---|
[320] | 2711 | # Get VM/VE list
|
---|
| 2712 | if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
|
---|
| 2713 | my ($ptr) = pb_conf_get($vlist);
|
---|
| 2714 | $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
|
---|
[105] | 2715 | $all = 1;
|
---|
[91] | 2716 | }
|
---|
[320] | 2717 | pb_log(2,"$vtype: $ENV{$pbv}\n");
|
---|
| 2718 | @v = split(/,/,$ENV{$pbv});
|
---|
| 2719 | return(\@v,$all);
|
---|
[91] | 2720 | }
|
---|
| 2721 |
|
---|
[1176] | 2722 | # Function to create a potentialy missing pb account on the VM/VE/RM, and adds it to sudo
|
---|
| 2723 | # Needs to use root account to connect to the VM/VE/RM
|
---|
[320] | 2724 | # pb will take your local public SSH key to access
|
---|
[1176] | 2725 | # the pb account in the VM/VE/RM later on if needed
|
---|
[772] | 2726 | sub pb_setup2v {
|
---|
[320] | 2727 |
|
---|
| 2728 | my $vtype = shift;
|
---|
[1140] | 2729 | my $sbx = shift || undef;
|
---|
[320] | 2730 |
|
---|
[772] | 2731 | my ($vm,$all) = pb_get2v($vtype);
|
---|
[353] | 2732 |
|
---|
[346] | 2733 | # Script generated
|
---|
| 2734 | my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
|
---|
[320] | 2735 |
|
---|
[1143] | 2736 | # Adapt // mode to memory size
|
---|
| 2737 | $pbparallel = pb_set_parallel($vtype);
|
---|
| 2738 |
|
---|
[1176] | 2739 | my $pm;
|
---|
| 2740 | if (defined $pbparallel) {
|
---|
| 2741 | $pm = new Parallel::ForkManager($pbparallel);
|
---|
[1143] | 2742 |
|
---|
[1176] | 2743 | # Set which port the VM/RM will use to communicate
|
---|
| 2744 | $pm->run_on_start(\&pb_set_port);
|
---|
| 2745 | }
|
---|
[1143] | 2746 |
|
---|
| 2747 | my $counter = 0;
|
---|
[652] | 2748 | foreach my $v (@$vm) {
|
---|
[1143] | 2749 | $counter++;
|
---|
| 2750 | # Modulo pbparallel
|
---|
[1176] | 2751 | $counter = 1 if ((defined $pbparallel) && ($counter > $pbparallel));
|
---|
[1143] | 2752 | $pm->start($counter) and next if (defined $pbparallel);
|
---|
| 2753 |
|
---|
[891] | 2754 | # Get distro context
|
---|
[1177] | 2755 | my $pbos = pb_distro_get_context($v);
|
---|
[891] | 2756 |
|
---|
[1216] | 2757 | # Deal with date sync.
|
---|
| 2758 | my $ntpline = pb_date2v($vtype,$pbos);
|
---|
| 2759 |
|
---|
[1176] | 2760 | # Name of the account to deal with for VM/VE/RM
|
---|
[353] | 2761 | # Do not use the one passed potentially with -a
|
---|
| 2762 | my ($pbac) = pb_conf_get($vtype."login");
|
---|
[354] | 2763 | my ($key,$zero0,$zero1,$zero2);
|
---|
[639] | 2764 | my ($vmexist,$vmpid);
|
---|
[346] | 2765 |
|
---|
[1176] | 2766 | # Prepare the script to be executed on the VM/VE/RM
|
---|
[681] | 2767 | # in $ENV{'PBDESTDIR'}/setupv
|
---|
| 2768 | open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
|
---|
| 2769 |
|
---|
| 2770 | print SCRIPT << 'EOF';
|
---|
| 2771 | #!/usr/bin/perl -w
|
---|
| 2772 |
|
---|
| 2773 | use strict;
|
---|
| 2774 | use File::Copy;
|
---|
| 2775 |
|
---|
| 2776 | # We should not need in this script more functions than what is provided
|
---|
[1140] | 2777 | # by Base, Conf and Distribution to avoid problems at exec time.
|
---|
[681] | 2778 | # They are appended at the end.
|
---|
| 2779 |
|
---|
[1156] | 2780 | # Define mandatory global vars
|
---|
[681] | 2781 | our $pbdebug;
|
---|
| 2782 | our $pbLOG;
|
---|
| 2783 | our $pbsynmsg = "pbscript";
|
---|
| 2784 | our $pbdisplaytype = "text";
|
---|
| 2785 | our $pblocale = "";
|
---|
| 2786 | pb_log_init($pbdebug, $pbLOG);
|
---|
[1425] | 2787 | EOF
|
---|
| 2788 | print SCRIPT << "EOF";
|
---|
| 2789 | pb_temp_init($pbkeep);
|
---|
[681] | 2790 |
|
---|
| 2791 | EOF
|
---|
| 2792 |
|
---|
[1176] | 2793 | # Launch the VM/VE/RM - Usage of snapshot disabled
|
---|
[773] | 2794 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0,0,0);
|
---|
[755] | 2795 |
|
---|
[1156] | 2796 | my $keyfile;
|
---|
| 2797 | my $nport;
|
---|
| 2798 | my $vmhost;
|
---|
| 2799 |
|
---|
[1255] | 2800 | # Prepare the key to be used and transfered remotely
|
---|
| 2801 | $keyfile = pb_ssh_get(1);
|
---|
| 2802 |
|
---|
[1176] | 2803 | if ($vtype =~ /(v|r)m/) {
|
---|
[1215] | 2804 | my ($vmport);
|
---|
| 2805 | ($vmhost,$vmport) = pb_conf_get($vtype."host",$vtype."port");
|
---|
[1179] | 2806 | $nport = pb_get_port($vmport,$pbos,$vtype);
|
---|
[347] | 2807 |
|
---|
[1176] | 2808 | # Skip that VM/RM if something went wrong
|
---|
[442] | 2809 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
[353] | 2810 |
|
---|
[354] | 2811 | # Store the pub key part in a variable
|
---|
| 2812 | open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
|
---|
| 2813 | ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
|
---|
| 2814 | close(FILE);
|
---|
| 2815 |
|
---|
| 2816 | $key = "\Q$zero1";
|
---|
| 2817 |
|
---|
[1105] | 2818 | # We call true to avoid problems if SELinux is not activated, but chcon is present and returns in that case 1
|
---|
| 2819 | pb_system("cat $keyfile.pub | ssh -q -o UserKnownHostsFile=/dev/null -p $nport -i $keyfile root\@$vmhost->{$ENV{'PBPROJ'}} \"mkdir -p .ssh ; chmod 700 .ssh ; cat >> .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys ; if [ -x /usr/bin/chcon ]; then /usr/bin/chcon -Rt home_ssh_t .ssh 2> /dev/null; /bin/true; fi\"","Copying local keys to $vtype. This may require the root password");
|
---|
[1176] | 2820 | # once this is done, we can do what we need on the VM/RM remotely
|
---|
[681] | 2821 | } elsif ($vtype eq "ve") {
|
---|
[1029] | 2822 | print SCRIPT << "EOF";
|
---|
[940] | 2823 | # For VE we need a good null dev
|
---|
| 2824 | pb_system("rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null");
|
---|
| 2825 | EOF
|
---|
[1029] | 2826 | print SCRIPT << "EOF";
|
---|
[681] | 2827 | # For VE we first need to mount some FS
|
---|
| 2828 | pb_system("mount -t proc /proc /proc");
|
---|
[346] | 2829 |
|
---|
[354] | 2830 | EOF
|
---|
[681] | 2831 | }
|
---|
[1029] | 2832 |
|
---|
[1190] | 2833 | if ($vtype =~ /(v|r)m/) {
|
---|
[354] | 2834 | print SCRIPT << 'EOF';
|
---|
| 2835 | # Removes duplicate in .ssh/authorized_keys of our key if needed
|
---|
| 2836 | #
|
---|
| 2837 | my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
|
---|
| 2838 | open(PBFILE,$file1) || die "Unable to open $file1";
|
---|
| 2839 | open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
|
---|
| 2840 | my $count = 0;
|
---|
| 2841 | while (<PBFILE>) {
|
---|
[517] | 2842 |
|
---|
[354] | 2843 | EOF
|
---|
| 2844 | print SCRIPT << "EOF";
|
---|
| 2845 | if (/ $key /) {
|
---|
| 2846 | \$count++;
|
---|
| 2847 | }
|
---|
| 2848 | print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
|
---|
| 2849 | }
|
---|
| 2850 | close(PBFILE);
|
---|
| 2851 | close(PBOUT);
|
---|
| 2852 | rename("\$file1.new",\$file1);
|
---|
| 2853 | chmod 0600,\$file1;
|
---|
[517] | 2854 |
|
---|
[354] | 2855 | EOF
|
---|
| 2856 | }
|
---|
| 2857 | print SCRIPT << 'EOF';
|
---|
| 2858 |
|
---|
| 2859 | # Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
|
---|
| 2860 | #
|
---|
[346] | 2861 | my $file="/etc/passwd";
|
---|
[320] | 2862 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 2863 | my $found = 0;
|
---|
| 2864 | while (<PBFILE>) {
|
---|
[346] | 2865 | EOF
|
---|
[353] | 2866 | print SCRIPT << "EOF";
|
---|
| 2867 | \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
|
---|
[346] | 2868 | EOF
|
---|
[891] | 2869 |
|
---|
[1176] | 2870 | # TODO: use an external parameter
|
---|
[891] | 2871 | my $home = "/home";
|
---|
| 2872 | # Solaris doesn't like that we use /home
|
---|
[1177] | 2873 | $home = "/export/home" if ($pbos->{'type'} eq "pkg");
|
---|
[891] | 2874 |
|
---|
| 2875 | print SCRIPT << "EOF";
|
---|
[320] | 2876 | }
|
---|
| 2877 | close(PBFILE);
|
---|
| 2878 |
|
---|
[891] | 2879 | if ( \$found == 0 ) {
|
---|
| 2880 | if ( ! -d "$home" ) {
|
---|
| 2881 | pb_mkdir_p("$home");
|
---|
[320] | 2882 | }
|
---|
[346] | 2883 | EOF
|
---|
[1179] | 2884 | # TODO: Level of portability of these cmds ? Critical now for RM
|
---|
[1255] | 2885 | # TODO: Check existence before adding to avoid errors
|
---|
[353] | 2886 | print SCRIPT << "EOF";
|
---|
[1051] | 2887 | pb_system("/usr/sbin/groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
|
---|
| 2888 | pb_system("/usr/sbin/useradd -g $pbac->{$ENV{'PBPROJ'}} -m -d $home/$pbac->{$ENV{'PBPROJ'}} $pbac->{$ENV{'PBPROJ'}}","Adding user $pbac->{$ENV{'PBPROJ'}} (group $pbac->{$ENV{'PBPROJ'}} - home $home/$pbac->{$ENV{'PBPROJ'}})");
|
---|
[427] | 2889 | }
|
---|
[661] | 2890 | EOF
|
---|
[320] | 2891 |
|
---|
[1176] | 2892 | # Copy the content of our local conf file to the VM/VE/RM
|
---|
[891] | 2893 | my $content = pb_get_content(pb_distro_conffile());
|
---|
| 2894 | print SCRIPT << "EOF";
|
---|
| 2895 | #
|
---|
| 2896 | # Create a temporary local conf file for distribution support
|
---|
| 2897 | # This is created here before its use later. Its place is hardcoded, so no choice for the path
|
---|
| 2898 | #
|
---|
| 2899 | my \$tempconf = pb_distro_conffile();
|
---|
| 2900 | pb_mkdir_p(dirname(\$tempconf));
|
---|
| 2901 | open(CONF,"> \$tempconf") || die "Unable to create \$tempconf";
|
---|
| 2902 | print CONF q{$content};
|
---|
| 2903 | close(CONF);
|
---|
| 2904 | EOF
|
---|
| 2905 |
|
---|
[1176] | 2906 | if ($vtype =~ /(v|r)m/) {
|
---|
[661] | 2907 | print SCRIPT << "EOF";
|
---|
[354] | 2908 | # allow ssh entry to build
|
---|
| 2909 | #
|
---|
[891] | 2910 | mkdir "$home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
|
---|
[347] | 2911 | # Allow those accessing root to access the build account
|
---|
[891] | 2912 | copy("\$ENV{'HOME'}/.ssh/authorized_keys","$home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
|
---|
[320] | 2913 | chmod 0600,".ssh/authorized_keys";
|
---|
[891] | 2914 | 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] | 2915 |
|
---|
[346] | 2916 | EOF
|
---|
[661] | 2917 | }
|
---|
[353] | 2918 | print SCRIPT << 'EOF';
|
---|
[347] | 2919 | # No passwd for build account only keys
|
---|
[320] | 2920 | $file="/etc/shadow";
|
---|
[684] | 2921 | if (-f $file) {
|
---|
| 2922 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 2923 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 2924 | while (<PBFILE>) {
|
---|
[346] | 2925 | EOF
|
---|
[353] | 2926 | print SCRIPT << "EOF";
|
---|
[684] | 2927 | s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
|
---|
| 2928 | s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
|
---|
[910] | 2929 | s/^$pbac->{$ENV{'PBPROJ'}}:\\*LK\\*:/$pbac->{$ENV{'PBPROJ'}}:NP:/; #Solaris e.g.
|
---|
[346] | 2930 | EOF
|
---|
[684] | 2931 | print SCRIPT << 'EOF';
|
---|
| 2932 | print PBOUT $_;
|
---|
| 2933 | }
|
---|
| 2934 | close(PBFILE);
|
---|
| 2935 | close(PBOUT);
|
---|
| 2936 | rename("$file.new",$file);
|
---|
| 2937 | chmod 0640,$file;
|
---|
| 2938 | }
|
---|
[320] | 2939 |
|
---|
[448] | 2940 | # Keep the VM in text mode
|
---|
| 2941 | $file="/etc/inittab";
|
---|
[450] | 2942 | if (-f $file) {
|
---|
| 2943 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 2944 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 2945 | while (<PBFILE>) {
|
---|
| 2946 | s/^(..):5:initdefault:$/$1:3:initdefault:/;
|
---|
| 2947 | print PBOUT $_;
|
---|
| 2948 | }
|
---|
| 2949 | close(PBFILE);
|
---|
| 2950 | close(PBOUT);
|
---|
| 2951 | rename("$file.new",$file);
|
---|
| 2952 | chmod 0640,$file;
|
---|
[448] | 2953 | }
|
---|
| 2954 |
|
---|
[320] | 2955 | # pb has to be added to portage group on gentoo
|
---|
| 2956 |
|
---|
[1177] | 2957 | # We need to have that pb_distro_get_context function
|
---|
[888] | 2958 | # Get it from Project-Builder::Distribution
|
---|
[891] | 2959 | # And we now need the conf file required for this to work created above
|
---|
[888] | 2960 |
|
---|
[1177] | 2961 | my $pbos = pb_distro_get_context();
|
---|
| 2962 | print "distro tuple: ".Dumper($pbos)."\n";
|
---|
[891] | 2963 |
|
---|
[346] | 2964 | # Adapt sudoers
|
---|
[888] | 2965 | # sudo is not default on Solaris and needs to be installed first
|
---|
| 2966 | # from http://www.sunfreeware.com/programlistsparc10.html#sudo
|
---|
[1177] | 2967 | if ($pbos->{'type'} eq "pkg") {
|
---|
[888] | 2968 | $file="/usr/local/etc/sudoers";
|
---|
| 2969 | } else {
|
---|
| 2970 | $file="/etc/sudoers";
|
---|
| 2971 | }
|
---|
[346] | 2972 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 2973 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 2974 | while (<PBFILE>) {
|
---|
| 2975 | EOF
|
---|
[1190] | 2976 | # Skip what will be generated
|
---|
[353] | 2977 | print SCRIPT << "EOF";
|
---|
[1190] | 2978 | next if (/^$pbac->{$ENV{'PBPROJ'}}\\s+/);
|
---|
| 2979 | next if (/^Defaults:$pbac->{$ENV{'PBPROJ'}}\\s+/);
|
---|
| 2980 | next if (/^Defaults:root \!requiretty/);
|
---|
[346] | 2981 | EOF
|
---|
[353] | 2982 | print SCRIPT << 'EOF';
|
---|
[346] | 2983 | s/Defaults[ \t]+requiretty//;
|
---|
| 2984 | print PBOUT $_;
|
---|
| 2985 | }
|
---|
| 2986 | close(PBFILE);
|
---|
| 2987 | EOF
|
---|
[353] | 2988 | print SCRIPT << "EOF";
|
---|
[1032] | 2989 | # Some distro force requiretty at compile time, so disable here
|
---|
| 2990 | print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} !requiretty\n";
|
---|
[1035] | 2991 | print PBOUT "Defaults:root !requiretty\n";
|
---|
[1179] | 2992 | # Keep proxy configuration while using sudo
|
---|
[1198] | 2993 | print PBOUT "Defaults:$pbac->{$ENV{'PBPROJ'}} env_keep += \\\"http_proxy ftp_proxy\\\"\n";
|
---|
[1179] | 2994 | EOF
|
---|
| 2995 | # Try to restrict security to what is really needed
|
---|
| 2996 | if ($vtype =~ /^vm/) {
|
---|
[1197] | 2997 | my $hpath = pb_distro_get_param($pbos,pb_conf_get("ospathcmd-halt"));
|
---|
[1198] | 2998 | my @sudocmds = pb_get_sudocmds($pbos,$ntpline,"sudo $hpath");
|
---|
[1179] | 2999 | print SCRIPT << "EOF";
|
---|
| 3000 | # This is needed in order to be able on VM to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
|
---|
| 3001 | # Build account $pbac->{$ENV{'PBPROJ'}} in VM also needs to setup date and install deps.
|
---|
| 3002 | # Nothing else should be needed
|
---|
| 3003 | EOF
|
---|
[1189] | 3004 | foreach my $c (@sudocmds) {
|
---|
[1426] | 3005 | print SCRIPT "print PBOUT \"$pbac->{$ENV{'PBPROJ'}} ALL = NOPASSWD: $c\\n\";\n";
|
---|
[1179] | 3006 | }
|
---|
| 3007 | } elsif ($vtype =~ /^rm/) {
|
---|
[1190] | 3008 | my @sudocmds = pb_get_sudocmds($pbos,$ntpline);
|
---|
[1179] | 3009 | print SCRIPT << "EOF";
|
---|
| 3010 | # Build account $pbac->{$ENV{'PBPROJ'}} in RM only needs to setup date and install deps if needed each time
|
---|
| 3011 | EOF
|
---|
[1189] | 3012 | foreach my $c (@sudocmds) {
|
---|
[1426] | 3013 | print SCRIPT "print PBOUT \"$pbac->{$ENV{'PBPROJ'}} ALL = NOPASSWD: $c\\n\";\n";
|
---|
[1179] | 3014 | }
|
---|
| 3015 | } else {
|
---|
| 3016 | print SCRIPT << "EOF";
|
---|
| 3017 | # Build account $pbac->{$ENV{'PBPROJ'}} for VE needs to do a lot in the host (and chroot), so allow without restriction for now
|
---|
[353] | 3018 | print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
|
---|
[346] | 3019 | EOF
|
---|
[1179] | 3020 | }
|
---|
[353] | 3021 | print SCRIPT << 'EOF';
|
---|
[346] | 3022 | close(PBOUT);
|
---|
| 3023 | rename("$file.new",$file);
|
---|
| 3024 | chmod 0440,$file;
|
---|
| 3025 |
|
---|
| 3026 | EOF
|
---|
[891] | 3027 |
|
---|
[1190] | 3028 | if ($vtype =~ /(v|r)m/) {
|
---|
| 3029 | # Sync date
|
---|
| 3030 | # do it after sudoers is setup
|
---|
| 3031 | print SCRIPT "pb_system(\"$ntpline\");\n";
|
---|
| 3032 | }
|
---|
[891] | 3033 | # We may need a proxy configuration. Get it from the local env
|
---|
| 3034 |
|
---|
| 3035 | if (defined $ENV{'http_proxy'}) {
|
---|
| 3036 | print SCRIPT "\$ENV\{'http_proxy'\}=\"$ENV{'http_proxy'}\";\n";
|
---|
| 3037 | }
|
---|
| 3038 |
|
---|
| 3039 | if (defined $ENV{'ftp_proxy'}) {
|
---|
| 3040 | print SCRIPT "\$ENV\{'ftp_proxy'\}=\"$ENV{'ftp_proxy'}\";\n";
|
---|
| 3041 | }
|
---|
| 3042 |
|
---|
| 3043 | print SCRIPT << 'EOF';
|
---|
[353] | 3044 |
|
---|
[346] | 3045 | # Suse wants sudoers as 640
|
---|
[1177] | 3046 | if ((($pbos->{'name'} eq "sles") && (($pbos->{'version'} =~ /10/) || ($pbos->{'version'} =~ /9/))) || (($pbos->{'name'} eq "opensuse") && ($pbos->{'version'} =~ /10.[012]/))) {
|
---|
[346] | 3047 | chmod 0640,$file;
|
---|
| 3048 | }
|
---|
| 3049 |
|
---|
[1109] | 3050 | # First install all required packages
|
---|
[1177] | 3051 | pb_system("yum clean all","Cleaning yum env") if (($pbos->{'name'} eq "fedora") || ($pbos->{'name'} eq "asianux") || ($pbos->{'name'} eq "rhel"));
|
---|
[1109] | 3052 | my ($ospkgdep) = pb_conf_get_if("ospkgdep");
|
---|
| 3053 |
|
---|
[1177] | 3054 | my $pkgdep = pb_distro_get_param($pbos,$ospkgdep);
|
---|
| 3055 | pb_distro_installdeps(undef,$pbos,pb_distro_only_deps_needed($pbos,join(' ',split(/,/,$pkgdep))));
|
---|
[1109] | 3056 |
|
---|
| 3057 | EOF
|
---|
[1177] | 3058 | my $itype = pb_distro_get_param($pbos,pb_conf_get("pbinstalltype"));
|
---|
[1176] | 3059 | # Install from sandbox mean a file base install
|
---|
| 3060 | $itype = "file" if (defined $sbx);
|
---|
[1132] | 3061 | if ($itype =~ /^file/) {
|
---|
[1140] | 3062 | my $cmdget;
|
---|
| 3063 | if (defined $sbx) {
|
---|
| 3064 | # Install from sandbox mean using the result of the just passed sbx2build command
|
---|
| 3065 | # Get content saved in cms2build
|
---|
| 3066 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
[1432] | 3067 | my $pbextdir = pb_get_extdir();
|
---|
[1140] | 3068 | die "Unable to get package list" if (not defined $pkg);
|
---|
| 3069 |
|
---|
| 3070 | # We consider 2 specific packages
|
---|
| 3071 | my $vertag1 = $pkg->{"ProjectBuilder"};
|
---|
| 3072 | my $vertag2 = $pkg->{"project-builder"};
|
---|
| 3073 | # get the version of the current package - maybe different
|
---|
[1459] | 3074 | pb_log(2,"Vertag1: $vertag1\n");
|
---|
| 3075 | pb_log(2,"Vertag2: $vertag2\n");
|
---|
[1140] | 3076 | my ($pbver1,$tmp1) = split(/-/,$vertag1);
|
---|
| 3077 | my ($pbver2,$tmp2) = split(/-/,$vertag2);
|
---|
[1156] | 3078 | # Copy inside the VE
|
---|
| 3079 | if ($vtype eq "ve") {
|
---|
| 3080 | my ($vepath) = pb_conf_get("vepath");
|
---|
[1432] | 3081 | copy("$ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz","$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/tmp");
|
---|
| 3082 | copy("$ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz","$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/tmp");
|
---|
[1156] | 3083 | } else {
|
---|
[1432] | 3084 | pb_system("scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport $ENV{'PBDESTDIR'}/ProjectBuilder-$pbver1$pbextdir.tar.gz $ENV{'PBDESTDIR'}/project-builder-$pbver2$pbextdir.tar.gz root\@$vmhost->{$ENV{'PBPROJ'}}:/tmp","Copying local project files to $vtype.");
|
---|
[1156] | 3085 | }
|
---|
[1432] | 3086 | $cmdget = "mv /tmp/ProjectBuilder-$pbver1$pbextdir.tar.gz ProjectBuilder-latest.tar.gz ; mv /tmp/project-builder-$pbver2$pbextdir.tar.gz project-builder-latest.tar.gz";
|
---|
[1140] | 3087 | } else {
|
---|
| 3088 | $cmdget = "wget --passive-ftp ftp://ftp.project-builder.org/src/ProjectBuilder-latest.tar.gz; wget --passive-ftp ftp://ftp.project-builder.org/src/project-builder-latest.tar.gz";
|
---|
| 3089 | }
|
---|
[1109] | 3090 | print SCRIPT << 'EOF';
|
---|
| 3091 | # Then install manually the missing perl modules
|
---|
| 3092 | my ($osperldep,$osperlver) = pb_conf_get_if("osperldep","osperlver");
|
---|
| 3093 |
|
---|
[1177] | 3094 | my $perldep = pb_distro_get_param($pbos,$osperldep);
|
---|
[1109] | 3095 | foreach my $m (split(/,/,$perldep)) {
|
---|
| 3096 | # Skip empty deps
|
---|
| 3097 | next if ($m =~ /^\s*$/);
|
---|
| 3098 | my $dir = $m;
|
---|
| 3099 | $dir =~ s/-.*//;
|
---|
| 3100 | pb_system("echo \"rm -rf $m* ; wget http://search.cpan.org/CPAN/modules/by-module/$dir/$m-$osperlver->{$m}.tar.gz ; gzip -cd $m-$osperlver->{$m}.tar.gz | tar xf - ; cd $m* ; if [ -f Build.PL ]; then perl Build.PL; ./Build ; ./Build install ; else perl Makefile.PL; make ; make install ; fi; cd .. ; rm -rf $m*\" | bash" ,"Installing perl module $m-$osperlver->{$m}");
|
---|
| 3101 | }
|
---|
[1140] | 3102 | EOF
|
---|
[1425] | 3103 | print SCRIPT << 'EOF';
|
---|
| 3104 | pb_system("rm -rf ProjectBuilder-* ; rm -rf project-builder-* ; rm -rf `perl -V:installvendorlib | awk -F\"'\" '{print \$2}'`/ProjectBuilder ;
|
---|
[1109] | 3105 | EOF
|
---|
[1425] | 3106 | print SCRIPT " $cmdget ; ";
|
---|
| 3107 | print SCRIPT << 'EOF'
|
---|
| 3108 | gzip -cd ProjectBuilder-latest.tar.gz | tar xf - ; cd ProjectBuilder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf ProjectBuilder-* ; gzip -cd project-builder-latest.tar.gz | tar xf - ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd .. ; rm -rf project-builder-* ;","Building Project-Builder");
|
---|
| 3109 | EOF
|
---|
[1132] | 3110 | } elsif ($itype =~ /^pkg/) {
|
---|
[1109] | 3111 | # pkg based install. We need to point to the project-builder.org repository
|
---|
| 3112 | print SCRIPT << 'EOF';
|
---|
[1177] | 3113 | my $pkgforpb = pb_distro_get_param($pbos,pb_conf_get_if("ospkg"));
|
---|
| 3114 | pb_distro_setuposrepo($pbos);
|
---|
| 3115 | pb_distro_installdeps(undef,$pbos,pb_distro_only_deps_needed($pbos,join(' ',split(/,/,$pkgforpb))));
|
---|
[1109] | 3116 | EOF
|
---|
| 3117 | } else {
|
---|
| 3118 | # Unknown install type
|
---|
| 3119 | die("Unknown install type $itype->{$ENV{'PBPROJ'}} for param pbinstalltype");
|
---|
| 3120 | }
|
---|
| 3121 | print SCRIPT << 'EOF';
|
---|
[902] | 3122 | pb_system("pb 2>&1 | head -5",undef,"verbose");
|
---|
[1189] | 3123 | pb_system("pbdistrocheck",undef,"verbose");
|
---|
[357] | 3124 | EOF
|
---|
[681] | 3125 | if ($vtype eq "ve") {
|
---|
| 3126 | print SCRIPT << 'EOF';
|
---|
| 3127 | # For VE we need to umount some FS at the end
|
---|
| 3128 |
|
---|
| 3129 | pb_system("umount /proc");
|
---|
[696] | 3130 |
|
---|
| 3131 | # Create a basic network file if not already there
|
---|
| 3132 |
|
---|
| 3133 | my $nf="/etc/sysconfig/network";
|
---|
[1177] | 3134 | if ((! -f $nf) && ($pbos->{'type'} eq "rpm")) {
|
---|
[696] | 3135 | open(NF,"> $nf") || die "Unable to create $nf";
|
---|
| 3136 | print NF "NETWORKING=yes\n";
|
---|
| 3137 | print NF "HOSTNAME=localhost\n";
|
---|
| 3138 | close(NF);
|
---|
| 3139 | }
|
---|
| 3140 | chmod 0755,$nf;
|
---|
[681] | 3141 | EOF
|
---|
| 3142 | }
|
---|
| 3143 |
|
---|
[1177] | 3144 | # Adds pb_distro_get_context and all functions needed from ProjectBuilder::Distribution, Conf and Base
|
---|
[353] | 3145 | foreach my $d (@INC) {
|
---|
[891] | 3146 | my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm","$d/ProjectBuilder/Conf.pm");
|
---|
[405] | 3147 | foreach my $f (@f) {
|
---|
| 3148 | if (-f "$f") {
|
---|
| 3149 | open(PBD,"$f") || die "Unable to open $f";
|
---|
| 3150 | while (<PBD>) {
|
---|
[891] | 3151 | next if (/^package/);
|
---|
| 3152 | next if (/^use Exporter/);
|
---|
| 3153 | next if (/^use ProjectBuilder::/);
|
---|
| 3154 | next if (/^our /);
|
---|
[405] | 3155 | print SCRIPT $_;
|
---|
| 3156 | }
|
---|
| 3157 | close(PBD);
|
---|
[353] | 3158 | }
|
---|
[347] | 3159 | }
|
---|
| 3160 | }
|
---|
[1156] | 3161 | # Use a fake pb_version_init version here
|
---|
| 3162 | print SCRIPT << "EOF";
|
---|
| 3163 | sub pb_version_init {
|
---|
| 3164 |
|
---|
| 3165 | return("$projectbuilderver","$projectbuilderrev");
|
---|
| 3166 | }
|
---|
| 3167 | 1;
|
---|
| 3168 | EOF
|
---|
[353] | 3169 | close(SCRIPT);
|
---|
| 3170 | chmod 0755,"$pbscript";
|
---|
| 3171 |
|
---|
[442] | 3172 | # That build script needs to be run as root and force stop of VM at end
|
---|
[353] | 3173 | $pbaccount = "root";
|
---|
[442] | 3174 |
|
---|
[1111] | 3175 | # Force shutdown of VM except if it was already launched
|
---|
[748] | 3176 | my $pbforce = 0;
|
---|
[442] | 3177 | if ((! $vmexist) && ($vtype eq "vm")) {
|
---|
[748] | 3178 | $pbforce = 1;
|
---|
[442] | 3179 | }
|
---|
| 3180 |
|
---|
[748] | 3181 | pb_script2v($pbscript,$vtype,$pbforce,$v);
|
---|
[1143] | 3182 | $pm->finish if (defined $pbparallel);
|
---|
[347] | 3183 | }
|
---|
[1176] | 3184 | $pm->wait_all_children if (defined $pbparallel);
|
---|
[353] | 3185 | return;
|
---|
[346] | 3186 | }
|
---|
| 3187 |
|
---|
[772] | 3188 | # Function to create a snapshot named 'pb' for VMs and a compressed tar for VEs
|
---|
| 3189 | sub pb_snap2v {
|
---|
[748] | 3190 |
|
---|
| 3191 | my $vtype = shift;
|
---|
| 3192 |
|
---|
[772] | 3193 | my ($vm,$all) = pb_get2v($vtype);
|
---|
[748] | 3194 |
|
---|
| 3195 | # Script generated
|
---|
| 3196 | my $pbscript = "$ENV{'PBDESTDIR'}/snapv";
|
---|
| 3197 |
|
---|
[898] | 3198 | my ($pbac) = pb_conf_get($vtype."login");
|
---|
| 3199 |
|
---|
[748] | 3200 | foreach my $v (@$vm) {
|
---|
[1138] | 3201 | if ($vtype eq "ve") {
|
---|
| 3202 | # Get distro context
|
---|
[1177] | 3203 | my $pbos = pb_distro_get_context($v);
|
---|
[1138] | 3204 | my ($vepath) = pb_conf_get("vepath");
|
---|
[971] | 3205 |
|
---|
[1138] | 3206 | # Test if an existing snapshot exists and remove it if there is a VE
|
---|
[1177] | 3207 | if ((-f "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz") &&
|
---|
| 3208 | (! -d "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}")) {
|
---|
| 3209 | pb_system("sudo rm -f $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz","Removing previous snapshot $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz");
|
---|
[1138] | 3210 | }
|
---|
[971] | 3211 | }
|
---|
| 3212 |
|
---|
[748] | 3213 | # Prepare the script to be executed on the VM/VE
|
---|
| 3214 | open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
|
---|
| 3215 | print SCRIPT << 'EOF';
|
---|
| 3216 | #!/bin/bash
|
---|
[776] | 3217 | sleep 2
|
---|
[748] | 3218 | EOF
|
---|
| 3219 | close(SCRIPT);
|
---|
| 3220 | chmod 0755,"$pbscript";
|
---|
| 3221 |
|
---|
| 3222 | # Force shutdown of VM/VE
|
---|
| 3223 | # Force snapshot of VM/VE
|
---|
[773] | 3224 | pb_script2v($pbscript,$vtype,1,$v,1);
|
---|
[748] | 3225 | }
|
---|
| 3226 | return;
|
---|
| 3227 | }
|
---|
| 3228 |
|
---|
[1176] | 3229 | # Function to update VMs/VEs/RMs with the latest distribution content
|
---|
[1111] | 3230 | sub pb_update2v {
|
---|
| 3231 |
|
---|
| 3232 | my $vtype = shift;
|
---|
| 3233 |
|
---|
| 3234 | my ($vm,$all) = pb_get2v($vtype);
|
---|
| 3235 |
|
---|
| 3236 | # Script generated
|
---|
| 3237 | my $pbscript = "$ENV{'PBDESTDIR'}/updatev";
|
---|
| 3238 |
|
---|
| 3239 | my ($pbac) = pb_conf_get($vtype."login");
|
---|
| 3240 |
|
---|
| 3241 | foreach my $v (@$vm) {
|
---|
| 3242 | # Get distro context
|
---|
[1177] | 3243 | my $pbos = pb_distro_get_context($v);
|
---|
[1111] | 3244 |
|
---|
[1176] | 3245 | # Prepare the script to be executed on the VM/VE/RM
|
---|
[1111] | 3246 | # in $ENV{'PBDESTDIR'}/updatev
|
---|
| 3247 | open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
|
---|
| 3248 |
|
---|
| 3249 | print SCRIPT << 'EOF';
|
---|
| 3250 | #!/bin/bash
|
---|
| 3251 | sleep 2
|
---|
| 3252 | EOF
|
---|
| 3253 | # VE needs a good /proc
|
---|
| 3254 | if ($vtype eq "ve") {
|
---|
[1179] | 3255 | print SCRIPT "sudo /bin/mount -t proc /proc /proc\n";
|
---|
[1111] | 3256 | }
|
---|
[1177] | 3257 | print SCRIPT "$pbos->{'update'}\n";
|
---|
[1111] | 3258 | if ($vtype eq "ve") {
|
---|
[1179] | 3259 | print SCRIPT "sudo /bin/umount /proc\n";
|
---|
[1111] | 3260 | }
|
---|
| 3261 | close(SCRIPT);
|
---|
| 3262 | chmod 0755,"$pbscript";
|
---|
| 3263 |
|
---|
| 3264 | # Force shutdown of VM except
|
---|
| 3265 | pb_script2v($pbscript,$vtype,1,$v);
|
---|
| 3266 | }
|
---|
| 3267 | return;
|
---|
| 3268 | }
|
---|
| 3269 |
|
---|
[471] | 3270 | sub pb_announce {
|
---|
| 3271 |
|
---|
[1386] | 3272 | my $antype = shift;
|
---|
| 3273 |
|
---|
[473] | 3274 | # Get all required parameters
|
---|
[477] | 3275 | my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
|
---|
[1392] | 3276 | my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
|
---|
| 3277 | if (((not defined $testver) || (not defined $testver->{$ENV{'PBPROJ'}}) || ($testver->{$ENV{'PBPROJ'}} !~ /true/i)) && ($antype eq "Clean")) {
|
---|
| 3278 | # We just clean for test versions
|
---|
| 3279 | pb_log(0,"Unable to clean SSH repository for non testver version\n");
|
---|
| 3280 | return;
|
---|
| 3281 | }
|
---|
[471] | 3282 | my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
|
---|
| 3283 | my @pkgs = @$pkg;
|
---|
| 3284 | my %pkgs;
|
---|
| 3285 | my $first = 0;
|
---|
| 3286 |
|
---|
[1282] | 3287 | # Get all distros concerned
|
---|
| 3288 | my $pbos = pb_distro_get_context();
|
---|
| 3289 | my $distrolist = pb_get_distros($pbos,undef);
|
---|
| 3290 | my %dl;
|
---|
[1386] | 3291 | my %theorlist;
|
---|
| 3292 | my %archlist;
|
---|
[1282] | 3293 | foreach my $d (split(/,/,$distrolist)) {
|
---|
[1386] | 3294 | my ($d1,$d2,$d3) = split(/-/,$d);
|
---|
[1282] | 3295 | $dl{$d1}++;
|
---|
| 3296 | }
|
---|
| 3297 |
|
---|
[473] | 3298 | # Command to find packages on repo
|
---|
[1282] | 3299 | my $findstr = "find ".join(" ",keys %dl)." ";
|
---|
[1392] | 3300 | my $srcstr = "";
|
---|
[473] | 3301 | # Generated announce files
|
---|
| 3302 | my @files;
|
---|
[471] | 3303 |
|
---|
| 3304 | foreach my $pbpkg (@pkgs) {
|
---|
| 3305 | if ($first != 0) {
|
---|
| 3306 | $findstr .= "-o ";
|
---|
| 3307 | }
|
---|
| 3308 | $first++;
|
---|
| 3309 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
| 3310 | $pbver = $pkgv->{$pbpkg};
|
---|
| 3311 | } else {
|
---|
| 3312 | $pbver = $ENV{'PBPROJVER'};
|
---|
| 3313 | }
|
---|
| 3314 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
| 3315 | $pbtag = $pkgt->{$pbpkg};
|
---|
| 3316 | } else {
|
---|
| 3317 | $pbtag = $ENV{'PBPROJTAG'};
|
---|
| 3318 | }
|
---|
| 3319 |
|
---|
[547] | 3320 | # TODO: use virtual/real names here now
|
---|
[1285] | 3321 | my $pbrealpkg = $pbpkg;
|
---|
| 3322 | my $pbrealpkgrpm = pb_cms_get_real_pkg($pbpkg,"rpm");
|
---|
| 3323 | my $pbrealpkgdeb = pb_cms_get_real_pkg($pbpkg,"deb");
|
---|
[1392] | 3324 | if ($antype eq "Clean") {
|
---|
[1432] | 3325 | # We only clean test versions anyway
|
---|
| 3326 | $pbtag = "0";
|
---|
| 3327 | my $nver = $pbver;
|
---|
| 3328 | my $ntag = "[2-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]";
|
---|
| 3329 | $pbver .= $ntag;
|
---|
| 3330 | $findstr .= "-name \'$pbrealpkgrpm-$pbver-$pbtag\.*.rpm\' -o -name \'$pbrealpkgrpm-debug-$pbver-$pbtag\.*.rpm\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag"."_*\.deb\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag.dsc\' -o -name \'$pbrealpkgdeb"."_$pbver-$pbtag.tar.gz\' -o -name \'$pbrealpkg-$nver"."_p$ntag\.ebuild\' -o -name \'$pbrealpkg-$pbver-$pbtag*\.pkg\' -o -name \'$pbrealpkg-$pbver-$pbtag*\.sd\' ";
|
---|
[1393] | 3331 | $srcstr .= "src/$pbrealpkg-$pbver.tar.gz src/$pbrealpkg-$pbver.pbconf.tar.gz ";
|
---|
[1392] | 3332 | } else {
|
---|
[1420] | 3333 | my @date=pb_get_date();
|
---|
| 3334 | # the matching is only done on packages made the same day for test version. Hopefully this is enough
|
---|
[1432] | 3335 | my $nver = $pbver;
|
---|
| 3336 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i) && ($antype eq "Check")) {
|
---|
| 3337 | $pbtag = "0";
|
---|
| 3338 | my $ntag .= strftime("%Y%m%d*", @date);
|
---|
| 3339 | $nver = $pbver."_p$ntag";
|
---|
| 3340 | $pbver .= $ntag;
|
---|
| 3341 | }
|
---|
| 3342 | $findstr .= "-name \'$pbrealpkgrpm-$pbver-$pbtag\.*.rpm\' -o -name \'$pbrealpkgdeb"."_$pbver*\.deb\' -o -name \'$pbrealpkg-$nver*\.ebuild\' -o -name \'$pbrealpkg-$pbver*\.pkg\' -o -name \'$pbrealpkg-$pbver*\.sd\' ";
|
---|
[1392] | 3343 | }
|
---|
[473] | 3344 |
|
---|
[1386] | 3345 | if ($antype eq "Announce") {
|
---|
| 3346 | my $chglog;
|
---|
[473] | 3347 |
|
---|
[1386] | 3348 | pb_cms_init($pbinit);
|
---|
| 3349 | # Get project info on log file and generate tmp files used later on
|
---|
| 3350 | $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
|
---|
| 3351 | $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
|
---|
| 3352 | $chglog = undef if (! -f $chglog);
|
---|
[473] | 3353 |
|
---|
[1386] | 3354 | open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
|
---|
| 3355 | my $pb;
|
---|
| 3356 | $pb->{'realpkg'} = $pbrealpkg;
|
---|
| 3357 | $pb->{'ver'} = $pbver;
|
---|
| 3358 | $pb->{'tag'} = $pbtag;
|
---|
| 3359 | $pb->{'date'} = $pbdate;
|
---|
[1432] | 3360 | $pb->{'extdir'} = pb_get_extdir();
|
---|
[1386] | 3361 | $pb->{'chglog'} = $chglog;
|
---|
| 3362 | $pb->{'packager'} = $pbpackager;
|
---|
| 3363 | $pb->{'proj'} = $ENV{'PBPROJ'};
|
---|
| 3364 | $pb->{'repo'} = $pbrepo;
|
---|
| 3365 | $pb->{'pbos'}->{'type'} = "announce";
|
---|
| 3366 | $pb->{'pbos'}->{'suffix'} = "none";
|
---|
| 3367 | pb_changelog($pb,\*OUT,"yes");
|
---|
| 3368 | close(OUT);
|
---|
| 3369 | push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
|
---|
[1392] | 3370 | } elsif ($antype eq "Check") {
|
---|
[1386] | 3371 | # For the check we also build the theoritical complete list we should get
|
---|
| 3372 | foreach my $d (split(/,/,$distrolist)) {
|
---|
| 3373 | $pbos = pb_distro_get_context($d);
|
---|
| 3374 | if ($pbos->{'type'} eq "rpm") {
|
---|
| 3375 | $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/$pbrealpkgrpm-$pbver-$pbtag$pbos->{'suffix'}"} = 0;
|
---|
| 3376 | } elsif ($pbos->{'type'} eq "deb") {
|
---|
| 3377 | $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkgdeb"."_$pbver-$pbtag"} = 0;
|
---|
[1420] | 3378 | # TODO are we always using the last arch ?
|
---|
[1386] | 3379 | $archlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkgdeb"."_$pbver-$pbtag"} = "$pbos->{'arch'}";
|
---|
| 3380 | } elsif ($pbos->{'type'} eq "ebuild") {
|
---|
[1424] | 3381 | my $prefix = "-r";
|
---|
| 3382 | $prefix = "_p" if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i));
|
---|
| 3383 | $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkg-$pbver$prefix$pbtag.ebuild"} = 0;
|
---|
| 3384 | $archlist{"$pbos->{'name'}/$pbos->{'version'}/$pbrealpkg-$pbver$prefix$pbtag.ebuild"} = "$pbos->{'arch'}";
|
---|
[1386] | 3385 | } elsif ($pbos->{'type'} eq "pkg") {
|
---|
| 3386 | $theorlist{"$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/$pbrealpkg-$pbver-$pbtag.pkg"} = 0;
|
---|
| 3387 | } else {
|
---|
| 3388 | pb_log(1,"No theoritical list possible for type $pbos->{'type'}\n");
|
---|
| 3389 | }
|
---|
| 3390 | }
|
---|
| 3391 | }
|
---|
| 3392 | pb_log(2,"theorlist : ".Dumper(%theorlist)."\n");
|
---|
[471] | 3393 | }
|
---|
[1392] | 3394 | if ($antype eq "Announce") {
|
---|
| 3395 | $findstr .= " | grep -Ev \'src.rpm\'";
|
---|
| 3396 | } elsif ($antype eq "Clean") {
|
---|
| 3397 | $findstr .= " | xargs rm -f -v $srcstr ";
|
---|
| 3398 | }
|
---|
[471] | 3399 |
|
---|
| 3400 | # Prepare the command to run and execute it
|
---|
| 3401 | open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
|
---|
[1392] | 3402 | print PBS "#!/bin/bash\n";
|
---|
[1282] | 3403 | print PBS "set -x\n" if ($pbdebug gt 1);
|
---|
[1295] | 3404 | print PBS "$findstr | sort 2> /dev/null\n";
|
---|
[471] | 3405 | close(PBS);
|
---|
| 3406 | chmod 0755,"$ENV{'PBTMP'}/pbscript";
|
---|
| 3407 | pb_send2target("Announce");
|
---|
| 3408 |
|
---|
[490] | 3409 | my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
|
---|
[1386] | 3410 | if ($antype eq "Announce") {
|
---|
| 3411 | # Get subject line
|
---|
| 3412 | pb_log(0,"Please enter the title of your announce\n");
|
---|
| 3413 | pb_log(0,"(By default: $sl)\n");
|
---|
| 3414 | my $sl2 = <STDIN>;
|
---|
| 3415 | $sl = $sl2 if ($sl2 !~ /^$/);
|
---|
[490] | 3416 |
|
---|
[1386] | 3417 | # Prepare a template of announce
|
---|
| 3418 | open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
|
---|
| 3419 | print ANN << "EOF";
|
---|
[490] | 3420 | $sl</p>
|
---|
[471] | 3421 |
|
---|
[473] | 3422 | <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] | 3423 | <p>
|
---|
| 3424 | Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
|
---|
| 3425 | </p>
|
---|
| 3426 | <p>
|
---|
| 3427 | EOF
|
---|
[1386] | 3428 | }
|
---|
| 3429 |
|
---|
[1137] | 3430 | open(LOG,"$ENV{'PBTMP'}/system.$$.log") || die "Unable to read $ENV{'PBTMP'}/system.$$.log: $!";
|
---|
[1386] | 3431 | if ($antype eq "Announce") {
|
---|
| 3432 | my $col = 2;
|
---|
| 3433 | my $i = 1;
|
---|
| 3434 | print ANN << 'EOF';
|
---|
[1440] | 3435 | <TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0">
|
---|
[473] | 3436 | <TR>
|
---|
| 3437 | EOF
|
---|
[1386] | 3438 | while (<LOG>) {
|
---|
| 3439 | print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
|
---|
| 3440 | $i++;
|
---|
| 3441 | if ($i > $col) {
|
---|
| 3442 | print ANN "</TR>\n<TR>";
|
---|
| 3443 | $i = 1;
|
---|
| 3444 | }
|
---|
[473] | 3445 | }
|
---|
[1393] | 3446 | } elsif ($antype eq "Clean") {
|
---|
| 3447 | while (<LOG>) {
|
---|
| 3448 | # skip errors
|
---|
| 3449 | next if ($_ !~ /^removed /);
|
---|
| 3450 | pb_log(0,"$_");
|
---|
| 3451 | }
|
---|
[1386] | 3452 | } else {
|
---|
| 3453 | # In Check mode we need to compare the 2 lists (real and theoritical)
|
---|
| 3454 | while (<LOG>) {
|
---|
| 3455 | # Get package name and remove what is in extra for the theoritical list (arch at the end)
|
---|
| 3456 | chomp();
|
---|
| 3457 | # skip find errors
|
---|
| 3458 | next if (/^find:/);
|
---|
| 3459 | my $p = $_;
|
---|
| 3460 | $p =~ s/\.(i[3456]86|x86_64|noarch|src)\.rpm$//;
|
---|
| 3461 | $p =~ s/_(i[3456]86|amd64|all).deb$//;
|
---|
[1424] | 3462 | $p =~ s/(-0\.[0-9]{8})[0-9]{6}/$1*/ if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i));
|
---|
| 3463 | $p =~ s/(-r|_p[0-9]+)\.ebuild/$1*/ if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i));
|
---|
[1386] | 3464 | $theorlist{$p} = -2 if (not defined $theorlist{$p});
|
---|
| 3465 | $theorlist{$p} = $theorlist{$p} + 1;
|
---|
| 3466 | }
|
---|
| 3467 | pb_log(2,"theorlist : ".Dumper(%theorlist)."\n");
|
---|
[471] | 3468 | }
|
---|
| 3469 | close(LOG);
|
---|
[1386] | 3470 |
|
---|
[1393] | 3471 | # Nothing more for the cleanssh case
|
---|
| 3472 | return if ($antype eq "Clean");
|
---|
| 3473 |
|
---|
[1386] | 3474 | if ($antype eq "Check") {
|
---|
| 3475 | my ($chkex) = pb_conf_get_if("checkexclude");
|
---|
| 3476 | my $vmbuildlist = "";
|
---|
| 3477 | my $vebuildlist = "";
|
---|
| 3478 | my $rmbuildlist = "";
|
---|
| 3479 | my @pt = pb_conf_get_if("vmlist","velist","rmlist");
|
---|
| 3480 | foreach my $t (sort keys %theorlist) {
|
---|
| 3481 | if (defined $theorlist{$t} and $theorlist{$t} >= 1) {
|
---|
| 3482 | pb_log(1,"Packages found for $t\n");
|
---|
| 3483 | } elsif (defined $theorlist{$t} and $theorlist{$t} < 0) {
|
---|
| 3484 | pb_log(0,"Extra Package found for $t\n");
|
---|
| 3485 | } else {
|
---|
[1420] | 3486 | pb_log(2,"Analyzing $t\n");
|
---|
[1386] | 3487 | my ($os,$ver,$arch,$package) = split(/\//,$t);
|
---|
| 3488 | # Some distro have no arch subdir
|
---|
| 3489 | if (not defined $package) {
|
---|
| 3490 | $package = $arch;
|
---|
| 3491 | # TODO: If both arch have failed, we just make the last one
|
---|
| 3492 | $arch = $archlist{$t};
|
---|
| 3493 | }
|
---|
| 3494 | my $pbos = pb_distro_get_context("$os-$ver-$arch");
|
---|
| 3495 | my $pkgn = $package;
|
---|
| 3496 | if ($pbos->{'type'} ne "deb") {
|
---|
| 3497 | # package name is more easily found from the end for non deb
|
---|
| 3498 | # as '-' is the separator, but it can also be used in names
|
---|
| 3499 | $pkgn = reverse($package);
|
---|
| 3500 | # search the second '-' and isolate the now last part which is the full name
|
---|
| 3501 | $pkgn =~ s/([^-]+)-([^-]+)-([\S])+$/$3/;
|
---|
| 3502 | } else {
|
---|
| 3503 | $pkgn =~ s/([^_]+)_([\S])+$/$2/;
|
---|
| 3504 | }
|
---|
| 3505 | my $found = 0;
|
---|
| 3506 | # Handle the exclusion of OSes
|
---|
| 3507 | my $excl = "";
|
---|
| 3508 | $excl .= $chkex->{$pkgn} if (defined $chkex->{$pkgn});
|
---|
| 3509 | $excl .= $chkex->{"all"} if (defined $chkex->{"all"});
|
---|
| 3510 | foreach my $ex (split(/,/,$excl)) {
|
---|
| 3511 | $found = 1 if ("$os-$ver-$arch" =~ /^$ex/);
|
---|
| 3512 | }
|
---|
| 3513 | # Skip as excluded
|
---|
| 3514 | next if ($found == 1);
|
---|
[1388] | 3515 | pb_log(0,"Package NOT found for $t\n");
|
---|
| 3516 | # Avoid duplicates in list
|
---|
[1386] | 3517 | next if ($vmbuildlist =~ /$os-$ver-$arch/);
|
---|
| 3518 | next if ($vebuildlist =~ /$os-$ver-$arch/);
|
---|
| 3519 | next if ($rmbuildlist =~ /$os-$ver-$arch/);
|
---|
| 3520 | # check with which method we need to build
|
---|
| 3521 | if ((defined $pt[0]->{$ENV{'PBPROJ'}}) and ($pt[0]->{$ENV{'PBPROJ'}} =~ /$os-$ver-$arch/)) {
|
---|
| 3522 | $vmbuildlist = "$os-$ver-$arch" if ($vmbuildlist eq "");
|
---|
[1388] | 3523 | $vmbuildlist .= ",$os-$ver-$arch" if ($vmbuildlist !~ /$os-$ver-$arch/);
|
---|
| 3524 | next;
|
---|
[1386] | 3525 | }
|
---|
| 3526 | if ((defined $pt[1]->{$ENV{'PBPROJ'}}) and ($pt[1]->{$ENV{'PBPROJ'}} =~ /$os-$ver-$arch/)) {
|
---|
| 3527 | $vebuildlist = "$os-$ver-$arch" if ($vebuildlist eq "");
|
---|
[1388] | 3528 | $vebuildlist .= ",$os-$ver-$arch" if ($vebuildlist !~ /$os-$ver-$arch/);
|
---|
| 3529 | next;
|
---|
[1386] | 3530 | }
|
---|
| 3531 | if ((defined $pt[2]->{$ENV{'PBPROJ'}}) and ($pt[2]->{$ENV{'PBPROJ'}} =~ /$os-$ver-$arch/)) {
|
---|
| 3532 | $rmbuildlist = "$os-$ver-$arch" if ($rmbuildlist eq "");
|
---|
[1388] | 3533 | $rmbuildlist .= ",$os-$ver-$arch" if ($rmbuildlist !~ /$os-$ver-$arch/);
|
---|
[1386] | 3534 | }
|
---|
| 3535 | }
|
---|
| 3536 | }
|
---|
| 3537 | # If we want to rebuild automatically, let's do it
|
---|
| 3538 | if (defined $opts{'rebuild'}) {
|
---|
| 3539 | # SandBox or CMS
|
---|
| 3540 | pb_log(0,"Rebuilding from SandBox\n");
|
---|
| 3541 | pb_log(0,"for VMs: $vmbuildlist\n") if ($vmbuildlist ne "");
|
---|
| 3542 | pb_log(0,"for VEs: $vebuildlist\n") if ($vebuildlist ne "");
|
---|
| 3543 | pb_log(0,"for RMs: $rmbuildlist\n") if ($rmbuildlist ne "");
|
---|
| 3544 | pb_cms2build("SandBox");
|
---|
| 3545 | # Which mode
|
---|
| 3546 | $ENV{'PBV'} = $vmbuildlist;
|
---|
| 3547 | pb_build2v("vm","build") if ($vmbuildlist ne "");
|
---|
| 3548 | $ENV{'PBV'} = $vebuildlist;
|
---|
| 3549 | pb_build2v("ve","build") if ($vebuildlist ne "");
|
---|
| 3550 | $ENV{'PBV'} = $rmbuildlist;
|
---|
| 3551 | pb_build2v("rm","build") if ($rmbuildlist ne "");
|
---|
| 3552 | }
|
---|
| 3553 | # For the check part this is now finished
|
---|
| 3554 | return;
|
---|
| 3555 | }
|
---|
| 3556 |
|
---|
[473] | 3557 | print ANN << "EOF";
|
---|
| 3558 | </TR>
|
---|
| 3559 | </TABLE>
|
---|
| 3560 | </p>
|
---|
[471] | 3561 |
|
---|
[473] | 3562 | <p>As usual source packages are also available in the same directory.</p>
|
---|
| 3563 |
|
---|
| 3564 | <p>
|
---|
| 3565 | Changes are :
|
---|
| 3566 | </p>
|
---|
| 3567 | <p>
|
---|
| 3568 | EOF
|
---|
| 3569 | # Get each package changelog content
|
---|
| 3570 | foreach my $f (sort(@files)) {
|
---|
| 3571 | open(IN,"$f") || die "Unable to read $f:$!";
|
---|
| 3572 | while (<IN>) {
|
---|
| 3573 | print ANN $_;
|
---|
| 3574 | }
|
---|
| 3575 | close(IN);
|
---|
| 3576 | print ANN "</p><p>\n";
|
---|
| 3577 | }
|
---|
| 3578 | print ANN "</p>\n";
|
---|
[471] | 3579 | close(ANN);
|
---|
[473] | 3580 |
|
---|
| 3581 | # Allow for modification
|
---|
[974] | 3582 | my $editor = "vi";
|
---|
| 3583 | $editor = $ENV{'EDITOR'} if (defined $ENV{'EDITOR'});
|
---|
| 3584 | pb_system("$editor $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
|
---|
[473] | 3585 |
|
---|
| 3586 | # Store it in DB for external usage (Web pages generation)
|
---|
| 3587 | my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
|
---|
| 3588 |
|
---|
| 3589 | my $precmd = "";
|
---|
| 3590 | if (! -f $db) {
|
---|
| 3591 | $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
|
---|
| 3592 | }
|
---|
| 3593 |
|
---|
| 3594 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
| 3595 | { RaiseError => 1, AutoCommit => 1 })
|
---|
| 3596 | || die "Unable to connect to $db";
|
---|
| 3597 |
|
---|
| 3598 | if ($precmd ne "") {
|
---|
| 3599 | my $sth = $dbh->prepare(qq{$precmd})
|
---|
| 3600 | || die "Unable to create table into $db";
|
---|
| 3601 | $sth->execute();
|
---|
| 3602 | }
|
---|
| 3603 |
|
---|
| 3604 | # To read whole file
|
---|
| 3605 | local $/;
|
---|
| 3606 | open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
|
---|
| 3607 | my $announce = <ANN>;
|
---|
| 3608 | close(ANN);
|
---|
| 3609 |
|
---|
| 3610 | pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
|
---|
| 3611 | my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
|
---|
| 3612 | || die "Unable to insert into $db";
|
---|
| 3613 | $sth->execute($pbdate, $announce);
|
---|
[698] | 3614 | $sth->finish();
|
---|
[473] | 3615 | $dbh->disconnect;
|
---|
| 3616 |
|
---|
| 3617 | # Then deliver it on the Web
|
---|
| 3618 | # $TOOLHOME/livwww www
|
---|
| 3619 |
|
---|
| 3620 | # Mail it to project's ML
|
---|
| 3621 | open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
|
---|
| 3622 | print ML << 'EOF';
|
---|
| 3623 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
|
---|
| 3624 |
|
---|
| 3625 | <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
|
---|
| 3626 | <head>
|
---|
| 3627 | </head>
|
---|
| 3628 | <body>
|
---|
| 3629 | <p>
|
---|
| 3630 | EOF
|
---|
| 3631 | open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
|
---|
| 3632 | while(<ANN>) {
|
---|
| 3633 | print ML $_;
|
---|
| 3634 | }
|
---|
| 3635 | print ML << 'EOF';
|
---|
| 3636 | </body>
|
---|
| 3637 | </html>
|
---|
| 3638 | EOF
|
---|
| 3639 | close(ML);
|
---|
| 3640 |
|
---|
[477] | 3641 | # To read whole file
|
---|
| 3642 | local $/;
|
---|
| 3643 | open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
|
---|
| 3644 | my $msg = <ANN>;
|
---|
| 3645 | close(ANN);
|
---|
| 3646 |
|
---|
| 3647 | # Preparation of headers
|
---|
[1134] | 3648 | eval
|
---|
| 3649 | {
|
---|
| 3650 | require Mail::Sendmail;
|
---|
| 3651 | Mail::Sendmail->import();
|
---|
| 3652 | };
|
---|
| 3653 | if ($@) {
|
---|
| 3654 | # Mail::Sendmail not found not sending mail !
|
---|
| 3655 | pb_log(0,"No Mail::Sendmail module found so not sending any mail !\n");
|
---|
| 3656 | } else {
|
---|
| 3657 | my %mail = (
|
---|
[477] | 3658 | To => $pbml->{$ENV{'PBPROJ'}},
|
---|
| 3659 | From => $pbpackager->{$ENV{'PBPROJ'}},
|
---|
| 3660 | Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
|
---|
| 3661 | Body => $msg,
|
---|
[490] | 3662 | Subject => "[ANNOUNCE] $sl",
|
---|
[477] | 3663 | );
|
---|
| 3664 |
|
---|
[1134] | 3665 | # Send mail
|
---|
| 3666 | if (! sendmail(%mail)) {
|
---|
| 3667 | if ((defined $Mail::Sendmail::error) and (defined $Mail::Sendmail::log)) {
|
---|
| 3668 | die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
|
---|
| 3669 | }
|
---|
[1109] | 3670 | }
|
---|
| 3671 | }
|
---|
[471] | 3672 | }
|
---|
| 3673 |
|
---|
[547] | 3674 | #
|
---|
| 3675 | # Creates a set of HTML file containing the news for the project
|
---|
| 3676 | # based on what has been generated by the pb_announce function
|
---|
| 3677 | #
|
---|
| 3678 | sub pb_web_news2html {
|
---|
| 3679 |
|
---|
[556] | 3680 | my $dest = shift || $ENV{'PBTMP'};
|
---|
| 3681 |
|
---|
[547] | 3682 | # Get all required parameters
|
---|
[1064] | 3683 | my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
|
---|
[547] | 3684 |
|
---|
| 3685 | # DB of announces for external usage (Web pages generation)
|
---|
| 3686 | my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
|
---|
| 3687 |
|
---|
| 3688 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
| 3689 | { RaiseError => 1, AutoCommit => 1 })
|
---|
| 3690 | || die "Unable to connect to $db";
|
---|
| 3691 | # For date handling
|
---|
| 3692 | $ENV{LANGUAGE}="C";
|
---|
[559] | 3693 | my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
|
---|
| 3694 | my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
|
---|
| 3695 | pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
|
---|
[547] | 3696 | my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
|
---|
[556] | 3697 | my %news;
|
---|
| 3698 | $news{"cy"} = ""; # current year's news
|
---|
| 3699 | $news{"ly"} = ""; # last year news
|
---|
| 3700 | $news{"py"} = ""; # previous years news
|
---|
| 3701 | $news{"fp"} = ""; # first page news
|
---|
[547] | 3702 | my $cpt = 4; # how many news for first page
|
---|
| 3703 | # Extract info from DB
|
---|
| 3704 | foreach my $row (@$all) {
|
---|
| 3705 | my ($id, $date, $announce) = @$row;
|
---|
[559] | 3706 | $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
|
---|
| 3707 | $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
|
---|
| 3708 | $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
|
---|
[556] | 3709 | $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
|
---|
[547] | 3710 | $cpt--;
|
---|
| 3711 | }
|
---|
[556] | 3712 | pb_log(1,"news{fp}: ".$news{"fp"}."\n");
|
---|
[547] | 3713 | $dbh->disconnect;
|
---|
[556] | 3714 |
|
---|
| 3715 | # Generate the HTML content
|
---|
| 3716 | foreach my $pref (keys %news) {
|
---|
| 3717 | open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
|
---|
| 3718 | print NEWS "$news{$pref}";
|
---|
| 3719 | close(NEWS);
|
---|
| 3720 | }
|
---|
[547] | 3721 | }
|
---|
| 3722 |
|
---|
[556] | 3723 |
|
---|
[347] | 3724 | # Return the SSH key file to use
|
---|
| 3725 | # Potentially create it if needed
|
---|
| 3726 |
|
---|
| 3727 | sub pb_ssh_get {
|
---|
| 3728 |
|
---|
| 3729 | my $create = shift || 0; # Do not create keys by default
|
---|
| 3730 |
|
---|
| 3731 | # Check the SSH environment
|
---|
| 3732 | my $keyfile = undef;
|
---|
| 3733 |
|
---|
| 3734 | # We have specific keys by default
|
---|
| 3735 | $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
|
---|
[348] | 3736 | if (!(-e $keyfile) && ($create eq 1)) {
|
---|
[347] | 3737 | pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
|
---|
| 3738 | }
|
---|
| 3739 |
|
---|
| 3740 | $keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
|
---|
| 3741 | $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
|
---|
| 3742 | $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
|
---|
| 3743 | die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
|
---|
| 3744 | return($keyfile);
|
---|
| 3745 | }
|
---|
| 3746 |
|
---|
| 3747 |
|
---|
[145] | 3748 | # Returns the pid of a running VM command using a specific VM file
|
---|
[142] | 3749 | sub pb_check_ps {
|
---|
| 3750 | my $vmcmd = shift;
|
---|
| 3751 | my $vmm = shift;
|
---|
| 3752 | my $vmexist = 0; # FALSE by default
|
---|
| 3753 |
|
---|
| 3754 | open(PS, "ps auxhww|") || die "Unable to call ps";
|
---|
| 3755 | while (<PS>) {
|
---|
| 3756 | next if (! /$vmcmd/);
|
---|
| 3757 | next if (! /$vmm/);
|
---|
| 3758 | my ($void1, $void2);
|
---|
| 3759 | ($void1, $vmexist, $void2) = split(/ +/);
|
---|
| 3760 | last;
|
---|
| 3761 | }
|
---|
| 3762 | return($vmexist);
|
---|
| 3763 | }
|
---|
| 3764 |
|
---|
| 3765 |
|
---|
[77] | 3766 | sub pb_extract_build_files {
|
---|
[25] | 3767 |
|
---|
| 3768 | my $src=shift;
|
---|
| 3769 | my $dir=shift;
|
---|
[26] | 3770 | my $ddir=shift;
|
---|
[500] | 3771 | my $mandatory=shift || "spec";
|
---|
[28] | 3772 | my @files;
|
---|
[25] | 3773 |
|
---|
[1219] | 3774 | my $flag = "mayfail" if (($mandatory eq "patch") || ($mandatory eq "src"));
|
---|
[500] | 3775 | my $res;
|
---|
| 3776 |
|
---|
[188] | 3777 | if ($src =~ /tar\.gz$/) {
|
---|
[500] | 3778 | $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
|
---|
[188] | 3779 | } elsif ($src =~ /tar\.bz2$/) {
|
---|
[500] | 3780 | $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
|
---|
[188] | 3781 | } else {
|
---|
| 3782 | die "Unknown compression algorithm for $src";
|
---|
| 3783 | }
|
---|
[500] | 3784 | # If not mandatory return now
|
---|
[1220] | 3785 | return() if (($res != 0) and (($mandatory eq "patch") || ($mandatory eq "src")));
|
---|
[1486] | 3786 | opendir(DIR,"$dir") || die "Unable to open directory $dir: $!";
|
---|
[25] | 3787 | foreach my $f (readdir(DIR)) {
|
---|
| 3788 | next if ($f =~ /^\./);
|
---|
[500] | 3789 | # Skip potential patch dir
|
---|
| 3790 | next if ($f =~ /^pbpatch/);
|
---|
[1219] | 3791 | # Skip potential source dir
|
---|
| 3792 | next if ($f =~ /^pbsrc/);
|
---|
[1480] | 3793 | # Skip potential backup files
|
---|
| 3794 | next if ($f =~ /~$/);
|
---|
[26] | 3795 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[315] | 3796 | pb_log(2,"mv $dir/$f $ddir\n");
|
---|
[28] | 3797 | push @files,"$ddir/$f";
|
---|
[25] | 3798 | }
|
---|
| 3799 | closedir(DIR);
|
---|
[26] | 3800 | # Not enough but still a first cleanup
|
---|
[74] | 3801 | pb_rm_rf("$dir");
|
---|
[28] | 3802 | return(@files);
|
---|
[25] | 3803 | }
|
---|
| 3804 |
|
---|
[315] | 3805 | sub pb_list_bfiles {
|
---|
| 3806 |
|
---|
| 3807 | my $dir = shift;
|
---|
| 3808 | my $pbpkg = shift;
|
---|
| 3809 | my $bfiles = shift;
|
---|
| 3810 | my $pkgfiles = shift;
|
---|
| 3811 | my $supfiles = shift;
|
---|
[1363] | 3812 | # subdir to keep if recursive mode, empty by default
|
---|
| 3813 | my $subdir = shift || "";
|
---|
[1367] | 3814 | # In a recursive function , we need a local var as DIR handle
|
---|
| 3815 | my $bdir;
|
---|
[315] | 3816 |
|
---|
[1363] | 3817 | pb_log(2,"DEBUG: entering pb_list_bfiles in $dir: ".Dumper($bfiles)."\n");
|
---|
[1367] | 3818 | opendir($bdir,"$dir") || die "Unable to open dir $dir: $!";
|
---|
| 3819 | foreach my $f (readdir($bdir)) {
|
---|
[1363] | 3820 | pb_log(3,"DEBUG: pb_list_bfiles found $f\n");
|
---|
[315] | 3821 | next if ($f =~ /^\./);
|
---|
[1363] | 3822 | if (-d "$dir/$f") {
|
---|
[1098] | 3823 | # Recurse for directories (Debian 3.0 format e.g.)
|
---|
[1363] | 3824 | pb_log(2,"DEBUG: pb_list_bfiles recurse in $dir/$f\n");
|
---|
| 3825 | pb_list_bfiles("$dir/$f",$pbpkg,$bfiles,$pkgfiles,$supfiles,$f);
|
---|
[1098] | 3826 | next;
|
---|
| 3827 | }
|
---|
[1363] | 3828 |
|
---|
| 3829 | my $key = $f;
|
---|
| 3830 | # if recursive then store also the subdir
|
---|
| 3831 | $key = "$subdir/$f" if ($subdir ne "");
|
---|
| 3832 | $bfiles->{$key} = "$dir/$f";
|
---|
| 3833 | $bfiles->{$key} =~ s~$ENV{'PBROOTDIR'}~~;
|
---|
[315] | 3834 | if (defined $supfiles->{$pbpkg}) {
|
---|
[1363] | 3835 | $pkgfiles->{$key} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
|
---|
[315] | 3836 | }
|
---|
| 3837 | }
|
---|
[1367] | 3838 | closedir($bdir);
|
---|
[1185] | 3839 | pb_log(2,"DEBUG: exiting pb_list_bfiles: ".Dumper($bfiles)."\n");
|
---|
[315] | 3840 | }
|
---|
| 3841 |
|
---|
[1185] | 3842 | sub pb_add_coma {
|
---|
| 3843 |
|
---|
| 3844 | my $str = shift;
|
---|
| 3845 | my $addstr = shift;
|
---|
| 3846 |
|
---|
| 3847 | $str .= "," if (defined $str);
|
---|
| 3848 | $str .= $addstr;
|
---|
| 3849 | return($str);
|
---|
| 3850 | }
|
---|
| 3851 |
|
---|
[1130] | 3852 | sub pb_list_sfiles {
|
---|
[395] | 3853 |
|
---|
[1130] | 3854 | my $sdir = shift;
|
---|
[1185] | 3855 | my $ptr = shift;
|
---|
[1177] | 3856 | my $pbos = shift;
|
---|
[1130] | 3857 | my $extdir = shift;
|
---|
| 3858 |
|
---|
[1185] | 3859 | pb_log(2,"DEBUG: entering pb_list_sfiles: ".Dumper($ptr)."\n");
|
---|
| 3860 | my $key = "$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
|
---|
| 3861 |
|
---|
[1130] | 3862 | # Prepare local sources for this distro - They are always applied first - May be a problem one day
|
---|
| 3863 | # This function works for both patches and additional sources
|
---|
| 3864 | foreach my $p (sort(<$sdir/*>)) {
|
---|
[1185] | 3865 | $ptr->{$key} = pb_add_coma($ptr->{$key},"file://$p") if (($p =~ /\.all$/) || ($p =~ /\.$pbos->{'os'}$/) || ($p =~ /\.$pbos->{'type'}$/) || ($p =~ /\.$pbos->{'family'}$/) || ($p =~ /\.$pbos->{'name'}$/) || ($p =~ /\.$pbos->{'name'}-$pbos->{'version'}$/) ||($p =~ /\.$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}$/));
|
---|
[1130] | 3866 | }
|
---|
| 3867 |
|
---|
| 3868 | # Prepare also remote sources to be included - Applied after the local ones
|
---|
[1185] | 3869 | foreach my $p ("all","$pbos->{'os'}","$pbos->{'type'}","$pbos->{'family'}","$pbos->{'name'}","$pbos->{'name'}-$pbos->{'version'}","$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}") {
|
---|
[1130] | 3870 | my $f = "$extdir.".".$p";
|
---|
| 3871 | next if (not -f $f);
|
---|
| 3872 | if (not open(PATCH,$f)) {
|
---|
| 3873 | pb_display("Unable to open existing external source file content $f\n");
|
---|
| 3874 | next;
|
---|
| 3875 | }
|
---|
| 3876 | while (<PATCH>) {
|
---|
| 3877 | chomp();
|
---|
[1185] | 3878 | $ptr->{$key} = pb_add_coma($ptr->{$key},"$_");
|
---|
[1130] | 3879 | }
|
---|
| 3880 | close(PATCH);
|
---|
| 3881 | }
|
---|
[1185] | 3882 | pb_log(2,"DEBUG: exiting pb_list_sfiles: ".Dumper($ptr)."\n");
|
---|
[1186] | 3883 | return($ptr);
|
---|
[1130] | 3884 | }
|
---|
| 3885 |
|
---|
[395] | 3886 | #
|
---|
| 3887 | # Return the list of packages we are working on in a non CMS action
|
---|
| 3888 | #
|
---|
| 3889 | sub pb_get_pkg {
|
---|
| 3890 |
|
---|
| 3891 | my @pkgs = ();
|
---|
| 3892 |
|
---|
| 3893 | my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
| 3894 | @pkgs = keys %$var;
|
---|
| 3895 |
|
---|
| 3896 | pb_log(0,"Packages: ".join(',',@pkgs)."\n");
|
---|
| 3897 | return(\@pkgs);
|
---|
| 3898 | }
|
---|
| 3899 |
|
---|
[1176] | 3900 | # Manages VM/RM SSH port communication
|
---|
[1143] | 3901 | sub pb_get_port {
|
---|
| 3902 |
|
---|
| 3903 | my $port = shift;
|
---|
[1179] | 3904 | my $pbos = shift;
|
---|
[1143] | 3905 | my $cmt = shift;
|
---|
[1179] | 3906 | my $nport;
|
---|
[1143] | 3907 |
|
---|
| 3908 | die "No port passed in parameter. Report to dev team\n" if (not defined $port);
|
---|
[1179] | 3909 | # key is project on VM, but machine tuple for RM
|
---|
| 3910 | if ($cmt =~ /^RM/i) {
|
---|
| 3911 | $nport = $port->{"$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}"};
|
---|
| 3912 | } else {
|
---|
| 3913 | $nport = $port->{$ENV{'PBPROJ'}};
|
---|
| 3914 | }
|
---|
| 3915 | pb_log(2,"pb_get_port with $nport\n");
|
---|
[1143] | 3916 | # Maybe a port was given as parameter so overwrite
|
---|
| 3917 | $nport = "$pbport" if (defined $pbport);
|
---|
[1268] | 3918 | # Maybe in // mode so use the env var set up as an offset to the base port, except when called from send2target for Packages or for RM
|
---|
[1281] | 3919 | if (($cmt ne "Packages") && ($cmt !~ /^RM/i)) {
|
---|
[1143] | 3920 | $nport += $ENV{'PBVMPORT'} if ((defined $pbparallel) && (defined $ENV{'PBVMPORT'}));
|
---|
| 3921 | }
|
---|
[1146] | 3922 | pb_log(2,"pb_get_port returns $nport\n");
|
---|
[1143] | 3923 | return($nport);
|
---|
| 3924 | }
|
---|
| 3925 |
|
---|
| 3926 | sub pb_set_port {
|
---|
| 3927 |
|
---|
| 3928 | my ($pid,$ident) = @_;
|
---|
[1146] | 3929 | pb_log(2,"pb_set_port for VM ($pid), id $ident\n");
|
---|
[1143] | 3930 | $ENV{'PBVMPORT'} = $ident;
|
---|
[1146] | 3931 | pb_log(2,"pb_set_port sets PBVMPORT in env to $ENV{'PBVMPORT'}\n");
|
---|
[1143] | 3932 | }
|
---|
| 3933 |
|
---|
| 3934 | sub pb_set_parallel {
|
---|
| 3935 |
|
---|
| 3936 | my $vtype = shift;
|
---|
| 3937 |
|
---|
[1146] | 3938 | pb_log(2,"pb_set_parallel vtype: $vtype\n");
|
---|
[1143] | 3939 | # Take care of memory size if VM, parallel mode and more than 1 action
|
---|
| 3940 | if ((defined $pbparallel) && ($pbparallel ne 1) && ($vtype eq "vm")) {
|
---|
| 3941 | eval
|
---|
| 3942 | {
|
---|
| 3943 | require Linux::SysInfo;
|
---|
| 3944 | Linux::SysInfo->import();
|
---|
| 3945 | };
|
---|
| 3946 | if ($@) {
|
---|
[1153] | 3947 | # Linux::SysInfo not found
|
---|
[1388] | 3948 | pb_log(1,"ADVISE: Install Linux::SysInfo to benefit from automatic parallelism optimization.\nOr optimize manually pbparallel in your pb.conf file\nUsing $pbparallel processes max at a time for the moment\nWARNING: This may consume too much memory for your system\n");
|
---|
[1143] | 3949 | } else {
|
---|
| 3950 | # Using the memory size
|
---|
| 3951 | my $si = Linux::SysInfo::sysinfo();
|
---|
| 3952 | if (not defined $si) {
|
---|
[1388] | 3953 | pb_log(1,"ADVISE: Install Linux::SysInfo to benefit from automatic parallelism optimization.\nOr optimize manually pbparallel in your pb.conf file\nUsing $pbparallel processes max at a time for the moment\nWARNING: This may consume too much memory for your system\n");
|
---|
[1143] | 3954 | } else {
|
---|
| 3955 | # Keep the number of VM whose memory can be allocated
|
---|
| 3956 | my $ram = $si->{"totalram"}-$si->{"sharedram"}-$si->{"bufferram"};
|
---|
| 3957 | my $ram2;
|
---|
[1153] | 3958 | my ($vmmem) = pb_conf_get_if("vmmem");
|
---|
[1146] | 3959 |
|
---|
[1153] | 3960 | my $v = "default";
|
---|
| 3961 | if ((defined $vmmem) and (defined $vmmem->{$v})) {
|
---|
| 3962 | $ram2 = $vmmem->{$v};
|
---|
[1143] | 3963 | } else {
|
---|
| 3964 | # Default for KVM/QEMU
|
---|
| 3965 | $ram2 = 128;
|
---|
| 3966 | }
|
---|
| 3967 | $pbparallel = sprintf("%d",$ram/$ram2);
|
---|
| 3968 | }
|
---|
[1153] | 3969 | pb_log(1,"Using $pbparallel processes at a time\n");
|
---|
[1143] | 3970 | }
|
---|
| 3971 | }
|
---|
[1176] | 3972 | pb_log(2,"pb_set_parallel returns: $pbparallel\n") if (defined $pbparallel);
|
---|
[1143] | 3973 | return($pbparallel);
|
---|
| 3974 | }
|
---|
| 3975 |
|
---|
[1179] | 3976 | sub pb_get_sudocmds {
|
---|
| 3977 |
|
---|
| 3978 | my $pbos = shift;
|
---|
[1190] | 3979 | my %sudocmds;
|
---|
[1143] | 3980 |
|
---|
[1198] | 3981 | pb_log(2,"pb_get_sudocmds entering with lines:".Dumper(@_)."\n");
|
---|
| 3982 | foreach my $c (split(/;/,$pbos->{'update'}),split(/;/,$pbos->{'install'}),@_) {
|
---|
| 3983 | pb_log(2,"pb_get_sudocmds analyses $c\n");
|
---|
| 3984 | next if ($c !~ /^\s*sudo/);
|
---|
| 3985 | # remove sudo and leading spaces
|
---|
| 3986 | $c =~ s/^\s*sudo\s+//;
|
---|
[1192] | 3987 | # keep only the command, not the params
|
---|
| 3988 | $c =~ s/([^\s]+)\s.*$/$1/;
|
---|
[1190] | 3989 | $sudocmds{$c} = "";
|
---|
[1179] | 3990 | }
|
---|
[1198] | 3991 | pb_log(2,"pb_get_sudocmds returns ".Dumper(keys %sudocmds)."\n");
|
---|
[1190] | 3992 | return(keys %sudocmds);
|
---|
[1179] | 3993 | }
|
---|
| 3994 |
|
---|
[1278] | 3995 | sub pb_sign_pkgs {
|
---|
[1179] | 3996 |
|
---|
[1278] | 3997 | my $pbos = shift;
|
---|
| 3998 | my $made = shift;
|
---|
| 3999 |
|
---|
| 4000 | pb_log(2,"entering pb_sign_pkg: $made ".Dumper($pbos)."\n");
|
---|
| 4001 | my ($passfile, $passphrase, $passpath) = pb_conf_get_if("pbpassfile","pbpassphrase","pbpasspath");
|
---|
| 4002 | $ENV{'PBPASSPHRASE'} = $passphrase->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSPHRASE'}) && (defined $passphrase->{$ENV{'PBPROJ'}}));
|
---|
| 4003 | $ENV{'PBPASSFILE'} = $passfile->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSFILE'})&& (defined $passfile->{$ENV{'PBPROJ'}})) ;
|
---|
| 4004 | $ENV{'PBPASSPATH'} = $passpath->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSPATH'})&& (defined $passpath->{$ENV{'PBPROJ'}})) ;
|
---|
| 4005 |
|
---|
[1279] | 4006 | # Remove extra spaces
|
---|
| 4007 | $made =~ s/\s+/ /g;
|
---|
| 4008 | $made =~ s/^\s//g;
|
---|
| 4009 | $made =~ s/\s$//g;
|
---|
| 4010 |
|
---|
[1278] | 4011 | if ($pbos->{'type'} eq "rpm") {
|
---|
| 4012 | eval
|
---|
| 4013 | {
|
---|
| 4014 | require RPM4::Sign;
|
---|
| 4015 | RPM4::Sign->import();
|
---|
| 4016 | };
|
---|
| 4017 | if ($@) {
|
---|
| 4018 | # RPM4::Sign not found
|
---|
| 4019 | pb_log(1,"WARNING: Install RPM4::Sign to benefit from automatic package signing.\n");
|
---|
| 4020 | } else {
|
---|
| 4021 | return if ((not defined $ENV{'PBPASSPHRASE'}) and (not defined $ENV{'PBPASSFILE'}));
|
---|
| 4022 | my $sign = RPM4::Sign->new(
|
---|
| 4023 | passphrase => $ENV{'PBPASSPHRASE'},
|
---|
| 4024 | name => $ENV{'PBPACKAGER'},
|
---|
| 4025 | path => $ENV{'PBPASSPATH'},
|
---|
| 4026 | password_file => $ENV{'PBPASSFILE'},
|
---|
| 4027 | );
|
---|
| 4028 |
|
---|
| 4029 | pb_log(0,"Signing RPM packages...\n");
|
---|
| 4030 | pb_log(2,"pb_sign_pkg: pkgs:".Dumper(split(/ /,$made))."\n");
|
---|
| 4031 | $sign->rpmssign(split(/ /,$made));
|
---|
| 4032 | }
|
---|
| 4033 | } elsif ($pbos->{'type'} eq "deb") {
|
---|
[1279] | 4034 | my $changes = "";
|
---|
| 4035 | foreach my $c (split(/ /,$made)) {
|
---|
| 4036 | $changes .= " $ENV{'PBBUILDDIR'}/$c" if ($c =~ /\.changes$/);
|
---|
| 4037 | }
|
---|
[1386] | 4038 | my $debsigncmd = pb_check_req("debsign",1);
|
---|
| 4039 | pb_system("$debsigncmd -m\'$ENV{'PBPACKAGER'}\' $changes","Signing DEB packages");
|
---|
[1278] | 4040 | } else {
|
---|
| 4041 | pb_log(0,"I don't know yet how to sign packages for type $pbos->{'type'}.\nPlease give feedback to dev team\n");
|
---|
[1279] | 4042 | }
|
---|
[1278] | 4043 | pb_log(2,"exiting pb_sign_pkg\n");
|
---|
| 4044 | }
|
---|
| 4045 |
|
---|
[1282] | 4046 | # return list of all distributins supported, coma separated
|
---|
| 4047 | sub pb_get_distros {
|
---|
| 4048 |
|
---|
| 4049 | my $pbos = shift;
|
---|
| 4050 | my $pbtarget = shift;
|
---|
| 4051 |
|
---|
| 4052 | my $tmpl = "$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'},";
|
---|
| 4053 |
|
---|
| 4054 | # Get list of distributions for which we need to generate build files if no target
|
---|
[1402] | 4055 | if (not defined $pbtarget) {
|
---|
[1282] | 4056 | my @pt = pb_conf_get_if("vmlist","velist","rmlist");
|
---|
| 4057 | if (defined $pt[0]->{$ENV{'PBPROJ'}}) {
|
---|
| 4058 | $tmpl .= $pt[0]->{$ENV{'PBPROJ'}};
|
---|
| 4059 | }
|
---|
| 4060 | if (defined $pt[1]->{$ENV{'PBPROJ'}}) {
|
---|
[1386] | 4061 | # The 2 lists need to be grouped with a ',' separating them
|
---|
[1282] | 4062 | if ($tmpl ne "") {
|
---|
| 4063 | $tmpl .= ",";
|
---|
| 4064 | }
|
---|
| 4065 | $tmpl .= $pt[1]->{$ENV{'PBPROJ'}}
|
---|
| 4066 | }
|
---|
| 4067 | if (defined $pt[2]->{$ENV{'PBPROJ'}}) {
|
---|
| 4068 | # The lists needs to be grouped with a ',' separating them
|
---|
| 4069 | if ($tmpl ne "") {
|
---|
| 4070 | $tmpl .= ",";
|
---|
| 4071 | }
|
---|
| 4072 | $tmpl .= $pt[2]->{$ENV{'PBPROJ'}}
|
---|
| 4073 | }
|
---|
| 4074 | }
|
---|
| 4075 | return($tmpl);
|
---|
| 4076 | }
|
---|
| 4077 |
|
---|
[1432] | 4078 | sub pb_get_extdir () {
|
---|
| 4079 |
|
---|
| 4080 | # the pbrc file should contain it and whatever the key, we take it
|
---|
| 4081 | my ($ed) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbextdir");
|
---|
| 4082 | pb_log(2,"ed: ".Dumper($ed)."\n");
|
---|
| 4083 | my $pbextdir = "";
|
---|
| 4084 | foreach my $k (keys %$ed) {
|
---|
| 4085 | $pbextdir = $ed->{$k};
|
---|
[1459] | 4086 | # In case we have an empty field, empty it completely
|
---|
| 4087 | pb_log(2,"pbextdir: ***$pbextdir***\n");
|
---|
| 4088 | $pbextdir =~ s/^\s*$//;
|
---|
[1432] | 4089 | }
|
---|
[1459] | 4090 | pb_log(2,"pbextdir: ***$pbextdir***\n");
|
---|
[1432] | 4091 | return($pbextdir);
|
---|
| 4092 | }
|
---|
| 4093 |
|
---|
[395] | 4094 | 1;
|
---|