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

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