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

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