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