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

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