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