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