[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)
|
---|
[628] | 65 | such as Subversion, CVS, Mercurial... or being a simple reference to a compressed tar file.
|
---|
[331] | 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.
|
---|
[628] | 141 | CMS supported are SVN, CVS and Mercurial
|
---|
[331] | 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'}}) {
|
---|
[665] | 561 | # the 2 lists need to be grouped with a ',' separated them
|
---|
[340] | 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")) {
|
---|
[665] | 585 | my %virt;
|
---|
| 586 | # De-duplicate similar VM and VE
|
---|
[556] | 587 | foreach my $d (split(/,/,$tmpl)) {
|
---|
[665] | 588 | $virt{$d} = $d;
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | foreach my $d (keys %virt) {
|
---|
[556] | 592 | my ($name,$ver,$arch) = split(/-/,$d);
|
---|
| 593 | chomp($arch);
|
---|
| 594 | my ($ddir, $dver, $dfam);
|
---|
[620] | 595 | ($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'}, $pb{'upd'}) = pb_distro_init($name,$ver);
|
---|
[556] | 596 | pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $pb{'dtype'}, $pb{'suf'})."\n");
|
---|
| 597 | pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
|
---|
| 598 |
|
---|
| 599 | # We need to compute the real name of the package
|
---|
| 600 | my $pbrealpkg = pb_cms_get_real_pkg($pbpkg,$pb{'dtype'});
|
---|
| 601 | $pb{'realpkg'} = $pbrealpkg;
|
---|
| 602 | pb_log(1,"Virtual package $pbpkg has a real package name of $pbrealpkg on $ddir-$dver\n") if ($pbrealpkg ne $pbpkg);
|
---|
| 603 |
|
---|
| 604 | # Filter build files from the less precise up to the most with overloading
|
---|
| 605 | # Filter all files found, keeping the name, and generating in dest
|
---|
| 606 |
|
---|
| 607 | # Find all build files first relatively to PBROOTDIR
|
---|
| 608 | # Find also all specific files referenced in the .pb conf file
|
---|
| 609 | my %bfiles = ();
|
---|
| 610 | my %pkgfiles = ();
|
---|
| 611 | $build{"$ddir-$dver-$arch"} = "yes";
|
---|
| 612 |
|
---|
| 613 | if (-d "$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}") {
|
---|
| 614 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$pb{'dtype'}",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 615 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$dfam") {
|
---|
| 616 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 617 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir") {
|
---|
| 618 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 619 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver") {
|
---|
| 620 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 621 | } elsif (-d "$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch") {
|
---|
| 622 | pb_list_bfiles("$ENV{'PBROOTDIR'}/$pbpkg/$ddir-$dver-$arch",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 623 | } else {
|
---|
| 624 | $build{"$ddir-$dver-$arch"} = "no";
|
---|
[500] | 625 | next;
|
---|
| 626 | }
|
---|
[556] | 627 | pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
|
---|
| 628 |
|
---|
| 629 | # Get all filters to apply
|
---|
| 630 | my $ptr = pb_get_filters($pbpkg, $pb{'dtype'}, $dfam, $ddir, $dver);
|
---|
| 631 |
|
---|
| 632 | # Prepare local patches for this distro - They are always applied first - May be a problem one day
|
---|
| 633 | foreach my $p (sort(<$ENV{'PBROOTDIR'}/$pbpkg/pbpatch/*>)) {
|
---|
| 634 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.all$/));
|
---|
| 635 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.all$/);
|
---|
| 636 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$pb{'dtype'}$/));
|
---|
| 637 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$pb{'dtype'}$/);
|
---|
| 638 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$dfam$/));
|
---|
| 639 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$dfam$/);
|
---|
| 640 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir$/));
|
---|
| 641 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir$/);
|
---|
| 642 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver$/));
|
---|
| 643 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver$/);
|
---|
| 644 | $patches{"$ddir-$dver-$arch"} .= "," if ((defined $patches{"$ddir-$dver-$arch"}) and ($p =~ /\.$ddir-$dver-$arch$/));
|
---|
| 645 | $patches{"$ddir-$dver-$arch"} .= "file://$p" if ($p =~ /\.$ddir-$dver-$arch$/);
|
---|
[500] | 646 | }
|
---|
[556] | 647 |
|
---|
| 648 | # Prepare also remote patches to be included - Applied after the local ones
|
---|
| 649 | foreach my $p ("all","$pb{'dtype'}","$dfam","$ddir","$ddir-$dver","$ddir-$dver-$arch") {
|
---|
| 650 | my $f = "$ENV{'PBROOTDIR'}/$pbpkg/pbextpatch.$p";
|
---|
| 651 | next if (not -f $f);
|
---|
| 652 | if (not open(PATCH,$f)) {
|
---|
| 653 | pb_display("Unable to open existing external patch file content $f\n");
|
---|
| 654 | next;
|
---|
| 655 | }
|
---|
| 656 | while (<PATCH>) {
|
---|
| 657 | chomp();
|
---|
| 658 | $patches{"$ddir-$dver-$arch"} .= "," if (defined $patches{"$ddir-$dver-$arch"});
|
---|
| 659 | $patches{"$ddir-$dver-$arch"} .= "$_";
|
---|
| 660 | }
|
---|
| 661 | close(PATCH);
|
---|
[16] | 662 | }
|
---|
[556] | 663 | pb_log(2,"DEBUG: pb->patches: ".Dumper($pb{'patches'})."\n");
|
---|
| 664 |
|
---|
| 665 | # Apply now all the filters on all the files concerned
|
---|
| 666 | # destination dir depends on the type of file
|
---|
| 667 | if (defined $ptr) {
|
---|
| 668 | # For patch support
|
---|
| 669 | $pb{'tuple'} = "$ddir-$dver-$arch";
|
---|
| 670 | foreach my $f (values %bfiles,values %pkgfiles) {
|
---|
| 671 | pb_filter_file("$ENV{'PBROOTDIR'}/$f",$ptr,"$dest/pbconf/$ddir-$dver-$arch/".basename($f),\%pb);
|
---|
| 672 | }
|
---|
| 673 | }
|
---|
[15] | 674 | }
|
---|
[556] | 675 | my @found;
|
---|
| 676 | my @notfound;
|
---|
| 677 | foreach my $b (keys %build) {
|
---|
| 678 | push @found,$b if ($build{$b} =~ /yes/);
|
---|
| 679 | push @notfound,$b if ($build{$b} =~ /no/);
|
---|
| 680 | }
|
---|
| 681 | pb_log(0,"Build files generated for ".join(',',sort(@found))."\n");
|
---|
| 682 | pb_log(0,"No Build files found for ".join(',',sort(@notfound))."\n") if (@notfound);
|
---|
| 683 | pb_log(2,"DEBUG: patches: ".Dumper(%patches)."\n");
|
---|
[18] | 684 | }
|
---|
[500] | 685 |
|
---|
[236] | 686 | # Get the generic filter (all.pbf) and
|
---|
| 687 | # apply those to the non-build files including those
|
---|
| 688 | # generated by pbinit if applicable
|
---|
| 689 |
|
---|
| 690 | # Get only all.pbf filter
|
---|
[357] | 691 | my $ptr = pb_get_filters($pbpkg);
|
---|
[236] | 692 |
|
---|
| 693 | my $liste ="";
|
---|
| 694 | if (defined $filteredfiles->{$pbpkg}) {
|
---|
| 695 | foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
|
---|
[499] | 696 | pb_filter_file_inplace($ptr,"$dest/$f",\%pb);
|
---|
[238] | 697 | $liste = "$f $liste";
|
---|
[236] | 698 | }
|
---|
| 699 | }
|
---|
[315] | 700 | pb_log(2,"Files ".$liste."have been filtered\n");
|
---|
[236] | 701 |
|
---|
[556] | 702 | # Do not do that for website
|
---|
| 703 | if ((not defined $param) || ($param ne "Web")) {
|
---|
| 704 | my %tmp;
|
---|
| 705 | # Filter potential patches (local + remote)
|
---|
| 706 | pb_log(0,"Delivering and compressing patches ");
|
---|
| 707 | foreach my $v (keys %patches) {
|
---|
| 708 | pb_mkdir_p("$dest/pbconf/$v/pbpatch");
|
---|
| 709 | foreach my $pf (split(/,/,$patches{$v})) {
|
---|
| 710 | my $pp = basename($pf);
|
---|
| 711 | pb_cms_export($pf,undef,"$dest/pbconf/$v/pbpatch");
|
---|
| 712 | pb_filter_file_inplace($ptr,"$dest/pbconf/$v/pbpatch/$pp",\%pb);
|
---|
| 713 | pb_system("gzip -9f $dest/pbconf/$v/pbpatch/$pp","","quiet");
|
---|
| 714 | $tmp{$pf} = "";
|
---|
| 715 | }
|
---|
[500] | 716 | }
|
---|
[556] | 717 | foreach my $v (keys %tmp) {
|
---|
| 718 | pb_log(0,"$v ");
|
---|
| 719 | }
|
---|
| 720 | pb_log(0,"\n");
|
---|
| 721 | } else {
|
---|
| 722 | # Instead call News generation
|
---|
| 723 | pb_web_news2html($dest);
|
---|
[559] | 724 | # And create an empty pbconf
|
---|
| 725 | pb_mkdir_p("$dest/pbconf");
|
---|
[560] | 726 | # And prepare the pbscript to execute remotely
|
---|
| 727 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 728 | print SCRIPT "#!/bin/bash\n";
|
---|
| 729 | print SCRIPT "#set -x\n";
|
---|
| 730 | print SCRIPT "echo ... Extracting Website content\n";
|
---|
| 731 | print SCRIPT "find . -type f | grep -Ev '^./$pbpkg-$pbver.tar.gz|^./pbscript' | xargs rm -f non-existent\n";
|
---|
| 732 | print SCRIPT "find * -type d -depth | xargs rmdir 2> /dev/null \n";
|
---|
| 733 | print SCRIPT "tar xfz $pbpkg-$pbver.tar.gz\n";
|
---|
| 734 | print SCRIPT "mv $pbpkg-$pbver/* .\n";
|
---|
| 735 | print SCRIPT "rm -f $pbpkg-$pbver.tar.gz\n";
|
---|
| 736 | print SCRIPT "rmdir $pbpkg-$pbver\n";
|
---|
| 737 | close(SCRIPT);
|
---|
[499] | 738 | }
|
---|
| 739 |
|
---|
[265] | 740 | # Prepare the dest directory for archive
|
---|
[340] | 741 | if (-x "$ENV{'PBROOTDIR'}/$pbpkg/pbinit") {
|
---|
[499] | 742 | pb_filter_file("$ENV{'PBROOTDIR'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",\%pb);
|
---|
[266] | 743 | chmod 0755,"$ENV{'PBTMP'}/pbinit";
|
---|
[490] | 744 | pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOTDIR'}/$pbpkg/pbinit","verbose");
|
---|
[265] | 745 | }
|
---|
| 746 |
|
---|
[18] | 747 | # Archive dest dir
|
---|
[69] | 748 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
[537] | 749 | if (defined $preserve) {
|
---|
| 750 | # In that case we want to preserve the original tar file for checksum purposes
|
---|
| 751 | # The one created is btw equivalent in that case to this one
|
---|
| 752 | # Maybe check basename of both to be sure they are the same ?
|
---|
| 753 | pb_log(0,"Preserving original tar file ");
|
---|
| 754 | move("$preserve","$pbpkg-$pbver.tar.gz");
|
---|
| 755 | } else {
|
---|
| 756 | # Possibility to look at PBSRC to guess more the filename
|
---|
| 757 | pb_system("tar cfz $pbpkg-$pbver.tar.gz --exclude=$pbpkg-$pbver/pbconf $pbpkg-$pbver","Creating $pbpkg tar files compressed");
|
---|
| 758 | }
|
---|
[344] | 759 | pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
|
---|
[493] | 760 | pb_system("tar cfz $pbpkg-$pbver.pbconf.tar.gz $pbpkg-$pbver/pbconf","Creating pbconf tar files compressed");
|
---|
| 761 | pb_log(0,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz\n");
|
---|
[83] | 762 |
|
---|
[357] | 763 | # Keep track of version-tag per pkg
|
---|
| 764 | $pkgs{$pbpkg} = "$pbver-$pbtag";
|
---|
[83] | 765 |
|
---|
[288] | 766 | # Final cleanup
|
---|
| 767 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 768 | }
|
---|
[357] | 769 |
|
---|
| 770 | # Keep track of per package version
|
---|
| 771 | pb_log(2,"DEBUG pkgs: ".Dumper(%pkgs)."\n");
|
---|
| 772 | open(PKG,"> $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb";
|
---|
[539] | 773 | foreach my $pbpkg (keys %pkgs) {
|
---|
[357] | 774 | print PKG "pbpkg $pbpkg = $pkgs{$pbpkg}\n";
|
---|
| 775 | }
|
---|
| 776 | close(PKG);
|
---|
| 777 |
|
---|
| 778 | # Keep track of what is generated by default
|
---|
| 779 | # We need to store the dir and info on version-tag
|
---|
| 780 | # Base our content on the existing .pb file
|
---|
| 781 | copy("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb","$ENV{'PBDESTDIR'}/pbrc");
|
---|
| 782 | open(LAST,">> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
|
---|
| 783 | print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOTDIR'}\n";
|
---|
| 784 | print LAST "pbprojver $ENV{'PBPROJ'} = $ENV{'PBPROJVER'}\n";
|
---|
| 785 | print LAST "pbprojtag $ENV{'PBPROJ'} = $ENV{'PBPROJTAG'}\n";
|
---|
| 786 | print LAST "pbpackager $ENV{'PBPROJ'} = $ENV{'PBPACKAGER'}\n";
|
---|
| 787 | close(LAST);
|
---|
[77] | 788 | }
|
---|
[22] | 789 |
|
---|
[77] | 790 | sub pb_build2pkg {
|
---|
| 791 |
|
---|
[22] | 792 | # Get the running distro to build on
|
---|
[620] | 793 | my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd) = pb_distro_init();
|
---|
| 794 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd))."\n");
|
---|
[22] | 795 |
|
---|
[353] | 796 | # Get list of packages to build
|
---|
[83] | 797 | # Get content saved in cms2build
|
---|
[353] | 798 | my $ptr = pb_get_pkg();
|
---|
| 799 | @pkgs = @$ptr;
|
---|
| 800 |
|
---|
[500] | 801 | my $arch = pb_get_arch();
|
---|
| 802 |
|
---|
[353] | 803 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
[83] | 804 | $pkg = { } if (not defined $pkg);
|
---|
| 805 |
|
---|
[25] | 806 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
[126] | 807 | my $made = ""; # pkgs made during build
|
---|
[27] | 808 | foreach my $pbpkg (@pkgs) {
|
---|
[88] | 809 | my $vertag = $pkg->{$pbpkg};
|
---|
[77] | 810 | # get the version of the current package - maybe different
|
---|
| 811 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 812 |
|
---|
[27] | 813 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[493] | 814 | my $src2="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
|
---|
[315] | 815 | pb_log(2,"Source file: $src\n");
|
---|
[493] | 816 | pb_log(2,"Pbconf file: $src2\n");
|
---|
[25] | 817 |
|
---|
[315] | 818 | pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
|
---|
[25] | 819 | if ($dtype eq "rpm") {
|
---|
| 820 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
[28] | 821 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
[96] | 822 | 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] | 823 | }
|
---|
[25] | 824 | }
|
---|
| 825 |
|
---|
[315] | 826 | # Remove in case a previous link/file was there
|
---|
[301] | 827 | unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
|
---|
[188] | 828 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
[25] | 829 | # We need to first extract the spec file
|
---|
[500] | 830 | my @specfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$ENV{'PBBUILDDIR'}/SPECS","spec");
|
---|
[25] | 831 |
|
---|
[493] | 832 | # We need to handle potential patches to upstream sources
|
---|
[500] | 833 | pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/pbpatch/","$ENV{'PBBUILDDIR'}/SOURCES","patch");
|
---|
[493] | 834 |
|
---|
[315] | 835 | pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
|
---|
[25] | 836 | # set LANGUAGE to check for correct log messages
|
---|
| 837 | $ENV{'LANGUAGE'}="C";
|
---|
[459] | 838 | # Older Redhat use _target_platform in %configure incorrectly
|
---|
| 839 | my $specialdef = "";
|
---|
| 840 | if (($ddir eq "redhat") || (($ddir eq "rhel") && ($dver eq "2.1"))) {
|
---|
| 841 | $specialdef = "--define \'_target_platform \"\"\'";
|
---|
| 842 | }
|
---|
[28] | 843 | foreach my $f (@specfile) {
|
---|
| 844 | if ($f =~ /\.spec$/) {
|
---|
[621] | 845 | pb_distro_installdeps("$f",$dtype,$pbupd);
|
---|
[483] | 846 | pb_system("rpmbuild $specialdef --define \'packager $ENV{'PBPACKAGER'}\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}","verbose");
|
---|
[28] | 847 | last;
|
---|
| 848 | }
|
---|
| 849 | }
|
---|
[540] | 850 | # Get the name of the generated packages
|
---|
| 851 | open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
|
---|
| 852 | while (<LOG>) {
|
---|
[572] | 853 | chomp($_);
|
---|
[540] | 854 | next if ($_ !~ /^Wrote:/);
|
---|
| 855 | s|.*/([S]*RPMS.*)|$1|;
|
---|
[572] | 856 | $made .=" $_";
|
---|
[540] | 857 | }
|
---|
[541] | 858 | close(LOG);
|
---|
[540] | 859 |
|
---|
[118] | 860 | } elsif ($dtype eq "deb") {
|
---|
[149] | 861 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
[274] | 862 | pb_system("tar xfz $src","Extracting sources");
|
---|
[493] | 863 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
[149] | 864 |
|
---|
| 865 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
[310] | 866 | pb_rm_rf("debian");
|
---|
[500] | 867 | symlink "pbconf/$ddir-$dver-$arch","debian" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
|
---|
[199] | 868 | chmod 0755,"debian/rules";
|
---|
[544] | 869 |
|
---|
[621] | 870 | pb_distro_installdeps("debian/control",$dtype,$pbupd);
|
---|
[544] | 871 | pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package","verbose");
|
---|
| 872 | # Get the name of the generated packages
|
---|
| 873 | open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to open $ENV{'PBTMP'}/system.log";
|
---|
| 874 | while (<LOG>) {
|
---|
| 875 | chomp();
|
---|
| 876 | my $tmp = $_;
|
---|
[567] | 877 | next if ($tmp !~ /^dpkg-deb.*:/);
|
---|
[544] | 878 | $tmp =~ s|.*../(.*)_(.*).deb.*|$1|;
|
---|
| 879 | $made="$made $tmp.dsc $tmp.tar.gz $tmp"."_*.deb $tmp"."_*.changes";
|
---|
[448] | 880 | }
|
---|
[544] | 881 | close(LOG);
|
---|
[87] | 882 | } elsif ($dtype eq "ebuild") {
|
---|
[149] | 883 | my @ebuildfile;
|
---|
| 884 | # For gentoo we need to take pb as subsystem name
|
---|
[295] | 885 | # We put every apps here under sys-apps. hope it's correct
|
---|
[435] | 886 | # We use pb's home dir in order to have a single OVERLAY line
|
---|
[295] | 887 | my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
|
---|
| 888 | pb_mkdir_p($tmpd) if (! -d "$tmpd");
|
---|
| 889 | pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
|
---|
[149] | 890 |
|
---|
[295] | 891 | # We need to first extract the ebuild file
|
---|
[500] | 892 | @ebuildfile = pb_extract_build_files($src2,"$pbpkg-$pbver/pbconf/$ddir-$dver-$arch/","$tmpd","ebuild");
|
---|
[149] | 893 |
|
---|
| 894 | # Prepare the build env for gentoo
|
---|
| 895 | my $found = 0;
|
---|
[295] | 896 | my $pbbd = $ENV{'HOME'};
|
---|
[150] | 897 | $pbbd =~ s|/|\\/|g;
|
---|
[295] | 898 | if (-r "/etc/make.conf") {
|
---|
| 899 | open(MAKE,"/etc/make.conf");
|
---|
| 900 | while (<MAKE>) {
|
---|
| 901 | $found = 1 if (/$pbbd\/portage/);
|
---|
| 902 | }
|
---|
| 903 | close(MAKE);
|
---|
[149] | 904 | }
|
---|
| 905 | if ($found == 0) {
|
---|
[295] | 906 | pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
|
---|
[149] | 907 | }
|
---|
[295] | 908 | #$found = 0;
|
---|
| 909 | #if (-r "/etc/portage/package.keywords") {
|
---|
| 910 | #open(KEYW,"/etc/portage/package.keywords");
|
---|
| 911 | #while (<KEYW>) {
|
---|
| 912 | #$found = 1 if (/portage\/pb/);
|
---|
| 913 | #}
|
---|
| 914 | #close(KEYW);
|
---|
| 915 | #}
|
---|
| 916 | #if ($found == 0) {
|
---|
| 917 | #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
|
---|
| 918 | #}
|
---|
[149] | 919 |
|
---|
| 920 | # Build
|
---|
| 921 | foreach my $f (@ebuildfile) {
|
---|
| 922 | if ($f =~ /\.ebuild$/) {
|
---|
[621] | 923 | pb_distro_installdeps("$f",$dtype,$pbupd);
|
---|
[295] | 924 | move($f,"$tmpd/$pbpkg-$pbver.ebuild");
|
---|
[529] | 925 | pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package","verbose");
|
---|
[295] | 926 | # Now move it where pb expects it
|
---|
| 927 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
|
---|
| 928 | move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
|
---|
[149] | 929 | }
|
---|
| 930 | }
|
---|
| 931 |
|
---|
[295] | 932 | $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
|
---|
[437] | 933 | } elsif ($dtype eq "tgz") {
|
---|
| 934 | # Slackware family
|
---|
[435] | 935 | $made="$made $pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
|
---|
| 936 |
|
---|
| 937 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
| 938 | pb_system("tar xfz $src","Extracting sources");
|
---|
[493] | 939 | pb_system("tar xfz $src2","Extracting pbconf");
|
---|
[435] | 940 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
[500] | 941 | symlink "pbconf/$ddir-$dver-$arch","install" || die "Unable to symlink to pbconf/$ddir-$dver-$arch";
|
---|
[435] | 942 | if (-x "install/pbslack") {
|
---|
[621] | 943 | pb_distro_installdeps("./install/pbslack",$dtype,$pbupd);
|
---|
[435] | 944 | pb_system("./install/pbslack","Building package");
|
---|
[529] | 945 | pb_system("sudo /sbin/makepkg -p -l y -c y $pbpkg","Packaging $pbpkg","verbose");
|
---|
[435] | 946 | }
|
---|
[87] | 947 | } else {
|
---|
[118] | 948 | die "Unknown dtype format $dtype";
|
---|
[87] | 949 | }
|
---|
| 950 | }
|
---|
[541] | 951 | # Packages check if needed
|
---|
| 952 | if ($dtype eq "rpm") {
|
---|
| 953 | if (-f "/usr/bin/rpmlint") {
|
---|
| 954 | pb_system("rpmlint $made","Checking validity of rpms with rpmlint","verbose");
|
---|
[572] | 955 | } else {
|
---|
| 956 | pb_log(0,"rpm packages generated: $made\n");
|
---|
[541] | 957 | }
|
---|
| 958 | } elsif ($dtype eq "deb") {
|
---|
[572] | 959 | my $made2 = "";
|
---|
[541] | 960 | if (-f "/usr/bin/lintian") {
|
---|
[545] | 961 | foreach my $f (split(/ /,$made)) {
|
---|
[611] | 962 | $made2 .= "../$f " if ($f =~ /\.changes$/);
|
---|
[545] | 963 | }
|
---|
| 964 | pb_system("lintian $made2","Checking validity of debs with lintian","verbose");
|
---|
[572] | 965 | } else {
|
---|
| 966 | pb_log(0,"deb packages generated: $made2\n");
|
---|
[541] | 967 | }
|
---|
| 968 | } else {
|
---|
[572] | 969 | pb_log(0,"No check done for $dtype yet\n");
|
---|
| 970 | pb_log(0,"Packages generated: $made\n");
|
---|
[541] | 971 | }
|
---|
| 972 |
|
---|
[118] | 973 | # Keep track of what is generated so that we can get them back from VMs
|
---|
[353] | 974 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
[118] | 975 | print KEEP "$made\n";
|
---|
| 976 | close(KEEP);
|
---|
[87] | 977 | }
|
---|
| 978 |
|
---|
[88] | 979 | sub pb_build2ssh {
|
---|
[320] | 980 | pb_send2target("Sources");
|
---|
[90] | 981 | }
|
---|
[87] | 982 |
|
---|
[90] | 983 | sub pb_pkg2ssh {
|
---|
[320] | 984 | pb_send2target("Packages");
|
---|
[90] | 985 | }
|
---|
| 986 |
|
---|
[108] | 987 | # By default deliver to the the public site hosting the
|
---|
[320] | 988 | # ftp structure (or whatever) or a VM/VE
|
---|
| 989 | sub pb_send2target {
|
---|
[90] | 990 |
|
---|
| 991 | my $cmt = shift;
|
---|
[320] | 992 | my $v = shift || undef;
|
---|
[142] | 993 | my $vmexist = shift || 0; # 0 is FALSE
|
---|
[200] | 994 | my $vmpid = shift || 0; # 0 is FALSE
|
---|
[320] | 995 |
|
---|
[444] | 996 | pb_log(2,"DEBUG: pb_send2target($cmt,".Dumper($v).",$vmexist,$vmpid)\n");
|
---|
[320] | 997 | my $host = "sshhost";
|
---|
| 998 | my $login = "sshlogin";
|
---|
| 999 | my $dir = "sshdir";
|
---|
| 1000 | my $port = "sshport";
|
---|
| 1001 | my $conf = "sshconf";
|
---|
| 1002 | my $rebuild = "sshrebuild";
|
---|
[415] | 1003 | my $tmout = "vmtmout";
|
---|
| 1004 | my $path = "vmpath";
|
---|
[681] | 1005 | if (($cmt eq "vm") || ($cmt eq "VMScript")) {
|
---|
[320] | 1006 | $login = "vmlogin";
|
---|
[322] | 1007 | $dir = "pbdefdir";
|
---|
[320] | 1008 | $tmout = "vmtmout";
|
---|
| 1009 | $rebuild = "vmrebuild";
|
---|
| 1010 | # Specific VM
|
---|
| 1011 | $host = "vmhost";
|
---|
| 1012 | $port = "vmport";
|
---|
[681] | 1013 | } elsif (($cmt eq "ve")|| ($cmt eq "VEScript")) {
|
---|
[320] | 1014 | $login = "velogin";
|
---|
[322] | 1015 | $dir = "pbdefdir";
|
---|
[320] | 1016 | # Specific VE
|
---|
| 1017 | $path = "vepath";
|
---|
| 1018 | $conf = "veconf";
|
---|
| 1019 | $rebuild = "verebuild";
|
---|
[556] | 1020 | } elsif ($cmt eq "Web") {
|
---|
| 1021 | $host = "websshhost";
|
---|
| 1022 | $login = "websshlogin";
|
---|
| 1023 | $dir = "websshdir";
|
---|
| 1024 | $port = "websshport";
|
---|
[320] | 1025 | }
|
---|
[158] | 1026 | my $cmd = "";
|
---|
[471] | 1027 | my $src = "";
|
---|
| 1028 | my ($odir,$over,$oarch) = (undef, undef, undef);
|
---|
| 1029 | my ($ddir, $dver, $dfam, $dtype, $pbsuf);
|
---|
[90] | 1030 |
|
---|
[471] | 1031 | if ($cmt ne "Announce") {
|
---|
| 1032 | my $ptr = pb_get_pkg();
|
---|
| 1033 | @pkgs = @$ptr;
|
---|
[87] | 1034 |
|
---|
[471] | 1035 | # Get the running distro to consider
|
---|
| 1036 | if (defined $v) {
|
---|
| 1037 | ($odir,$over,$oarch) = split(/-/,$v);
|
---|
| 1038 | }
|
---|
[621] | 1039 | ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
|
---|
[471] | 1040 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
|
---|
[87] | 1041 |
|
---|
[471] | 1042 | # Get list of packages to build
|
---|
| 1043 | # Get content saved in cms2build
|
---|
| 1044 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
| 1045 | $pkg = { } if (not defined $pkg);
|
---|
[87] | 1046 |
|
---|
[471] | 1047 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
| 1048 | foreach my $pbpkg (@pkgs) {
|
---|
| 1049 | my $vertag = $pkg->{$pbpkg};
|
---|
| 1050 | # get the version of the current package - maybe different
|
---|
| 1051 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
[87] | 1052 |
|
---|
[471] | 1053 | if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
[493] | 1054 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/$pbpkg-$pbver.pbconf.tar.gz";
|
---|
[471] | 1055 | if ($cmd eq "") {
|
---|
| 1056 | $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
| 1057 | } else {
|
---|
| 1058 | $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
| 1059 | }
|
---|
[560] | 1060 | } elsif ($cmt eq "Web") {
|
---|
| 1061 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz"
|
---|
[166] | 1062 | }
|
---|
[118] | 1063 | }
|
---|
[471] | 1064 | # Adds conf file for availability of conf elements
|
---|
| 1065 | pb_conf_add("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb");
|
---|
[118] | 1066 | }
|
---|
[417] | 1067 |
|
---|
[320] | 1068 | if (($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
[444] | 1069 | $src="$src $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb $ENV{'PBETC'} $ENV{'PBDESTDIR'}/pbrc $ENV{'PBDESTDIR'}/pbscript";
|
---|
[681] | 1070 | } elsif (($cmt =~ /V[EM]Script/) || ($cmt eq "Web")) {
|
---|
[492] | 1071 | $src="$src $ENV{'PBDESTDIR'}/pbscript";
|
---|
[560] | 1072 | } elsif ($cmt eq "Announce") {
|
---|
[471] | 1073 | $src="$src $ENV{'PBTMP'}/pbscript";
|
---|
[118] | 1074 | } elsif ($cmt eq "Packages") {
|
---|
| 1075 | # Get package list from file made during build2pkg
|
---|
[353] | 1076 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
[126] | 1077 | $src = <KEEP>;
|
---|
[118] | 1078 | chomp($src);
|
---|
| 1079 | close(KEEP);
|
---|
[681] | 1080 | $src="$src $ENV{'PBBUILDDIR'}/pbscript";
|
---|
[87] | 1081 | }
|
---|
[320] | 1082 | # Remove potential leading spaces (cause problem with basename)
|
---|
[132] | 1083 | $src =~ s/^ *//;
|
---|
[129] | 1084 | my $basesrc = "";
|
---|
[131] | 1085 | foreach my $i (split(/ +/,$src)) {
|
---|
| 1086 | $basesrc .= " ".basename($i);
|
---|
[130] | 1087 | }
|
---|
[118] | 1088 |
|
---|
[320] | 1089 | pb_log(0,"Sources handled ($cmt): $src\n");
|
---|
[355] | 1090 | pb_log(2,"values: ".Dumper(($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf))."\n");
|
---|
[415] | 1091 | my ($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vepath) = pb_conf_get($host,$login,$dir,$port,$tmout,$path);
|
---|
[681] | 1092 | # Not mandatory
|
---|
| 1093 | my ($vrebuild,$veconf,$testver) = pb_conf_get_if($rebuild,$conf,"testver");
|
---|
[320] | 1094 | pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf))."\n");
|
---|
| 1095 |
|
---|
| 1096 | my $mac;
|
---|
[681] | 1097 | if (($cmt ne "ve") && ($cmt ne "VEScript")) {
|
---|
[320] | 1098 | $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
|
---|
| 1099 | # Overwrite account value if passed as parameter
|
---|
| 1100 | $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
|
---|
[355] | 1101 | pb_log(2, "DEBUG: pbaccount: $pbaccount => mac: $mac\n") if (defined $pbaccount);
|
---|
[681] | 1102 | } else {
|
---|
| 1103 | # VE
|
---|
| 1104 | # Overwrite account value if passed as parameter (typically for setup_ve)
|
---|
| 1105 | $mac = $sshlogin->{$ENV{'PBPROJ'}};
|
---|
| 1106 | $mac = $pbaccount if (defined $pbaccount);
|
---|
[320] | 1107 | }
|
---|
| 1108 |
|
---|
[108] | 1109 | my $tdir;
|
---|
[136] | 1110 | my $bdir;
|
---|
[681] | 1111 | if (($cmt eq "Sources") || ($cmt =~ /V[EM]Script/)) {
|
---|
[471] | 1112 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/src";
|
---|
[435] | 1113 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
| 1114 | # This is a test pkg => target dir is under test
|
---|
[471] | 1115 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/src";
|
---|
[435] | 1116 | }
|
---|
[320] | 1117 | } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
| 1118 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
|
---|
| 1119 | $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
|
---|
[136] | 1120 | # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
|
---|
| 1121 | $bdir =~ s|\$ENV.+\}/||;
|
---|
[471] | 1122 | } elsif ($cmt eq "Announce") {
|
---|
| 1123 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
|
---|
| 1124 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
| 1125 | # This is a test pkg => target dir is under test
|
---|
| 1126 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test";
|
---|
| 1127 | }
|
---|
[556] | 1128 | } elsif ($cmt eq "Web") {
|
---|
| 1129 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
|
---|
| 1130 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
| 1131 | # This is a test website => target dir is under test
|
---|
[650] | 1132 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/../test";
|
---|
[556] | 1133 | }
|
---|
[90] | 1134 | } elsif ($cmt eq "Packages") {
|
---|
[471] | 1135 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ddir/$dver";
|
---|
[429] | 1136 |
|
---|
[337] | 1137 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} =~ /true/i)) {
|
---|
[289] | 1138 | # This is a test pkg => target dir is under test
|
---|
[471] | 1139 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/test/$ddir/$dver";
|
---|
[291] | 1140 | }
|
---|
[429] | 1141 |
|
---|
| 1142 | my $repodir = $tdir;
|
---|
| 1143 | $repodir =~ s|^$sshdir->{$ENV{'PBPROJ'}}/||;
|
---|
| 1144 |
|
---|
| 1145 | my ($pbrepo) = pb_conf_get("pbrepo");
|
---|
| 1146 |
|
---|
| 1147 | # Repository management
|
---|
[444] | 1148 | open(PBS,"> $ENV{'PBBUILDDIR'}/pbscript") || die "Unable to create $ENV{'PBBUILDDIR'}/pbscript";
|
---|
[429] | 1149 | if ($dtype eq "rpm") {
|
---|
| 1150 | # Also make a pbscript to generate yum/urpmi bases
|
---|
| 1151 | print PBS << "EOF";
|
---|
[433] | 1152 | #!/bin/bash
|
---|
[429] | 1153 | # Prepare a script to ease yum setup
|
---|
| 1154 | cat > $ENV{'PBPROJ'}.repo << EOT
|
---|
| 1155 | [$ENV{'PBPROJ'}]
|
---|
| 1156 | name=$ddir $dver - $ENV{'PBPROJ'} Vanilla Packages
|
---|
[433] | 1157 | baseurl=$pbrepo->{$ENV{'PBPROJ'}}/$repodir
|
---|
[429] | 1158 | enabled=1
|
---|
| 1159 | gpgcheck=0
|
---|
| 1160 | EOT
|
---|
| 1161 | chmod 644 $ENV{'PBPROJ'}.repo
|
---|
| 1162 |
|
---|
| 1163 | # Clean up old repo content
|
---|
| 1164 | rm -rf headers/ repodata/
|
---|
| 1165 | # Create yum repo
|
---|
| 1166 | yum-arch .
|
---|
| 1167 | # Create repodata
|
---|
| 1168 | createrepo .
|
---|
| 1169 | EOF
|
---|
| 1170 | if ($dfam eq "md") {
|
---|
| 1171 | # For Mandriva add urpmi management
|
---|
| 1172 | print PBS << "EOF";
|
---|
| 1173 | # Prepare a script to ease urpmi setup
|
---|
| 1174 | cat > $ENV{'PBPROJ'}.addmedia << EOT
|
---|
[433] | 1175 | urpmi.addmedia $ENV{'PBPROJ'} $pbrepo->{$ENV{'PBPROJ'}}/$repodir with hdlist.cz
|
---|
[429] | 1176 | EOT
|
---|
| 1177 | chmod 755 $ENV{'PBPROJ'}.addmedia
|
---|
| 1178 |
|
---|
| 1179 | # Clean up old repo content
|
---|
[437] | 1180 | rm -f hdlist.cz synthesis.hdlist.cz
|
---|
[429] | 1181 | # Create urpmi repo
|
---|
| 1182 | genhdlist .
|
---|
| 1183 | EOF
|
---|
| 1184 | }
|
---|
[484] | 1185 | if ($ddir eq "fedora") {
|
---|
| 1186 | # Extract the spec file to please Fedora maintainers :-(
|
---|
| 1187 | print PBS << "EOF";
|
---|
| 1188 | for p in $basesrc; do
|
---|
| 1189 | echo \$p | grep -q 'src.rpm'
|
---|
| 1190 | if [ \$\? -eq 0 ]; then
|
---|
| 1191 | rpm2cpio \$p | cpio -ivdum --quiet '*.spec'
|
---|
| 1192 | fi
|
---|
| 1193 | done
|
---|
| 1194 | EOF
|
---|
| 1195 | }
|
---|
[429] | 1196 | } elsif ($dtype eq "deb") {
|
---|
| 1197 | # Also make a pbscript to generate apt bases
|
---|
[460] | 1198 | # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
|
---|
[465] | 1199 | my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
|
---|
[460] | 1200 | print PBS << "EOF";
|
---|
[465] | 1201 | #!/bin/bash
|
---|
| 1202 | # Prepare a script to ease apt setup
|
---|
| 1203 | cat > $ENV{'PBPROJ'}.sources.list << EOT
|
---|
| 1204 | deb $rpd $dver contrib
|
---|
| 1205 | deb-src $rpd $dver contrib
|
---|
[460] | 1206 | EOT
|
---|
[465] | 1207 | chmod 644 $ENV{'PBPROJ'}.sources.list
|
---|
[460] | 1208 |
|
---|
| 1209 | # Prepare a script to create apt info file
|
---|
[465] | 1210 | (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] | 1211 | #(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] | 1212 | EOF
|
---|
[586] | 1213 | } elsif ($dtype eq "ebuild") {
|
---|
| 1214 | # make a pbscript to generate links to latest version
|
---|
| 1215 | print PBS << "EOF";
|
---|
| 1216 | #!/bin/bash
|
---|
| 1217 | # Prepare a script to create correct links
|
---|
| 1218 | for p in $src; do
|
---|
| 1219 | echo \$p | grep -q '.ebuild'
|
---|
| 1220 | if [ \$\? -eq 0 ]; then
|
---|
| 1221 | j=`basename \$p`
|
---|
| 1222 | pp=`echo \$j | cut -d'-' -f1`
|
---|
| 1223 | ln -sf \$j \$pp.ebuild
|
---|
| 1224 | fi
|
---|
| 1225 | done
|
---|
| 1226 | EOF
|
---|
[429] | 1227 | }
|
---|
| 1228 | close(PBS);
|
---|
[444] | 1229 | chmod 0755,"$ENV{'PBBUILDDIR'}/pbscript";
|
---|
[90] | 1230 | } else {
|
---|
| 1231 | return;
|
---|
[22] | 1232 | }
|
---|
[239] | 1233 |
|
---|
[320] | 1234 | # Useless for VE
|
---|
| 1235 | my $nport;
|
---|
[681] | 1236 | if (($cmt ne "ve") && ($cmt ne "VEScript")) {
|
---|
[320] | 1237 | $nport = $sshport->{$ENV{'PBPROJ'}};
|
---|
| 1238 | $nport = "$pbport" if (defined $pbport);
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
[136] | 1241 | # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
|
---|
[132] | 1242 | $tdir =~ s|\$ENV.+\}/||;
|
---|
| 1243 |
|
---|
[320] | 1244 | my $tm = $vtmout->{$ENV{'PBPROJ'}};
|
---|
| 1245 |
|
---|
| 1246 | # ssh communication if not VE
|
---|
[349] | 1247 | # should use a hash instead...
|
---|
[320] | 1248 | my ($shcmd,$cpcmd,$cptarget,$cp2target);
|
---|
[681] | 1249 | if (($cmt ne "ve") && ($cmt ne "VEScript")) {
|
---|
[347] | 1250 | my $keyfile = pb_ssh_get(0);
|
---|
[435] | 1251 | $shcmd = "ssh -i $keyfile -q -o UserKnownHostsFile=/dev/null -p $nport $mac";
|
---|
| 1252 | $cpcmd = "scp -i $keyfile -p -o UserKnownHostsFile=/dev/null -P $nport";
|
---|
[320] | 1253 | $cptarget = "$mac:$tdir";
|
---|
[351] | 1254 | if ($cmt eq "vm") {
|
---|
| 1255 | $cp2target = "$mac:$bdir";
|
---|
| 1256 | }
|
---|
[320] | 1257 | } else {
|
---|
| 1258 | my $tp = $vepath->{$ENV{'PBPROJ'}};
|
---|
[681] | 1259 | ($odir,$over,$oarch) = split(/-/,$v);
|
---|
| 1260 | my $tpdir = "$tp/$odir/$over/$oarch";
|
---|
| 1261 | my ($ptr) = pb_conf_get("vetype");
|
---|
| 1262 | my $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
| 1263 | if ($vetype eq "chroot") {
|
---|
| 1264 | $shcmd = "sudo chroot $tpdir /bin/su - $mac -c ";
|
---|
| 1265 | $cpcmd = "sudo cp -r ";
|
---|
| 1266 | } elsif ($vetype eq "schroot") {
|
---|
| 1267 | $shcmd = "schroot $tp -u $mac -- ";
|
---|
| 1268 | $cpcmd = "sudo cp -r ";
|
---|
| 1269 | }
|
---|
| 1270 | # We need to get the home dir of the target account to deliver in the right place
|
---|
| 1271 | open(PASS,"$tpdir/etc/passwd") || die "Unable to open $tpdir/etc/passwd";
|
---|
| 1272 | my $homedir = "";
|
---|
| 1273 | while (<PASS>) {
|
---|
| 1274 | my ($c1,$c2,$c3,$c4,$c5,$c6,$c7) = split(/:/);
|
---|
| 1275 | $homedir = $c6 if ($c1 =~ /^$mac$/);
|
---|
| 1276 | pb_log(3,"Homedir: $homedir - account: $c6\n");
|
---|
| 1277 | }
|
---|
| 1278 | close(PASS);
|
---|
| 1279 | $cptarget = "$tpdir/$homedir/$tdir";
|
---|
| 1280 | if ($cmt eq "ve") {
|
---|
| 1281 | $cp2target = "$tpdir/$homedir/$bdir";
|
---|
| 1282 | }
|
---|
| 1283 | pb_log(2,"On VE using $cptarget as target dir to copy to\n");
|
---|
[320] | 1284 | }
|
---|
| 1285 |
|
---|
[471] | 1286 | my $logres = "";
|
---|
| 1287 | # Do not touch when just announcing
|
---|
| 1288 | if ($cmt ne "Announce") {
|
---|
| 1289 | 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");
|
---|
| 1290 | } else {
|
---|
| 1291 | $logres = "> ";
|
---|
| 1292 | }
|
---|
[320] | 1293 | pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
|
---|
[444] | 1294 |
|
---|
[681] | 1295 | # For VE we need to change the owner manually
|
---|
| 1296 | if ($cmt eq "ve") {
|
---|
| 1297 | pb_system("$shcmd \"sudo chown -R $mac $tdir\"","Adapt owner in $tdir to $mac");
|
---|
| 1298 | }
|
---|
| 1299 |
|
---|
[492] | 1300 | pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi ; rm -f ./pbscript\' | bash\"","Executing pbscript on $cptarget if needed","verbose");
|
---|
[320] | 1301 | if (($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
[128] | 1302 | # Get back info on pkg produced, compute their name and get them from the VM
|
---|
[353] | 1303 | pb_system("$cpcmd $cp2target/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'} $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
|
---|
[681] | 1304 | # For VE we need to change the owner manually
|
---|
| 1305 | if ($cmt eq "ve") {
|
---|
| 1306 | pb_system("sudo chown $UID $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}","Adapt owner in $tdir to $UID");
|
---|
| 1307 | }
|
---|
[353] | 1308 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
[118] | 1309 | my $src = <KEEP>;
|
---|
| 1310 | chomp($src);
|
---|
| 1311 | close(KEEP);
|
---|
[131] | 1312 | $src =~ s/^ *//;
|
---|
[136] | 1313 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
|
---|
[320] | 1314 | # Change pgben to make the next send2target happy
|
---|
[143] | 1315 | my $made = "";
|
---|
[353] | 1316 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}";
|
---|
[136] | 1317 | foreach my $p (split(/ +/,$src)) {
|
---|
[139] | 1318 | my $j = basename($p);
|
---|
[320] | 1319 | pb_system("$cpcmd $cp2target/\'$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $cp2target");
|
---|
[572] | 1320 | $made="$made $odir/$over/$j"; # if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
|
---|
[136] | 1321 | }
|
---|
[143] | 1322 | print KEEP "$made\n";
|
---|
[139] | 1323 | close(KEEP);
|
---|
[320] | 1324 | pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
|
---|
[355] | 1325 |
|
---|
[623] | 1326 | # Sign packages locally
|
---|
| 1327 | if ($dtype eq "rpm") {
|
---|
[626] | 1328 | #pb_system("rpm --addsign --define \'_signature gpg\' --define \'__gpg_sign_cmd /usr/bin/gpg --batch --no-verbose --no-armor --no-secmem-warning -u \"$ENV{'PBPACKAGER'}\" -sbo %{__signature_filename} %{__plaintext_filename} --use-agent\' $made","Signing RPM packages packages");
|
---|
[623] | 1329 | } elsif ($dtype eq "deb") {
|
---|
[626] | 1330 | #pb_system("debsign $made","Signing DEB packages");
|
---|
[623] | 1331 | } else {
|
---|
| 1332 | pb_log(0,"I don't know yet how to sign packages for type $dtype. Please give feedback to dev team");
|
---|
| 1333 | }
|
---|
| 1334 |
|
---|
[355] | 1335 | # We want to send them to the ssh account so overwrite what has been done before
|
---|
| 1336 | undef $pbaccount;
|
---|
[357] | 1337 | pb_log(2,"Before sending pkgs, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[355] | 1338 | pb_send2target("Packages",$odir."-".$over."-".$oarch,$vmexist,$vmpid);
|
---|
[141] | 1339 | pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
|
---|
[108] | 1340 | }
|
---|
[442] | 1341 | pb_log(2,"Before halt, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[681] | 1342 | if ((! $vmexist) && (($cmt eq "vm") || ($cmt eq "VMScript"))) {
|
---|
[442] | 1343 | 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)");
|
---|
| 1344 | }
|
---|
[9] | 1345 | }
|
---|
[16] | 1346 |
|
---|
[320] | 1347 | sub pb_script2v {
|
---|
[142] | 1348 | my $pbscript=shift;
|
---|
[320] | 1349 | my $vtype=shift;
|
---|
[442] | 1350 | my $force=shift || 0; # Force stop of VM. Default not
|
---|
| 1351 | my $vm1=shift || undef; # Only that VM to treat
|
---|
| 1352 | my $vm;
|
---|
| 1353 | my $all;
|
---|
[141] | 1354 |
|
---|
[669] | 1355 | pb_log(2,"DEBUG: pb_script2v($pbscript,$vtype,$force)\n");
|
---|
[141] | 1356 | # Prepare the script to be executed on the VM
|
---|
| 1357 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
[142] | 1358 | if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
|
---|
| 1359 | copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 1360 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
| 1361 | }
|
---|
[141] | 1362 |
|
---|
[442] | 1363 | if (not defined $vm1) {
|
---|
| 1364 | ($vm,$all) = pb_get_v($vtype);
|
---|
| 1365 | } else {
|
---|
| 1366 | @$vm = ($vm1);
|
---|
| 1367 | }
|
---|
[320] | 1368 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
[142] | 1369 |
|
---|
[141] | 1370 | foreach my $v (@$vm) {
|
---|
[320] | 1371 | # Launch the VM/VE
|
---|
| 1372 | if ($vtype eq "vm") {
|
---|
| 1373 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
[442] | 1374 | pb_log(2,"DEBUG: After pb_launchv, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[141] | 1375 |
|
---|
[320] | 1376 | # Skip that VM if something went wrong
|
---|
[442] | 1377 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
| 1378 |
|
---|
| 1379 | # If force stopping the VM then reset vmexist
|
---|
| 1380 | if ($force == 1) {
|
---|
| 1381 | $vmpid = $vmexist;
|
---|
| 1382 | $vmexist = 0;
|
---|
| 1383 | }
|
---|
[670] | 1384 | } else {
|
---|
| 1385 | #VE
|
---|
| 1386 | $vmexist = 0;
|
---|
| 1387 | $vmpid = 0;
|
---|
[320] | 1388 | }
|
---|
[274] | 1389 |
|
---|
[142] | 1390 | # Gather all required files to send them to the VM
|
---|
[320] | 1391 | # and launch the build through pbscript
|
---|
[442] | 1392 | pb_log(2,"DEBUG: Before send2target, vmexist: $vmexist, vmpid: $vmpid\n");
|
---|
[681] | 1393 | pb_send2target(uc($vtype)."Script","$v",$vmexist,$vmpid);
|
---|
[169] | 1394 |
|
---|
[142] | 1395 | }
|
---|
| 1396 | }
|
---|
| 1397 |
|
---|
[320] | 1398 | sub pb_launchv {
|
---|
| 1399 | my $vtype = shift;
|
---|
| 1400 | my $v = shift;
|
---|
| 1401 | my $create = shift || 0; # By default do not create a VM
|
---|
[310] | 1402 |
|
---|
[442] | 1403 | pb_log(2,"DEBUG: pb_launchv($vtype,$v,$create)\n");
|
---|
[320] | 1404 | die "No VM/VE defined, unable to launch" if (not defined $v);
|
---|
| 1405 | # Keep only the first VM in case many were given
|
---|
| 1406 | $v =~ s/,.*//;
|
---|
[310] | 1407 |
|
---|
[500] | 1408 | my $arch = pb_get_arch();
|
---|
[310] | 1409 |
|
---|
[320] | 1410 | # Launch the VMs/VEs
|
---|
| 1411 | if ($vtype eq "vm") {
|
---|
| 1412 | die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
|
---|
[310] | 1413 |
|
---|
[415] | 1414 | my ($ptr,$vmopt,$vmpath,$vmport,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmpath","vmport","vmtmout","vmsize");
|
---|
[320] | 1415 |
|
---|
| 1416 | my $vmtype = $ptr->{$ENV{'PBPROJ'}};
|
---|
| 1417 | if (not defined $ENV{'PBVMOPT'}) {
|
---|
| 1418 | $ENV{'PBVMOPT'} = "";
|
---|
[310] | 1419 | }
|
---|
[639] | 1420 | # Save the current status for later restoration
|
---|
| 1421 | $ENV{'PBOLDVMOPT'} = $ENV{'PBVMOPT'};
|
---|
[483] | 1422 | # Set a default timeout of 2 minutes
|
---|
| 1423 | if (not defined $ENV{'PBVMTMOUT'}) {
|
---|
| 1424 | $ENV{'PBVMTMOUT'} = "120";
|
---|
| 1425 | }
|
---|
| 1426 | if (defined $vmopt->{$v}) {
|
---|
| 1427 | $ENV{'PBVMOPT'} .= " $vmopt->{$v}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$v}/);
|
---|
| 1428 | } elsif (defined $vmopt->{$ENV{'PBPROJ'}}) {
|
---|
[320] | 1429 | $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
|
---|
| 1430 | }
|
---|
[483] | 1431 | if (defined $vmtmout->{$v}) {
|
---|
| 1432 | $ENV{'PBVMTMOUT'} = $vmtmout->{$v};
|
---|
| 1433 | } elsif (defined $vmtmout->{$ENV{'PBPROJ'}}) {
|
---|
| 1434 | $ENV{'PBVMTMOUT'} = $vmtmout->{$ENV{'PBPROJ'}};
|
---|
| 1435 | }
|
---|
[320] | 1436 | my $nport = $vmport->{$ENV{'PBPROJ'}};
|
---|
| 1437 | $nport = "$pbport" if (defined $pbport);
|
---|
| 1438 |
|
---|
| 1439 | my $cmd;
|
---|
| 1440 | my $vmcmd; # has to be used for pb_check_ps
|
---|
| 1441 | my $vmm; # has to be used for pb_check_ps
|
---|
[677] | 1442 | if (($vmtype eq "qemu") || ($vmtype eq "kvm")) {
|
---|
[320] | 1443 | my $qemucmd32;
|
---|
| 1444 | my $qemucmd64;
|
---|
| 1445 | if ($arch eq "x86_64") {
|
---|
| 1446 | $qemucmd32 = "/usr/bin/qemu-system-i386";
|
---|
| 1447 | $qemucmd64 = "/usr/bin/qemu";
|
---|
| 1448 | } else {
|
---|
| 1449 | $qemucmd32 = "/usr/bin/qemu";
|
---|
| 1450 | $qemucmd64 = "/usr/bin/qemu-system-x86_64";
|
---|
| 1451 | }
|
---|
[677] | 1452 | if ($v =~ /x86_64/) {
|
---|
| 1453 | $vmcmd = "$qemucmd64";
|
---|
| 1454 | } else {
|
---|
| 1455 | $vmcmd = "$qemucmd32";
|
---|
| 1456 | }
|
---|
| 1457 | if ($vmtype eq "kvm") {
|
---|
| 1458 | $vmcmd = "/usr/bin/kvm";
|
---|
| 1459 | }
|
---|
| 1460 | $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
|
---|
| 1461 | if ($create != 0) {
|
---|
| 1462 | $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
|
---|
[320] | 1463 | }
|
---|
[677] | 1464 | $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
|
---|
[320] | 1465 | } elsif ($vmtype eq "xen") {
|
---|
| 1466 | } elsif ($vmtype eq "vmware") {
|
---|
[310] | 1467 | } else {
|
---|
[320] | 1468 | die "VM of type $vmtype not supported. Report to the dev team";
|
---|
[310] | 1469 | }
|
---|
[639] | 1470 | # Restore the ENV VAR Value
|
---|
[641] | 1471 | $ENV{'PBVMOPT'} = $ENV{'PBOLDVMOPT'};
|
---|
[639] | 1472 |
|
---|
[320] | 1473 | my ($tmpcmd,$void) = split(/ +/,$cmd);
|
---|
| 1474 | my $vmexist = pb_check_ps($tmpcmd,$vmm);
|
---|
| 1475 | my $vmpid = 0;
|
---|
| 1476 | if (! $vmexist) {
|
---|
| 1477 | if ($create != 0) {
|
---|
[653] | 1478 | die("Found an existing Virtual machine $vmm. Won't overwrite") if (-r $vmm);
|
---|
[677] | 1479 | if (($vmtype eq "qemu") || ($vmtype eq "xen") || ($vmtype eq "kvm")) {
|
---|
[320] | 1480 | pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
|
---|
| 1481 | } elsif ($vmtype eq "vmware") {
|
---|
| 1482 | } else {
|
---|
| 1483 | }
|
---|
| 1484 | }
|
---|
| 1485 | if (! -f "$vmm") {
|
---|
| 1486 | pb_log(0,"Unable to find VM $vmm\n");
|
---|
| 1487 | } else {
|
---|
| 1488 | pb_system("$cmd &","Launching the VM $vmm");
|
---|
[483] | 1489 | pb_system("sleep $ENV{'PBVMTMOUT'}","Waiting $ENV{'PBVMTMOUT'} s for VM $v to come up");
|
---|
[320] | 1490 | $vmpid = pb_check_ps($tmpcmd,$vmm);
|
---|
[357] | 1491 | pb_log(0,"VM $vmm launched (pid $vmpid)\n");
|
---|
[320] | 1492 | }
|
---|
[310] | 1493 | } else {
|
---|
[320] | 1494 | pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
|
---|
[310] | 1495 | }
|
---|
[442] | 1496 | pb_log(2,"DEBUG: pb_launchv returns ($vmexist,$vmpid)\n");
|
---|
[320] | 1497 | return($vmexist,$vmpid);
|
---|
| 1498 | # VE here
|
---|
[310] | 1499 | } else {
|
---|
[320] | 1500 | # Get VE context
|
---|
[658] | 1501 | my ($ptr,$vetmout,$vepath,$verebuild,$veconf,$vepostinstall) = pb_conf_get("vetype","vetmout","vepath","verebuild","veconf");
|
---|
[670] | 1502 | my ($veb4pi,$vepkglist) = pb_conf_get_if("veb4pi","vepkglist");
|
---|
[320] | 1503 | my $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
[310] | 1504 |
|
---|
[320] | 1505 | # Get distro context
|
---|
| 1506 | my ($name,$ver,$darch) = split(/-/,$v);
|
---|
| 1507 | chomp($darch);
|
---|
[621] | 1508 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
|
---|
[142] | 1509 |
|
---|
[681] | 1510 | if (($vetype eq "chroot") || ($vetype eq "schroot")) {
|
---|
[320] | 1511 | # Architecture consistency
|
---|
| 1512 | if ($arch ne $darch) {
|
---|
| 1513 | die "Unable to launch a VE of architecture $darch on a $arch platform" if (not (($darch eq "x86_64") && ($arch =~ /i?86/)));
|
---|
| 1514 | }
|
---|
[142] | 1515 |
|
---|
[670] | 1516 | my ($verpmtype) = pb_conf_get("verpmtype");
|
---|
[320] | 1517 | if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($force == 1)) {
|
---|
| 1518 | # We have to rebuild the chroot
|
---|
| 1519 | if ($dtype eq "rpm") {
|
---|
[670] | 1520 |
|
---|
| 1521 | my $verpmstyle = pb_get_dist_param($ddir,$dver,$darch,$verpmtype);
|
---|
| 1522 | if ($verpmstyle eq "rinse") {
|
---|
| 1523 | # Need to reshape the mirrors generated
|
---|
| 1524 | my $post = "--before-post-install ";
|
---|
| 1525 | my $postparam = pb_get_dist_param($ddir,$dver,$darch,$veb4pi);
|
---|
| 1526 | if ($postparam eq "") {
|
---|
| 1527 | $post = "";
|
---|
| 1528 | } else {
|
---|
| 1529 | $post .= $postparam;
|
---|
| 1530 | }
|
---|
| 1531 |
|
---|
| 1532 | # Need to reshape the package list for pb
|
---|
| 1533 | my $addpkgs;
|
---|
| 1534 | $postparam = pb_get_dist_param($ddir,$dver,$darch,$vepkglist);
|
---|
| 1535 | if ($postparam eq "") {
|
---|
| 1536 | $addpkgs = "";
|
---|
| 1537 | } else {
|
---|
| 1538 | my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
|
---|
| 1539 | open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
|
---|
| 1540 | foreach my $p (split(/,/,$postparam)) {
|
---|
| 1541 | print PKG "$p\n";
|
---|
| 1542 | }
|
---|
| 1543 | close(PKG);
|
---|
| 1544 | $addpkgs = "--add-pkg-list $pkgfile";
|
---|
| 1545 | }
|
---|
[681] | 1546 | my $rinseverb = "";
|
---|
| 1547 | $rinseverb = "--verbose" if ($pbdebug gt 0);
|
---|
[670] | 1548 |
|
---|
| 1549 | pb_system("sudo /usr/sbin/rinse --directory \"$vepath->{$ENV{'PBPROJ'}}/$ddir/$dver/$darch\" --arch \"$darch\" --distribution \"$ddir-$dver\" --config \"$veconf->{$ENV{'PBPROJ'}}\" $post $addpkgs $rinseverb","Creating the rinse VE for $ddir-$dver ($darch)", "verbose");
|
---|
| 1550 | } elsif ($verpmstyle eq "mock") {
|
---|
| 1551 | pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE for $ddir-$dver ($darch)");
|
---|
| 1552 | # Once setup we need to install some packages, the pb account, ...
|
---|
| 1553 | pb_system("sudo /usr/sbin/mock --install --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
|
---|
[658] | 1554 | }
|
---|
[320] | 1555 | } elsif ($dtype eq "deb") {
|
---|
[681] | 1556 | pb_system("","Creating the pbuilder VE TBD");
|
---|
[320] | 1557 | } elsif ($dtype eq "ebuild") {
|
---|
| 1558 | die "Please teach the dev team how to build gentoo chroot";
|
---|
| 1559 | } else {
|
---|
| 1560 | die "Unknown distribution type $dtype. Report to dev team";
|
---|
| 1561 | }
|
---|
[310] | 1562 | }
|
---|
[320] | 1563 | # Nothing more to do for VE. No real launch
|
---|
[274] | 1564 | } else {
|
---|
[320] | 1565 | die "VE of type $vetype not supported. Report to the dev team";
|
---|
[262] | 1566 | }
|
---|
[141] | 1567 | }
|
---|
| 1568 | }
|
---|
[142] | 1569 |
|
---|
[639] | 1570 | # Return string for date synchro
|
---|
| 1571 | sub pb_date_v {
|
---|
| 1572 |
|
---|
| 1573 | my $vtype = shift;
|
---|
[652] | 1574 | my $v = shift;
|
---|
[639] | 1575 |
|
---|
| 1576 | my ($ntp) = pb_conf_get($vtype."ntp");
|
---|
| 1577 | my $vntp = $ntp->{$ENV{'PBPROJ'}};
|
---|
| 1578 | my $ntpline;
|
---|
| 1579 |
|
---|
| 1580 | if (defined $vntp) {
|
---|
[652] | 1581 | my ($ntpcmd) = pb_conf_get($vtype."ntpcmd");
|
---|
| 1582 | my $vntpcmd;
|
---|
| 1583 | if (defined $ntpcmd->{$v}) {
|
---|
| 1584 | $vntpcmd = $ntpcmd->{$v};
|
---|
| 1585 | } elsif (defined $vntpcmd->{$ENV{'PBPROJ'}}) {
|
---|
| 1586 | $vntpcmd = $ntpcmd->{$ENV{'PBPROJ'}};
|
---|
| 1587 | } else {
|
---|
| 1588 | $vntpcmd = "/bin/true";
|
---|
| 1589 | }
|
---|
| 1590 | $ntpline = "sudo $vntpcmd $vntp";
|
---|
[639] | 1591 | } else {
|
---|
| 1592 | $ntpline = undef;
|
---|
| 1593 | }
|
---|
| 1594 | # Force new date to be in the future compared to the date
|
---|
| 1595 | # of the host by adding 1 minute
|
---|
| 1596 | my @date=pb_get_date();
|
---|
| 1597 | $date[1]++;
|
---|
| 1598 | my $upddate = strftime("%m%d%H%M%Y", @date);
|
---|
| 1599 | my $dateline = "sudo date $upddate";
|
---|
| 1600 | return($ntpline,$dateline);
|
---|
| 1601 | }
|
---|
| 1602 |
|
---|
[320] | 1603 | sub pb_build2v {
|
---|
[118] | 1604 |
|
---|
[320] | 1605 | my $vtype = shift;
|
---|
[142] | 1606 |
|
---|
[320] | 1607 | my ($v,$all) = pb_get_v($vtype);
|
---|
| 1608 |
|
---|
| 1609 | # Send tar files when we do a global generation
|
---|
| 1610 | pb_build2ssh() if ($all == 1);
|
---|
| 1611 |
|
---|
| 1612 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
| 1613 |
|
---|
| 1614 | foreach my $v (@$v) {
|
---|
[652] | 1615 | # Prepare the script to be executed on the VM/VE
|
---|
| 1616 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
| 1617 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 1618 | print SCRIPT "#!/bin/bash\n";
|
---|
| 1619 | print SCRIPT "echo ... Execution needed\n";
|
---|
| 1620 | print SCRIPT "# This is in directory delivery\n";
|
---|
| 1621 | print SCRIPT "# Setup the variables required for building\n";
|
---|
| 1622 | print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
|
---|
| 1623 | print SCRIPT "# Preparation for pb\n";
|
---|
| 1624 | print SCRIPT "mv .pbrc \$HOME\n";
|
---|
| 1625 | print SCRIPT "cd ..\n";
|
---|
[686] | 1626 |
|
---|
| 1627 | # VE needs a good /proc
|
---|
[687] | 1628 | if ($vtype eq "ve") {
|
---|
[686] | 1629 | print SCRIPT "sudo mount -t proc /proc /proc\n";
|
---|
| 1630 | }
|
---|
[652] | 1631 |
|
---|
| 1632 | # Get list of packages to build and get some ENV vars as well
|
---|
| 1633 | my $ptr = pb_get_pkg();
|
---|
| 1634 | @pkgs = @$ptr;
|
---|
| 1635 | my $p = join(' ',@pkgs) if (@pkgs);
|
---|
| 1636 | print SCRIPT "export PBPROJVER=$ENV{'PBPROJVER'}\n";
|
---|
| 1637 | print SCRIPT "export PBPROJTAG=$ENV{'PBPROJTAG'}\n";
|
---|
| 1638 | print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
|
---|
| 1639 |
|
---|
| 1640 | my ($ntpline,$dateline) = pb_date_v($vtype,$v);
|
---|
| 1641 | print SCRIPT "# Time sync\n";
|
---|
| 1642 | if (defined $ntpline) {
|
---|
| 1643 | print SCRIPT "$ntpline\n";
|
---|
| 1644 | } else {
|
---|
| 1645 | print SCRIPT "$dateline\n";
|
---|
| 1646 | }
|
---|
| 1647 |
|
---|
| 1648 | # Transmit the verbosity level to the virtual env/mach.
|
---|
| 1649 | my $verbose = "";
|
---|
| 1650 | my $i = 0; # minimal debug level
|
---|
| 1651 | while ($i lt $pbdebug) {
|
---|
| 1652 | $verbose .= "-v ";
|
---|
| 1653 | $i++;
|
---|
| 1654 | }
|
---|
| 1655 | # Quiet if asked to be so on the original system
|
---|
| 1656 | $verbose = "-q" if ($pbdebug eq -1);
|
---|
| 1657 |
|
---|
| 1658 | print SCRIPT "# Build\n";
|
---|
| 1659 | print SCRIPT "echo Building packages on $vtype...\n";
|
---|
| 1660 | print SCRIPT "pb $verbose -p $ENV{'PBPROJ'} build2pkg $p\n";
|
---|
[687] | 1661 | if ($vtype eq "ve") {
|
---|
[686] | 1662 | print SCRIPT "sudo umount /proc\n";
|
---|
| 1663 | }
|
---|
[652] | 1664 | close(SCRIPT);
|
---|
| 1665 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
| 1666 |
|
---|
[320] | 1667 | if ($vtype eq "vm") {
|
---|
[142] | 1668 | # Launch the VM
|
---|
[357] | 1669 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
[118] | 1670 |
|
---|
[274] | 1671 | # Skip that VM if it something went wrong
|
---|
| 1672 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
[658] | 1673 | } else {
|
---|
| 1674 | # VE
|
---|
| 1675 | $vmexist = 0;
|
---|
| 1676 | $vmpid = 0;
|
---|
[118] | 1677 | }
|
---|
[320] | 1678 | # Gather all required files to send them to the VM/VE
|
---|
[347] | 1679 | # and launch the build through pbscript
|
---|
[357] | 1680 | pb_log(2,"Calling send2target $vtype,$v,$vmexist,$vmpid\n");
|
---|
[320] | 1681 | pb_send2target($vtype,"$v",$vmexist,$vmpid);
|
---|
[105] | 1682 | }
|
---|
[320] | 1683 | }
|
---|
[105] | 1684 |
|
---|
[262] | 1685 |
|
---|
[199] | 1686 | sub pb_newver {
|
---|
| 1687 |
|
---|
[204] | 1688 | die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
|
---|
[340] | 1689 |
|
---|
[366] | 1690 | # Need this call for PBDIR
|
---|
| 1691 | my ($scheme2,$uri) = pb_cms_init($pbinit);
|
---|
[361] | 1692 |
|
---|
[415] | 1693 | my ($pbconf) = pb_conf_get("pbconfurl");
|
---|
[366] | 1694 | $uri = $pbconf->{$ENV{'PBPROJ'}};
|
---|
| 1695 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
|
---|
| 1696 |
|
---|
[361] | 1697 | # Checking CMS repositories status
|
---|
[358] | 1698 | my ($pburl) = pb_conf_get("pburl");
|
---|
[366] | 1699 | ($scheme2, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
|
---|
[340] | 1700 |
|
---|
| 1701 | if ($scheme !~ /^svn/) {
|
---|
[199] | 1702 | die "Only SVN is supported at the moment";
|
---|
| 1703 | }
|
---|
[483] | 1704 |
|
---|
[358] | 1705 | my $res = pb_cms_isdiff($scheme,$ENV{'PBROOTDIR'});
|
---|
[361] | 1706 | die "ERROR: No differences accepted in CMS for $ENV{'PBROOTDIR'} before creating a new version" if ($res != 0);
|
---|
[358] | 1707 |
|
---|
| 1708 | $res = pb_cms_isdiff($scheme2,$ENV{'PBDIR'});
|
---|
[361] | 1709 | die "ERROR: No differences accepted in CMS for $ENV{'PBDIR'} before creating a new version" if ($res != 0);
|
---|
[358] | 1710 |
|
---|
| 1711 | # Tree identical between PBCONFDIR and PBROOTDIR. The delta is what
|
---|
| 1712 | # we want to get for the root of the new URL
|
---|
| 1713 |
|
---|
| 1714 | my $tmp = $ENV{'PBROOTDIR'};
|
---|
| 1715 | $tmp =~ s|^$ENV{'PBCONFDIR'}||;
|
---|
| 1716 |
|
---|
| 1717 | my $newurl = "$uri/".dirname($tmp)."/$newver";
|
---|
[366] | 1718 | # Should probably use projver in the old file
|
---|
| 1719 | my $oldver= basename($tmp);
|
---|
[361] | 1720 |
|
---|
[366] | 1721 | # Duplicate and extract project-builder part
|
---|
[361] | 1722 | pb_log(2,"Copying $uri/$tmp to $newurl\n");
|
---|
[366] | 1723 | pb_cms_copy($scheme,"$uri/$tmp",$newurl);
|
---|
| 1724 | pb_log(2,"Checkout $newurl to $ENV{'PBROOTDIR'}/../$newver\n");
|
---|
[383] | 1725 | pb_cms_up($scheme,"$ENV{'PBCONFDIR'}/..");
|
---|
[361] | 1726 |
|
---|
[366] | 1727 | # Duplicate and extract project
|
---|
| 1728 | my $newurl2 = "$pburl->{$ENV{'PBPROJ'}}/".dirname($tmp)."/$newver";
|
---|
| 1729 |
|
---|
| 1730 | pb_log(2,"Copying $pburl->{$ENV{'PBPROJ'}}/$tmp to $newurl2\n");
|
---|
[632] | 1731 | pb_cms_copy($scheme2,"$pburl->{$ENV{'PBPROJ'}}/$tmp",$newurl2);
|
---|
[366] | 1732 | pb_log(2,"Checkout $newurl2 to $ENV{'PBDIR'}/../$newver\n");
|
---|
[632] | 1733 | pb_cms_up($scheme2,"$ENV{'PBDIR'}/..");
|
---|
[366] | 1734 |
|
---|
[361] | 1735 | # Update the .pb file
|
---|
[358] | 1736 | open(FILE,"$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb";
|
---|
| 1737 | open(OUT,"> $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new";
|
---|
[208] | 1738 | while(<FILE>) {
|
---|
[361] | 1739 | s/^projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
|
---|
| 1740 | 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/);
|
---|
| 1741 | s/^testver/#testver/;
|
---|
| 1742 | pb_log(0,"Commenting testver in $ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb\n") if (/^testver/);
|
---|
[211] | 1743 | print OUT $_;
|
---|
[208] | 1744 | }
|
---|
| 1745 | close(FILE);
|
---|
[211] | 1746 | close(OUT);
|
---|
[358] | 1747 | rename("$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOTDIR'}/../$newver/$ENV{'PBPROJ'}.pb");
|
---|
[363] | 1748 |
|
---|
[479] | 1749 | # Checking pbcl files
|
---|
| 1750 | foreach my $f (<$ENV{'PBROOTDIR'}/*/pbcl>) {
|
---|
[590] | 1751 | # Compute new pbcl file
|
---|
| 1752 | my $f2 = $f;
|
---|
| 1753 | $f2 =~ s|$ENV{'PBROOTDIR'}|$ENV{'PBROOTDIR'}/../$newver/|;
|
---|
[479] | 1754 | open(PBCL,$f) || die "Unable to open $f";
|
---|
| 1755 | my $foundnew = 0;
|
---|
| 1756 | while (<PBCL>) {
|
---|
| 1757 | $foundnew = 1 if (/^$newver \(/);
|
---|
| 1758 | }
|
---|
| 1759 | close(PBCL);
|
---|
[590] | 1760 | open(OUT,"> $f2") || die "Unable to write to $f2: $!";
|
---|
[479] | 1761 | open(PBCL,$f) || die "Unable to open $f";
|
---|
| 1762 | while (<PBCL>) {
|
---|
[480] | 1763 | print OUT "$_" if (not /^$oldver \(/);
|
---|
[479] | 1764 | if ((/^$oldver \(/) && ($foundnew == 0)) {
|
---|
| 1765 | print OUT "$newver ($pbdate)\n";
|
---|
| 1766 | print OUT "- TBD\n";
|
---|
| 1767 | print OUT "\n";
|
---|
[590] | 1768 | pb_log(0,"WARNING: version $newver not found in $f so added to $f2...\n") if ($foundnew == 0);
|
---|
[479] | 1769 | }
|
---|
| 1770 | }
|
---|
| 1771 | close(OUT);
|
---|
| 1772 | close(PBCL);
|
---|
| 1773 | }
|
---|
| 1774 |
|
---|
[358] | 1775 | pb_log(2,"Checkin $ENV{'PBROOTDIR'}/../$newver\n");
|
---|
[452] | 1776 | pb_cms_checkin($scheme,"$ENV{'PBROOTDIR'}/../$newver",undef);
|
---|
[199] | 1777 | }
|
---|
| 1778 |
|
---|
[293] | 1779 | #
|
---|
[320] | 1780 | # Return the list of VMs/VEs we are working on
|
---|
[105] | 1781 | # $all is a flag to know if we return all of them
|
---|
| 1782 | # or only some (if all we publish also tar files in addition to pkgs
|
---|
| 1783 | #
|
---|
[320] | 1784 | sub pb_get_v {
|
---|
[91] | 1785 |
|
---|
[320] | 1786 | my $vtype = shift;
|
---|
| 1787 | my @v;
|
---|
[105] | 1788 | my $all = 0;
|
---|
[320] | 1789 | my $vlist;
|
---|
| 1790 | my $pbv = 'PBV';
|
---|
[91] | 1791 |
|
---|
[320] | 1792 | if ($vtype eq "vm") {
|
---|
| 1793 | $vlist = "vmlist";
|
---|
| 1794 | } elsif ($vtype eq "ve") {
|
---|
| 1795 | $vlist = "velist";
|
---|
| 1796 | }
|
---|
| 1797 | # Get VM/VE list
|
---|
| 1798 | if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
|
---|
| 1799 | my ($ptr) = pb_conf_get($vlist);
|
---|
| 1800 | $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
|
---|
[105] | 1801 | $all = 1;
|
---|
[91] | 1802 | }
|
---|
[320] | 1803 | pb_log(2,"$vtype: $ENV{$pbv}\n");
|
---|
| 1804 | @v = split(/,/,$ENV{$pbv});
|
---|
| 1805 | return(\@v,$all);
|
---|
[91] | 1806 | }
|
---|
| 1807 |
|
---|
[320] | 1808 | # Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
|
---|
| 1809 | # Needs to use root account to connect to the VM/VE
|
---|
| 1810 | # pb will take your local public SSH key to access
|
---|
[346] | 1811 | # the pb account in the VM later on if needed
|
---|
| 1812 | sub pb_setup_v {
|
---|
[320] | 1813 |
|
---|
| 1814 | my $vtype = shift;
|
---|
| 1815 |
|
---|
[353] | 1816 | my ($vm,$all) = pb_get_v($vtype);
|
---|
| 1817 |
|
---|
[346] | 1818 | # Script generated
|
---|
| 1819 | my $pbscript = "$ENV{'PBDESTDIR'}/setupv";
|
---|
[320] | 1820 |
|
---|
[652] | 1821 | foreach my $v (@$vm) {
|
---|
| 1822 | # Deal with date sync.
|
---|
| 1823 | my ($ntpline,$dateline) = pb_date_v($vtype,$v);
|
---|
[639] | 1824 |
|
---|
[353] | 1825 | # Name of the account to deal with for VM/VE
|
---|
| 1826 | # Do not use the one passed potentially with -a
|
---|
| 1827 | my ($pbac) = pb_conf_get($vtype."login");
|
---|
[354] | 1828 | my ($key,$zero0,$zero1,$zero2);
|
---|
[639] | 1829 | my ($vmexist,$vmpid);
|
---|
[346] | 1830 |
|
---|
[681] | 1831 | # Prepare the script to be executed on the VM/VE
|
---|
| 1832 | # in $ENV{'PBDESTDIR'}/setupv
|
---|
| 1833 | open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
|
---|
| 1834 |
|
---|
| 1835 | print SCRIPT << 'EOF';
|
---|
| 1836 | #!/usr/bin/perl -w
|
---|
| 1837 |
|
---|
| 1838 | use strict;
|
---|
| 1839 | use File::Copy;
|
---|
| 1840 |
|
---|
| 1841 | # We should not need in this script more functions than what is provided
|
---|
| 1842 | # by Base and Distribution to avoid problems at exec time.
|
---|
| 1843 | # They are appended at the end.
|
---|
| 1844 |
|
---|
| 1845 | our $pbdebug;
|
---|
| 1846 | our $pbLOG;
|
---|
| 1847 | our $pbsynmsg = "pbscript";
|
---|
| 1848 | our $pbdisplaytype = "text";
|
---|
| 1849 | our $pblocale = "";
|
---|
| 1850 | pb_log_init($pbdebug, $pbLOG);
|
---|
| 1851 | pb_temp_init();
|
---|
| 1852 |
|
---|
| 1853 | EOF
|
---|
| 1854 |
|
---|
[353] | 1855 | if ($vtype eq "vm") {
|
---|
| 1856 | # Prepare the key to be used and transfered remotely
|
---|
| 1857 | my $keyfile = pb_ssh_get(1);
|
---|
| 1858 |
|
---|
[517] | 1859 | my ($vmhost,$vmport,$vmntp) = pb_conf_get("vmhost","vmport","vmntp");
|
---|
[353] | 1860 | my $nport = $vmport->{$ENV{'PBPROJ'}};
|
---|
| 1861 | $nport = "$pbport" if (defined $pbport);
|
---|
[347] | 1862 |
|
---|
[353] | 1863 | # Launch the VM
|
---|
[357] | 1864 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
[347] | 1865 |
|
---|
[353] | 1866 | # Skip that VM if something went wrong
|
---|
[442] | 1867 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
[353] | 1868 |
|
---|
[354] | 1869 | # Store the pub key part in a variable
|
---|
| 1870 | open(FILE,"$keyfile.pub") || die "Unable to open $keyfile.pub";
|
---|
| 1871 | ($zero0,$zero1,$zero2) = split(/ /,<FILE>);
|
---|
| 1872 | close(FILE);
|
---|
| 1873 |
|
---|
| 1874 | $key = "\Q$zero1";
|
---|
| 1875 |
|
---|
[498] | 1876 | 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] | 1877 | # once this is done, we can do what we want on the VM remotely
|
---|
[681] | 1878 | } elsif ($vtype eq "ve") {
|
---|
| 1879 | # We need to finish the setup of packages needed in the VE if needed
|
---|
| 1880 | # rinse at least needs it
|
---|
| 1881 | my ($vepkglist) = pb_conf_get_if("vepkglist");
|
---|
| 1882 |
|
---|
| 1883 | if (defined $vepkglist) {
|
---|
| 1884 | # Get distro context
|
---|
| 1885 | my ($name,$ver,$darch) = split(/-/,$v);
|
---|
| 1886 | chomp($darch);
|
---|
| 1887 | my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd) = pb_distro_init($name,$ver);
|
---|
[353] | 1888 |
|
---|
[681] | 1889 | my $postparam = pb_get_dist_param($ddir,$dver,$darch,$vepkglist);
|
---|
| 1890 | # Change the list of pkg in to a space separated list
|
---|
| 1891 | $postparam =~ s/,/ /g;
|
---|
| 1892 | # remove potential sudo from the update command for this time,
|
---|
| 1893 | # as this will be run as root anyway, and if not we will have
|
---|
| 1894 | # a problem with tty
|
---|
| 1895 | $pbupd =~ s/sudo //g;
|
---|
[320] | 1896 |
|
---|
[681] | 1897 | print SCRIPT << "EOF";
|
---|
| 1898 | # For VE we first need to mount some FS
|
---|
| 1899 | pb_system("mount -t proc /proc /proc");
|
---|
[346] | 1900 |
|
---|
[681] | 1901 | # For VE we need a good null dev
|
---|
| 1902 | pb_system("rm -f /dev/null; mknod /dev/null c 1 3; chmod 777 /dev/null");
|
---|
[517] | 1903 |
|
---|
[427] | 1904 |
|
---|
[681] | 1905 | # For VE we need some additional packages that are not there yet
|
---|
| 1906 | pb_system("$pbupd $postparam");
|
---|
| 1907 |
|
---|
[354] | 1908 | EOF
|
---|
[681] | 1909 | }
|
---|
| 1910 | }
|
---|
[354] | 1911 | if ($vtype eq "vm") {
|
---|
| 1912 | print SCRIPT << 'EOF';
|
---|
| 1913 | # Removes duplicate in .ssh/authorized_keys of our key if needed
|
---|
| 1914 | #
|
---|
| 1915 | my $file1="$ENV{'HOME'}/.ssh/authorized_keys";
|
---|
| 1916 | open(PBFILE,$file1) || die "Unable to open $file1";
|
---|
| 1917 | open(PBOUT,"> $file1.new") || die "Unable to open $file1.new";
|
---|
| 1918 | my $count = 0;
|
---|
| 1919 | while (<PBFILE>) {
|
---|
[517] | 1920 |
|
---|
[354] | 1921 | EOF
|
---|
| 1922 | print SCRIPT << "EOF";
|
---|
| 1923 | if (/ $key /) {
|
---|
| 1924 | \$count++;
|
---|
| 1925 | }
|
---|
| 1926 | print PBOUT \$_ if ((\$count <= 1) || (\$_ !~ / $key /));
|
---|
| 1927 | }
|
---|
| 1928 | close(PBFILE);
|
---|
| 1929 | close(PBOUT);
|
---|
| 1930 | rename("\$file1.new",\$file1);
|
---|
| 1931 | chmod 0600,\$file1;
|
---|
[517] | 1932 |
|
---|
| 1933 | # Sync date
|
---|
[354] | 1934 | EOF
|
---|
[639] | 1935 | if (defined $ntpline) {
|
---|
[652] | 1936 | print SCRIPT "system(\"$ntpline\");\n";
|
---|
| 1937 | } else {
|
---|
| 1938 | print SCRIPT "system(\"$dateline\");\n";
|
---|
[639] | 1939 | }
|
---|
[354] | 1940 | }
|
---|
| 1941 | print SCRIPT << 'EOF';
|
---|
| 1942 |
|
---|
| 1943 | # Adds $pbac->{$ENV{'PBPROJ'}} as an account if needed
|
---|
| 1944 | #
|
---|
[346] | 1945 | my $file="/etc/passwd";
|
---|
[320] | 1946 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 1947 | my $found = 0;
|
---|
| 1948 | while (<PBFILE>) {
|
---|
[346] | 1949 | EOF
|
---|
[353] | 1950 | print SCRIPT << "EOF";
|
---|
| 1951 | \$found = 1 if (/^$pbac->{$ENV{'PBPROJ'}}:/);
|
---|
[346] | 1952 | EOF
|
---|
[353] | 1953 | print SCRIPT << 'EOF';
|
---|
[320] | 1954 | }
|
---|
| 1955 | close(PBFILE);
|
---|
| 1956 |
|
---|
| 1957 | if ( $found == 0 ) {
|
---|
| 1958 | if ( ! -d "/home" ) {
|
---|
[427] | 1959 | pb_mkdir("/home");
|
---|
[320] | 1960 | }
|
---|
[346] | 1961 | EOF
|
---|
[353] | 1962 | print SCRIPT << "EOF";
|
---|
[427] | 1963 | pb_system("groupadd $pbac->{$ENV{'PBPROJ'}}","Adding group $pbac->{$ENV{'PBPROJ'}}");
|
---|
| 1964 | 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'}}");
|
---|
| 1965 | }
|
---|
[661] | 1966 | EOF
|
---|
[320] | 1967 |
|
---|
[661] | 1968 | if ($vtype eq "vm") {
|
---|
| 1969 | print SCRIPT << "EOF";
|
---|
[354] | 1970 | # allow ssh entry to build
|
---|
| 1971 | #
|
---|
[427] | 1972 | mkdir "/home/$pbac->{$ENV{'PBPROJ'}}/.ssh",0700;
|
---|
[347] | 1973 | # Allow those accessing root to access the build account
|
---|
[427] | 1974 | copy("\$ENV{'HOME'}/.ssh/authorized_keys","/home/$pbac->{$ENV{'PBPROJ'}}/.ssh/authorized_keys");
|
---|
[320] | 1975 | chmod 0600,".ssh/authorized_keys";
|
---|
[427] | 1976 | 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] | 1977 |
|
---|
[346] | 1978 | EOF
|
---|
[661] | 1979 | }
|
---|
[353] | 1980 | print SCRIPT << 'EOF';
|
---|
[347] | 1981 | # No passwd for build account only keys
|
---|
[320] | 1982 | $file="/etc/shadow";
|
---|
[684] | 1983 | if (-f $file) {
|
---|
| 1984 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 1985 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 1986 | while (<PBFILE>) {
|
---|
[346] | 1987 | EOF
|
---|
[353] | 1988 | print SCRIPT << "EOF";
|
---|
[684] | 1989 | s/^$pbac->{$ENV{'PBPROJ'}}:\!\!:/$pbac->{$ENV{'PBPROJ'}}:*:/;
|
---|
| 1990 | s/^$pbac->{$ENV{'PBPROJ'}}:\!:/$pbac->{$ENV{'PBPROJ'}}:*:/; #SLES 9 e.g.
|
---|
[346] | 1991 | EOF
|
---|
[684] | 1992 | print SCRIPT << 'EOF';
|
---|
| 1993 | print PBOUT $_;
|
---|
| 1994 | }
|
---|
| 1995 | close(PBFILE);
|
---|
| 1996 | close(PBOUT);
|
---|
| 1997 | rename("$file.new",$file);
|
---|
| 1998 | chmod 0640,$file;
|
---|
| 1999 | }
|
---|
[320] | 2000 |
|
---|
[448] | 2001 | # Keep the VM in text mode
|
---|
| 2002 | $file="/etc/inittab";
|
---|
[450] | 2003 | if (-f $file) {
|
---|
| 2004 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 2005 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 2006 | while (<PBFILE>) {
|
---|
| 2007 | s/^(..):5:initdefault:$/$1:3:initdefault:/;
|
---|
| 2008 | print PBOUT $_;
|
---|
| 2009 | }
|
---|
| 2010 | close(PBFILE);
|
---|
| 2011 | close(PBOUT);
|
---|
| 2012 | rename("$file.new",$file);
|
---|
| 2013 | chmod 0640,$file;
|
---|
[448] | 2014 | }
|
---|
| 2015 |
|
---|
[320] | 2016 | # pb has to be added to portage group on gentoo
|
---|
| 2017 |
|
---|
[346] | 2018 | # Adapt sudoers
|
---|
| 2019 | $file="/etc/sudoers";
|
---|
| 2020 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 2021 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 2022 | while (<PBFILE>) {
|
---|
| 2023 | EOF
|
---|
[353] | 2024 | print SCRIPT << "EOF";
|
---|
| 2025 | next if (/^$pbac->{$ENV{'PBPROJ'}} /);
|
---|
[346] | 2026 | EOF
|
---|
[353] | 2027 | print SCRIPT << 'EOF';
|
---|
[346] | 2028 | s/Defaults[ \t]+requiretty//;
|
---|
| 2029 | print PBOUT $_;
|
---|
| 2030 | }
|
---|
| 2031 | close(PBFILE);
|
---|
| 2032 | EOF
|
---|
[353] | 2033 | print SCRIPT << "EOF";
|
---|
| 2034 | # This is needed in order to be able to halt the machine from the $pbac->{$ENV{'PBPROJ'}} account at least
|
---|
| 2035 | print PBOUT "$pbac->{$ENV{'PBPROJ'}} ALL=(ALL) NOPASSWD:ALL\n";
|
---|
[346] | 2036 | EOF
|
---|
[353] | 2037 | print SCRIPT << 'EOF';
|
---|
[346] | 2038 | close(PBOUT);
|
---|
| 2039 | rename("$file.new",$file);
|
---|
| 2040 | chmod 0440,$file;
|
---|
| 2041 |
|
---|
| 2042 | EOF
|
---|
[353] | 2043 |
|
---|
| 2044 | my $SCRIPT = \*SCRIPT;
|
---|
| 2045 |
|
---|
| 2046 | pb_install_deps($SCRIPT);
|
---|
| 2047 |
|
---|
| 2048 | print SCRIPT << 'EOF';
|
---|
[346] | 2049 | # Suse wants sudoers as 640
|
---|
[528] | 2050 | if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver =~ /10.[012]/)) {
|
---|
[346] | 2051 | chmod 0640,$file;
|
---|
| 2052 | }
|
---|
| 2053 |
|
---|
[565] | 2054 | 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] | 2055 | system "pb 2>&1 | head -5";
|
---|
[357] | 2056 | EOF
|
---|
[681] | 2057 | if ($vtype eq "ve") {
|
---|
| 2058 | print SCRIPT << 'EOF';
|
---|
| 2059 | # For VE we need to umount some FS at the end
|
---|
| 2060 |
|
---|
| 2061 | pb_system("umount /proc");
|
---|
[696] | 2062 |
|
---|
| 2063 | # Create a basic network file if not already there
|
---|
| 2064 |
|
---|
| 2065 | my $nf="/etc/sysconfig/network";
|
---|
| 2066 | if (! -f $nf) {
|
---|
| 2067 | open(NF,"> $nf") || die "Unable to create $nf";
|
---|
| 2068 | print NF "NETWORKING=yes\n";
|
---|
| 2069 | print NF "HOSTNAME=localhost\n";
|
---|
| 2070 | close(NF);
|
---|
| 2071 | }
|
---|
| 2072 | chmod 0755,$nf;
|
---|
[681] | 2073 | EOF
|
---|
| 2074 | }
|
---|
| 2075 |
|
---|
[517] | 2076 | # Adds pb_distro_init from ProjectBuilder::Distribution and Base
|
---|
[353] | 2077 | foreach my $d (@INC) {
|
---|
[405] | 2078 | my @f = ("$d/ProjectBuilder/Base.pm","$d/ProjectBuilder/Distribution.pm");
|
---|
| 2079 | foreach my $f (@f) {
|
---|
| 2080 | if (-f "$f") {
|
---|
| 2081 | open(PBD,"$f") || die "Unable to open $f";
|
---|
| 2082 | while (<PBD>) {
|
---|
[427] | 2083 | next if (/^package/);
|
---|
| 2084 | next if (/^use Exporter/);
|
---|
| 2085 | next if (/^use ProjectBuilder::/);
|
---|
| 2086 | next if (/^our /);
|
---|
[405] | 2087 | print SCRIPT $_;
|
---|
| 2088 | }
|
---|
| 2089 | close(PBD);
|
---|
[353] | 2090 | }
|
---|
[347] | 2091 | }
|
---|
| 2092 | }
|
---|
[353] | 2093 | close(SCRIPT);
|
---|
| 2094 | chmod 0755,"$pbscript";
|
---|
| 2095 |
|
---|
[442] | 2096 | # That build script needs to be run as root and force stop of VM at end
|
---|
[353] | 2097 | $pbaccount = "root";
|
---|
[442] | 2098 |
|
---|
| 2099 | # Force shutdown of VM exept if it was already launched
|
---|
| 2100 | my $force = 0;
|
---|
| 2101 | if ((! $vmexist) && ($vtype eq "vm")) {
|
---|
| 2102 | $force = 1;
|
---|
| 2103 | }
|
---|
| 2104 |
|
---|
| 2105 | pb_script2v($pbscript,$vtype,$force,$v);
|
---|
[347] | 2106 | }
|
---|
[353] | 2107 | return;
|
---|
[346] | 2108 | }
|
---|
| 2109 |
|
---|
[347] | 2110 | sub pb_install_deps {
|
---|
[346] | 2111 |
|
---|
[348] | 2112 | my $SCRIPT = shift;
|
---|
[346] | 2113 |
|
---|
[348] | 2114 | print {$SCRIPT} << 'EOF';
|
---|
[346] | 2115 | # We need to have that pb_distro_init function
|
---|
[347] | 2116 | # Get it from Project-Builder::Distribution
|
---|
[620] | 2117 | my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd) = pb_distro_init();
|
---|
[320] | 2118 | print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
|
---|
| 2119 |
|
---|
| 2120 | # Get and install pb
|
---|
[437] | 2121 | 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] | 2122 | 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] | 2123 | 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] | 2124 | 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] | 2125 | 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*";
|
---|
[427] | 2126 | my $cmtdm = "Installing Date-Manip perl module";
|
---|
| 2127 | my $cmtmb = "Installing Module-Build perl module";
|
---|
| 2128 | my $cmtfm = "Installing File-MimeInfo perl module";
|
---|
| 2129 | my $cmtfb = "Installing File-Basedir perl module";
|
---|
[498] | 2130 | my $cmtms = "Installing Perl-Sendmail perl module";
|
---|
[427] | 2131 | my $cmtall = "Installing required modules";
|
---|
[357] | 2132 |
|
---|
[320] | 2133 | if ( $ddir eq "fedora" ) {
|
---|
[427] | 2134 | pb_system("yum clean all","Cleaning yum env");
|
---|
[619] | 2135 | if ($dver == 4) {
|
---|
[622] | 2136 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"rpm-build wget patch ntp sudo perl-DateManip perl-ExtUtils-MakeMaker"));
|
---|
[427] | 2137 | pb_system("$insmb","$cmtmb");
|
---|
| 2138 | pb_system("$insfm","$cmtfm");
|
---|
| 2139 | pb_system("$insfb","$cmtfb");
|
---|
[517] | 2140 | pb_system("$insms","$cmtms");
|
---|
| 2141 | } else {
|
---|
[681] | 2142 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"rpm-build wget patch ntp sudo perl-DateManip perl-ExtUtils-MakeMaker perl-File-MimeInfo perl-Mail-Sendmail"));
|
---|
[357] | 2143 | }
|
---|
| 2144 | } elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || ($ddir eq "slackware")) {
|
---|
[358] | 2145 | # Suppose pkg are installed already as no online mirror available
|
---|
[427] | 2146 | pb_system("rpm -e lsb 2>&1 > /dev/null","Removing lsb package");
|
---|
| 2147 | pb_system("$insdm","$cmtdm");
|
---|
| 2148 | pb_system("$insmb","$cmtmb");
|
---|
| 2149 | pb_system("$insfm","$cmtfm");
|
---|
| 2150 | pb_system("$insfb","$cmtfb");
|
---|
[498] | 2151 | pb_system("$insms","$cmtms");
|
---|
[320] | 2152 | } elsif ($ddir eq "suse") {
|
---|
| 2153 | # New OpenSuSE
|
---|
[652] | 2154 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"make wget patch sudo ntp"));
|
---|
[427] | 2155 | pb_system("$insmb","$cmtmb");
|
---|
| 2156 | pb_system("$insfm","$cmtfm");
|
---|
| 2157 | pb_system("$insfb","$cmtfb");
|
---|
[652] | 2158 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"perl-Date-Manip perl-File-HomeDir perl-Mail-Sendmail"));
|
---|
| 2159 | if ($dver < 11) {
|
---|
| 2160 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"ntp"));
|
---|
| 2161 | } else {
|
---|
| 2162 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"sntp"));
|
---|
| 2163 | }
|
---|
[320] | 2164 | } elsif ( $dfam eq "md" ) {
|
---|
[622] | 2165 | my $addp = "";
|
---|
[357] | 2166 | if (($ddir eq "mandrake") && ($dver eq "10.1")) {
|
---|
[427] | 2167 | pb_system("$insdm","$cmtdm");
|
---|
[357] | 2168 | } else {
|
---|
[681] | 2169 | $addp ="perl-DateManip";
|
---|
[357] | 2170 | }
|
---|
[681] | 2171 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"rpm-build wget sudo patch ntp-client perl-File-MimeInfo perl-Mail-Sendmail $addp"));
|
---|
[320] | 2172 | } elsif ( $dfam eq "du" ) {
|
---|
| 2173 | if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
|
---|
[427] | 2174 | pb_system("$insfb","$cmtfb");
|
---|
| 2175 | pb_system("$insfm","$cmtfm");
|
---|
[681] | 2176 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libmodule-build-perl libdate-manip-perl libmail-sendmail-perl"));
|
---|
[320] | 2177 | } else {
|
---|
[681] | 2178 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"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"));
|
---|
[320] | 2179 | }
|
---|
| 2180 | } elsif ( $dfam eq "gen" ) {
|
---|
[427] | 2181 | #system "emerge -u system";
|
---|
[681] | 2182 | pb_distro_installdeps(undef,$dtype,$pbupd,pb_distro_only_deps_needed($dtype,"wget sudo ntp DateManip File-MimeInfo Mail-Sendmail"));
|
---|
[320] | 2183 | } else {
|
---|
[495] | 2184 | pb_log(0,"No pkg to install\n");
|
---|
[320] | 2185 | }
|
---|
| 2186 | EOF
|
---|
| 2187 | }
|
---|
| 2188 |
|
---|
[471] | 2189 | sub pb_announce {
|
---|
| 2190 |
|
---|
[473] | 2191 | # Get all required parameters
|
---|
[477] | 2192 | my ($pbpackager,$pbrepo,$pbml,$pbsmtp) = pb_conf_get("pbpackager","pbrepo","pbml","pbsmtp");
|
---|
[471] | 2193 | my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
|
---|
| 2194 | my $pkg = pb_cms_get_pkg($defpkgdir,$extpkgdir);
|
---|
| 2195 | my @pkgs = @$pkg;
|
---|
| 2196 | my %pkgs;
|
---|
| 2197 | my $first = 0;
|
---|
| 2198 |
|
---|
[473] | 2199 | # Command to find packages on repo
|
---|
[471] | 2200 | my $findstr = "find . ";
|
---|
[473] | 2201 | # Generated announce files
|
---|
| 2202 | my @files;
|
---|
[471] | 2203 |
|
---|
| 2204 | foreach my $pbpkg (@pkgs) {
|
---|
| 2205 | if ($first != 0) {
|
---|
| 2206 | $findstr .= "-o ";
|
---|
| 2207 | }
|
---|
| 2208 | $first++;
|
---|
| 2209 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
| 2210 | $pbver = $pkgv->{$pbpkg};
|
---|
| 2211 | } else {
|
---|
| 2212 | $pbver = $ENV{'PBPROJVER'};
|
---|
| 2213 | }
|
---|
| 2214 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
| 2215 | $pbtag = $pkgt->{$pbpkg};
|
---|
| 2216 | } else {
|
---|
| 2217 | $pbtag = $ENV{'PBPROJTAG'};
|
---|
| 2218 | }
|
---|
| 2219 |
|
---|
[547] | 2220 | # TODO: use virtual/real names here now
|
---|
[471] | 2221 | $findstr .= "-name \'$pbpkg-$pbver-$pbtag\.*.rpm\' -o -name \'$pbpkg"."_$pbver*\.deb\' -o -name \'$pbpkg-$pbver\.ebuild\' ";
|
---|
[473] | 2222 |
|
---|
| 2223 | my $chglog;
|
---|
| 2224 |
|
---|
| 2225 | # Get project info on log file and generate tmp files used later on
|
---|
| 2226 | pb_cms_init($pbinit);
|
---|
| 2227 | $chglog = "$ENV{'PBROOTDIR'}/$pbpkg/pbcl";
|
---|
| 2228 | $chglog = "$ENV{'PBROOTDIR'}/pbcl" if (! -f $chglog);
|
---|
| 2229 | $chglog = undef if (! -f $chglog);
|
---|
| 2230 |
|
---|
| 2231 | open(OUT,"> $ENV{'PBTMP'}/$pbpkg.ann") || die "Unable to create $ENV{'PBTMP'}/$pbpkg.ann: $!";
|
---|
[585] | 2232 | my %pb;
|
---|
| 2233 | $pb{'dtype'} = "announce";
|
---|
| 2234 | $pb{'realpkg'} = $pbpkg;
|
---|
| 2235 | $pb{'ver'} = $pbver;
|
---|
| 2236 | $pb{'tag'} = $pbtag;
|
---|
| 2237 | $pb{'suf'} = "N/A"; # Should not be empty even if unused
|
---|
| 2238 | $pb{'date'} = $pbdate;
|
---|
| 2239 | $pb{'chglog'} = $chglog;
|
---|
| 2240 | $pb{'packager'} = $pbpackager;
|
---|
| 2241 | $pb{'proj'} = $ENV{'PBPROJ'};
|
---|
| 2242 | $pb{'repo'} = $pbrepo;
|
---|
| 2243 | pb_changelog(\%pb,\*OUT,"yes");
|
---|
[473] | 2244 | close(OUT);
|
---|
| 2245 | push(@files,"$ENV{'PBTMP'}/$pbpkg.ann");
|
---|
[471] | 2246 | }
|
---|
| 2247 | $findstr .= " | grep -Ev \'src.rpm\'";
|
---|
| 2248 | if ((not defined $testver) || (not defined $testver->{$ENV{'PBPROJ'}}) || ($testver->{$ENV{'PBPROJ'}} !~ /true/i)) {
|
---|
| 2249 | $findstr .= " | grep -v ./test/";
|
---|
| 2250 | }
|
---|
| 2251 |
|
---|
| 2252 | # Prepare the command to run and execute it
|
---|
| 2253 | open(PBS,"> $ENV{'PBTMP'}/pbscript") || die "Unable to create $ENV{'PBTMP'}/pbscript";
|
---|
| 2254 | print PBS "$findstr\n";
|
---|
| 2255 | close(PBS);
|
---|
| 2256 | chmod 0755,"$ENV{'PBTMP'}/pbscript";
|
---|
| 2257 | pb_send2target("Announce");
|
---|
| 2258 |
|
---|
[490] | 2259 | # Get subject line
|
---|
| 2260 | my $sl = "Project $ENV{'PBPROJ'} version $ENV{'PBPROJVER'} is now available";
|
---|
[495] | 2261 | pb_log(0,"Please enter the title of your announce\n");
|
---|
| 2262 | pb_log(0,"(By default: $sl)\n");
|
---|
[490] | 2263 | my $sl2 = <STDIN>;
|
---|
| 2264 | $sl = $sl2 if ($sl2 !~ /^$/);
|
---|
| 2265 |
|
---|
[471] | 2266 | # Prepare a template of announce
|
---|
[473] | 2267 | open(ANN,"> $ENV{'PBTMP'}/announce.html") || die "Unable to create $ENV{'PBTMP'}/announce.html: $!";
|
---|
[471] | 2268 | print ANN << "EOF";
|
---|
[490] | 2269 | $sl</p>
|
---|
[471] | 2270 |
|
---|
[473] | 2271 | <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] | 2272 | <p>
|
---|
| 2273 | Now available at <a href="$pbrepo->{$ENV{'PBPROJ'}}">$pbrepo->{$ENV{'PBPROJ'}}</a>
|
---|
| 2274 | </p>
|
---|
| 2275 | <p>
|
---|
| 2276 | EOF
|
---|
| 2277 | open(LOG,"$ENV{'PBTMP'}/system.log") || die "Unable to read $ENV{'PBTMP'}/system.log: $!";
|
---|
[473] | 2278 | my $col = 2;
|
---|
| 2279 | my $i = 1;
|
---|
| 2280 | print ANN << 'EOF';
|
---|
| 2281 | <TABLE WIDTH="700" CELLPADDING="0" CELLSPACING="0" BORDER="0">
|
---|
| 2282 | <TR>
|
---|
| 2283 | EOF
|
---|
[471] | 2284 | while (<LOG>) {
|
---|
[697] | 2285 | print ANN "<TD><A HREF=\"$pbrepo->{$ENV{'PBPROJ'}}/$_\">$_</A></TD>";
|
---|
[473] | 2286 | $i++;
|
---|
| 2287 | if ($i > $col) {
|
---|
| 2288 | print ANN "</TR>\n<TR>";
|
---|
| 2289 | $i = 1;
|
---|
| 2290 | }
|
---|
[471] | 2291 | }
|
---|
| 2292 | close(LOG);
|
---|
[473] | 2293 | print ANN << "EOF";
|
---|
| 2294 | </TR>
|
---|
| 2295 | </TABLE>
|
---|
| 2296 | </p>
|
---|
[471] | 2297 |
|
---|
[473] | 2298 | <p>As usual source packages are also available in the same directory.</p>
|
---|
| 2299 |
|
---|
| 2300 | <p>
|
---|
| 2301 | Changes are :
|
---|
| 2302 | </p>
|
---|
| 2303 | <p>
|
---|
| 2304 | EOF
|
---|
| 2305 | # Get each package changelog content
|
---|
| 2306 | foreach my $f (sort(@files)) {
|
---|
| 2307 | open(IN,"$f") || die "Unable to read $f:$!";
|
---|
| 2308 | while (<IN>) {
|
---|
| 2309 | print ANN $_;
|
---|
| 2310 | }
|
---|
| 2311 | close(IN);
|
---|
| 2312 | print ANN "</p><p>\n";
|
---|
| 2313 | }
|
---|
| 2314 | print ANN "</p>\n";
|
---|
[471] | 2315 | close(ANN);
|
---|
[473] | 2316 |
|
---|
| 2317 | # Allow for modification
|
---|
| 2318 | pb_system("vi $ENV{'PBTMP'}/announce.html","Allowing modification of the announce","noredir");
|
---|
| 2319 |
|
---|
| 2320 | # Store it in DB for external usage (Web pages generation)
|
---|
| 2321 | my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
|
---|
| 2322 |
|
---|
| 2323 | my $precmd = "";
|
---|
| 2324 | if (! -f $db) {
|
---|
| 2325 | $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
|
---|
| 2326 | }
|
---|
| 2327 |
|
---|
| 2328 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
| 2329 | { RaiseError => 1, AutoCommit => 1 })
|
---|
| 2330 | || die "Unable to connect to $db";
|
---|
| 2331 |
|
---|
| 2332 | if ($precmd ne "") {
|
---|
| 2333 | my $sth = $dbh->prepare(qq{$precmd})
|
---|
| 2334 | || die "Unable to create table into $db";
|
---|
| 2335 | $sth->execute();
|
---|
| 2336 | }
|
---|
| 2337 |
|
---|
| 2338 | # To read whole file
|
---|
| 2339 | local $/;
|
---|
| 2340 | open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
|
---|
| 2341 | my $announce = <ANN>;
|
---|
| 2342 | close(ANN);
|
---|
| 2343 |
|
---|
| 2344 | pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
|
---|
| 2345 | my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
|
---|
| 2346 | || die "Unable to insert into $db";
|
---|
| 2347 | $sth->execute($pbdate, $announce);
|
---|
[698] | 2348 | $sth->finish();
|
---|
[473] | 2349 | $dbh->disconnect;
|
---|
| 2350 |
|
---|
| 2351 | # Then deliver it on the Web
|
---|
| 2352 | # $TOOLHOME/livwww www
|
---|
| 2353 |
|
---|
| 2354 | # Mail it to project's ML
|
---|
| 2355 | open(ML,"| w3m -dump -T text/html > $ENV{'PBTMP'}/announce.txt") || die "Unable to create $ENV{'PBTMP'}/announce.txt: $!";
|
---|
| 2356 | print ML << 'EOF';
|
---|
| 2357 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/x html1/DTD/xhtml1-strict.dtd">
|
---|
| 2358 |
|
---|
| 2359 | <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="en" lang="en">
|
---|
| 2360 | <head>
|
---|
| 2361 | </head>
|
---|
| 2362 | <body>
|
---|
| 2363 | <p>
|
---|
| 2364 | EOF
|
---|
| 2365 | open(ANN,"$ENV{'PBTMP'}/announce.html") || die "Unable to read $ENV{'PBTMP'}/announce.html: $!";
|
---|
| 2366 | while(<ANN>) {
|
---|
| 2367 | print ML $_;
|
---|
| 2368 | }
|
---|
| 2369 | print ML << 'EOF';
|
---|
| 2370 | </body>
|
---|
| 2371 | </html>
|
---|
| 2372 | EOF
|
---|
| 2373 | close(ML);
|
---|
| 2374 |
|
---|
[477] | 2375 | # To read whole file
|
---|
| 2376 | local $/;
|
---|
| 2377 | open(ANN,"$ENV{'PBTMP'}/announce.txt") || die "Unable to read $ENV{'PBTMP'}/announce.txt: $!";
|
---|
| 2378 | my $msg = <ANN>;
|
---|
| 2379 | close(ANN);
|
---|
| 2380 |
|
---|
| 2381 | # Preparation of headers
|
---|
| 2382 |
|
---|
| 2383 | my %mail = (
|
---|
| 2384 | To => $pbml->{$ENV{'PBPROJ'}},
|
---|
| 2385 | From => $pbpackager->{$ENV{'PBPROJ'}},
|
---|
| 2386 | Smtp => $pbsmtp->{$ENV{'PBPROJ'}},
|
---|
| 2387 | Body => $msg,
|
---|
[490] | 2388 | Subject => "[ANNOUNCE] $sl",
|
---|
[477] | 2389 | );
|
---|
| 2390 |
|
---|
| 2391 | # Send mail
|
---|
| 2392 | sendmail(%mail) or die "Unable to send mail ($Mail::Sendmail::error): $Mail::Sendmail::log";
|
---|
[471] | 2393 | }
|
---|
| 2394 |
|
---|
[547] | 2395 | #
|
---|
| 2396 | # Creates a set of HTML file containing the news for the project
|
---|
| 2397 | # based on what has been generated by the pb_announce function
|
---|
| 2398 | #
|
---|
| 2399 | sub pb_web_news2html {
|
---|
| 2400 |
|
---|
[556] | 2401 | my $dest = shift || $ENV{'PBTMP'};
|
---|
| 2402 |
|
---|
[547] | 2403 | # Get all required parameters
|
---|
| 2404 | my ($pkgv, $pkgt, $testver) = pb_conf_get_if("pkgver","pkgtag","testver");
|
---|
| 2405 |
|
---|
| 2406 | # DB of announces for external usage (Web pages generation)
|
---|
| 2407 | my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
|
---|
| 2408 |
|
---|
| 2409 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
|
---|
| 2410 | { RaiseError => 1, AutoCommit => 1 })
|
---|
| 2411 | || die "Unable to connect to $db";
|
---|
| 2412 | # For date handling
|
---|
| 2413 | $ENV{LANGUAGE}="C";
|
---|
[559] | 2414 | my $firstjan = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year(), 0, 0, -1);
|
---|
| 2415 | my $oldfirst = strftime("%Y-%m-%d", 0, 0, 0, 1, 0, localtime->year()-1, 0, 0, -1);
|
---|
| 2416 | pb_log(2,"firstjan: $firstjan, oldfirst: $oldfirst, pbdate:$pbdate\n");
|
---|
[547] | 2417 | my $all = $dbh->selectall_arrayref("SELECT id,date,announce FROM announces ORDER BY date DESC");
|
---|
[556] | 2418 | my %news;
|
---|
| 2419 | $news{"cy"} = ""; # current year's news
|
---|
| 2420 | $news{"ly"} = ""; # last year news
|
---|
| 2421 | $news{"py"} = ""; # previous years news
|
---|
| 2422 | $news{"fp"} = ""; # first page news
|
---|
[547] | 2423 | my $cpt = 4; # how many news for first page
|
---|
| 2424 | # Extract info from DB
|
---|
| 2425 | foreach my $row (@$all) {
|
---|
| 2426 | my ($id, $date, $announce) = @$row;
|
---|
[559] | 2427 | $news{"cy"} = $news{"cy"}."<p><B>$date</B> $announce\n" if ((($date cmp $pbdate) le 0) && (($firstjan cmp $date) le 0));
|
---|
| 2428 | $news{"ly"} = $news{"ly"}."<p><B>$date</B> $announce\n" if ((($date cmp $firstjan) le 0) && (($oldfirst cmp $date) le 0));
|
---|
| 2429 | $news{"py"} = $news{"py"}."<p><B>$date</B> $announce\n" if (($date cmp $oldfirst) le 0);
|
---|
[556] | 2430 | $news{"fp"} = $news{"fp"}."<p><B>$date</B> $announce\n" if ($cpt > 0);
|
---|
[547] | 2431 | $cpt--;
|
---|
| 2432 | }
|
---|
[556] | 2433 | pb_log(1,"news{fp}: ".$news{"fp"}."\n");
|
---|
[547] | 2434 | $dbh->disconnect;
|
---|
[556] | 2435 |
|
---|
| 2436 | # Generate the HTML content
|
---|
| 2437 | foreach my $pref (keys %news) {
|
---|
| 2438 | open(NEWS,"> $dest/pb_web_$pref"."news.html") || die "Unable to create $dest/pb_web_$pref"."news.html: $!";
|
---|
| 2439 | print NEWS "$news{$pref}";
|
---|
| 2440 | close(NEWS);
|
---|
| 2441 | }
|
---|
[547] | 2442 | }
|
---|
| 2443 |
|
---|
[556] | 2444 |
|
---|
[347] | 2445 | # Return the SSH key file to use
|
---|
| 2446 | # Potentially create it if needed
|
---|
| 2447 |
|
---|
| 2448 | sub pb_ssh_get {
|
---|
| 2449 |
|
---|
| 2450 | my $create = shift || 0; # Do not create keys by default
|
---|
| 2451 |
|
---|
| 2452 | # Check the SSH environment
|
---|
| 2453 | my $keyfile = undef;
|
---|
| 2454 |
|
---|
| 2455 | # We have specific keys by default
|
---|
| 2456 | $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
|
---|
[348] | 2457 | if (!(-e $keyfile) && ($create eq 1)) {
|
---|
[347] | 2458 | pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb");
|
---|
| 2459 | }
|
---|
| 2460 |
|
---|
| 2461 | $keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
|
---|
| 2462 | $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
|
---|
| 2463 | $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
|
---|
| 2464 | die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
|
---|
| 2465 | return($keyfile);
|
---|
| 2466 | }
|
---|
| 2467 |
|
---|
| 2468 |
|
---|
[145] | 2469 | # Returns the pid of a running VM command using a specific VM file
|
---|
[142] | 2470 | sub pb_check_ps {
|
---|
| 2471 | my $vmcmd = shift;
|
---|
| 2472 | my $vmm = shift;
|
---|
| 2473 | my $vmexist = 0; # FALSE by default
|
---|
| 2474 |
|
---|
| 2475 | open(PS, "ps auxhww|") || die "Unable to call ps";
|
---|
| 2476 | while (<PS>) {
|
---|
| 2477 | next if (! /$vmcmd/);
|
---|
| 2478 | next if (! /$vmm/);
|
---|
| 2479 | my ($void1, $void2);
|
---|
| 2480 | ($void1, $vmexist, $void2) = split(/ +/);
|
---|
| 2481 | last;
|
---|
| 2482 | }
|
---|
| 2483 | return($vmexist);
|
---|
| 2484 | }
|
---|
| 2485 |
|
---|
| 2486 |
|
---|
[77] | 2487 | sub pb_extract_build_files {
|
---|
[25] | 2488 |
|
---|
| 2489 | my $src=shift;
|
---|
| 2490 | my $dir=shift;
|
---|
[26] | 2491 | my $ddir=shift;
|
---|
[500] | 2492 | my $mandatory=shift || "spec";
|
---|
[28] | 2493 | my @files;
|
---|
[25] | 2494 |
|
---|
[500] | 2495 | my $flag = "mayfail" if ($mandatory eq "patch");
|
---|
| 2496 | my $res;
|
---|
| 2497 |
|
---|
[188] | 2498 | if ($src =~ /tar\.gz$/) {
|
---|
[500] | 2499 | $res = pb_system("tar xfpz $src $dir","Extracting $mandatory files from $src",$flag);
|
---|
[188] | 2500 | } elsif ($src =~ /tar\.bz2$/) {
|
---|
[500] | 2501 | $res = pb_system("tar xfpj $src $dir","Extracting $mandatory files from $src",$flag);
|
---|
[188] | 2502 | } else {
|
---|
| 2503 | die "Unknown compression algorithm for $src";
|
---|
| 2504 | }
|
---|
[500] | 2505 | # If not mandatory return now
|
---|
| 2506 | return() if (($res != 0) and ($mandatory eq "patch"));
|
---|
[25] | 2507 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
| 2508 | foreach my $f (readdir(DIR)) {
|
---|
| 2509 | next if ($f =~ /^\./);
|
---|
[500] | 2510 | # Skip potential patch dir
|
---|
| 2511 | next if ($f =~ /^pbpatch/);
|
---|
[26] | 2512 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[315] | 2513 | pb_log(2,"mv $dir/$f $ddir\n");
|
---|
[28] | 2514 | push @files,"$ddir/$f";
|
---|
[25] | 2515 | }
|
---|
| 2516 | closedir(DIR);
|
---|
[26] | 2517 | # Not enough but still a first cleanup
|
---|
[74] | 2518 | pb_rm_rf("$dir");
|
---|
[28] | 2519 | return(@files);
|
---|
[25] | 2520 | }
|
---|
| 2521 |
|
---|
[315] | 2522 | sub pb_list_bfiles {
|
---|
| 2523 |
|
---|
| 2524 | my $dir = shift;
|
---|
| 2525 | my $pbpkg = shift;
|
---|
| 2526 | my $bfiles = shift;
|
---|
| 2527 | my $pkgfiles = shift;
|
---|
| 2528 | my $supfiles = shift;
|
---|
| 2529 |
|
---|
| 2530 | opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
|
---|
| 2531 | foreach my $f (readdir(BDIR)) {
|
---|
| 2532 | next if ($f =~ /^\./);
|
---|
| 2533 | $bfiles->{$f} = "$dir/$f";
|
---|
[340] | 2534 | $bfiles->{$f} =~ s~$ENV{'PBROOTDIR'}~~;
|
---|
[315] | 2535 | if (defined $supfiles->{$pbpkg}) {
|
---|
| 2536 | $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
|
---|
| 2537 | }
|
---|
| 2538 | }
|
---|
| 2539 | closedir(BDIR);
|
---|
| 2540 | }
|
---|
| 2541 |
|
---|
[395] | 2542 |
|
---|
| 2543 | #
|
---|
| 2544 | # Return the list of packages we are working on in a non CMS action
|
---|
| 2545 | #
|
---|
| 2546 | sub pb_get_pkg {
|
---|
| 2547 |
|
---|
| 2548 | my @pkgs = ();
|
---|
| 2549 |
|
---|
| 2550 | my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
|
---|
| 2551 | @pkgs = keys %$var;
|
---|
| 2552 |
|
---|
| 2553 | pb_log(0,"Packages: ".join(',',@pkgs)."\n");
|
---|
| 2554 | return(\@pkgs);
|
---|
| 2555 | }
|
---|
| 2556 |
|
---|
[500] | 2557 | # Which is our local arch ? (standardize on i386 for those platforms)
|
---|
| 2558 | sub pb_get_arch {
|
---|
| 2559 |
|
---|
| 2560 | my $arch = `uname -m`;
|
---|
| 2561 | chomp($arch);
|
---|
| 2562 | $arch =~ s/i.86/i386/;
|
---|
| 2563 | return($arch);
|
---|
| 2564 | }
|
---|
| 2565 |
|
---|
[670] | 2566 | sub pb_get_dist_param {
|
---|
| 2567 |
|
---|
| 2568 | my $param = "";
|
---|
| 2569 | my $ddir = shift;
|
---|
| 2570 | my $dver = shift;
|
---|
| 2571 | my $darch = shift;
|
---|
| 2572 | my $opt = shift;
|
---|
| 2573 |
|
---|
| 2574 | if (defined $opt->{"$ddir-$dver-$darch"}) {
|
---|
| 2575 | $param = $opt->{"$ddir-$dver-$darch"};
|
---|
| 2576 | } elsif (defined $opt->{"$ddir-$dver"}) {
|
---|
| 2577 | $param = $opt->{"$ddir-$dver"};
|
---|
| 2578 | } elsif (defined $opt->{"$ddir"}) {
|
---|
| 2579 | $param = $opt->{"$ddir"};
|
---|
| 2580 | } elsif (defined $opt->{"default"}) {
|
---|
| 2581 | $param = $opt->{"default"};
|
---|
| 2582 | } else {
|
---|
| 2583 | $param = "";
|
---|
| 2584 | }
|
---|
| 2585 | return($param);
|
---|
| 2586 | }
|
---|
| 2587 |
|
---|
[395] | 2588 | 1;
|
---|