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