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