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