source: ProjectBuilder/devel/pb-modules/lib/ProjectBuilder/Distribution.pm@ 1540

Last change on this file since 1540 was 1540, checked in by Bruno Cornec, 12 years ago
  • vmmonport is now optional
  • vmmem is also now really optional (wasn't working before as wasn't correctly tested)
  • We are allowed to kill the sleep during VMs wait without it aborting the process
  • newv(e|m) doesn't require execution of cms2build before being available
  • Fix another git support error introduced earlier
File size: 21.3 KB
RevLine 
[11]1#!/usr/bin/perl -w
[2]2#
[11]3# Creates common environment for distributions
[2]4#
[1528]5# Copyright B. Cornec 2007-2012
6# Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard
7# Provided under the GPL v2
8#
[2]9# $Id$
10#
11
[329]12package ProjectBuilder::Distribution;
13
[11]14use strict;
[423]15use Data::Dumper;
[1515]16use Carp 'confess';
[1148]17use ProjectBuilder::Version;
[395]18use ProjectBuilder::Base;
[702]19use ProjectBuilder::Conf;
20use File::Basename;
21use File::Copy;
[1507]22# requires perl 5.004 minimum in VM/VE
23use File::Compare;
[2]24
[1148]25# Global vars
[329]26# Inherit from the "Exporter" module which handles exporting functions.
27
[1156]28use vars qw($VERSION $REVISION @ISA @EXPORT);
[329]29use Exporter;
30
31# Export, by default, all the functions into the namespace of
32# any code which uses this module.
33
34our @ISA = qw(Exporter);
[1177]35our @EXPORT = qw(pb_distro_conffile pb_distro_get pb_distro_getlsb pb_distro_installdeps pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_setuposrepo pb_distro_get_param pb_distro_get_context);
[1156]36($VERSION,$REVISION) = pb_version_init();
[329]37
[391]38=pod
39
40=head1 NAME
41
42ProjectBuilder::Distribution, part of the project-builder.org - module dealing with distribution detection
43
44=head1 DESCRIPTION
45
46This modules provides functions to allow detection of Linux distributions, and giving back some attributes concerning them.
47
48=head1 SYNOPSIS
49
50 use ProjectBuilder::Distribution;
51
52 #
53 # Return information on the running distro
54 #
[1177]55 my $pbos = pb_distro_get_context();
56 print "distro tuple: ".Dumper($pbos->name, $pbos->ver, $pbos->fam, $pbos->type, $pbos->pbsuf, $pbos->pbupd, $pbos->pbins, $pbos->arch)."\n";
[391]57 #
58 # Return information on the requested distro
59 #
[1177]60 my $pbos = pb_distro_get_context("ubuntu-7.10-x86_64");
61 print "distro tuple: ".Dumper($pbos->name, $pbos->ver, $pbos->fam, $pbos->type, $pbos->pbsuf, $pbos->pbupd, $pbos->pbins, $pbos->arch)."\n";
[391]62 #
63 # Return information on the running distro
64 #
[622]65 my ($ddir,$dver) = pb_distro_get();
[391]66
67=head1 USAGE
68
69=over 4
70
[891]71=item B<pb_distro_conffile>
72
73This function returns the mandatory configuration file used for distribution/OS detection
74
75=cut
76
77sub pb_distro_conffile {
78
79return("CCCC/pb.conf");
80}
81
82
[756]83=item B<pb_distro_init>
[395]84
[1177]85This function returns a hash of parameters indicating the distribution name, version, family, type of build system, suffix of packages, update command line, installation command line and architecture of the underlying Linux distribution. The value of the fields may be "unknown" in case the function was unable to recognize on which distribution it is running.
[391]86
[756]87As an example, Ubuntu and Debian are in the same "du" family. As well as RedHat, RHEL, CentOS, fedora are on the same "rh" family.
[1177]88Mandriva, Open SuSE and Fedora have all the same "rpm" type of build system. Ubuntu and Debian have the same "deb" type of build system.
[756]89And "fc" is the extension generated for all Fedora packages (Version will be added by pb).
[1177]90All this information is stored in an external configuration file typically at /etc/pb/pb.conf
[391]91
[756]92When passing the distribution name and version as parameters, the B<pb_distro_init> function returns the parameter of that distribution instead of the underlying one.
[391]93
[756]94Cf: http://linuxmafia.com/faq/Admin/release-files.html
95Ideas taken from http://search.cpan.org/~kerberus/Linux-Distribution-0.14/lib/Linux/Distribution.pm
96
[391]97=cut
98
[756]99
[74]100sub pb_distro_init {
[2]101
[1177]102my $pbos = {
103 'name' => undef,
104 'version' => undef,
105 'arch' => undef,
106 'family' => "unknown",
107 'suffix' => "unknown",
108 'update' => "unknown",
109 'install' => "unknown",
110 'type' => "unknown",
111 'os' => "unknown",
112 'nover' => "false",
113 'rmdot' => "false",
[1540]114 'useminor' => "false",
[1177]115 };
116$pbos->{'name'} = shift;
117$pbos->{'version'} = shift;
118$pbos->{'arch'} = shift;
[2]119
[869]120# Adds conf file for distribution description
121# the location of the conf file is finalyzed at install time
122# depending whether we deal with package install or tar file install
[891]123pb_conf_add(pb_distro_conffile());
[869]124
[11]125# If we don't know which distribution we're on, then guess it
[1177]126($pbos->{'name'},$pbos->{'version'}) = pb_distro_get() if ((not defined $pbos->{'name'}) || (not defined $pbos->{'version'}));
[2]127
[1159]128# For some rare cases, typically nover ones
[1177]129$pbos->{'name'} = "unknown" if (not defined $pbos->{'name'});
130$pbos->{'version'} = "unknown" if (not defined $pbos->{'version'});
[1159]131
[757]132# Initialize arch
[1177]133$pbos->{'arch'} = pb_get_arch() if (not defined $pbos->{'arch'});
[757]134
[969]135# Dig into the tuple to find the best answer
[1177]136# Do NOT factorize here, as it won't work as of now for hash creation
[1530]137# Do NOT change order without caution
138$pbos->{'useminor'} = pb_distro_get_param($pbos,pb_conf_get("osuseminorrel"));
[1177]139$pbos->{'family'} = pb_distro_get_param($pbos,pb_conf_get("osfamily"));
140$pbos->{'type'} = pb_distro_get_param($pbos,pb_conf_get("ostype"));
[1530]141($pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("os","osins","ossuffix","osnover","osremovedotinver","osupd"));
[1177]142#($pbos->{'family'},$pbos->{'type'},$pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("osfamily","ostype","os","osins","ossuffix","osnover","osremovedotinver","osupd"));
[867]143
144# Some OS have no interesting version
[1177]145$pbos->{'version'} = "nover" if ((defined $pbos->{'nover'}) && ($pbos->{'nover'} eq "true"));
[867]146
[1167]147# For some OS remove the . in version name for extension
[1177]148my $dver2 = $pbos->{'version'};
149$dver2 =~ s/\.//g if ((defined $pbos->{'rmdot'}) && ($pbos->{'rmdot'} eq "true"));
[867]150
[1177]151if ((not defined $pbos->{'suffix'}) || ($pbos->{'suffix'} eq "")) {
152 # By default suffix is a concatenation of name and version
153 $pbos->{'suffix'} = ".$pbos->{'name'}$dver2"
[11]154} else {
[867]155 # concat just the version to what has been found
[1177]156 $pbos->{'suffix'} = ".$pbos->{'suffix'}$dver2";
[11]157}
158
[867]159# if ($arch eq "x86_64") {
160# $opt="--exclude=*.i?86";
161# }
[1177]162pb_log(2,"DEBUG: pb_distro_init: ".Dumper($pbos)."\n");
[867]163
[1177]164return($pbos);
[11]165}
[23]166
[756]167=item B<pb_distro_get>
[395]168
[756]169This function returns a list of 2 parameters indicating the distribution name and version of the underlying Linux distribution. The value of those 2 fields may be "unknown" in case the function was unable to recognize on which distribution it is running.
[395]170
[1156]171On my home machine it would currently report ("mandriva","2010.2").
[395]172
173=cut
174
[622]175sub pb_distro_get {
[23]176
[869]177# 1: List of files that unambiguously indicates what distro we have
178# 2: List of files that ambiguously indicates what distro we have
179# 3: Should have the same keys as the previous one. If ambiguity, which other distributions should be checked
180# 4: Matching Rg. Expr to detect distribution and version
181my ($single_rel_files, $ambiguous_rel_files,$distro_similar,$distro_match) = pb_conf_get("osrelfile","osrelambfile","osambiguous","osrelexpr");
[23]182
183my $release;
184my $distro;
185
[391]186# Begin to test presence of non-ambiguous files
[23]187# that way we reduce the choice
[24]188my ($d,$r);
[869]189while (($d,$r) = each %$single_rel_files) {
[1027]190 if (defined $ambiguous_rel_files->{$d}) {
191 print STDERR "The key $d is considered as both unambiguous and ambigous.\n";
[1029]192 print STDERR "Please fix your configuration file.\n"
[1027]193 }
[869]194 if (-f "$r" && ! -l "$r") {
195 my $tmp=pb_get_content("$r");
[23]196 # Found the only possibility.
197 # Try to get version and return
[869]198 if (defined ($distro_match->{$d})) {
199 ($release) = $tmp =~ m/$distro_match->{$d}/m;
[23]200 } else {
[1102]201 print STDERR "Unable to find $d version in $r (non-ambiguous)\n";
[23]202 print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
203 $release = "unknown";
204 }
205 return($d,$release);
206 }
207}
208
[423]209# Now look at ambiguous files
[1027]210# Ubuntu before 10.04 includes a /etc/debian_version file that creates an ambiguity with debian
[423]211# So we need to look at distros in reverse alphabetic order to treat ubuntu always first via lsb
[869]212foreach $d (reverse keys %$ambiguous_rel_files) {
213 $r = $ambiguous_rel_files->{$d};
214 if (-f "$r" && !-l "$r") {
[23]215 # Found one possibility.
216 # Get all distros concerned by that file
[869]217 my $tmp=pb_get_content("$r");
[24]218 my $found = 0;
[869]219 my $ptr = $distro_similar->{$d};
[423]220 pb_log(2,"amb: ".Dumper($ptr)."\n");
[24]221 $release = "unknown";
[869]222 foreach my $dd (split(/,/,$ptr)) {
[423]223 pb_log(2,"check $dd\n");
[23]224 # Try to check pattern
[869]225 if (defined $distro_match->{$dd}) {
226 pb_log(2,"cmp: $distro_match->{$dd} - vs - $tmp\n");
227 ($release) = $tmp =~ m/$distro_match->{$dd}/m;
[24]228 if ((defined $release) && ($release ne "unknown")) {
229 $distro = $dd;
230 $found = 1;
231 last;
232 }
[23]233 }
234 }
235 if ($found == 0) {
[1102]236 print STDERR "Unable to find $d version in $r (ambiguous)\n";
[23]237 print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
238 $release = "unknown";
239 } else {
240 return($distro,$release);
241 }
242 }
243}
244return("unknown","unknown");
[24]245}
[23]246
[1071]247=item B<pb_distro_getlsb>
[621]248
[1071]249This function returns the 5 lsb values LSB version, distribution ID, Description, release and codename.
250As entry it takes an optional parameter to specify whether the output is short or not.
251
252=cut
253
254sub pb_distro_getlsb {
255
256my $s = shift;
257pb_log(3,"Entering pb_distro_getlsb\n");
258
259my ($ambiguous_rel_files) = pb_conf_get("osrelambfile");
260my $lsbf = $ambiguous_rel_files->{"lsb"};
261
262# LSB has not been configured.
263if (not defined $lsbf) {
264 print STDERR "no lsb entry defined for osrelambfile\n";
265 die "You modified upstream delivery and lost !\n";
266}
267
268if (-r $lsbf) {
269 my $rep = pb_get_content($lsbf);
270 # Create elementary fields
271 my ($c, $r, $d, $i, $l) = ("", "", "", "", "");
272 for my $f (split(/\n/,$rep)) {
273 pb_log(3,"Reading file part ***$f***\n");
274 $c = $f if ($f =~ /^DISTRIB_CODENAME/);
275 $c =~ s/DISTRIB_CODENAME=/Codename:\t/;
276 $r = $f if ($f =~ /^DISTRIB_RELEASE/);
277 $r =~ s/DISTRIB_RELEASE=/Release:\t/;
278 $d = $f if ($f =~ /^DISTRIB_DESCRIPTION/);
279 $d =~ s/DISTRIB_DESCRIPTION=/Description:\t/;
280 $d =~ s/"//g;
281 $i = $f if ($f =~ /^DISTRIB_ID/);
282 $i =~ s/DISTRIB_ID=/Distributor ID:\t/;
283 $l = $f if ($f =~ /^LSB_VERSION/);
284 $l =~ s/LSB_VERSION=/LSB Version:\t/;
285 }
[1177]286 my $regexp = "^[A-z ]*:[\t ]*";
287 $c =~ s/$regexp// if (defined $s);
288 $r =~ s/$regexp// if (defined $s);
289 $d =~ s/$regexp// if (defined $s);
290 $i =~ s/$regexp// if (defined $s);
291 $l =~ s/$regexp// if (defined $s);
[1071]292 return($l, $i, $d, $r, $c);
293} else {
294 print STDERR "Unable to read $lsbf file\n";
295 die "Please report to the maintainer bruno_at_project-builder.org\n";
296}
297}
298
[1517]299# Internal function
300
301sub pb_apply_conf_proxy ($) {
302my ($pbos) = @_;
303
304my $ftp_proxy = pb_distro_get_param($pbos,pb_conf_get_if("ftp_proxy"));
305my $http_proxy = pb_distro_get_param($pbos,pb_conf_get_if("http_proxy"));
306
307# We do not overwrite shell settings
308$ENV{ftp_proxy} ||= $ftp_proxy;
309$ENV{http_proxy} ||= $http_proxy;
310}
311
[621]312=item B<pb_distro_installdeps>
313
[1177]314This function install the dependencies required to build the package on a distro.
315Dependencies can be passed as a parameter in which case they are not computed
[621]316
317=cut
318
319sub pb_distro_installdeps {
320
321# SPEC file
322my $f = shift || undef;
[1177]323my $pbos = shift;
[621]324my $deps = shift || undef;
325
[1519]326# Protection
327die "Missing install command for $pbos->{name}-$pbos->{version}-$pbos->{arch}" unless (defined $pbos->{install} && $pbos->{install} =~ /\w/);
[1517]328pb_apply_conf_proxy($pbos);
[621]329
[1177]330# Get dependencies in the build file if not forced
[1505]331$deps = pb_distro_getdeps($f,$pbos) if (not defined $deps);
[1517]332pb_log(1, "ftp_proxy=$ENV{ftp_proxy} http_proxy=$ENV{http_proxy}\n");
[621]333pb_log(2,"deps: $deps\n");
[623]334return if ((not defined $deps) || ($deps =~ /^\s*$/));
[1505]335
336# This may not be // proof. We should test for availability of repo and sleep if not
337my $cmd = "$pbos->{'install'} $deps";
[1539]338my $ret = pb_system($cmd, "Installing dependencies ($cmd)",undef,1);
[1515]339# Try to accomodate deficient proxies
340if ($ret != 0) {
341 pb_system($cmd, "Re-trying installing dependencies ($cmd)");
[621]342}
[1517]343# Check that all deps have been installed correctly
344$deps = pb_distro_getdeps($f, $pbos);
345die "Some dependencies did not install ($deps)" if ((defined $deps) && ($deps =~ /\S/));
[1515]346}
[621]347
348=item B<pb_distro_getdeps>
349
350This function computes the dependencies indicated in the build file and return them as a string of packages to install
351
352=cut
353
354sub pb_distro_getdeps {
355
356my $f = shift || undef;
[1177]357my $pbos = shift;
[621]358
359my $regexp = "";
360my $deps = "";
361my $sep = $/;
362
363# Protection
[1177]364return("") if (not defined $pbos->{'type'});
[899]365return("") if (not defined $f);
366
[1177]367pb_log(3,"entering pb_distro_getdeps: $pbos->{'type'} - $f\n");
368if ($pbos->{'type'} eq "rpm") {
[621]369 # In RPM this could include files, but we do not handle them atm.
370 $regexp = '^BuildRequires:(.*)$';
[1177]371} elsif ($pbos->{'type'} eq "deb") {
[621]372 $regexp = '^Build-Depends:(.*)$';
[1177]373} elsif ($pbos->{'type'} eq "ebuild") {
[621]374 $sep = '"'.$/;
375 $regexp = '^DEPEND="(.*)"\n'
376} else {
377 # No idea
[622]378 return("");
[621]379}
380pb_log(2,"regexp: $regexp\n");
381
382# Preserve separator before using the one we need
383my $oldsep = $/;
384$/ = $sep;
385open(DESC,"$f") || die "Unable to open $f";
386while (<DESC>) {
387 pb_log(4,"read: $_\n");
388 next if (! /$regexp/);
389 chomp();
[1514]390
391 my $nextline;
392 # Support multi-lines deps for .deb
393 if ($pbos->{type} eq 'deb') {
394 while ($nextline = <DESC>) {
395 last unless $nextline =~ /^\s+(.+)$/o;
396 $_ .= $1;
397 }
398 }
399
[621]400 # What we found with the regexp is the list of deps.
401 pb_log(2,"found deps: $_\n");
[681]402 s/$regexp/$1/i;
[698]403 # Remove conditions in the middle and at the end for deb
[931]404 s/\(\s*[><=]+.*\)[^,]*,/,/g;
[698]405 s/\(\s*[><=]+.*$//g;
406 # Same for rpm
[931]407 s/[><=]+[^,]*,/,/g;
[652]408 s/[><=]+.*$//g;
[621]409 # Improve string format (remove , and spaces at start, end and in double
[652]410 s/,/ /g;
[621]411 s/^\s*//;
412 s/\s*$//;
413 s/\s+/ /g;
414 $deps .= " ".$_;
[1514]415
416 # Support multi-lines deps for .deb (fwup)
417 if (defined $nextline) {
418 $_ = $nextline;
419 redo;
420 }
[621]421}
422close(DESC);
423$/ = $oldsep;
424pb_log(2,"now deps: $deps\n");
[1177]425my $deps2 = pb_distro_only_deps_needed($pbos,$deps);
[622]426return($deps2);
427}
428
429
430=item B<pb_distro_only_deps_needed>
431
432This function returns only the dependencies not yet installed
433
434=cut
435
436sub pb_distro_only_deps_needed {
437
[1177]438my $pbos = shift;
[622]439my $deps = shift || undef;
440
[623]441return("") if ((not defined $deps) || ($deps =~ /^\s*$/));
[621]442my $deps2 = "";
443# Avoid to install what is already there
[1524]444delete $ENV{COLUMNS};
[1505]445foreach my $p (split(/\s+/,$deps)) {
446 next if $p =~ /^\s*$/o;
[1177]447 if ($pbos->{'type'} eq "rpm") {
[1539]448 my $res = pb_system("rpm -q --whatprovides --quiet $p","","quiet",1);
[621]449 next if ($res eq 0);
[1524]450 pb_log(1, "INFO: missing dependency $p\n");
[1177]451 } elsif ($pbos->{'type'} eq "deb") {
[1539]452 my $res = pb_system("dpkg -L $p","","quiet",1);
[621]453 next if ($res eq 0);
[1516]454 open(CMD,"dpkg -l $p |") or die "Unable to run dpkg -l $p: $!";
455 my $ok = 0;
456 while (<CMD>) {
457 $ok = 1 if /^ii\s+$p/;
458 }
[1530]459 close(CMD);
[1516]460 next if $ok;
[1524]461 pb_log(1, "INFO: missing dependency $p\n");
[1177]462 } elsif ($pbos->{'type'} eq "ebuild") {
[621]463 } else {
464 # Not reached
465 }
466 pb_log(2,"found deps2: $p\n");
467 $deps2 .= " $p";
468}
469
470$deps2 =~ s/^\s*//;
471pb_log(2,"now deps2: $deps2\n");
472return($deps2);
473}
474
[1132]475=item B<pb_distro_setuposrepo>
476
477This function sets up potential additional repository for the setup phase
478
479=cut
480
481sub pb_distro_setuposrepo {
482
[1177]483my $pbos = shift;
[1132]484
[1177]485pb_distro_setuprepo_gen($pbos,pb_distro_conffile(),"osrepo");
[1132]486}
487
[702]488=item B<pb_distro_setuprepo>
489
490This function sets up potential additional repository to the build environment
491
492=cut
493
494sub pb_distro_setuprepo {
495
[1177]496my $pbos = shift;
[702]497
[1177]498pb_distro_setuprepo_gen($pbos,"$ENV{'PBDESTDIR'}/pbrc","addrepo");
[1132]499}
500
[1507]501# Internal
502sub pb_distro_compare_repo {
503
504my $src = shift;
505my $dest = shift;
506
[1514]507if (not -f $dest) {
[1524]508 pb_log(1, "INFO: Creating new file $dest\n");
[1514]509} elsif (-f $dest && -s $dest == 0) {
[1524]510 pb_log(1, "INFO: Overwriting empty file $dest\n");
[1507]511} elsif (-f $dest && compare("$src", $dest) == 0) {
[1524]512 pb_log(1, "INFO: Overwriting identical file $dest\n");
[1507]513} else {
514 pb_log(0, "ERROR: destination file $dest exists and is different than source $src\n");
[1524]515 pb_system("cat $dest","INFO: Dest...\n");
516 pb_system("cat $src","INFO: New...\n");
517 pb_log("INFO: Returning...\n");
[1507]518 return(0);
519}
520# TRUE
521return(1);
522}
523
[1132]524=item B<pb_distro_setuprepo_gen>
525
526This function sets up in a generic way potential additional repository
527
528=cut
529
530sub pb_distro_setuprepo_gen {
531
[1177]532my $pbos = shift;
[1132]533my $pbconf = shift || undef;
534my $pbkey = shift || undef;
535
536return if (not defined $pbconf);
537return if (not defined $pbkey);
538my ($addrepo) = pb_conf_read($pbconf,$pbkey);
[702]539return if (not defined $addrepo);
540
[1177]541my $param = pb_distro_get_param($pbos,$addrepo);
[702]542return if ($param eq "");
543
[1517]544pb_apply_conf_proxy($pbos);
545
[702]546# Loop on the list of additional repo
547foreach my $i (split(/,/,$param)) {
548
549 my ($scheme, $account, $host, $port, $path) = pb_get_uri($i);
550 my $bn = basename($i);
551
552 # The repo file can be local or remote. download or copy at the right place
553 if (($scheme eq "ftp") || ($scheme eq "http")) {
[1507]554 pb_system("wget -O $ENV{'PBTMP'}/$bn $i","Downloading additional repository file $i");
[702]555 } else {
556 copy($i,$ENV{'PBTMP'}/$bn);
557 }
558
559 # The repo file can be a real file or a package
[1177]560 if ($pbos->{'type'} eq "rpm") {
[702]561 if ($bn =~ /\.rpm$/) {
[721]562 my $pn = $bn;
563 $pn =~ s/\.rpm//;
[1517]564 if (pb_system("rpm -q --quiet $pn","","quiet",1) != 0) {
[721]565 pb_system("sudo rpm -Uvh $ENV{'PBTMP'}/$bn","Adding package to setup repository");
566 }
567 } elsif ($bn =~ /\.repo$/) {
[1521]568 my $dirdest = "";
569 my $reponame = "";
570 # TODO: could go in pb.conf in fact
571 if ($pbos->{install} =~ /\byum\b/) {
572 $reponame="yum";
573 $dirdest = "/etc/yum.repos.d";
574 } elsif ($pbos->{install} =~ /\bzypper\b/) {
575 $reponame="zypper";
576 $dirdest = "/etc/zypp/repos.d";
577 } else {
578 die "Unknown location for repository file for '$pbos->{install}' command";
579 }
580 my $dest = "$dirdest/$bn";
[1507]581 return if (pb_distro_compare_repo($ENV{'PBTMP'}/$bn,$dest));
[1521]582 die "Missing directory $dirdest ($reponame)" unless (-d $dirdest);
583 pb_system("sudo mv $ENV{'PBTMP'}/$bn $dirdest/$bn","Adding $reponame repository") if (not -f "$dirdest/$bn");
[702]584 } elsif ($bn =~ /\.addmedia/) {
585 # URPMI repo
[721]586 # We should test that it's not already a urpmi repo
[702]587 pb_system("chmod 755 $ENV{'PBTMP'}/$bn ; sudo $ENV{'PBTMP'}/$bn 2>&1 > /dev/null","Adding urpmi repository");
588 } else {
[1507]589 pb_log(0,"ERROR: Unable to deal with repository file $i on rpm distro ! Please report to dev team\n");
[702]590 }
[1177]591 } elsif ($pbos->{'type'} eq "deb") {
[1507]592 if ($bn =~ /\.sources.list$/) {
593 my $dest = "/etc/apt/sources.list.d/$bn";
594 return if (pb_distro_compare_repo($ENV{'PBTMP'}/$bn,$dest));
[711]595 pb_system("sudo mv $ENV{'PBTMP'}/$bn /etc/apt/sources.list.d","Adding apt repository");
596 pb_system("sudo apt-get update","Updating apt repository");
[702]597 } else {
[1507]598 pb_log(0,"ERROR: Unable to deal with repository file $i on deb distro ! Please report to dev team\n");
[702]599 }
600 } else {
[1507]601 pb_log(0,"ERROR: Unable to deal with repository file $i on that distro ! Please report to dev team\n");
[702]602 }
603}
604return;
605}
606
[1523]607=item B<pb_pbos_to_keylist>
608
609Given a pbos object and the generic key, get the list of possible keys for looking up variable for
610filter names. The list will be sorted most-specific to least specific.
611
612=cut
613
614sub pb_pbos_to_keylist ($$) {
615
616my ($pbos, $generic) = @_;
617
618foreach my $key (qw/name version arch family type os/) {
[1529]619 confess "missing pbos key $key" unless (defined $pbos->{$key});
[1523]620}
621
622my @keylist = ("$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}", "$pbos->{'name'}-$pbos->{'version'}");
623
624# Loop to include also previous minor versions
625# if configured so
[1530]626if ((defined $pbos->{'useminor'}) && ($pbos->{'useminor'} eq "true") && ($pbos->{'version'} =~ /^(\d+)\.(\d+)$/o)) {
[1523]627 my ($major, $minor) = ($1, $2);
628 while ($minor > 0) {
629 $minor--;
[1530]630 push (@keylist, "$pbos->{'name'}-${major}.$minor");
[1523]631 }
[1530]632 push (@keylist, "$pbos->{'name'}-$major");
[1523]633}
634
[1530]635push (@keylist, $pbos->{'name'}, $pbos->{'family'}, $pbos->{'type'}, $pbos->{'os'}, $generic);
[1523]636return @keylist;
637}
638
[702]639=item B<pb_distro_get_param>
640
641This function gets the parameter in the conf file from the most precise tuple up to default
642
643=cut
644
645sub pb_distro_get_param {
646
[1540]647my @param = ();
[1177]648my $pbos = shift;
[702]649
[1523]650my @keylist = pb_pbos_to_keylist($pbos,"default");
[1177]651pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} for ".Dumper(@_)."\n");
652foreach my $opt (@_) {
[1523]653 my $param = "";
654 foreach my $key (@keylist) {
655 if (defined $opt->{$key}) {
656 $param = $opt->{$key};
657 last;
658 }
[1177]659 }
660 # Allow replacement of variables inside the parameter such as name, version, arch for rpmbootstrap
661 # but not shell variable which are backslashed
662 if ($param =~ /[^\\]\$/) {
663 pb_log(3,"Expanding variable on $param\n");
[1181]664 eval { $param =~ s/(\$\w+->{\'\w+\'})/$1/eeg };
[1177]665 }
666 push @param,$param;
[702]667}
[974]668
[1177]669pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} returns ==".Dumper(@param)."==\n");
670
[1523]671# Return one param if user only asked for one lookup, an array if not.
[1177]672my $nb = @param;
673if ($nb eq 1) {
[1523]674 return($param[0]);
[1177]675} else {
676 return(@param);
[982]677}
[1177]678}
[974]679
[1177]680=item B<pb_distro_get_context>
[702]681
[1177]682This function gets the OS context passed as parameter and return the corresponding distribution hash
[1402]683If passed undef or "" then auto-detects
[1177]684
685=cut
686
687
688sub pb_distro_get_context {
689
690my $os = shift;
691my $pbos;
692
[1402]693if ((defined $os) && ($os ne "")) {
[1177]694 my ($name,$ver,$darch) = split(/-/,$os);
695 pb_log(0,"Bad format for $os") if ((not defined $name) || (not defined $ver) || (not defined $darch)) ;
696 chomp($darch);
697 $pbos = pb_distro_init($name,$ver,$darch);
698} else {
699 $pbos = pb_distro_init();
[702]700}
[1177]701return($pbos);
702}
[749]703
[395]704=back
[23]705
[395]706=head1 WEB SITES
[23]707
[395]708The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
709
710=head1 USER MAILING LIST
711
712None exists for the moment.
713
714=head1 AUTHORS
715
716The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
717
718=head1 COPYRIGHT
719
720Project-Builder.org is distributed under the GPL v2.0 license
721described in the file C<COPYING> included with the distribution.
722
723=cut
724
725
[11]7261;
Note: See TracBrowser for help on using the repository browser.