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