[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';
|
---|
[5] | 13 | use Getopt::Std;
|
---|
[9] | 14 | use Data::Dumper;
|
---|
| 15 | use English;
|
---|
[16] | 16 | use File::Basename;
|
---|
[26] | 17 | use File::Copy;
|
---|
[13] | 18 | use Time::localtime qw(localtime);
|
---|
| 19 | use POSIX qw(strftime);
|
---|
[5] | 20 |
|
---|
[73] | 21 | # Global variables
|
---|
[17] | 22 | use lib qw (lib);
|
---|
[74] | 23 | use ProjectBuilder::Distribution qw (pb_distro_init);
|
---|
| 24 | use ProjectBuilder::Version qw (pb_version_init);
|
---|
[318] | 25 | use ProjectBuilder::Base;
|
---|
[5] | 26 |
|
---|
| 27 | my %opts; # CLI Options
|
---|
[9] | 28 | my $action; # action to realize
|
---|
[320] | 29 | my $test = "FALSE"; # Not used
|
---|
| 30 | my $force = 0; # Force VE/VM rebuild
|
---|
| 31 | my $option = ""; # Not used
|
---|
| 32 | my @pkgs; # list of packages
|
---|
[95] | 33 | my $pbtag; # Global Tag variable
|
---|
| 34 | my $pbver; # Global Version variable
|
---|
[141] | 35 | my $pbscript; # Name of the script
|
---|
[77] | 36 | my %pbver; # per package
|
---|
| 37 | my %pbtag; # per package
|
---|
[53] | 38 | my $pbrev; # Global REVISION variable
|
---|
[152] | 39 | my $pbaccount; # Login to use to connect to the VM
|
---|
[162] | 40 | my $pbport; # Port to use to connect to the VM
|
---|
[199] | 41 | my $newver; # New version to create
|
---|
[262] | 42 | my $iso; # ISO iage for the VM to create
|
---|
[5] | 43 |
|
---|
[320] | 44 | my @date = pb_get_date();
|
---|
| 45 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
[5] | 46 |
|
---|
[320] | 47 | getopts('a:fhi:l:m:P:p:qr:s:tvV:',\%opts);
|
---|
| 48 |
|
---|
[75] | 49 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
[21] | 50 | if (defined $opts{'h'}) {
|
---|
[74] | 51 | pb_syntax();
|
---|
[21] | 52 | exit(0);
|
---|
| 53 | }
|
---|
| 54 | if (defined $opts{'v'}) {
|
---|
[318] | 55 | $debug = 2;
|
---|
| 56 | #$debug = $opts{'v'};
|
---|
| 57 | pb_log(0,"Debug value: $debug\n");
|
---|
[21] | 58 | }
|
---|
[320] | 59 | if (defined $opts{'f'}) {
|
---|
| 60 | $force=1;
|
---|
| 61 | }
|
---|
[21] | 62 | if (defined $opts{'q'}) {
|
---|
| 63 | $debug=-1;
|
---|
| 64 | }
|
---|
[22] | 65 | if (defined $opts{'l'}) {
|
---|
| 66 | open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
| 67 | $LOG = *LOG;
|
---|
| 68 | $debug = 0 if ($debug == -1);
|
---|
| 69 | }
|
---|
[315] | 70 | pb_log_init($debug, $LOG);
|
---|
| 71 |
|
---|
[9] | 72 | # Handles test option
|
---|
| 73 | if (defined $opts{'t'}) {
|
---|
| 74 | $test = "TRUE";
|
---|
| 75 | # Works only for SVN
|
---|
| 76 | $option = "-r BASE";
|
---|
| 77 | }
|
---|
[5] | 78 |
|
---|
[67] | 79 | # Handle root of the project if defined
|
---|
| 80 | if (defined $opts{'r'}) {
|
---|
| 81 | $ENV{'PBROOT'} = $opts{'r'};
|
---|
| 82 | }
|
---|
[91] | 83 | # Handle virtual machines if any
|
---|
| 84 | if (defined $opts{'m'}) {
|
---|
[320] | 85 | $ENV{'PBV'} = $opts{'m'};
|
---|
[91] | 86 | }
|
---|
[141] | 87 | if (defined $opts{'s'}) {
|
---|
| 88 | $pbscript = $opts{'s'};
|
---|
| 89 | }
|
---|
[152] | 90 | if (defined $opts{'a'}) {
|
---|
| 91 | $pbaccount = $opts{'a'};
|
---|
| 92 | }
|
---|
[162] | 93 | if (defined $opts{'P'}) {
|
---|
| 94 | $pbport = $opts{'P'};
|
---|
| 95 | }
|
---|
[199] | 96 | if (defined $opts{'V'}) {
|
---|
| 97 | $newver = $opts{'V'};
|
---|
| 98 | }
|
---|
[262] | 99 | if (defined $opts{'i'}) {
|
---|
| 100 | $iso = $opts{'i'};
|
---|
| 101 | }
|
---|
[108] | 102 |
|
---|
| 103 | # Get Action
|
---|
| 104 | $action = shift @ARGV;
|
---|
| 105 | die pb_syntax() if (not defined $action);
|
---|
| 106 |
|
---|
[314] | 107 | my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
|
---|
[273] | 108 | my $pbinit = undef;
|
---|
| 109 | $pbinit = 1 if ($action =~ /^newproj$/);
|
---|
[108] | 110 |
|
---|
[59] | 111 | # Handles project name if any
|
---|
[108] | 112 | # And get global params
|
---|
[59] | 113 | if (defined $opts{'p'}) {
|
---|
[315] | 114 | ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
|
---|
[273] | 115 | = pb_env_init($opts{'p'},$pbinit);
|
---|
[59] | 116 | } else {
|
---|
[315] | 117 | ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir)
|
---|
[273] | 118 | = pb_env_init(undef,$pbinit);
|
---|
[59] | 119 | }
|
---|
| 120 |
|
---|
[315] | 121 | pb_log(0,"Project: $ENV{'PBPROJ'}\n");
|
---|
| 122 | pb_log(0,"Action: $action\n");
|
---|
[9] | 123 |
|
---|
[91] | 124 | # Keep those project values to store them at the end each time
|
---|
[83] | 125 | my $pbprojtag = $ENV{'PBTAG'};
|
---|
| 126 | my $pbprojver = $ENV{'PBVER'};
|
---|
| 127 |
|
---|
[9] | 128 | # Act depending on action
|
---|
| 129 | if ($action =~ /^cms2build$/) {
|
---|
[77] | 130 | pb_cms2build();
|
---|
| 131 | } elsif ($action =~ /^build2pkg$/) {
|
---|
| 132 | pb_build2pkg();
|
---|
| 133 | } elsif ($action =~ /^cms2pkg$/) {
|
---|
| 134 | pb_cms2build();
|
---|
| 135 | pb_build2pkg();
|
---|
[88] | 136 | } elsif ($action =~ /^build2ssh$/) {
|
---|
| 137 | pb_build2ssh();
|
---|
[220] | 138 | } elsif ($action =~ /^cms2ssh$/) {
|
---|
| 139 | pb_cms2build();
|
---|
| 140 | pb_build2ssh();
|
---|
[88] | 141 | } elsif ($action =~ /^pkg2ssh$/) {
|
---|
| 142 | pb_pkg2ssh();
|
---|
[320] | 143 | } elsif ($action =~ /^build2ve$/) {
|
---|
| 144 | pb_build2v("ve");
|
---|
[91] | 145 | } elsif ($action =~ /^build2vm$/) {
|
---|
[320] | 146 | pb_build2v("vm");
|
---|
| 147 | } elsif ($action =~ /^cms2ve$/) {
|
---|
| 148 | pb_cms2build();
|
---|
| 149 | pb_build2v("ve");
|
---|
[91] | 150 | } elsif ($action =~ /^cms2vm$/) {
|
---|
| 151 | pb_cms2build();
|
---|
[320] | 152 | pb_build2v("vm");
|
---|
[141] | 153 | } elsif ($action =~ /^launchvm$/) {
|
---|
[320] | 154 | pb_launchv("vm",$ENV{'PBV'},0);
|
---|
| 155 | } elsif ($action =~ /^launchve$/) {
|
---|
| 156 | pb_launchv("ve",$ENV{'PBV'},0);
|
---|
[142] | 157 | } elsif ($action =~ /^script2vm$/) {
|
---|
[320] | 158 | pb_script2v($pbscript,"vm");
|
---|
| 159 | } elsif ($action =~ /^script2ve$/) {
|
---|
| 160 | pb_script2v($pbscript,"ve");
|
---|
[199] | 161 | } elsif ($action =~ /^newver$/) {
|
---|
| 162 | pb_newver();
|
---|
[320] | 163 | } elsif ($action =~ /^newve$/) {
|
---|
| 164 | pb_launchv("ve",$ENV{'PBV'},1);
|
---|
[262] | 165 | } elsif ($action =~ /^newvm$/) {
|
---|
[320] | 166 | pb_launchv("vm",$ENV{'PBV'},1);
|
---|
[273] | 167 | } elsif ($action =~ /^newproj$/) {
|
---|
| 168 | # Nothing to do - already done in pb_env_init
|
---|
[106] | 169 | } elsif ($action =~ /^clean$/) {
|
---|
[77] | 170 | } else {
|
---|
[315] | 171 | pb_log(0,"\'$action\' is not available\n");
|
---|
[77] | 172 | pb_syntax();
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | sub pb_cms2build {
|
---|
| 176 |
|
---|
[112] | 177 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
[22] | 178 | @pkgs = @$ptr;
|
---|
[315] | 179 | my ($scheme,$uri)=pb_cms_init($ENV{'PBPROJ'});
|
---|
[9] | 180 |
|
---|
[313] | 181 | my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
|
---|
[174] | 182 |
|
---|
| 183 | # declare packager for filtering
|
---|
[320] | 184 | my ($tmp) = pb_conf_get("pbpackager");
|
---|
[174] | 185 | my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
|
---|
| 186 |
|
---|
[27] | 187 | foreach my $pbpkg (@pkgs) {
|
---|
[115] | 188 | $ENV{'PBPKG'} = $pbpkg;
|
---|
[274] | 189 | $ENV{'PBVER'} = $pbprojver;
|
---|
| 190 | $ENV{'PBTAG'} = $pbprojtag;
|
---|
[98] | 191 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
| 192 | $pbver = $pkgv->{$pbpkg};
|
---|
[115] | 193 | $ENV{'PBVER'} = $pbver;
|
---|
[9] | 194 | } else {
|
---|
[16] | 195 | $pbver = $ENV{'PBVER'};
|
---|
[9] | 196 | }
|
---|
[98] | 197 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
| 198 | $pbtag = $pkgt->{$pbpkg};
|
---|
[115] | 199 | $ENV{'PBTAG'} = $pbtag;
|
---|
[9] | 200 | } else {
|
---|
[16] | 201 | $pbtag = $ENV{'PBTAG'};
|
---|
[9] | 202 | }
|
---|
[95] | 203 |
|
---|
[16] | 204 | $pbrev = $ENV{'PBREVISION'};
|
---|
[319] | 205 | pb_log(0,"\n");
|
---|
| 206 | pb_log(0,"Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n");
|
---|
[9] | 207 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
[16] | 208 | # Clean up dest if necessary. The export will recreate it
|
---|
[27] | 209 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
|
---|
[74] | 210 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 211 |
|
---|
| 212 | # Export CMS tree for the concerned package to dest
|
---|
| 213 | # And generate some additional files
|
---|
| 214 | $OUTPUT_AUTOFLUSH=1;
|
---|
[29] | 215 |
|
---|
[9] | 216 | # computes in which dir we have to work
|
---|
[113] | 217 | my $dir = $defpkgdir->{$pbpkg};
|
---|
| 218 | $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
|
---|
[315] | 219 | pb_log(2,"def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n");
|
---|
[9] | 220 |
|
---|
[315] | 221 | # If it isn't a flat CMS, then we have the choice to export subdir
|
---|
[319] | 222 | #$dir = "$uri/$dir" if ($ENV{'PBREVISION'} ne "flat");
|
---|
| 223 | pb_cms_export($uri,"$dir",$dest);
|
---|
[315] | 224 |
|
---|
[285] | 225 | # Get project info on authors and log file
|
---|
| 226 | my $chglog = "$ENV{'PBCONF'}/$pbpkg/pbcl";
|
---|
| 227 | $chglog = "$ENV{'PBCONF'}/pbcl" if (! -f $chglog);
|
---|
| 228 | $chglog = undef if (! -f $chglog);
|
---|
| 229 |
|
---|
| 230 | my $authors = "$ENV{'PBCONF'}/$pbpkg/pbauthors";
|
---|
| 231 | $authors = "$ENV{'PBCONF'}/pbauthors" if (! -f $authors);
|
---|
| 232 | $authors = "/dev/null" if (! -f $authors);
|
---|
| 233 |
|
---|
[9] | 234 | # Extract cms log history and store it
|
---|
[285] | 235 | if ((defined $chglog) && (! -f "$dest/NEWS")) {
|
---|
[315] | 236 | pb_log(2,"Generating NEWS file from $chglog\n");
|
---|
[285] | 237 | copy($chglog,"$dest/NEWS") || die "Unable to create $dest/NEWS";
|
---|
| 238 | }
|
---|
[315] | 239 | pb_cms_log($scheme,$dir,$dest,$chglog,$authors);
|
---|
[29] | 240 |
|
---|
[21] | 241 | my %build;
|
---|
[91] | 242 |
|
---|
[320] | 243 | my ($ptr) = pb_conf_get_if("vmlist","velist");
|
---|
[91] | 244 | foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
|
---|
[315] | 245 | my ($name,$ver,$arch) = split(/-/,$d);
|
---|
| 246 | chomp($arch);
|
---|
[99] | 247 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
|
---|
[315] | 248 | pb_log(2,"DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n");
|
---|
| 249 | pb_log(2,"DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n");
|
---|
[13] | 250 |
|
---|
[16] | 251 | # Filter build files from the less precise up to the most with overloading
|
---|
[13] | 252 | # Filter all files found, keeping the name, and generating in dest
|
---|
[16] | 253 |
|
---|
| 254 | # Find all build files first relatively to PBROOT
|
---|
[300] | 255 | # Find also all specific files referenced in the .pb conf file
|
---|
[320] | 256 | my %bfiles = ();
|
---|
| 257 | my %pkgfiles = ();
|
---|
[315] | 258 | pb_log(2,"DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n");
|
---|
[21] | 259 | $build{"$ddir-$dver"} = "yes";
|
---|
[315] | 260 |
|
---|
| 261 | if (-d "$ENV{'PBROOT'}/$pbpkg/$dtype") {
|
---|
| 262 | pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$dtype",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 263 | } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$dfam") {
|
---|
| 264 | pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$dfam",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 265 | } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$ddir") {
|
---|
| 266 | pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$ddir",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
| 267 | } elsif (-d "$ENV{'PBROOT'}/$pbpkg/$ddir-$dver") {
|
---|
| 268 | pb_list_bfiles("$ENV{'PBROOT'}/$pbpkg/$ddir-$dver",$pbpkg,\%bfiles,\%pkgfiles,$supfiles);
|
---|
[13] | 269 | } else {
|
---|
[21] | 270 | $build{"$ddir-$dver"} = "no";
|
---|
[13] | 271 | next;
|
---|
| 272 | }
|
---|
[315] | 273 | pb_log(2,"DEBUG bfiles: ".Dumper(\%bfiles)."\n");
|
---|
[13] | 274 |
|
---|
[15] | 275 | # Get all filters to apply
|
---|
[77] | 276 | my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
|
---|
[15] | 277 |
|
---|
[19] | 278 | # Apply now all the filters on all the files concerned
|
---|
| 279 | # destination dir depends on the type of file
|
---|
| 280 | if (defined $ptr) {
|
---|
[300] | 281 | foreach my $f (values %bfiles,values %pkgfiles) {
|
---|
[297] | 282 | pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$pbpackager,$chglog);
|
---|
[16] | 283 | }
|
---|
[15] | 284 | }
|
---|
[18] | 285 | }
|
---|
[315] | 286 | my @found;
|
---|
| 287 | my @notfound;
|
---|
| 288 | foreach my $b (keys %build) {
|
---|
| 289 | push @found,$b if ($build{$b} =~ /yes/);
|
---|
| 290 | push @notfound,$b if ($build{$b} =~ /no/);
|
---|
[21] | 291 | }
|
---|
[315] | 292 | pb_log(0,"Build files generated for ".join(',',@found)."\n");
|
---|
| 293 | pb_log(0,"No Build files found for ".join(',',@notfound)."\n") if (@notfound);
|
---|
[236] | 294 | # Get the generic filter (all.pbf) and
|
---|
| 295 | # apply those to the non-build files including those
|
---|
| 296 | # generated by pbinit if applicable
|
---|
| 297 |
|
---|
| 298 | # Get only all.pbf filter
|
---|
[237] | 299 | $ptr = pb_get_filters($pbpkg);
|
---|
[236] | 300 |
|
---|
| 301 | my $liste ="";
|
---|
| 302 | if (defined $filteredfiles->{$pbpkg}) {
|
---|
| 303 | foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
|
---|
[315] | 304 | pb_filter_file_inplace($ptr,"$dest/$f",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
|
---|
[238] | 305 | $liste = "$f $liste";
|
---|
[236] | 306 | }
|
---|
| 307 | }
|
---|
[315] | 308 | pb_log(2,"Files ".$liste."have been filtered\n");
|
---|
[236] | 309 |
|
---|
[265] | 310 | # Prepare the dest directory for archive
|
---|
[315] | 311 | if (-x "$ENV{'PBROOT'}/$pbpkg/pbinit") {
|
---|
| 312 | pb_filter_file("$ENV{'PBROOT'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$ENV{'PBPROJ'},$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
|
---|
[266] | 313 | chmod 0755,"$ENV{'PBTMP'}/pbinit";
|
---|
[315] | 314 | pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBROOT'}/$pbpkg/pbinit");
|
---|
[265] | 315 | }
|
---|
| 316 |
|
---|
[18] | 317 | # Archive dest dir
|
---|
[69] | 318 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
[25] | 319 | # Possibility to look at PBSRC to guess more the filename
|
---|
[94] | 320 | pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
|
---|
[315] | 321 | pb_log(2,"Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n");
|
---|
[83] | 322 |
|
---|
[314] | 323 | # Keep track of what is generated by default
|
---|
| 324 | open(LAST,"> $ENV{'PBDESTDIR'}/pbrc") || die "Unable to create $ENV{'PBDESTDIR'}/pbrc";
|
---|
| 325 | #print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n";
|
---|
| 326 | # Why not use pbproj ?
|
---|
| 327 | print LAST "pbroot $ENV{'PBPROJ'} = $ENV{'PBROOT'}\n";
|
---|
[83] | 328 | close(LAST);
|
---|
| 329 |
|
---|
| 330 | # Keep track of per package version
|
---|
[314] | 331 | my ($pkg) = pb_conf_read_if("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[83] | 332 | $pkg = { } if (not defined $pkg);
|
---|
[88] | 333 | if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) {
|
---|
| 334 | $pkg->{$pbpkg} = "$pbver-$pbtag";
|
---|
[83] | 335 | }
|
---|
| 336 |
|
---|
[315] | 337 | pb_log(2,"DEBUG pkg: ".Dumper($pkg)."\n");
|
---|
[83] | 338 | open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
|
---|
[88] | 339 | foreach my $p (keys %$pkg) {
|
---|
| 340 | print PKG "pbpkg $p = $pkg->{$p}\n";
|
---|
[83] | 341 | }
|
---|
| 342 | close(PKG);
|
---|
[288] | 343 |
|
---|
| 344 | # Final cleanup
|
---|
| 345 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 346 | }
|
---|
[77] | 347 | }
|
---|
[22] | 348 |
|
---|
[77] | 349 | sub pb_build2pkg {
|
---|
| 350 |
|
---|
[22] | 351 | # Get list of packages to build
|
---|
[112] | 352 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
[22] | 353 | @pkgs = @$ptr;
|
---|
| 354 |
|
---|
| 355 | # Get the running distro to build on
|
---|
[99] | 356 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
[315] | 357 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
|
---|
[22] | 358 |
|
---|
[83] | 359 | # Get content saved in cms2build
|
---|
[89] | 360 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[83] | 361 | $pkg = { } if (not defined $pkg);
|
---|
| 362 |
|
---|
[320] | 363 | # declare packager (via env var in VM/VE
|
---|
| 364 | my $pbpackager;
|
---|
| 365 | if (not defined $ENV{'PBPACKAGER'}) {
|
---|
| 366 | my ($tmp) = pb_conf_get("pbpackager");
|
---|
| 367 | $pbpackager = $tmp->{$ENV{'PBPROJ'}};
|
---|
| 368 | } else {
|
---|
| 369 | $pbpackager = $ENV{'PBPACKAGER'};
|
---|
| 370 | }
|
---|
[174] | 371 |
|
---|
[25] | 372 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
[126] | 373 | my $made = ""; # pkgs made during build
|
---|
[27] | 374 | foreach my $pbpkg (@pkgs) {
|
---|
[88] | 375 | my $vertag = $pkg->{$pbpkg};
|
---|
[77] | 376 | # get the version of the current package - maybe different
|
---|
| 377 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 378 |
|
---|
[27] | 379 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[315] | 380 | pb_log(2,"Source file: $src\n");
|
---|
[25] | 381 |
|
---|
[315] | 382 | pb_log(2,"Working directory: $ENV{'PBBUILDDIR'}\n");
|
---|
[25] | 383 | if ($dtype eq "rpm") {
|
---|
| 384 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
[28] | 385 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
[96] | 386 | 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] | 387 | }
|
---|
[25] | 388 | }
|
---|
| 389 |
|
---|
[315] | 390 | # Remove in case a previous link/file was there
|
---|
[301] | 391 | unlink "$ENV{'PBBUILDDIR'}/SOURCES/".basename($src);
|
---|
[188] | 392 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
[25] | 393 | # We need to first extract the spec file
|
---|
[28] | 394 | my @specfile;
|
---|
[77] | 395 | @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
|
---|
[25] | 396 |
|
---|
[315] | 397 | pb_log(2,"specfile: ".Dumper(\@specfile)."\n");
|
---|
[25] | 398 | # set LANGUAGE to check for correct log messages
|
---|
| 399 | $ENV{'LANGUAGE'}="C";
|
---|
[28] | 400 | foreach my $f (@specfile) {
|
---|
| 401 | if ($f =~ /\.spec$/) {
|
---|
[291] | 402 | pb_system("rpmbuild --define \'packager $pbpackager\' --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
|
---|
[28] | 403 | last;
|
---|
| 404 | }
|
---|
| 405 | }
|
---|
[136] | 406 | $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
|
---|
[149] | 407 | if (-f "/usr/bin/rpmlint") {
|
---|
| 408 | pb_system("rpmlint $made","Checking validity of rpms with rpmlint");
|
---|
[150] | 409 | }
|
---|
[118] | 410 | } elsif ($dtype eq "deb") {
|
---|
[149] | 411 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
[274] | 412 | pb_system("tar xfz $src","Extracting sources");
|
---|
[149] | 413 |
|
---|
| 414 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
[310] | 415 | pb_rm_rf("debian");
|
---|
[149] | 416 | symlink "pbconf/$ddir-$dver","debian" || die "Unable to symlink to pbconf/$ddir-$dver";
|
---|
[199] | 417 | chmod 0755,"debian/rules";
|
---|
[149] | 418 | pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
|
---|
[136] | 419 | $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
|
---|
[315] | 420 | if (-f "/usr/bin/lintian") {
|
---|
| 421 | pb_system("lintian $made","Checking validity of debs with lintian");
|
---|
| 422 | }
|
---|
[87] | 423 | } elsif ($dtype eq "ebuild") {
|
---|
[149] | 424 | my @ebuildfile;
|
---|
| 425 | # For gentoo we need to take pb as subsystem name
|
---|
[295] | 426 | # We put every apps here under sys-apps. hope it's correct
|
---|
| 427 | # We use pb's home dir in order o have a single OVERLAY line
|
---|
| 428 | my $tmpd = "$ENV{'HOME'}/portage/pb/sys-apps/$pbpkg";
|
---|
| 429 | pb_mkdir_p($tmpd) if (! -d "$tmpd");
|
---|
| 430 | pb_mkdir_p("$ENV{'HOME'}/portage/distfiles") if (! -d "$ENV{'HOME'}/portage/distfiles");
|
---|
[149] | 431 |
|
---|
[295] | 432 | # We need to first extract the ebuild file
|
---|
| 433 | @ebuildfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$tmpd");
|
---|
[149] | 434 |
|
---|
| 435 | # Prepare the build env for gentoo
|
---|
| 436 | my $found = 0;
|
---|
[295] | 437 | my $pbbd = $ENV{'HOME'};
|
---|
[150] | 438 | $pbbd =~ s|/|\\/|g;
|
---|
[295] | 439 | if (-r "/etc/make.conf") {
|
---|
| 440 | open(MAKE,"/etc/make.conf");
|
---|
| 441 | while (<MAKE>) {
|
---|
| 442 | $found = 1 if (/$pbbd\/portage/);
|
---|
| 443 | }
|
---|
| 444 | close(MAKE);
|
---|
[149] | 445 | }
|
---|
| 446 | if ($found == 0) {
|
---|
[295] | 447 | pb_system("sudo sh -c 'echo PORTDIR_OVERLAY=\"$ENV{'HOME'}/portage\" >> /etc/make.conf'");
|
---|
[149] | 448 | }
|
---|
[295] | 449 | #$found = 0;
|
---|
| 450 | #if (-r "/etc/portage/package.keywords") {
|
---|
| 451 | #open(KEYW,"/etc/portage/package.keywords");
|
---|
| 452 | #while (<KEYW>) {
|
---|
| 453 | #$found = 1 if (/portage\/pb/);
|
---|
| 454 | #}
|
---|
| 455 | #close(KEYW);
|
---|
| 456 | #}
|
---|
| 457 | #if ($found == 0) {
|
---|
| 458 | #pb_system("sudo sh -c \"echo portage/pb >> /etc/portage/package.keywords\"");
|
---|
| 459 | #}
|
---|
[149] | 460 |
|
---|
| 461 | # Build
|
---|
| 462 | foreach my $f (@ebuildfile) {
|
---|
| 463 | if ($f =~ /\.ebuild$/) {
|
---|
[295] | 464 | move($f,"$tmpd/$pbpkg-$pbver.ebuild");
|
---|
| 465 | pb_system("cd $tmpd ; ebuild $pbpkg-$pbver.ebuild clean ; ebuild $pbpkg-$pbver.ebuild digest ; ebuild $pbpkg-$pbver.ebuild package");
|
---|
| 466 | # Now move it where pb expects it
|
---|
| 467 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
|
---|
| 468 | move("$tmpd/$pbpkg-$pbver.ebuild","$ENV{'PBBUILDDIR'}/portage/pb/sys-apps/$pbpkg");
|
---|
[149] | 469 | }
|
---|
| 470 | }
|
---|
| 471 |
|
---|
[295] | 472 | $made="$made portage/pb/sys-apps/$pbpkg/$pbpkg-$pbver.ebuild";
|
---|
[118] | 473 | } elsif ($dtype eq "slackware") {
|
---|
[136] | 474 | $made="$made build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
|
---|
[118] | 475 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
|
---|
[87] | 476 | } else {
|
---|
[118] | 477 | die "Unknown dtype format $dtype";
|
---|
[87] | 478 | }
|
---|
| 479 | }
|
---|
[118] | 480 | # Keep track of what is generated so that we can get them back from VMs
|
---|
[129] | 481 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[118] | 482 | print KEEP "$made\n";
|
---|
| 483 | close(KEEP);
|
---|
[87] | 484 | }
|
---|
| 485 |
|
---|
[88] | 486 | sub pb_build2ssh {
|
---|
[320] | 487 | pb_send2target("Sources");
|
---|
[90] | 488 | }
|
---|
[87] | 489 |
|
---|
[90] | 490 | sub pb_pkg2ssh {
|
---|
[320] | 491 | pb_send2target("Packages");
|
---|
[90] | 492 | }
|
---|
| 493 |
|
---|
[108] | 494 | # By default deliver to the the public site hosting the
|
---|
[320] | 495 | # ftp structure (or whatever) or a VM/VE
|
---|
| 496 | sub pb_send2target {
|
---|
[90] | 497 |
|
---|
| 498 | my $cmt = shift;
|
---|
[320] | 499 | my $v = shift || undef;
|
---|
[142] | 500 | my $vmexist = shift || 0; # 0 is FALSE
|
---|
[200] | 501 | my $vmpid = shift || 0; # 0 is FALSE
|
---|
[320] | 502 |
|
---|
| 503 | my $host = "sshhost";
|
---|
| 504 | my $login = "sshlogin";
|
---|
| 505 | my $dir = "sshdir";
|
---|
| 506 | my $port = "sshport";
|
---|
| 507 | my $tmout = "sshtmout";
|
---|
| 508 | my $path = "sshpath";
|
---|
| 509 | my $conf = "sshconf";
|
---|
| 510 | my $rebuild = "sshrebuild";
|
---|
| 511 | if ($cmt eq "vm") {
|
---|
| 512 | $login = "vmlogin";
|
---|
[322] | 513 | $dir = "pbdefdir";
|
---|
[320] | 514 | $tmout = "vmtmout";
|
---|
| 515 | $rebuild = "vmrebuild";
|
---|
| 516 | # Specific VM
|
---|
| 517 | $host = "vmhost";
|
---|
| 518 | $port = "vmport";
|
---|
| 519 | } elsif ($cmt eq "ve") {
|
---|
| 520 | $login = "velogin";
|
---|
[322] | 521 | $dir = "pbdefdir";
|
---|
[320] | 522 | $tmout = "vetmout";
|
---|
| 523 | # Specific VE
|
---|
| 524 | $path = "vepath";
|
---|
| 525 | $conf = "veconf";
|
---|
| 526 | $rebuild = "verebuild";
|
---|
| 527 | }
|
---|
[158] | 528 | my $cmd = "";
|
---|
[90] | 529 |
|
---|
[87] | 530 | # Get list of packages to build
|
---|
[112] | 531 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
[87] | 532 | @pkgs = @$ptr;
|
---|
| 533 |
|
---|
[136] | 534 | # Get the running distro to consider
|
---|
[320] | 535 | my ($odir,$over,$oarch) = (undef, undef);
|
---|
| 536 | if (defined $v) {
|
---|
| 537 | ($odir,$over,$oarch) = split(/-/,$v);
|
---|
[118] | 538 | }
|
---|
| 539 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
|
---|
[315] | 540 | pb_log(2,"DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n");
|
---|
[87] | 541 |
|
---|
| 542 | # Get content saved in cms2build
|
---|
[89] | 543 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[87] | 544 | $pkg = { } if (not defined $pkg);
|
---|
| 545 |
|
---|
[118] | 546 | my $src = "";
|
---|
[87] | 547 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
| 548 | foreach my $pbpkg (@pkgs) {
|
---|
[88] | 549 | my $vertag = $pkg->{$pbpkg};
|
---|
[87] | 550 | # get the version of the current package - maybe different
|
---|
| 551 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 552 |
|
---|
[320] | 553 | if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
[158] | 554 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[166] | 555 | if ($cmd eq "") {
|
---|
| 556 | $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
| 557 | } else {
|
---|
| 558 | $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
| 559 | }
|
---|
[118] | 560 | }
|
---|
| 561 | }
|
---|
[320] | 562 | if (($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
| 563 | $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}";
|
---|
[142] | 564 | } elsif ($cmt eq "Script") {
|
---|
| 565 | $src="$src $ENV{'PBDESTDIR'}/pbscript";
|
---|
[118] | 566 | } elsif ($cmt eq "Packages") {
|
---|
| 567 | # Get package list from file made during build2pkg
|
---|
[129] | 568 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[126] | 569 | $src = <KEEP>;
|
---|
[118] | 570 | chomp($src);
|
---|
| 571 | close(KEEP);
|
---|
| 572 | if ($dtype eq "rpm") {
|
---|
| 573 | # Also make a pbscript to generate yum/urpmi bases
|
---|
[108] | 574 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
|
---|
[118] | 575 | } elsif ($dtype eq "deb") {
|
---|
| 576 | # Also make a pbscript to generate apt bases
|
---|
| 577 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
|
---|
[90] | 578 | }
|
---|
[87] | 579 | }
|
---|
[320] | 580 | # Remove potential leading spaces (cause problem with basename)
|
---|
[132] | 581 | $src =~ s/^ *//;
|
---|
[129] | 582 | my $basesrc = "";
|
---|
[131] | 583 | foreach my $i (split(/ +/,$src)) {
|
---|
| 584 | $basesrc .= " ".basename($i);
|
---|
[130] | 585 | }
|
---|
[118] | 586 |
|
---|
[320] | 587 | pb_log(0,"Sources handled ($cmt): $src\n");
|
---|
| 588 | my ($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf) = pb_conf_get($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf);
|
---|
| 589 | pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf))."\n");
|
---|
| 590 | # Not mandatory
|
---|
| 591 | my ($testver) = pb_conf_get_if("testver");
|
---|
| 592 |
|
---|
| 593 | my $mac;
|
---|
| 594 | # Useless for VE
|
---|
| 595 | if ($cmt ne "ve") {
|
---|
| 596 | $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
|
---|
| 597 | # Overwrite account value if passed as parameter
|
---|
| 598 | $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[108] | 601 | my $tdir;
|
---|
[136] | 602 | my $bdir;
|
---|
[142] | 603 | if (($cmt eq "Sources") || ($cmt eq "Script")) {
|
---|
[108] | 604 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
|
---|
[320] | 605 | } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
| 606 | $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
|
---|
| 607 | $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
|
---|
[136] | 608 | # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
|
---|
| 609 | $bdir =~ s|\$ENV.+\}/||;
|
---|
[90] | 610 | } elsif ($cmt eq "Packages") {
|
---|
[108] | 611 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
|
---|
[320] | 612 | if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} eq "true")) {
|
---|
[289] | 613 | # This is a test pkg => target dir is under test
|
---|
| 614 | $tdir .= "/test";
|
---|
[291] | 615 | }
|
---|
[90] | 616 | } else {
|
---|
| 617 | return;
|
---|
[22] | 618 | }
|
---|
[239] | 619 |
|
---|
[320] | 620 | # Useless for VE
|
---|
| 621 | my $nport;
|
---|
| 622 | if ($cmt ne "ve") {
|
---|
| 623 | $nport = $sshport->{$ENV{'PBPROJ'}};
|
---|
| 624 | $nport = "$pbport" if (defined $pbport);
|
---|
| 625 | }
|
---|
| 626 |
|
---|
[136] | 627 | # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
|
---|
[132] | 628 | $tdir =~ s|\$ENV.+\}/||;
|
---|
| 629 |
|
---|
[320] | 630 | my $tm = $vtmout->{$ENV{'PBPROJ'}};
|
---|
| 631 |
|
---|
| 632 | # ssh communication if not VE
|
---|
| 633 | my ($shcmd,$cpcmd,$cptarget,$cp2target);
|
---|
| 634 | if ($cmt ne "ve") {
|
---|
| 635 | $shcmd = "ssh -q -p $nport $mac";
|
---|
| 636 | $cpcmd = "scp -p -P $nport";
|
---|
| 637 | $cptarget = "$mac:$tdir";
|
---|
| 638 | $cp2target = "$mac:$bdir";
|
---|
| 639 | } else {
|
---|
| 640 | my $tp = $vepath->{$ENV{'PBPROJ'}};
|
---|
| 641 | $shcmd = "sudo chroot $tp/$v /bin/su - $sshlogin->{$ENV{'PBPROJ'}} -c ";
|
---|
| 642 | $cpcmd = "cp -a ";
|
---|
| 643 | $cptarget = "$tp/$tdir";
|
---|
| 644 | $cp2target = "$tp/$bdir";
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | 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");
|
---|
| 648 | pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
|
---|
| 649 | # For VE we need to change the owner manually - To be tested if needed
|
---|
| 650 | #if ($cmt eq "ve") {
|
---|
| 651 | #pb_system("cd $cptarget ; sudo chown -R $sshlogin->{$ENV{'PBPROJ'}} .","$cmt chown in $cptarget to $sshlogin->{$ENV{'PBPROJ'}}");
|
---|
| 652 | #}
|
---|
| 653 | pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $cptarget if needed");
|
---|
| 654 | if (($cmt eq "vm") || ($cmt eq "ve")) {
|
---|
[128] | 655 | # Get back info on pkg produced, compute their name and get them from the VM
|
---|
[320] | 656 | pb_system("$cpcmd $cp2target/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
|
---|
[129] | 657 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[118] | 658 | my $src = <KEEP>;
|
---|
| 659 | chomp($src);
|
---|
| 660 | close(KEEP);
|
---|
[131] | 661 | $src =~ s/^ *//;
|
---|
[136] | 662 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
|
---|
[320] | 663 | # Change pgben to make the next send2target happy
|
---|
[143] | 664 | my $made = "";
|
---|
[139] | 665 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[136] | 666 | foreach my $p (split(/ +/,$src)) {
|
---|
[139] | 667 | my $j = basename($p);
|
---|
[320] | 668 | pb_system("$cpcmd $cp2target/\'$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $cp2target");
|
---|
[144] | 669 | $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
|
---|
[136] | 670 | }
|
---|
[143] | 671 | print KEEP "$made\n";
|
---|
[139] | 672 | close(KEEP);
|
---|
[320] | 673 | pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
|
---|
| 674 | pb_send2target("Packages","$odir"."_"."$over");
|
---|
| 675 | if ((! $vmexist) && ($cmt eq "vm")) {
|
---|
| 676 | 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] | 677 | }
|
---|
[141] | 678 | pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
|
---|
[108] | 679 | }
|
---|
[9] | 680 | }
|
---|
[16] | 681 |
|
---|
[320] | 682 | sub pb_script2v {
|
---|
[142] | 683 | my $pbscript=shift;
|
---|
[320] | 684 | my $vtype=shift;
|
---|
[141] | 685 |
|
---|
| 686 | # Prepare the script to be executed on the VM
|
---|
| 687 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
[142] | 688 | if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
|
---|
| 689 | copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 690 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
| 691 | }
|
---|
[141] | 692 |
|
---|
[320] | 693 | my ($vm,$all) = pb_get_v($vtype);
|
---|
| 694 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
[142] | 695 |
|
---|
[141] | 696 | foreach my $v (@$vm) {
|
---|
[320] | 697 | # Launch the VM/VE
|
---|
| 698 | if ($vtype eq "vm") {
|
---|
| 699 | ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
[141] | 700 |
|
---|
[320] | 701 | # Skip that VM if something went wrong
|
---|
| 702 | next if (($vmpid == 0) && ($vmexist ==0));
|
---|
| 703 | }
|
---|
[274] | 704 |
|
---|
[142] | 705 | # Gather all required files to send them to the VM
|
---|
[320] | 706 | # and launch the build through pbscript
|
---|
| 707 | pb_send2target("Script","$v",$vmexist,$vmpid);
|
---|
[169] | 708 |
|
---|
[142] | 709 | }
|
---|
| 710 | }
|
---|
| 711 |
|
---|
[320] | 712 | sub pb_launchv {
|
---|
| 713 | my $vtype = shift;
|
---|
| 714 | my $v = shift;
|
---|
| 715 | my $create = shift || 0; # By default do not create a VM
|
---|
[310] | 716 |
|
---|
[320] | 717 | die "No VM/VE defined, unable to launch" if (not defined $v);
|
---|
| 718 | # Keep only the first VM in case many were given
|
---|
| 719 | $v =~ s/,.*//;
|
---|
[310] | 720 |
|
---|
[320] | 721 | # Which is our local arch ? (standardize on i386 for those platforms)
|
---|
| 722 | my $arch = `uname -m`;
|
---|
| 723 | chomp($arch);
|
---|
| 724 | $arch =~ s/i.86/i386/;
|
---|
[310] | 725 |
|
---|
[320] | 726 | # Launch the VMs/VEs
|
---|
| 727 | if ($vtype eq "vm") {
|
---|
| 728 | die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
|
---|
[310] | 729 |
|
---|
[320] | 730 | my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
|
---|
| 731 |
|
---|
| 732 | my $vmtype = $ptr->{$ENV{'PBPROJ'}};
|
---|
| 733 | if (not defined $ENV{'PBVMOPT'}) {
|
---|
| 734 | $ENV{'PBVMOPT'} = "";
|
---|
[310] | 735 | }
|
---|
[320] | 736 | if (defined $vmopt->{$ENV{'PBPROJ'}}) {
|
---|
| 737 | $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
|
---|
| 738 | }
|
---|
| 739 | my $nport = $vmport->{$ENV{'PBPROJ'}};
|
---|
| 740 | $nport = "$pbport" if (defined $pbport);
|
---|
| 741 |
|
---|
| 742 | my $cmd;
|
---|
| 743 | my $vmcmd; # has to be used for pb_check_ps
|
---|
| 744 | my $vmm; # has to be used for pb_check_ps
|
---|
| 745 | if ($vmtype eq "qemu") {
|
---|
| 746 | my $qemucmd32;
|
---|
| 747 | my $qemucmd64;
|
---|
| 748 | if ($arch eq "x86_64") {
|
---|
| 749 | $qemucmd32 = "/usr/bin/qemu-system-i386";
|
---|
| 750 | $qemucmd64 = "/usr/bin/qemu";
|
---|
| 751 | } else {
|
---|
| 752 | $qemucmd32 = "/usr/bin/qemu";
|
---|
| 753 | $qemucmd64 = "/usr/bin/qemu-system-x86_64";
|
---|
| 754 | }
|
---|
| 755 | if ($v =~ /x86_64/) {
|
---|
| 756 | $vmcmd = "$qemucmd64 -no-kqemu";
|
---|
| 757 | } else {
|
---|
| 758 | $vmcmd = "$qemucmd32";
|
---|
| 759 | }
|
---|
| 760 | $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
|
---|
| 761 | if ($create != 0) {
|
---|
| 762 | $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
|
---|
| 763 | }
|
---|
| 764 | $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
|
---|
| 765 | } elsif ($vmtype eq "xen") {
|
---|
| 766 | } elsif ($vmtype eq "vmware") {
|
---|
[310] | 767 | } else {
|
---|
[320] | 768 | die "VM of type $vmtype not supported. Report to the dev team";
|
---|
[310] | 769 | }
|
---|
[320] | 770 | my ($tmpcmd,$void) = split(/ +/,$cmd);
|
---|
| 771 | my $vmexist = pb_check_ps($tmpcmd,$vmm);
|
---|
| 772 | my $vmpid = 0;
|
---|
| 773 | if (! $vmexist) {
|
---|
| 774 | if ($create != 0) {
|
---|
| 775 | if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
|
---|
| 776 | pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
|
---|
| 777 | } elsif ($vmtype eq "vmware") {
|
---|
| 778 | } else {
|
---|
| 779 | }
|
---|
| 780 | }
|
---|
| 781 | if (! -f "$vmm") {
|
---|
| 782 | pb_log(0,"Unable to find VM $vmm\n");
|
---|
| 783 | } else {
|
---|
| 784 | pb_system("$cmd &","Launching the VM $vmm");
|
---|
| 785 | pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $v to come up");
|
---|
| 786 | $vmpid = pb_check_ps($tmpcmd,$vmm);
|
---|
| 787 | }
|
---|
[310] | 788 | } else {
|
---|
[320] | 789 | pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
|
---|
[310] | 790 | }
|
---|
[320] | 791 | return($vmexist,$vmpid);
|
---|
| 792 | # VE here
|
---|
[310] | 793 | } else {
|
---|
[320] | 794 | # Get VE context
|
---|
| 795 | my ($ptr,$vepath,$vetmout,$verebuild,$veconf) = pb_conf_get("vetype","vepath","vetmout","verebuild","veconf");
|
---|
| 796 | my $vetype = $ptr->{$ENV{'PBPROJ'}};
|
---|
[310] | 797 |
|
---|
[320] | 798 | # Get distro context
|
---|
| 799 | my ($name,$ver,$darch) = split(/-/,$v);
|
---|
| 800 | chomp($darch);
|
---|
| 801 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
|
---|
[142] | 802 |
|
---|
[320] | 803 | if ($vetype eq "chroot") {
|
---|
| 804 | # Architecture consistency
|
---|
| 805 | if ($arch ne $darch) {
|
---|
| 806 | die "Unable to launch a VE of architecture $darch on a $arch platform" if (not (($darch eq "x86_64") && ($arch =~ /i?86/)));
|
---|
| 807 | }
|
---|
[142] | 808 |
|
---|
[320] | 809 | if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($force == 1)) {
|
---|
| 810 | # We have to rebuild the chroot
|
---|
| 811 | if ($dtype eq "rpm") {
|
---|
| 812 | pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
|
---|
| 813 | # Once setup we need to install some packages, the pb account, ...
|
---|
| 814 | pb_system("sudo /usr/sbin/mock --install --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
|
---|
| 815 | #pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" --basedir=\"$vepath->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
|
---|
| 816 | } elsif ($dtype eq "deb") {
|
---|
| 817 | pb_system("","Creating the pbuilder VE");
|
---|
| 818 | } elsif ($dtype eq "ebuild") {
|
---|
| 819 | die "Please teach the dev team how to build gentoo chroot";
|
---|
| 820 | } else {
|
---|
| 821 | die "Unknown distribution type $dtype. Report to dev team";
|
---|
| 822 | }
|
---|
[310] | 823 | }
|
---|
[320] | 824 | # Nothing more to do for VE. No real launch
|
---|
[274] | 825 | } else {
|
---|
[320] | 826 | die "VE of type $vetype not supported. Report to the dev team";
|
---|
[262] | 827 | }
|
---|
[141] | 828 | }
|
---|
| 829 | }
|
---|
[142] | 830 |
|
---|
[320] | 831 | sub pb_build2v {
|
---|
[118] | 832 |
|
---|
[320] | 833 | my $vtype = shift;
|
---|
[142] | 834 |
|
---|
[320] | 835 | # Prepare the script to be executed on the VM/VE
|
---|
| 836 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
| 837 | my ($ntp) = pb_conf_get($vtype."ntp");
|
---|
| 838 | my $vntp = $ntp->{$ENV{'PBPROJ'}};
|
---|
[118] | 839 |
|
---|
[320] | 840 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 841 | print SCRIPT "#!/bin/bash\n";
|
---|
| 842 | print SCRIPT "echo ... Execution needed\n";
|
---|
| 843 | print SCRIPT "# This is in directory delivery\n";
|
---|
| 844 | print SCRIPT "# Setup the variables required for building\n";
|
---|
| 845 | print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
|
---|
| 846 | print SCRIPT "# Preparation for pb\n";
|
---|
| 847 | print SCRIPT "mv .pbrc \$HOME\n";
|
---|
| 848 | print SCRIPT "cd ..\n";
|
---|
| 849 | # Force new date to be in the future compared to the date of the tar file by adding 1 minute
|
---|
| 850 | my @date=pb_get_date();
|
---|
| 851 | $date[1]++;
|
---|
| 852 | my $upddate = strftime("%m%d%H%M%Y", @date);
|
---|
| 853 | print SCRIPT "echo Setting up date on $vntp...\n";
|
---|
| 854 | # Or use ntpdate if available TBC
|
---|
| 855 | print SCRIPT "sudo date $upddate\n";
|
---|
| 856 | # This exports avoids pb_env_init to deal with PBCONF stuff
|
---|
| 857 | print SCRIPT "export PBCONF=/tmp\n";
|
---|
| 858 | print SCRIPT "export PBVER=$ENV{'PBVER'}\n";
|
---|
| 859 | print SCRIPT "export PBTAG=$ENV{'PBTAG'}\n";
|
---|
| 860 | print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
|
---|
| 861 | print SCRIPT "# Build\n";
|
---|
| 862 | # Get list of packages to build
|
---|
| 863 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
| 864 | @pkgs = @$ptr;
|
---|
| 865 | my $p = join(' ',@pkgs) if (@pkgs);
|
---|
| 866 | print SCRIPT "echo Building packages on $vtype...\n";
|
---|
| 867 | print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
|
---|
| 868 | close(SCRIPT);
|
---|
| 869 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
| 870 |
|
---|
| 871 | my ($v,$all) = pb_get_v($vtype);
|
---|
| 872 |
|
---|
| 873 | # Send tar files when we do a global generation
|
---|
| 874 | pb_build2ssh() if ($all == 1);
|
---|
| 875 |
|
---|
| 876 | my ($vmexist,$vmpid) = (undef,undef);
|
---|
| 877 |
|
---|
| 878 | foreach my $v (@$v) {
|
---|
| 879 | if ($vtype eq "vm") {
|
---|
[142] | 880 | # Launch the VM
|
---|
[320] | 881 | my ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
|
---|
[118] | 882 |
|
---|
[274] | 883 | # Skip that VM if it something went wrong
|
---|
| 884 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
[118] | 885 | }
|
---|
[320] | 886 | # Gather all required files to send them to the VM/VE
|
---|
| 887 | # and launch the build thourgh pbscript
|
---|
| 888 | pb_send2target($vtype,"$v",$vmexist,$vmpid);
|
---|
[105] | 889 | }
|
---|
[320] | 890 | }
|
---|
[105] | 891 |
|
---|
[262] | 892 |
|
---|
[199] | 893 | sub pb_newver {
|
---|
| 894 |
|
---|
[204] | 895 | die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
|
---|
[315] | 896 | my $scheme=pb_cms_init($ENV{'PBPROJ'});
|
---|
| 897 | if ($scheme ne "svn") {
|
---|
[199] | 898 | die "Only SVN is supported at the moment";
|
---|
| 899 | }
|
---|
[315] | 900 | my $res = pb_cms_isdiff($scheme);
|
---|
[199] | 901 | die "You need to have no differences before creating a new version" if ($res != 0);
|
---|
[315] | 902 | my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBROOT'},"URL:");
|
---|
[204] | 903 | my $newurl = dirname($cmsurl)."/$newver";
|
---|
[315] | 904 | pb_cms_copy($scheme,$cmsurl,$newurl);
|
---|
| 905 | pb_cms_checkout($scheme,$newurl,"$ENV{'PBROOT'}/../$newver");
|
---|
[208] | 906 | my $oldver=basename($cmsurl);
|
---|
[211] | 907 | open(FILE,"$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb";
|
---|
| 908 | open(OUT,"> $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new";
|
---|
[208] | 909 | while(<FILE>) {
|
---|
[209] | 910 | s/projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
|
---|
[211] | 911 | print OUT $_;
|
---|
[208] | 912 | }
|
---|
| 913 | close(FILE);
|
---|
[211] | 914 | close(OUT);
|
---|
| 915 | rename("$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb");
|
---|
[315] | 916 | pb_cms_checkin($scheme,"$ENV{'PBROOT'}/../$newver");
|
---|
[199] | 917 | }
|
---|
| 918 |
|
---|
[293] | 919 | #
|
---|
[320] | 920 | # Return the list of VMs/VEs we are working on
|
---|
[105] | 921 | # $all is a flag to know if we return all of them
|
---|
| 922 | # or only some (if all we publish also tar files in addition to pkgs
|
---|
| 923 | #
|
---|
[320] | 924 | sub pb_get_v {
|
---|
[91] | 925 |
|
---|
[320] | 926 | my $vtype = shift;
|
---|
| 927 | my @v;
|
---|
[105] | 928 | my $all = 0;
|
---|
[320] | 929 | my $vlist;
|
---|
| 930 | my $pbv = 'PBV';
|
---|
[91] | 931 |
|
---|
[320] | 932 | if ($vtype eq "vm") {
|
---|
| 933 | $vlist = "vmlist";
|
---|
| 934 | } elsif ($vtype eq "ve") {
|
---|
| 935 | $vlist = "velist";
|
---|
| 936 | }
|
---|
| 937 | # Get VM/VE list
|
---|
| 938 | if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
|
---|
| 939 | my ($ptr) = pb_conf_get($vlist);
|
---|
| 940 | $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
|
---|
[105] | 941 | $all = 1;
|
---|
[91] | 942 | }
|
---|
[320] | 943 | pb_log(2,"$vtype: $ENV{$pbv}\n");
|
---|
| 944 | @v = split(/,/,$ENV{$pbv});
|
---|
| 945 | return(\@v,$all);
|
---|
[91] | 946 | }
|
---|
| 947 |
|
---|
[320] | 948 | sub pb_setup_v {
|
---|
| 949 | # Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
|
---|
| 950 | # Needs to use root account to connect to the VM/VE
|
---|
| 951 |
|
---|
| 952 | # pb will take your local public SSH key to access
|
---|
| 953 | # the pb account in the VM later on
|
---|
| 954 |
|
---|
| 955 | my $vtype = shift;
|
---|
| 956 |
|
---|
| 957 | my $file = "$ENV{'HOME'}/.ssh/id_dsa.pub";
|
---|
| 958 | die "Unable to find your public ssh key as $file";
|
---|
| 959 |
|
---|
| 960 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 961 | print SCRIPT << 'EOF';
|
---|
| 962 | #!/usr/bin/perl -w
|
---|
| 963 |
|
---|
| 964 | $file="/etc/passwd";
|
---|
| 965 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 966 | my $found = 0;
|
---|
| 967 | while (<PBFILE>) {
|
---|
| 968 | $found = 1 if (/^pb:/);
|
---|
| 969 | }
|
---|
| 970 | close(PBFILE);
|
---|
| 971 |
|
---|
| 972 | if ( $found == 0 ) {
|
---|
| 973 | if ( ! -d "/home" ) {
|
---|
| 974 | mkdir "/home";
|
---|
| 975 | }
|
---|
| 976 | system "groupadd pb";
|
---|
| 977 | system "useradd pb -g pb -m -d /home/pb";
|
---|
| 978 | }
|
---|
| 979 |
|
---|
| 980 | # For root
|
---|
| 981 | mkdir ".ssh",0700;
|
---|
| 982 | system 'cp /tmp/pbkey .ssh/authorized_keys';
|
---|
| 983 | chmod 0600,".ssh/authorized_keys";
|
---|
| 984 |
|
---|
| 985 | # For pb
|
---|
| 986 | chdir "/home/pb";
|
---|
| 987 | mkdir ".ssh",0700;
|
---|
| 988 | system 'cp /tmp/pbkey .ssh/authorized_keys';
|
---|
| 989 | chmod 0600,".ssh/authorized_keys";
|
---|
| 990 | system 'chown -R pb:pb .ssh';
|
---|
| 991 |
|
---|
| 992 | # No passwd for pb only keys
|
---|
| 993 | $file="/etc/shadow";
|
---|
| 994 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 995 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 996 | while (<PBFILE>) {
|
---|
| 997 | s/^pb:\!\!:/pb:*:/;
|
---|
| 998 | s/^pb:\!:/pb:*:/; #SLES 9 e.g.
|
---|
| 999 | print PBOUT $_;
|
---|
| 1000 | }
|
---|
| 1001 | close(PBFILE);
|
---|
| 1002 | close(PBOUT);
|
---|
| 1003 | rename("$file.new",$file);
|
---|
| 1004 | chmod 0640,$file;
|
---|
| 1005 |
|
---|
| 1006 | # pb has to be added to portage group on gentoo
|
---|
| 1007 | unlink "/tmp/pbkey";
|
---|
| 1008 |
|
---|
| 1009 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
| 1010 | print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
|
---|
| 1011 |
|
---|
| 1012 | # Get and install pb
|
---|
| 1013 | if ( $ddir eq "fedora" ) {
|
---|
| 1014 | system "yum clean all";
|
---|
| 1015 | system "yum update -y";
|
---|
| 1016 | my $arch=`uname -m`;
|
---|
| 1017 | my $opt = "";
|
---|
| 1018 | chomp($arch);
|
---|
| 1019 | if ($arch eq "x86_64") {
|
---|
| 1020 | $opt="--exclude=*.i?86";
|
---|
| 1021 | }
|
---|
| 1022 |
|
---|
| 1023 | system "yum -y $opt install rpm-build wget patch ntp sudo perl-DateManip perl-ExtUtils-MakeMaker";
|
---|
| 1024 | } elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || (($ddir eq "mandrake") && ($dver eq "10.1"))) {
|
---|
| 1025 | # Suppose pkg are installed already
|
---|
| 1026 | system "rpm -e lsb 2>&1 > /dev/null";
|
---|
| 1027 | system "rm -rf DateManip* ; wget http://search.cpan.org/CPAN/authors/id/S/SB/SBECK/Date-Manip-5.46.tar.gz ; tar xvfz Date-Manip-5.46.tar.gz ; cd Date-Manip* ; perl Makefile.PL ; make ; make install ; cd .. ";
|
---|
| 1028 | } elsif ($ddir eq "suse") {
|
---|
| 1029 | # New OpenSuSE
|
---|
| 1030 | 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";
|
---|
| 1031 | } elsif ( $dfam eq "md" ) {
|
---|
| 1032 | system "urpmi.update -a ; urpmi --auto rpm-build wget sudo patch ntp-client perl-DateManip";
|
---|
| 1033 | } elsif ( $dfam eq "du" ) {
|
---|
| 1034 | if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
|
---|
| 1035 | system "apt-get update; apt-get -y install wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libdate-manip-perl";
|
---|
| 1036 | } else {
|
---|
| 1037 | system "apt-get update; apt-get -y install wget patch openssh-server dpkg-dev sudo debian-builder dh-make fakeroot ntpdate rses5-dev libdate-manip-perl";
|
---|
| 1038 | }
|
---|
| 1039 | } elsif ( $dfam eq "gen" ) {
|
---|
| 1040 | system "emerge -u system ; emerge wget sudo ntp DateManip";
|
---|
| 1041 | } else {
|
---|
| 1042 | print "No pkg to install\n";
|
---|
| 1043 | }
|
---|
| 1044 |
|
---|
| 1045 | # Adapt sudoers
|
---|
| 1046 | $file="/etc/sudoers";
|
---|
| 1047 | open(PBFILE,$file) || die "Unable to open $file";
|
---|
| 1048 | open(PBOUT,"> $file.new") || die "Unable to open $file.new";
|
---|
| 1049 | while (<PBFILE>) {
|
---|
| 1050 | next if (/^pb /);
|
---|
| 1051 | s/Defaults[ \t]+requiretty//;
|
---|
| 1052 | print PBOUT $_;
|
---|
| 1053 | }
|
---|
| 1054 | close(PBFILE);
|
---|
| 1055 | print PBOUT "pb ALL=(ALL) NOPASSWD:ALL\n";
|
---|
| 1056 | close(PBOUT);
|
---|
| 1057 | rename("$file.new",$file);
|
---|
| 1058 | chmod 0440,$file;
|
---|
| 1059 |
|
---|
| 1060 | # Suse wants sudoers as 640
|
---|
| 1061 | if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {
|
---|
| 1062 | chmod 0640,$file;
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
| 1065 | # Sync date
|
---|
| 1066 | system "/usr/sbin/ntpdate ntp.pool.org";
|
---|
| 1067 |
|
---|
| 1068 | 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 ..";
|
---|
| 1069 | EOF
|
---|
| 1070 | close(SCRIPT);
|
---|
| 1071 | }
|
---|
| 1072 |
|
---|
[145] | 1073 | # Returns the pid of a running VM command using a specific VM file
|
---|
[142] | 1074 | sub pb_check_ps {
|
---|
| 1075 | my $vmcmd = shift;
|
---|
| 1076 | my $vmm = shift;
|
---|
| 1077 | my $vmexist = 0; # FALSE by default
|
---|
| 1078 |
|
---|
| 1079 | open(PS, "ps auxhww|") || die "Unable to call ps";
|
---|
| 1080 | while (<PS>) {
|
---|
| 1081 | next if (! /$vmcmd/);
|
---|
| 1082 | next if (! /$vmm/);
|
---|
| 1083 | my ($void1, $void2);
|
---|
| 1084 | ($void1, $vmexist, $void2) = split(/ +/);
|
---|
| 1085 | last;
|
---|
| 1086 | }
|
---|
| 1087 | return($vmexist);
|
---|
| 1088 | }
|
---|
| 1089 |
|
---|
| 1090 |
|
---|
[77] | 1091 | sub pb_extract_build_files {
|
---|
[25] | 1092 |
|
---|
| 1093 | my $src=shift;
|
---|
| 1094 | my $dir=shift;
|
---|
[26] | 1095 | my $ddir=shift;
|
---|
[28] | 1096 | my @files;
|
---|
[25] | 1097 |
|
---|
[188] | 1098 | if ($src =~ /tar\.gz$/) {
|
---|
| 1099 | pb_system("tar xfpz $src $dir","Extracting build files");
|
---|
| 1100 | } elsif ($src =~ /tar\.bz2$/) {
|
---|
| 1101 | pb_system("tar xfpj $src $dir","Extracting build files");
|
---|
| 1102 | } else {
|
---|
| 1103 | die "Unknown compression algorithm for $src";
|
---|
| 1104 | }
|
---|
[25] | 1105 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
| 1106 | foreach my $f (readdir(DIR)) {
|
---|
| 1107 | next if ($f =~ /^\./);
|
---|
[26] | 1108 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[315] | 1109 | pb_log(2,"mv $dir/$f $ddir\n");
|
---|
[28] | 1110 | push @files,"$ddir/$f";
|
---|
[25] | 1111 | }
|
---|
| 1112 | closedir(DIR);
|
---|
[26] | 1113 | # Not enough but still a first cleanup
|
---|
[74] | 1114 | pb_rm_rf("$dir");
|
---|
[28] | 1115 | return(@files);
|
---|
[25] | 1116 | }
|
---|
| 1117 |
|
---|
[315] | 1118 | sub pb_list_bfiles {
|
---|
| 1119 |
|
---|
| 1120 | my $dir = shift;
|
---|
| 1121 | my $pbpkg = shift;
|
---|
| 1122 | my $bfiles = shift;
|
---|
| 1123 | my $pkgfiles = shift;
|
---|
| 1124 | my $supfiles = shift;
|
---|
| 1125 |
|
---|
| 1126 | opendir(BDIR,"$dir") || die "Unable to open dir $dir: $!";
|
---|
| 1127 | foreach my $f (readdir(BDIR)) {
|
---|
| 1128 | next if ($f =~ /^\./);
|
---|
| 1129 | $bfiles->{$f} = "$dir/$f";
|
---|
| 1130 | $bfiles->{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 1131 | if (defined $supfiles->{$pbpkg}) {
|
---|
| 1132 | $pkgfiles->{$f} = "$dir/$f" if ($f =~ /$supfiles->{$pbpkg}/);
|
---|
| 1133 | }
|
---|
| 1134 | }
|
---|
| 1135 | closedir(BDIR);
|
---|
| 1136 | }
|
---|
| 1137 |
|
---|
[74] | 1138 | sub pb_syntax {
|
---|
[21] | 1139 |
|
---|
[53] | 1140 | print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
|
---|
| 1141 | print "\n";
|
---|
[313] | 1142 | print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"][-i iso] <action> [<pkg1> ...]\n";
|
---|
[21] | 1143 | print "\n";
|
---|
[310] | 1144 | print "-h: This help file\n";
|
---|
| 1145 | print "-q: Quiet mode\n";
|
---|
| 1146 | print "-t: Test mode (not done yet)\n";
|
---|
| 1147 | print "-v: Verbose mode\n";
|
---|
[21] | 1148 | print "\n";
|
---|
[310] | 1149 | print "-m machine: Name of the Virtual Machines (VM) you want\n";
|
---|
| 1150 | print " to build on (coma separated). All if none precised\n";
|
---|
[320] | 1151 | print " (or use the env variable PBV) \n";
|
---|
[69] | 1152 | print "\n";
|
---|
[310] | 1153 | print "-s script: Name of the script you want\n";
|
---|
| 1154 | print " to execute on the related VMs.\n";
|
---|
[141] | 1155 | print "\n";
|
---|
[310] | 1156 | print "-i iso: Name of the ISO image of the distribution you want\n";
|
---|
| 1157 | print " to install on the related VMs.\n";
|
---|
[288] | 1158 | print "\n";
|
---|
[310] | 1159 | print "-a account: Name of the account to use\n";
|
---|
| 1160 | print " to connect on the related VMs.\n";
|
---|
[152] | 1161 | print "\n";
|
---|
[313] | 1162 | print "-P port: Port number to use\n";
|
---|
[310] | 1163 | print " to connect on the related VMs.\n";
|
---|
[199] | 1164 | print "\n";
|
---|
[310] | 1165 | print "-p project: Name of the project you're working on\n";
|
---|
| 1166 | print " (or use the env variable PBPROJ) \n";
|
---|
[21] | 1167 | print "\n";
|
---|
[310] | 1168 | print "-r pbroot: Path Name of project under the CMS \n";
|
---|
| 1169 | print " (or use the env variable PBROOT) \n";
|
---|
[91] | 1170 | print "\n";
|
---|
[310] | 1171 | print "-V newver: New version of the project to create\n";
|
---|
| 1172 | print " from the current one. \n";
|
---|
[199] | 1173 | print "\n";
|
---|
[21] | 1174 | print "<action> can be:\n";
|
---|
| 1175 | print "\n";
|
---|
[310] | 1176 | print "\tcms2build: Create tar files for the project under your CMS\n";
|
---|
| 1177 | print "\t CMS supported are SVN and CVS\n";
|
---|
| 1178 | print "\t parameters are packages to build\n";
|
---|
| 1179 | print "\t if not using default list\n";
|
---|
[21] | 1180 | print "\n";
|
---|
[310] | 1181 | print "\tbuild2pkg: Create packages for your running distribution \n";
|
---|
[21] | 1182 | print "\n";
|
---|
[310] | 1183 | print "\tcms2pkg: cms2build + build2pkg\n";
|
---|
[169] | 1184 | print "\n";
|
---|
[310] | 1185 | print "\tbuild2ssh: Send the tar files to a SSH host \n";
|
---|
[105] | 1186 | print "\n";
|
---|
[310] | 1187 | print "\tcms2ssh: cms2build + build2ssh\n";
|
---|
[220] | 1188 | print "\n";
|
---|
[310] | 1189 | print "\tpkg2ssh: Send the packages built to a SSH host \n";
|
---|
[105] | 1190 | print "\n";
|
---|
[310] | 1191 | print "\tbuild2vm: Create packages in VMs, launching them if needed\n";
|
---|
| 1192 | print "\t and send those packages to a SSH host once built\n";
|
---|
| 1193 | print "\t VM type supported are QEMU \n";
|
---|
[136] | 1194 | print "\n";
|
---|
[320] | 1195 | print "\tbuild2ve: Create packages in VEs, creating it if needed\n";
|
---|
[310] | 1196 | print "\t and send those packages to a SSH host once built\n";
|
---|
[169] | 1197 | print "\n";
|
---|
[310] | 1198 | print "\tcms2vm: cms2build + build2vm\n";
|
---|
[141] | 1199 | print "\n";
|
---|
[320] | 1200 | print "\tcms2ve: cms2build + build2ve\n";
|
---|
| 1201 | print "\n";
|
---|
[310] | 1202 | print "\tlaunchvm: Launch one virtual machine\n";
|
---|
[142] | 1203 | print "\n";
|
---|
[320] | 1204 | print "\tlaunchve: Launch one virtual environment\n";
|
---|
| 1205 | print "\n";
|
---|
[310] | 1206 | print "\tscript2vm: Launch one virtual machine if needed \n";
|
---|
| 1207 | print "\t and executes a script on it \n";
|
---|
[199] | 1208 | print "\n";
|
---|
[320] | 1209 | print "\tscript2ve: Execute a script in a virtual environment \n";
|
---|
| 1210 | print "\n";
|
---|
[310] | 1211 | print "\tnewvm: Create a new virtual machine\n";
|
---|
[262] | 1212 | print "\n";
|
---|
[320] | 1213 | print "\tnewve: Create a new virtual environment\n";
|
---|
[273] | 1214 | print "\n";
|
---|
[310] | 1215 | print "\tnewver: Create a new version of the project derived \n";
|
---|
| 1216 | print "\t from the current one \n";
|
---|
| 1217 | print "\n";
|
---|
| 1218 | print "\tnewproj: Create a new project and a template set of \n";
|
---|
| 1219 | print "\t configuration files under pbconf \n";
|
---|
| 1220 | print "\n";
|
---|
[21] | 1221 | }
|
---|