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

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