[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 AppConfig qw(:argcount :expand);
|
---|
| 17 | use File::Basename;
|
---|
[26] | 18 | use File::Copy;
|
---|
[13] | 19 | use Time::localtime qw(localtime);
|
---|
| 20 | use POSIX qw(strftime);
|
---|
[5] | 21 |
|
---|
[73] | 22 | # Global variables
|
---|
[17] | 23 | use lib qw (lib);
|
---|
[74] | 24 | use ProjectBuilder::Distribution qw (pb_distro_init);
|
---|
| 25 | use ProjectBuilder::Version qw (pb_version_init);
|
---|
[204] | 26 | use ProjectBuilder::Base qw (pb_conf_read pb_conf_get pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout);
|
---|
[5] | 27 |
|
---|
| 28 | my %opts; # CLI Options
|
---|
[9] | 29 | my $action; # action to realize
|
---|
| 30 | my $test = "FALSE";
|
---|
| 31 | my $option = "";
|
---|
| 32 | my @pkgs;
|
---|
[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
|
---|
[16] | 39 | my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
---|
| 40 | my $pbdate = strftime("%Y-%m-%d", @date);
|
---|
[112] | 41 | my $pbdatecvs = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
[108] | 42 | my $debug = 0;
|
---|
[152] | 43 | my $pbaccount; # Login to use to connect to the VM
|
---|
[162] | 44 | my $pbport; # Port to use to connect to the VM
|
---|
[199] | 45 | my $newver; # New version to create
|
---|
[262] | 46 | my $iso; # ISO iage for the VM to create
|
---|
[108] | 47 | my $LOG = \*STDOUT;
|
---|
[5] | 48 |
|
---|
[262] | 49 | getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts);
|
---|
[5] | 50 |
|
---|
[75] | 51 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
[21] | 52 | if (defined $opts{'h'}) {
|
---|
[74] | 53 | pb_syntax();
|
---|
[21] | 54 | exit(0);
|
---|
| 55 | }
|
---|
| 56 | if (defined $opts{'v'}) {
|
---|
| 57 | $debug++;
|
---|
| 58 | }
|
---|
| 59 | if (defined $opts{'q'}) {
|
---|
| 60 | $debug=-1;
|
---|
| 61 | }
|
---|
[22] | 62 | if (defined $opts{'l'}) {
|
---|
| 63 | open(LOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
| 64 | $LOG = *LOG;
|
---|
| 65 | $debug = 0 if ($debug == -1);
|
---|
| 66 | }
|
---|
[9] | 67 | # Handles test option
|
---|
| 68 | if (defined $opts{'t'}) {
|
---|
| 69 | $test = "TRUE";
|
---|
| 70 | # Works only for SVN
|
---|
| 71 | $option = "-r BASE";
|
---|
| 72 | }
|
---|
[5] | 73 |
|
---|
[67] | 74 | # Handle root of the project if defined
|
---|
| 75 | if (defined $opts{'r'}) {
|
---|
| 76 | $ENV{'PBROOT'} = $opts{'r'};
|
---|
| 77 | }
|
---|
[91] | 78 | # Handle virtual machines if any
|
---|
| 79 | if (defined $opts{'m'}) {
|
---|
| 80 | $ENV{'PBVM'} = $opts{'m'};
|
---|
| 81 | }
|
---|
[141] | 82 | if (defined $opts{'s'}) {
|
---|
| 83 | $pbscript = $opts{'s'};
|
---|
| 84 | }
|
---|
[152] | 85 | if (defined $opts{'a'}) {
|
---|
| 86 | $pbaccount = $opts{'a'};
|
---|
| 87 | }
|
---|
[162] | 88 | if (defined $opts{'P'}) {
|
---|
| 89 | $pbport = $opts{'P'};
|
---|
| 90 | }
|
---|
[199] | 91 | if (defined $opts{'V'}) {
|
---|
| 92 | $newver = $opts{'V'};
|
---|
| 93 | }
|
---|
[262] | 94 | if (defined $opts{'i'}) {
|
---|
| 95 | $iso = $opts{'i'};
|
---|
| 96 | }
|
---|
[108] | 97 |
|
---|
| 98 | # Get Action
|
---|
| 99 | $action = shift @ARGV;
|
---|
| 100 | die pb_syntax() if (not defined $action);
|
---|
| 101 |
|
---|
| 102 | my ($pbrc, $filteredfiles, $defpkgdir, $extpkgdir);
|
---|
[273] | 103 | my $pbinit = undef;
|
---|
| 104 | $pbinit = 1 if ($action =~ /^newproj$/);
|
---|
[108] | 105 |
|
---|
[59] | 106 | # Handles project name if any
|
---|
[108] | 107 | # And get global params
|
---|
[59] | 108 | if (defined $opts{'p'}) {
|
---|
[107] | 109 | ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
|
---|
[273] | 110 | = pb_env_init($opts{'p'},$pbinit);
|
---|
[59] | 111 | } else {
|
---|
[107] | 112 | ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
|
---|
[273] | 113 | = pb_env_init(undef,$pbinit);
|
---|
[59] | 114 | }
|
---|
| 115 |
|
---|
[108] | 116 | print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
|
---|
[22] | 117 | print $LOG "Action: $action\n" if ($debug >= 0);
|
---|
[9] | 118 |
|
---|
[91] | 119 | # Keep those project values to store them at the end each time
|
---|
[83] | 120 | my $pbprojtag = $ENV{'PBTAG'};
|
---|
| 121 | my $pbprojver = $ENV{'PBVER'};
|
---|
| 122 |
|
---|
[9] | 123 | # Act depending on action
|
---|
| 124 | if ($action =~ /^cms2build$/) {
|
---|
[77] | 125 | pb_cms2build();
|
---|
| 126 | } elsif ($action =~ /^build2pkg$/) {
|
---|
| 127 | pb_build2pkg();
|
---|
| 128 | } elsif ($action =~ /^cms2pkg$/) {
|
---|
| 129 | pb_cms2build();
|
---|
| 130 | pb_build2pkg();
|
---|
[88] | 131 | } elsif ($action =~ /^build2ssh$/) {
|
---|
| 132 | pb_build2ssh();
|
---|
[220] | 133 | } elsif ($action =~ /^cms2ssh$/) {
|
---|
| 134 | pb_cms2build();
|
---|
| 135 | pb_build2ssh();
|
---|
[88] | 136 | } elsif ($action =~ /^pkg2ssh$/) {
|
---|
| 137 | pb_pkg2ssh();
|
---|
[91] | 138 | } elsif ($action =~ /^build2vm$/) {
|
---|
| 139 | pb_build2vm();
|
---|
| 140 | } elsif ($action =~ /^cms2vm$/) {
|
---|
| 141 | pb_cms2build();
|
---|
| 142 | pb_build2vm();
|
---|
[141] | 143 | } elsif ($action =~ /^launchvm$/) {
|
---|
[262] | 144 | pb_launchvm($ENV{'PBVM'},0);
|
---|
[142] | 145 | } elsif ($action =~ /^script2vm$/) {
|
---|
| 146 | pb_script2vm($pbscript);
|
---|
[199] | 147 | } elsif ($action =~ /^newver$/) {
|
---|
| 148 | pb_newver();
|
---|
[262] | 149 | } elsif ($action =~ /^newvm$/) {
|
---|
| 150 | pb_launchvm($ENV{'PBVM'},1);
|
---|
[273] | 151 | } elsif ($action =~ /^newproj$/) {
|
---|
| 152 | # Nothing to do - already done in pb_env_init
|
---|
[106] | 153 | } elsif ($action =~ /^clean$/) {
|
---|
[77] | 154 | } else {
|
---|
| 155 | print $LOG "'$action' is not available\n";
|
---|
| 156 | pb_syntax();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | sub pb_cms2build {
|
---|
| 160 |
|
---|
[112] | 161 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
[22] | 162 | @pkgs = @$ptr;
|
---|
[112] | 163 | my $cms=pb_cms_init($ENV{'PBPROJ'});
|
---|
[9] | 164 |
|
---|
[98] | 165 | my ($pkgv, $pkgt) = pb_conf_read("$ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb","pkgver","pkgtag");
|
---|
[174] | 166 |
|
---|
| 167 | # declare packager for filtering
|
---|
| 168 | my ($tmp) = pb_conf_get("packager");
|
---|
| 169 | my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
|
---|
| 170 |
|
---|
[27] | 171 | foreach my $pbpkg (@pkgs) {
|
---|
[115] | 172 | $ENV{'PBPKG'} = $pbpkg;
|
---|
[274] | 173 | $ENV{'PBVER'} = $pbprojver;
|
---|
| 174 | $ENV{'PBTAG'} = $pbprojtag;
|
---|
[98] | 175 | if ((defined $pkgv) && (defined $pkgv->{$pbpkg})) {
|
---|
| 176 | $pbver = $pkgv->{$pbpkg};
|
---|
[115] | 177 | $ENV{'PBVER'} = $pbver;
|
---|
[9] | 178 | } else {
|
---|
[16] | 179 | $pbver = $ENV{'PBVER'};
|
---|
[9] | 180 | }
|
---|
[98] | 181 | if ((defined $pkgt) && (defined $pkgt->{$pbpkg})) {
|
---|
| 182 | $pbtag = $pkgt->{$pbpkg};
|
---|
[115] | 183 | $ENV{'PBTAG'} = $pbtag;
|
---|
[9] | 184 | } else {
|
---|
[16] | 185 | $pbtag = $ENV{'PBTAG'};
|
---|
[9] | 186 | }
|
---|
[95] | 187 |
|
---|
[16] | 188 | $pbrev = $ENV{'PBREVISION'};
|
---|
[112] | 189 | print $LOG "\n";
|
---|
| 190 | print $LOG "Management of $pbpkg $pbver-$pbtag (rev $pbrev)\n";
|
---|
[9] | 191 | die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
|
---|
[16] | 192 | # Clean up dest if necessary. The export will recreate it
|
---|
[27] | 193 | my $dest = "$ENV{'PBDESTDIR'}/$pbpkg-$pbver";
|
---|
[74] | 194 | pb_rm_rf($dest) if (-d $dest);
|
---|
[9] | 195 |
|
---|
| 196 | # Export CMS tree for the concerned package to dest
|
---|
| 197 | # And generate some additional files
|
---|
| 198 | $OUTPUT_AUTOFLUSH=1;
|
---|
[29] | 199 |
|
---|
[9] | 200 | # computes in which dir we have to work
|
---|
[113] | 201 | my $dir = $defpkgdir->{$pbpkg};
|
---|
| 202 | $dir = $extpkgdir->{$pbpkg} if (not defined $dir);
|
---|
[114] | 203 | print "def:".Dumper($defpkgdir)." ext: ".Dumper($extpkgdir)." \n" if ($debug >= 1);
|
---|
[112] | 204 | pb_cms_export($cms,$pbdatecvs,"$ENV{'PBROOT'}/$dir",$dest);
|
---|
[9] | 205 |
|
---|
| 206 | # Extract cms log history and store it
|
---|
[106] | 207 | pb_cms_log($cms,"$ENV{'PBROOT'}/$dir","$dest/$ENV{'PBCMSLOGFILE'}");
|
---|
[29] | 208 |
|
---|
[21] | 209 | my %build;
|
---|
[91] | 210 |
|
---|
| 211 | my ($ptr) = pb_conf_get("vmlist");
|
---|
| 212 | foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
|
---|
| 213 | my ($name,$ver) = split(/_/,$d);
|
---|
[11] | 214 | chomp($ver);
|
---|
[99] | 215 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
|
---|
| 216 | print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf)."\n" if ($debug >= 1);
|
---|
[22] | 217 | print $LOG "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
|
---|
[13] | 218 |
|
---|
[16] | 219 | # Filter build files from the less precise up to the most with overloading
|
---|
[13] | 220 | # Filter all files found, keeping the name, and generating in dest
|
---|
[16] | 221 |
|
---|
| 222 | # Find all build files first relatively to PBROOT
|
---|
| 223 | my %bfiles;
|
---|
[27] | 224 | print $LOG "DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n" if ($debug >= 1);
|
---|
[21] | 225 | $build{"$ddir-$dver"} = "yes";
|
---|
[27] | 226 | if (-d "$ENV{'PBCONF'}/$pbpkg/$dtype") {
|
---|
| 227 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dtype") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dtype: $!";
|
---|
[16] | 228 | foreach my $f (readdir(BDIR)) {
|
---|
| 229 | next if ($f =~ /^\./);
|
---|
[27] | 230 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dtype/$f";
|
---|
[16] | 231 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 232 | }
|
---|
[13] | 233 | closedir(BDIR);
|
---|
[27] | 234 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$dfam") {
|
---|
| 235 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$dfam") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$dfam: $!";
|
---|
[16] | 236 | foreach my $f (readdir(BDIR)) {
|
---|
| 237 | next if ($f =~ /^\./);
|
---|
[27] | 238 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$dfam/$f";
|
---|
[16] | 239 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 240 | }
|
---|
| 241 | closedir(BDIR);
|
---|
[27] | 242 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir") {
|
---|
| 243 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir: $!";
|
---|
[16] | 244 | foreach my $f (readdir(BDIR)) {
|
---|
| 245 | next if ($f =~ /^\./);
|
---|
[27] | 246 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir/$f";
|
---|
[16] | 247 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 248 | }
|
---|
[13] | 249 | closedir(BDIR);
|
---|
[27] | 250 | } elsif (-d "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") {
|
---|
| 251 | opendir(BDIR,"$ENV{'PBCONF'}/$pbpkg/$ddir-$dver") || die "Unable to open dir $ENV{'PBCONF'}/$pbpkg/$ddir-$dver: $!";
|
---|
[16] | 252 | foreach my $f (readdir(BDIR)) {
|
---|
| 253 | next if ($f =~ /^\./);
|
---|
[27] | 254 | $bfiles{$f} = "$ENV{'PBCONF'}/$pbpkg/$ddir-$dver/$f";
|
---|
[16] | 255 | $bfiles{$f} =~ s~$ENV{'PBROOT'}~~;
|
---|
| 256 | }
|
---|
[13] | 257 | closedir(BDIR);
|
---|
| 258 | } else {
|
---|
[21] | 259 | $build{"$ddir-$dver"} = "no";
|
---|
[13] | 260 | next;
|
---|
| 261 | }
|
---|
[22] | 262 | print $LOG "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
|
---|
[13] | 263 |
|
---|
[15] | 264 | # Get all filters to apply
|
---|
[77] | 265 | my $ptr = pb_get_filters($pbpkg, $dtype, $dfam, $ddir, $dver);
|
---|
[15] | 266 |
|
---|
[19] | 267 | # Apply now all the filters on all the files concerned
|
---|
| 268 | # destination dir depends on the type of file
|
---|
| 269 | if (defined $ptr) {
|
---|
| 270 | foreach my $f (values %bfiles) {
|
---|
[194] | 271 | pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$defpkgdir,$extpkgdir,$pbpackager);
|
---|
[16] | 272 | }
|
---|
[15] | 273 | }
|
---|
[18] | 274 | }
|
---|
[21] | 275 | if ($debug >= 0) {
|
---|
| 276 | my @found;
|
---|
| 277 | my @notfound;
|
---|
| 278 | foreach my $b (keys %build) {
|
---|
| 279 | push @found,$b if ($build{$b} =~ /yes/);
|
---|
| 280 | push @notfound,$b if ($build{$b} =~ /no/);
|
---|
| 281 | }
|
---|
[22] | 282 | print $LOG "Build files generated for ".join(',',@found)."\n";
|
---|
| 283 | print $LOG "No Build files found for ".join(',',@notfound)."\n";
|
---|
[21] | 284 | }
|
---|
[236] | 285 | # Get the generic filter (all.pbf) and
|
---|
| 286 | # apply those to the non-build files including those
|
---|
| 287 | # generated by pbinit if applicable
|
---|
| 288 |
|
---|
| 289 | # Get only all.pbf filter
|
---|
[237] | 290 | $ptr = pb_get_filters($pbpkg);
|
---|
[236] | 291 |
|
---|
| 292 | my $liste ="";
|
---|
| 293 | if (defined $filteredfiles->{$pbpkg}) {
|
---|
| 294 | foreach my $f (split(/,/,$filteredfiles->{$pbpkg})) {
|
---|
| 295 | pb_filter_file("$ENV{'PBROOT'}/$dir/$f",$ptr,"$dest/$f",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
|
---|
[238] | 296 | $liste = "$f $liste";
|
---|
[236] | 297 | }
|
---|
| 298 | }
|
---|
[239] | 299 | print $LOG "Files ".$liste."have been filtered\n";
|
---|
[236] | 300 |
|
---|
[265] | 301 | # Prepare the dest directory for archive
|
---|
| 302 | if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
|
---|
[266] | 303 | pb_filter_file("$ENV{'PBCONF'}/$pbpkg/pbinit",$ptr,"$ENV{'PBTMP'}/pbinit",$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
|
---|
| 304 | chmod 0755,"$ENV{'PBTMP'}/pbinit";
|
---|
| 305 | pb_system("cd $dest ; $ENV{'PBTMP'}/pbinit","Executing init script from $ENV{'PBCONF'}/$pbpkg/pbinit");
|
---|
[265] | 306 | }
|
---|
| 307 |
|
---|
[18] | 308 | # Archive dest dir
|
---|
[69] | 309 | chdir "$ENV{'PBDESTDIR'}" || die "Unable to change dir to $ENV{'PBDESTDIR'}";
|
---|
[25] | 310 | # Possibility to look at PBSRC to guess more the filename
|
---|
[94] | 311 | pb_system("tar cfz $pbpkg-$pbver.tar.gz $pbpkg-$pbver","Creating $pbpkg tar files compressed");
|
---|
[31] | 312 | print $LOG "Under $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz\n" if ($debug >= 0);
|
---|
[83] | 313 |
|
---|
[70] | 314 | # Keep track of what is generated for default
|
---|
[113] | 315 | open(LAST,"> $pbrc->{$ENV{'PBPROJ'}}") || die "Unable to create $pbrc->{$ENV{'PBPROJ'}}";
|
---|
[83] | 316 | print LAST "pbroot $pbprojver-$pbprojtag = $ENV{'PBROOT'}\n";
|
---|
| 317 | close(LAST);
|
---|
| 318 |
|
---|
| 319 | # Keep track of per package version
|
---|
| 320 | if (! -f "$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") {
|
---|
| 321 | open(PKG,">$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
|
---|
| 322 | print PKG "# Empty\n";
|
---|
| 323 | close(PKG);
|
---|
| 324 | }
|
---|
[89] | 325 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[83] | 326 | $pkg = { } if (not defined $pkg);
|
---|
[88] | 327 | if ((not defined $pkg->{$pbpkg}) || ($pkg->{$pbpkg} ne "$pbver-$pbtag")) {
|
---|
| 328 | $pkg->{$pbpkg} = "$pbver-$pbtag";
|
---|
[83] | 329 | }
|
---|
| 330 |
|
---|
[88] | 331 | print $LOG "DEBUG pkg: ".Dumper($pkg)."\n" if ($debug >= 1);
|
---|
[83] | 332 | open(PKG,"> $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb") || die "Unable to create $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb";
|
---|
[88] | 333 | foreach my $p (keys %$pkg) {
|
---|
| 334 | print PKG "pbpkg $p = $pkg->{$p}\n";
|
---|
[83] | 335 | }
|
---|
| 336 | close(PKG);
|
---|
[9] | 337 | }
|
---|
[77] | 338 | }
|
---|
[22] | 339 |
|
---|
[77] | 340 | sub pb_build2pkg {
|
---|
| 341 |
|
---|
[22] | 342 | # Get list of packages to build
|
---|
[112] | 343 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
[22] | 344 | @pkgs = @$ptr;
|
---|
| 345 |
|
---|
| 346 | # Get the running distro to build on
|
---|
[99] | 347 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
|
---|
| 348 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
|
---|
[22] | 349 |
|
---|
[83] | 350 | # Get content saved in cms2build
|
---|
[89] | 351 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[83] | 352 | $pkg = { } if (not defined $pkg);
|
---|
| 353 |
|
---|
[174] | 354 | # declare packager
|
---|
| 355 | my ($tmp) = pb_conf_get("packager");
|
---|
| 356 | my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
|
---|
| 357 |
|
---|
[25] | 358 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
[126] | 359 | my $made = ""; # pkgs made during build
|
---|
[27] | 360 | foreach my $pbpkg (@pkgs) {
|
---|
[88] | 361 | my $vertag = $pkg->{$pbpkg};
|
---|
[77] | 362 | # get the version of the current package - maybe different
|
---|
| 363 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 364 |
|
---|
[27] | 365 | my $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[200] | 366 | # Suse 10.0 forces tar.bz2 usage :-(
|
---|
| 367 | if (($ddir eq "suse") && ($dver eq "10.0")) {
|
---|
| 368 | print "SuSE 10.0 needs bz2 type of packages so recompressing...\n";
|
---|
[188] | 369 | my $newsrc="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.bz2";
|
---|
| 370 | system "gzip -cd $src | bzip2 -c6 > $newsrc";
|
---|
| 371 | $src = $newsrc;
|
---|
| 372 | }
|
---|
[67] | 373 | print $LOG "Source file: $src\n" if ($debug >= 0);
|
---|
[25] | 374 |
|
---|
[149] | 375 | print $LOG "Working directory: $ENV{'PBBUILDDIR'}\n" if ($debug >= 0);
|
---|
[25] | 376 | if ($dtype eq "rpm") {
|
---|
| 377 | foreach my $d ('RPMS','SRPMS','SPECS','SOURCES','BUILD') {
|
---|
[28] | 378 | if (! -d "$ENV{'PBBUILDDIR'}/$d") {
|
---|
[96] | 379 | 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] | 380 | }
|
---|
[25] | 381 | }
|
---|
| 382 |
|
---|
[188] | 383 | symlink "$src","$ENV{'PBBUILDDIR'}/SOURCES/".basename($src) || die "Unable to symlink $src in $ENV{'PBBUILDDIR'}/SOURCES";
|
---|
[25] | 384 | # We need to first extract the spec file
|
---|
[28] | 385 | my @specfile;
|
---|
[77] | 386 | @specfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/SPECS");
|
---|
[25] | 387 |
|
---|
[28] | 388 | print $LOG "specfile: ".Dumper(\@specfile)."\n" if ($debug >= 1);
|
---|
[25] | 389 | # set LANGUAGE to check for correct log messages
|
---|
| 390 | $ENV{'LANGUAGE'}="C";
|
---|
[28] | 391 | #system("ls -R $ENV{'PBBUILDDIR'}") if ($debug >= 1);
|
---|
| 392 | foreach my $f (@specfile) {
|
---|
| 393 | if ($f =~ /\.spec$/) {
|
---|
[174] | 394 | pb_system("rpmbuild --define \"packager $pbpackager\" --define \"_topdir $ENV{'PBBUILDDIR'}\" -ba $f","Building package with $f under $ENV{'PBBUILDDIR'}");
|
---|
[28] | 395 | last;
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
[136] | 398 | $made="$made RPMS/*/$pbpkg-$pbver-$pbtag$pbsuf.*.rpm SRPMS/$pbpkg-$pbver-$pbtag$pbsuf.src.rpm";
|
---|
[149] | 399 | if (-f "/usr/bin/rpmlint") {
|
---|
| 400 | pb_system("rpmlint $made","Checking validity of rpms with rpmlint");
|
---|
[150] | 401 | }
|
---|
[118] | 402 | } elsif ($dtype eq "deb") {
|
---|
[149] | 403 | chdir "$ENV{'PBBUILDDIR'}" || die "Unable to chdir to $ENV{'PBBUILDDIR'}";
|
---|
[274] | 404 | pb_system("tar xfz $src","Extracting sources");
|
---|
[149] | 405 |
|
---|
| 406 | chdir "$pbpkg-$pbver" || die "Unable to chdir to $pbpkg-$pbver";
|
---|
| 407 | symlink "pbconf/$ddir-$dver","debian" || die "Unable to symlink to pbconf/$ddir-$dver";
|
---|
[199] | 408 | chmod 0755,"debian/rules";
|
---|
[149] | 409 | pb_system("dpkg-buildpackage -us -uc -rfakeroot","Building package");
|
---|
[136] | 410 | $made="$made $pbpkg"."_*.deb $pbpkg"."_*.dsc $pbpkg"."_*.tar.gz";
|
---|
[87] | 411 | } elsif ($dtype eq "ebuild") {
|
---|
[149] | 412 | my @ebuildfile;
|
---|
| 413 | # For gentoo we need to take pb as subsystem name
|
---|
| 414 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/portage/pb/$pbpkg") if (! -d "$ENV{'PBBUILDDIR'}/portage/pb/$pbpkg");
|
---|
| 415 |
|
---|
| 416 | # We need to first extract the ebuild file
|
---|
| 417 | @ebuildfile = pb_extract_build_files($src,"$pbpkg-$pbver/pbconf/$ddir-$dver/","$ENV{'PBBUILDDIR'}/portage/pb/$pbpkg");
|
---|
| 418 |
|
---|
| 419 | # Prepare the build env for gentoo
|
---|
| 420 | my $found = 0;
|
---|
| 421 | my $pbbd = $ENV{'PBBUILDDIR'};
|
---|
[150] | 422 | $pbbd =~ s|/|\\/|g;
|
---|
[149] | 423 | open(MAKE,"/etc/make.conf") || die "Unable to open /etc/make.conf";
|
---|
| 424 | while (<MAKE>) {
|
---|
| 425 | $found = 1 if (/$pbbd\/portage/);
|
---|
| 426 | }
|
---|
| 427 | close(MAKE);
|
---|
| 428 | if ($found == 0) {
|
---|
| 429 | pb_system("sudo \'echo \"$ENV{'PBBUILDDIR'}/portage\" >> /etc/make.conf\'");
|
---|
| 430 | }
|
---|
| 431 | $found = 0;
|
---|
| 432 | open(KEYW,"/etc/portage/package.keywords") || die "Unable to open /etc/portage/package.keywords";
|
---|
| 433 | while (<KEYW>) {
|
---|
| 434 | $found = 1 if (/portage\/pb/);
|
---|
| 435 | }
|
---|
| 436 | close(KEYW);
|
---|
| 437 | if ($found == 0) {
|
---|
| 438 | pb_system("sudo \'echo \"portage/pb\" >> /etc/portage/package.keywords\'");
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | # Build
|
---|
| 442 | foreach my $f (@ebuildfile) {
|
---|
| 443 | if ($f =~ /\.ebuild$/) {
|
---|
| 444 | pb_system("ebuild $f digest ; ebuild $f package");
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | print $LOG "ebuild file: ".Dumper(\@ebuildfile)."\n" if ($debug >= 1);
|
---|
| 448 |
|
---|
| 449 | $made="$made portage/pb/$pbpkg/$pbpkg-$pbver.ebuild";
|
---|
[118] | 450 | } elsif ($dtype eq "slackware") {
|
---|
[136] | 451 | $made="$made build-$pbpkg/$pbpkg-$pbver-*-$pbtag.tgz";
|
---|
[118] | 452 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/install") if (! -d "$ENV{'PBBUILDDIR'}/install");
|
---|
[87] | 453 | } else {
|
---|
[118] | 454 | die "Unknown dtype format $dtype";
|
---|
[87] | 455 | }
|
---|
| 456 | }
|
---|
[118] | 457 | # Keep track of what is generated so that we can get them back from VMs
|
---|
[129] | 458 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to create $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[118] | 459 | print KEEP "$made\n";
|
---|
| 460 | close(KEEP);
|
---|
[87] | 461 | }
|
---|
| 462 |
|
---|
[88] | 463 | sub pb_build2ssh {
|
---|
[90] | 464 | pb_send2ssh("Sources");
|
---|
| 465 | }
|
---|
[87] | 466 |
|
---|
[90] | 467 | sub pb_pkg2ssh {
|
---|
| 468 | pb_send2ssh("Packages");
|
---|
| 469 | }
|
---|
| 470 |
|
---|
[108] | 471 | # By default deliver to the the public site hosting the
|
---|
| 472 | # ftp structure (or whatever) or a VM
|
---|
[90] | 473 | sub pb_send2ssh {
|
---|
| 474 |
|
---|
| 475 | my $cmt = shift;
|
---|
[118] | 476 | my $vm = shift || undef;
|
---|
[142] | 477 | my $vmexist = shift || 0; # 0 is FALSE
|
---|
[200] | 478 | my $vmpid = shift || 0; # 0 is FALSE
|
---|
[108] | 479 | my $host = shift || "sshhost";
|
---|
| 480 | my $login = shift || "sshlogin";
|
---|
| 481 | my $dir = shift || "sshdir";
|
---|
| 482 | my $port = shift || "sshport";
|
---|
[203] | 483 | my $tmout = shift || "vmtmout";
|
---|
[158] | 484 | my $cmd = "";
|
---|
[90] | 485 |
|
---|
[87] | 486 | # Get list of packages to build
|
---|
[112] | 487 | my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
|
---|
[87] | 488 | @pkgs = @$ptr;
|
---|
| 489 |
|
---|
[136] | 490 | # Get the running distro to consider
|
---|
[118] | 491 | my ($odir,$over) = (undef, undef);
|
---|
| 492 | if (defined $vm) {
|
---|
| 493 | ($odir,$over) = split(/_/,$vm);
|
---|
| 494 | }
|
---|
| 495 | my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
|
---|
[99] | 496 | print $LOG "DEBUG: distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n" if ($debug >= 1);
|
---|
[87] | 497 |
|
---|
| 498 | # Get content saved in cms2build
|
---|
[89] | 499 | my ($pkg) = pb_conf_read("$ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb","pbpkg");
|
---|
[87] | 500 | $pkg = { } if (not defined $pkg);
|
---|
| 501 |
|
---|
[118] | 502 | my $src = "";
|
---|
[87] | 503 | chdir "$ENV{'PBBUILDDIR'}";
|
---|
| 504 | foreach my $pbpkg (@pkgs) {
|
---|
[88] | 505 | my $vertag = $pkg->{$pbpkg};
|
---|
[87] | 506 | # get the version of the current package - maybe different
|
---|
| 507 | ($pbver,$pbtag) = split(/-/,$vertag);
|
---|
| 508 |
|
---|
[118] | 509 | if (($cmt eq "Sources") || ($cmt eq "VMs")) {
|
---|
[158] | 510 | $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
|
---|
[166] | 511 | if ($cmd eq "") {
|
---|
| 512 | $cmd = "ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
| 513 | } else {
|
---|
| 514 | $cmd = "$cmd ; ln -sf $pbpkg-$pbver.tar.gz $pbpkg-latest.tar.gz";
|
---|
| 515 | }
|
---|
[118] | 516 | }
|
---|
| 517 | }
|
---|
| 518 | if ($cmt eq "VMs") {
|
---|
[132] | 519 | $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}";
|
---|
[142] | 520 | } elsif ($cmt eq "Script") {
|
---|
| 521 | $src="$src $ENV{'PBDESTDIR'}/pbscript";
|
---|
[118] | 522 | } elsif ($cmt eq "Packages") {
|
---|
| 523 | # Get package list from file made during build2pkg
|
---|
[129] | 524 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[126] | 525 | $src = <KEEP>;
|
---|
[118] | 526 | chomp($src);
|
---|
| 527 | close(KEEP);
|
---|
| 528 | if ($dtype eq "rpm") {
|
---|
| 529 | # Also make a pbscript to generate yum/urpmi bases
|
---|
[108] | 530 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
|
---|
[118] | 531 | } elsif ($dtype eq "deb") {
|
---|
| 532 | # Also make a pbscript to generate apt bases
|
---|
| 533 | # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
|
---|
[90] | 534 | }
|
---|
[87] | 535 | }
|
---|
[132] | 536 | # Remove potential leading spaces (cause pb with basename)
|
---|
| 537 | $src =~ s/^ *//;
|
---|
[129] | 538 | my $basesrc = "";
|
---|
[131] | 539 | foreach my $i (split(/ +/,$src)) {
|
---|
| 540 | $basesrc .= " ".basename($i);
|
---|
[130] | 541 | }
|
---|
[118] | 542 |
|
---|
[128] | 543 | print $LOG "Sources handled ($cmt): $src\n" if ($debug >= 0);
|
---|
[203] | 544 | my ($sshhost,$sshlogin,$sshdir,$sshport,$vmtmout) = pb_conf_get($host,$login,$dir,$port,$tmout);
|
---|
[88] | 545 | my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
|
---|
[152] | 546 | # Overwrite account value if passed as parameter
|
---|
| 547 | $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
|
---|
[108] | 548 | my $tdir;
|
---|
[136] | 549 | my $bdir;
|
---|
[142] | 550 | if (($cmt eq "Sources") || ($cmt eq "Script")) {
|
---|
[108] | 551 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
|
---|
| 552 | } elsif ($cmt eq "VMs") {
|
---|
[136] | 553 | $tdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/delivery";
|
---|
| 554 | $bdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/build";
|
---|
| 555 | # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
|
---|
| 556 | $bdir =~ s|\$ENV.+\}/||;
|
---|
[90] | 557 | } elsif ($cmt eq "Packages") {
|
---|
[108] | 558 | $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
|
---|
[90] | 559 | } else {
|
---|
| 560 | return;
|
---|
[22] | 561 | }
|
---|
[239] | 562 | my $nport = $sshport->{$ENV{'PBPROJ'}};
|
---|
| 563 | $nport = "$pbport" if (defined $pbport);
|
---|
| 564 |
|
---|
[136] | 565 | # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
|
---|
[132] | 566 | $tdir =~ s|\$ENV.+\}/||;
|
---|
| 567 |
|
---|
[203] | 568 | my $tm = $vmtmout->{$ENV{'PBPROJ'}};
|
---|
[239] | 569 | pb_system("ssh -q -p $nport $mac \"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 $mac");
|
---|
| 570 | pb_system("cd $ENV{'PBBUILDDIR'} ; scp -p -P $nport $src $mac:$tdir 2> /dev/null","$cmt delivery in $tdir on $mac");
|
---|
| 571 | pb_system("ssh -q -p $nport $mac \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $mac if needed");
|
---|
[108] | 572 | if ($cmt eq "VMs") {
|
---|
[128] | 573 | # Get back info on pkg produced, compute their name and get them from the VM
|
---|
[239] | 574 | pb_system("scp -p -P $nport $mac:$bdir/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $bdir on $mac");
|
---|
[129] | 575 | open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[118] | 576 | my $src = <KEEP>;
|
---|
| 577 | chomp($src);
|
---|
| 578 | close(KEEP);
|
---|
[131] | 579 | $src =~ s/^ *//;
|
---|
[136] | 580 | pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
|
---|
[139] | 581 | # Change pgben to make the next send2ssh happy
|
---|
[143] | 582 | my $made = "";
|
---|
[139] | 583 | open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
|
---|
[136] | 584 | foreach my $p (split(/ +/,$src)) {
|
---|
[139] | 585 | my $j = basename($p);
|
---|
[239] | 586 | pb_system("scp -p -P $nport $mac:\'$bdir/$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $bdir from $mac");
|
---|
[144] | 587 | $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
|
---|
[136] | 588 | }
|
---|
[143] | 589 | print KEEP "$made\n";
|
---|
[139] | 590 | close(KEEP);
|
---|
[239] | 591 | pb_system("ssh -q -p $nport $mac \"rm -rf $tdir $bdir\"","VM cleanup on $mac");
|
---|
[142] | 592 | if (! $vmexist) {
|
---|
[239] | 593 | pb_system("ssh -q -p $nport $mac \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $vm halt (pid $vmpid)");
|
---|
[142] | 594 | }
|
---|
[126] | 595 | pb_send2ssh("Packages","$odir"."_"."$over");
|
---|
[141] | 596 | pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
|
---|
[108] | 597 | }
|
---|
[9] | 598 | }
|
---|
[16] | 599 |
|
---|
[142] | 600 | sub pb_script2vm {
|
---|
| 601 | my $pbscript=shift;
|
---|
[141] | 602 |
|
---|
| 603 | # Prepare the script to be executed on the VM
|
---|
| 604 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
[142] | 605 | if ((defined $pbscript ) && ($pbscript ne "$ENV{'PBDESTDIR'}/pbscript")) {
|
---|
| 606 | copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 607 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
| 608 | }
|
---|
[141] | 609 |
|
---|
[142] | 610 | my ($vm,$all) = pb_get_vm();
|
---|
| 611 |
|
---|
[141] | 612 | foreach my $v (@$vm) {
|
---|
[142] | 613 | # Launch the VM
|
---|
[262] | 614 | my ($vmexist,$vmpid) = pb_launchvm($v,0);
|
---|
[141] | 615 |
|
---|
[274] | 616 | # Skip that VM if it something went wrong
|
---|
| 617 | next if (($vmpid == 0) && ($vmexist ==0));
|
---|
| 618 |
|
---|
[142] | 619 | # Gather all required files to send them to the VM
|
---|
| 620 | # and launch the build thourgh pbscript
|
---|
[200] | 621 | pb_send2ssh("Script","$v",$vmexist,$vmpid,"vmhost","vmlogin","pbrc","vmport","vmtmout");
|
---|
[169] | 622 |
|
---|
[142] | 623 | }
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | sub pb_launchvm {
|
---|
| 627 | my $vm = shift;
|
---|
[262] | 628 | my $create = shift || 0; # By default do not create a VM
|
---|
[142] | 629 |
|
---|
[262] | 630 | die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
|
---|
[142] | 631 | die "No VM defined, unable to launch" if (not defined $vm);
|
---|
| 632 | # Keep only the first VM in case many were given
|
---|
| 633 | $vm =~ s/,.*//;
|
---|
| 634 |
|
---|
| 635 | # Launch the VMs
|
---|
[262] | 636 | my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
|
---|
[142] | 637 | my $vmtype = $ptr->{$ENV{'PBPROJ'}};
|
---|
[262] | 638 | if (not defined $ENV{'PBVMOPT'}) {
|
---|
[142] | 639 | $ENV{'PBVMOPT'} = "";
|
---|
| 640 | }
|
---|
[262] | 641 | if (defined $vmopt->{$ENV{'PBPROJ'}}) {
|
---|
| 642 | $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}";
|
---|
| 643 | }
|
---|
[239] | 644 | my $nport = $vmport->{$ENV{'PBPROJ'}};
|
---|
| 645 | $nport = "$pbport" if (defined $pbport);
|
---|
[142] | 646 |
|
---|
| 647 | my $cmd;
|
---|
| 648 | my $vmcmd; # has to be used for pb_check_ps
|
---|
| 649 | my $vmm; # has to be used for pb_check_ps
|
---|
| 650 | if ($vmtype eq "qemu") {
|
---|
| 651 | my $arch = `uname -m`;
|
---|
| 652 | chomp($arch);
|
---|
| 653 | my $qemucmd32;
|
---|
| 654 | my $qemucmd64;
|
---|
| 655 | if ($arch eq "x86_64") {
|
---|
| 656 | $qemucmd32 = "/usr/bin/qemu-system-i386";
|
---|
| 657 | $qemucmd64 = "/usr/bin/qemu";
|
---|
[141] | 658 | } else {
|
---|
[142] | 659 | $qemucmd32 = "/usr/bin/qemu";
|
---|
| 660 | $qemucmd64 = "/usr/bin/qemu-system-x86_64";
|
---|
[141] | 661 | }
|
---|
[142] | 662 | if ($vm =~ /_64/) {
|
---|
| 663 | $vmcmd = "$qemucmd64 -no-kqemu";
|
---|
| 664 | } else {
|
---|
| 665 | $vmcmd = "$qemucmd32";
|
---|
| 666 | }
|
---|
| 667 | $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$vm.qemu";
|
---|
[262] | 668 | if ($create != 0) {
|
---|
| 669 | $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
|
---|
[142] | 670 | }
|
---|
[239] | 671 | $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
|
---|
[142] | 672 | } elsif ($vmtype eq "xen") {
|
---|
| 673 | } elsif ($vmtype eq "vmware") {
|
---|
| 674 | } else {
|
---|
| 675 | die "VM of type $vmtype not supported. Report to the dev team";
|
---|
| 676 | }
|
---|
[199] | 677 | my ($tmpcmd,$void) = split(/ +/,$cmd);
|
---|
| 678 | my $vmexist = pb_check_ps($tmpcmd,$vmm);
|
---|
[200] | 679 | my $vmpid = 0;
|
---|
[142] | 680 | if (! $vmexist) {
|
---|
[262] | 681 | if ($create != 0) {
|
---|
| 682 | pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
|
---|
| 683 | }
|
---|
| 684 | if (! -f "$vmm") {
|
---|
[274] | 685 | print "Unable to find VM $vmm\n";
|
---|
| 686 | } else {
|
---|
| 687 | pb_system("$cmd &","Launching the VM $vmm");
|
---|
| 688 | pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $vm to come up");
|
---|
| 689 | $vmpid = pb_check_ps($tmpcmd,$vmm);
|
---|
[262] | 690 | }
|
---|
[200] | 691 | } else {
|
---|
| 692 | print "Found an existing VM $vmm (pid $vmexist)\n";
|
---|
[141] | 693 | }
|
---|
[200] | 694 | return($vmexist,$vmpid);
|
---|
[141] | 695 | }
|
---|
[142] | 696 |
|
---|
[105] | 697 | sub pb_build2vm {
|
---|
[108] | 698 | # Prepare the script to be executed on the VM
|
---|
| 699 | # in $ENV{'PBDESTDIR'}/pbscript
|
---|
[220] | 700 | my ($ntp) = pb_conf_get("vmntp");
|
---|
| 701 | my $vmntp = $ntp->{$ENV{'PBPROJ'}};
|
---|
[118] | 702 | open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
|
---|
| 703 | print SCRIPT "#!/bin/bash\n";
|
---|
[126] | 704 | print SCRIPT "echo ... Execution needed\n";
|
---|
[132] | 705 | print SCRIPT "# This is in directory delivery\n";
|
---|
[118] | 706 | print SCRIPT "# Setup the variables required for building\n";
|
---|
| 707 | print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
|
---|
[132] | 708 | print SCRIPT "# Preparation for pb\n";
|
---|
| 709 | print SCRIPT "mkdir -p ../pbconf\n";
|
---|
| 710 | print SCRIPT "mv $ENV{'PBPROJ'}.pb ../pbconf\n";
|
---|
| 711 | print SCRIPT "mv .pbrc \$HOME\n";
|
---|
| 712 | print SCRIPT "cd ..\n";
|
---|
[268] | 713 | # Force new date to be in the future compared to the date of the tar file by adding 1 minute
|
---|
[226] | 714 | my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
|
---|
[268] | 715 | $date[1]++;
|
---|
[220] | 716 | my $upddate = strftime("%m%d%H%M%Y", @date);
|
---|
| 717 | print SCRIPT "echo Setting up date on $vmntp...\n";
|
---|
[268] | 718 | # Or use ntpdate if available
|
---|
[220] | 719 | print SCRIPT "sudo date $upddate\n";
|
---|
[118] | 720 | print SCRIPT "export PBROOT=\`pwd\`\n";
|
---|
| 721 | print SCRIPT "# Build\n";
|
---|
[127] | 722 | my $p = "";
|
---|
[272] | 723 | $p = join(' ',@ARGV) if (defined $ARGV[0]);
|
---|
[132] | 724 | print SCRIPT "echo Building packages on VM...\n";
|
---|
[166] | 725 | print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
|
---|
[118] | 726 | close(SCRIPT);
|
---|
| 727 | chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
|
---|
| 728 |
|
---|
[142] | 729 | my ($vm,$all) = pb_get_vm();
|
---|
| 730 |
|
---|
[106] | 731 | # Send tar files when we do a global generation
|
---|
| 732 | pb_build2ssh() if ($all == 1);
|
---|
[118] | 733 |
|
---|
| 734 | foreach my $v (@$vm) {
|
---|
[142] | 735 | # Launch the VM
|
---|
[262] | 736 | my ($vmexist,$vmpid) = pb_launchvm($v,0);
|
---|
[118] | 737 |
|
---|
[274] | 738 | # Skip that VM if it something went wrong
|
---|
| 739 | next if (($vmpid == 0) && ($vmexist == 0));
|
---|
| 740 |
|
---|
[142] | 741 | # Gather all required files to send them to the VM
|
---|
| 742 | # and launch the build thourgh pbscript
|
---|
[200] | 743 | pb_send2ssh("VMs","$v",$vmexist,$vmpid,"vmhost","vmlogin","pbrc","vmport","vmtmout");
|
---|
[118] | 744 | }
|
---|
[105] | 745 | }
|
---|
| 746 |
|
---|
[262] | 747 |
|
---|
[199] | 748 | sub pb_newver {
|
---|
| 749 |
|
---|
[204] | 750 | die "-V Version parameter needed" if ((not defined $newver) || ($newver eq ""));
|
---|
[199] | 751 | my $cms=pb_cms_init($ENV{'PBPROJ'});
|
---|
| 752 | if ($cms->{$ENV{'PBPROJ'}} ne "svn") {
|
---|
| 753 | die "Only SVN is supported at the moment";
|
---|
| 754 | }
|
---|
| 755 | my $res = pb_cms_isdiff($cms);
|
---|
| 756 | die "You need to have no differences before creating a new version" if ($res != 0);
|
---|
| 757 | my $cmsurl = pb_cms_getinfo($cms);
|
---|
[204] | 758 | my $newurl = dirname($cmsurl)."/$newver";
|
---|
| 759 | pb_cms_copy($cms,$cmsurl,$newurl);
|
---|
[208] | 760 | pb_cms_checkout($cms,$newurl,"$ENV{'PBROOT'}/../$newver");
|
---|
| 761 | my $oldver=basename($cmsurl);
|
---|
[211] | 762 | open(FILE,"$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb") || die "Unable to open $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb";
|
---|
| 763 | open(OUT,"> $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new") || die "Unable to write to $ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new";
|
---|
[208] | 764 | while(<FILE>) {
|
---|
[209] | 765 | s/projver\s+$ENV{'PBPROJ'}\s*=\s*$oldver/projver $ENV{'PBPROJ'} = $newver/;
|
---|
[211] | 766 | print OUT $_;
|
---|
[208] | 767 | }
|
---|
| 768 | close(FILE);
|
---|
[211] | 769 | close(OUT);
|
---|
| 770 | rename("$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb.new","$ENV{'PBROOT'}/../$newver/pbconf/$ENV{'PBPROJ'}.pb");
|
---|
[208] | 771 | pb_cms_checkin($cms,"$ENV{'PBROOT'}/../$newver");
|
---|
[199] | 772 | }
|
---|
| 773 |
|
---|
[77] | 774 | sub pb_get_pkg {
|
---|
[16] | 775 |
|
---|
[22] | 776 | my @pkgs;
|
---|
[108] | 777 | my $defpkgdir = shift;
|
---|
| 778 | my $extpkgdir = shift;
|
---|
[22] | 779 |
|
---|
| 780 | # Get packages list
|
---|
| 781 | if (not defined $ARGV[0]) {
|
---|
[112] | 782 | @pkgs = keys %$defpkgdir;
|
---|
[22] | 783 | } elsif ($ARGV[0] =~ /^all$/) {
|
---|
[112] | 784 | @pkgs = keys %$defpkgdir;
|
---|
| 785 | push(@pkgs, keys %$extpkgdir);
|
---|
[22] | 786 | } else {
|
---|
| 787 | @pkgs = @ARGV;
|
---|
| 788 | }
|
---|
| 789 | print $LOG "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
|
---|
| 790 | return(\@pkgs);
|
---|
| 791 | }
|
---|
| 792 |
|
---|
[105] | 793 | #
|
---|
| 794 | # Return the list of VMs we are working on
|
---|
| 795 | # $all is a flag to know if we return all of them
|
---|
| 796 | # or only some (if all we publish also tar files in addition to pkgs
|
---|
| 797 | #
|
---|
[91] | 798 | sub pb_get_vm {
|
---|
| 799 |
|
---|
| 800 | my @vm;
|
---|
[105] | 801 | my $all = 0;
|
---|
[91] | 802 |
|
---|
| 803 | # Get VM list
|
---|
[105] | 804 | if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
|
---|
[108] | 805 | my ($ptr) = pb_conf_get("vmlist");
|
---|
[274] | 806 | my $ptr2 = $ptr->{$ENV{'PBPROJ'}};
|
---|
| 807 | $ptr2 =~ s/,/_64,/g;
|
---|
| 808 | $ptr2 =~ s/$/_64/g;
|
---|
| 809 | $ENV{'PBVM'} = "$ptr->{$ENV{'PBPROJ'}},$ptr2";
|
---|
[105] | 810 | $all = 1;
|
---|
[91] | 811 | }
|
---|
[274] | 812 | print $LOG "VMs: $ENV{'PBVM'}\n";
|
---|
[105] | 813 | @vm = split(/,/,$ENV{'PBVM'});
|
---|
| 814 | return(\@vm,$all);
|
---|
[91] | 815 | }
|
---|
| 816 |
|
---|
[145] | 817 | # Returns the pid of a running VM command using a specific VM file
|
---|
[142] | 818 | sub pb_check_ps {
|
---|
| 819 | my $vmcmd = shift;
|
---|
| 820 | my $vmm = shift;
|
---|
| 821 | my $vmexist = 0; # FALSE by default
|
---|
| 822 |
|
---|
| 823 | open(PS, "ps auxhww|") || die "Unable to call ps";
|
---|
| 824 | while (<PS>) {
|
---|
| 825 | next if (! /$vmcmd/);
|
---|
| 826 | next if (! /$vmm/);
|
---|
| 827 | my ($void1, $void2);
|
---|
| 828 | ($void1, $vmexist, $void2) = split(/ +/);
|
---|
| 829 | last;
|
---|
| 830 | }
|
---|
| 831 | return($vmexist);
|
---|
| 832 | }
|
---|
| 833 |
|
---|
| 834 |
|
---|
[77] | 835 | sub pb_extract_build_files {
|
---|
[25] | 836 |
|
---|
| 837 | my $src=shift;
|
---|
| 838 | my $dir=shift;
|
---|
[26] | 839 | my $ddir=shift;
|
---|
[28] | 840 | my @files;
|
---|
[25] | 841 |
|
---|
[188] | 842 | if ($src =~ /tar\.gz$/) {
|
---|
| 843 | pb_system("tar xfpz $src $dir","Extracting build files");
|
---|
| 844 | } elsif ($src =~ /tar\.bz2$/) {
|
---|
| 845 | pb_system("tar xfpj $src $dir","Extracting build files");
|
---|
| 846 | } else {
|
---|
| 847 | die "Unknown compression algorithm for $src";
|
---|
| 848 | }
|
---|
[25] | 849 | opendir(DIR,"$dir") || die "Unable to open directory $dir";
|
---|
| 850 | foreach my $f (readdir(DIR)) {
|
---|
| 851 | next if ($f =~ /^\./);
|
---|
[26] | 852 | move("$dir/$f","$ddir") || die "Unable to move $dir/$f to $ddir";
|
---|
[28] | 853 | print $LOG "mv $dir/$f $ddir\n" if ($debug >= 1);
|
---|
| 854 | push @files,"$ddir/$f";
|
---|
[25] | 855 | }
|
---|
| 856 | closedir(DIR);
|
---|
[26] | 857 | # Not enough but still a first cleanup
|
---|
[74] | 858 | pb_rm_rf("$dir");
|
---|
[28] | 859 | return(@files);
|
---|
[25] | 860 | }
|
---|
| 861 |
|
---|
[74] | 862 | sub pb_syntax {
|
---|
[21] | 863 |
|
---|
[53] | 864 | print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
|
---|
| 865 | print "\n";
|
---|
[169] | 866 | print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"] <action> [<pkg1>...]\n";
|
---|
[21] | 867 | print "\n";
|
---|
| 868 | print "-h : This help file\n";
|
---|
| 869 | print "-q : Quiet mode\n";
|
---|
| 870 | print "-t : Test mode (not done yet)\n";
|
---|
| 871 | print "-v : Verbose mode\n";
|
---|
| 872 | print "\n";
|
---|
[142] | 873 | print "-m machine : Name of the Virtual Machines (VM) you want\n";
|
---|
| 874 | print " to build on (coma separated). All if none precised\n";
|
---|
[91] | 875 | print " (or use the env variable PBVM) \n";
|
---|
[69] | 876 | print "\n";
|
---|
[141] | 877 | print "-s script : Name of the script you want\n";
|
---|
| 878 | print " to execute on the related VMs.\n";
|
---|
| 879 | print "\n";
|
---|
[152] | 880 | print "-a account : Name of the account to use\n";
|
---|
| 881 | print " to connect on the related VMs.\n";
|
---|
| 882 | print "\n";
|
---|
[199] | 883 | print "-P port : Number of the port to use\n";
|
---|
| 884 | print " to connect on the related VMs.\n";
|
---|
| 885 | print "\n";
|
---|
[21] | 886 | print "-p project : Name of the project you're working on\n";
|
---|
| 887 | print " (or use the env variable PBPROJ) \n";
|
---|
| 888 | print "\n";
|
---|
[91] | 889 | print "-r pbroot : Path Name of project under the CMS \n";
|
---|
| 890 | print " (or use the env variable PBROOT) \n";
|
---|
| 891 | print "\n";
|
---|
[199] | 892 | print "-V newver : New version of the project to create\n";
|
---|
| 893 | print " from the current one. \n";
|
---|
| 894 | print "\n";
|
---|
[21] | 895 | print "<action> can be:\n";
|
---|
| 896 | print "\n";
|
---|
[105] | 897 | print "\tcms2build: Create tar files for the project under your CMS\n";
|
---|
[21] | 898 | print "\t CMS supported are SVN and CVS\n";
|
---|
[22] | 899 | print "\t parameters are packages to build\n";
|
---|
| 900 | print "\t if not using default list\n";
|
---|
[21] | 901 | print "\n";
|
---|
| 902 | print "\tbuild2pkg: Create packages for your running distribution \n";
|
---|
| 903 | print "\n";
|
---|
[169] | 904 | print "\tcms2pkg: cms2build + build2pkg\n";
|
---|
| 905 | print "\n";
|
---|
[105] | 906 | print "\tbuild2ssh: Send the tar files to a SSH host \n";
|
---|
| 907 | print "\n";
|
---|
[220] | 908 | print "\tcms2ssh: cms2build + build2ssh\n";
|
---|
| 909 | print "\n";
|
---|
[105] | 910 | print "\tpkg2ssh: Send the packages built to a SSH host \n";
|
---|
| 911 | print "\n";
|
---|
[142] | 912 | print "\tbuild2vm: Create packages in VMs, launching them if needed\n";
|
---|
| 913 | print "\t and send those packages to a SSH host once built\n";
|
---|
| 914 | print "\t VM type supported are QEMU \n";
|
---|
[136] | 915 | print "\n";
|
---|
[169] | 916 | print "\tcms2vm: cms2build + build2vm\n";
|
---|
| 917 | print "\n";
|
---|
[142] | 918 | print "\tlaunchvm: Launch one virtual machine\n";
|
---|
[141] | 919 | print "\n";
|
---|
[142] | 920 | print "\tscript2vm: Launch one virtual machine if needed \n";
|
---|
| 921 | print "\t and executes a script on it \n";
|
---|
| 922 | print "\n";
|
---|
[262] | 923 | print "\tnewvm: Create a new virtual machine\n";
|
---|
[199] | 924 | print "\n";
|
---|
[262] | 925 | print "\tnewver: Create a new version of the project derived \n";
|
---|
| 926 | print "\t from the current one \n";
|
---|
| 927 | print "\n";
|
---|
[273] | 928 | print "\tnewproj: Create a new project and a template set of \n";
|
---|
| 929 | print "\t configuration files under pbconf \n";
|
---|
| 930 | print "\n";
|
---|
[21] | 931 | }
|
---|