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