1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Creates common environment for distributions
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 |
|
---|
8 | package ProjectBuilder::Distribution;
|
---|
9 |
|
---|
10 | use strict;
|
---|
11 | use Data::Dumper;
|
---|
12 | use ProjectBuilder::Base;
|
---|
13 | use ProjectBuilder::Conf;
|
---|
14 | use File::Basename;
|
---|
15 | use File::Copy;
|
---|
16 |
|
---|
17 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
18 |
|
---|
19 | use Exporter;
|
---|
20 |
|
---|
21 | # Export, by default, all the functions into the namespace of
|
---|
22 | # any code which uses this module.
|
---|
23 |
|
---|
24 | our @ISA = qw(Exporter);
|
---|
25 | our @EXPORT = qw(pb_distro_init pb_distro_get pb_distro_installdeps pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_get_param);
|
---|
26 |
|
---|
27 | =pod
|
---|
28 |
|
---|
29 | =head1 NAME
|
---|
30 |
|
---|
31 | ProjectBuilder::Distribution, part of the project-builder.org - module dealing with distribution detection
|
---|
32 |
|
---|
33 | =head1 DESCRIPTION
|
---|
34 |
|
---|
35 | This modules provides functions to allow detection of Linux distributions, and giving back some attributes concerning them.
|
---|
36 |
|
---|
37 | =head1 SYNOPSIS
|
---|
38 |
|
---|
39 | use ProjectBuilder::Distribution;
|
---|
40 |
|
---|
41 | #
|
---|
42 | # Return information on the running distro
|
---|
43 | #
|
---|
44 | my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch) = pb_distro_init();
|
---|
45 | print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch)."\n";
|
---|
46 | #
|
---|
47 | # Return information on the requested distro
|
---|
48 | #
|
---|
49 | my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch) = pb_distro_init("ubuntu","7.10","x86_64");
|
---|
50 | print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch)."\n";
|
---|
51 | #
|
---|
52 | # Return information on the running distro
|
---|
53 | #
|
---|
54 | my ($ddir,$dver) = pb_distro_get();
|
---|
55 | my ($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch) = pb_distro_init($ddir,$dver);
|
---|
56 | print "distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $pbsuf, $pbupd, $arch)."\n";
|
---|
57 |
|
---|
58 | =head1 USAGE
|
---|
59 |
|
---|
60 | =over 4
|
---|
61 |
|
---|
62 | =item B<pb_distro_init>
|
---|
63 |
|
---|
64 | This function returns a list of 7 parameters indicating the distribution name, version, family, type of build system, suffix of packages, update command line and architecture of the underlying Linux distribution. The value of the 7 fields may be "unknown" in case the function was unable to recognize on which distribution it is running.
|
---|
65 |
|
---|
66 | As an example, Ubuntu and Debian are in the same "du" family. As well as RedHat, RHEL, CentOS, fedora are on the same "rh" family.
|
---|
67 | Mandriva, Open SuSE and Fedora have all the same "rpm" type of build system. Ubuntu ad Debian have the same "deb" type of build system.
|
---|
68 | And "fc" is the extension generated for all Fedora packages (Version will be added by pb).
|
---|
69 |
|
---|
70 | When 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.
|
---|
71 |
|
---|
72 | Cf: http://linuxmafia.com/faq/Admin/release-files.html
|
---|
73 | Ideas taken from http://search.cpan.org/~kerberus/Linux-Distribution-0.14/lib/Linux/Distribution.pm
|
---|
74 |
|
---|
75 | =cut
|
---|
76 |
|
---|
77 |
|
---|
78 | sub pb_distro_init {
|
---|
79 |
|
---|
80 | my $ddir = shift || undef;
|
---|
81 | my $dver = shift || undef;
|
---|
82 | my $dfam = "unknown";
|
---|
83 | my $dtype = "unknown";
|
---|
84 | my $dsuf = "unknown";
|
---|
85 | my $dupd = "unknown";
|
---|
86 | my $arch = shift || undef;
|
---|
87 |
|
---|
88 | # If we don't know which distribution we're on, then guess it
|
---|
89 | ($ddir,$dver) = pb_distro_get() if ((not defined $ddir) || (not defined $dver));
|
---|
90 |
|
---|
91 | # Initialize arch
|
---|
92 | $arch=pb_get_arch() if (not defined $arch);
|
---|
93 |
|
---|
94 | # There should be unicity of names between ddir dfam and dtype
|
---|
95 | # In case of duplicate, bad things can happen
|
---|
96 | if (($ddir =~ /debian/) ||
|
---|
97 | ($ddir =~ /ubuntu/)) {
|
---|
98 | $dfam="du";
|
---|
99 | $dtype="deb";
|
---|
100 | $dsuf=".$ddir$dver";
|
---|
101 | # Chaining the commands allow to only test for what is able o be installed,
|
---|
102 | # not the update of the repo which may well be unaccessible if too old
|
---|
103 | $dupd="sudo apt-get update ; sudo apt-get -y install ";
|
---|
104 | } elsif ($ddir =~ /gentoo/) {
|
---|
105 | $dfam="gen";
|
---|
106 | $dtype="ebuild";
|
---|
107 | $dver="nover";
|
---|
108 | $dsuf=".$ddir";
|
---|
109 | $dupd="sudo emerge ";
|
---|
110 | } elsif ($ddir =~ /slackware/) {
|
---|
111 | $dfam="slack";
|
---|
112 | $dtype="tgz";
|
---|
113 | $dsuf=".$dfam$dver";
|
---|
114 | } elsif (($ddir =~ /suse/) ||
|
---|
115 | ($ddir =~ /sles/)) {
|
---|
116 | $dfam="novell";
|
---|
117 | $dtype="rpm";
|
---|
118 | $dsuf=".$ddir$dver";
|
---|
119 | $dupd="export TERM=linux ; export PATH=\$PATH:/sbin:/usr/sbin ; sudo yast2 -i ";
|
---|
120 | } elsif (($ddir =~ /redhat/) ||
|
---|
121 | ($ddir =~ /rhel/) ||
|
---|
122 | ($ddir =~ /fedora/) ||
|
---|
123 | ($ddir =~ /vmware/) ||
|
---|
124 | ($ddir =~ /asianux/) ||
|
---|
125 | ($ddir =~ /centos/)) {
|
---|
126 | $dfam="rh";
|
---|
127 | $dtype="rpm";
|
---|
128 | my $dver1 = $dver;
|
---|
129 | $dver1 =~ s/\.//;
|
---|
130 |
|
---|
131 | # By defaut propose yum
|
---|
132 | my $opt = "";
|
---|
133 | if ($arch eq "x86_64") {
|
---|
134 | $opt="--exclude=*.i?86";
|
---|
135 | }
|
---|
136 | $dupd="sudo yum clean all; sudo yum -y update ; sudo yum -y $opt install ";
|
---|
137 | if ($ddir =~ /fedora/) {
|
---|
138 | $dsuf=".fc$dver1";
|
---|
139 | } elsif ($ddir =~ /redhat/) {
|
---|
140 | $dsuf=".rh$dver1";
|
---|
141 | $dupd="unknown";
|
---|
142 | } elsif ($ddir =~ /asianux/) {
|
---|
143 | $dsuf=".asianux$dver1";
|
---|
144 | } elsif ($ddir =~ /vmware/) {
|
---|
145 | $dsuf=".vwm$dver1";
|
---|
146 | $dupd="unknown";
|
---|
147 | } else {
|
---|
148 | # older versions of rhel ran up2date
|
---|
149 | if ((($dver eq "2.1") || ($dver eq "3") || ($dver eq "4")) && ($ddir eq "rhel")) {
|
---|
150 | $dupd="sudo up2date -y ";
|
---|
151 | }
|
---|
152 | $dsuf=".$ddir$dver1";
|
---|
153 | }
|
---|
154 | } elsif (($ddir =~ /mandrake/) ||
|
---|
155 | ($ddir =~ /mandrakelinux/) ||
|
---|
156 | ($ddir =~ /mandriva/)) {
|
---|
157 | $dfam="md";
|
---|
158 | $dtype="rpm";
|
---|
159 | if ($ddir =~ /mandrakelinux/) {
|
---|
160 | $ddir = "mandrake";
|
---|
161 | }
|
---|
162 | if ($ddir =~ /mandrake/) {
|
---|
163 | my $dver1 = $dver;
|
---|
164 | $dver1 =~ s/\.//;
|
---|
165 | $dsuf=".mdk$dver1";
|
---|
166 | } else {
|
---|
167 | $dsuf=".mdv$dver";
|
---|
168 | }
|
---|
169 | # Chaining the commands allow to only test for what is able o be installed,
|
---|
170 | # not the update of the repo which may well be unaccessible if too old
|
---|
171 | $dupd="sudo urpmi.update -a ; sudo urpmi --auto ";
|
---|
172 | } elsif ($ddir =~ /freebsd/) {
|
---|
173 | $dfam="bsd";
|
---|
174 | $dtype="port";
|
---|
175 | my $dver1 = $dver;
|
---|
176 | $dver1 =~ s/\.//;
|
---|
177 | $dsuf=".$dfam$dver1";
|
---|
178 | } else {
|
---|
179 | $dfam="unknown";
|
---|
180 | }
|
---|
181 |
|
---|
182 | return($ddir, $dver, $dfam, $dtype, $dsuf, $dupd, $arch);
|
---|
183 | }
|
---|
184 |
|
---|
185 | =item B<pb_distro_get>
|
---|
186 |
|
---|
187 | This 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.
|
---|
188 |
|
---|
189 | On my home machine it would currently report ("mandriva","2009.0").
|
---|
190 |
|
---|
191 | =cut
|
---|
192 |
|
---|
193 | sub pb_distro_get {
|
---|
194 |
|
---|
195 | my $base="/etc";
|
---|
196 |
|
---|
197 | # List of files that unambiguously indicates what distro we have
|
---|
198 | my %single_rel_files = (
|
---|
199 | # Tested
|
---|
200 | 'gentoo' => 'gentoo-release', # >= 1.6
|
---|
201 | 'slackware' => 'slackware-version', # >= 10.2
|
---|
202 | 'mandriva' => 'mandriva-release', # >=2006.0
|
---|
203 | 'mandrakelinux' => 'mandrakelinux-release',# = 10.2
|
---|
204 | 'fedora' => 'fedora-release', # >= 4
|
---|
205 | 'vmware' => 'vmware-release', # >= 3
|
---|
206 | 'sles' => 'sles-release', # Doesn't exist as of 10
|
---|
207 | 'asianux' => 'asianux-release', # >= 2.2
|
---|
208 | # Untested
|
---|
209 | 'knoppix' => 'knoppix_version', #
|
---|
210 | 'yellowdog' => 'yellowdog-release', #
|
---|
211 | 'esmith' => 'e-smith-release', #
|
---|
212 | 'turbolinux' => 'turbolinux-release', #
|
---|
213 | 'blackcat' => 'blackcat-release', #
|
---|
214 | 'aurox' => 'aurox-release', #
|
---|
215 | 'annvix' => 'annvix-release', #
|
---|
216 | 'cobalt' => 'cobalt-release', #
|
---|
217 | 'redflag' => 'redflag-release', #
|
---|
218 | 'ark' => 'ark-release', #
|
---|
219 | 'pld' => 'pld-release', #
|
---|
220 | 'nld' => 'nld-release', #
|
---|
221 | 'lfs' => 'lfs-release', #
|
---|
222 | 'mk' => 'mk-release', #
|
---|
223 | 'conectiva' => 'conectiva-release', #
|
---|
224 | 'immunix' => 'immunix-release', #
|
---|
225 | 'tinysofa' => 'tinysofa-release', #
|
---|
226 | 'trustix' => 'trustix-release', #
|
---|
227 | 'adamantix' => 'adamantix_version', #
|
---|
228 | 'yoper' => 'yoper-release', #
|
---|
229 | 'arch' => 'arch-release', #
|
---|
230 | 'libranet' => 'libranet_version', #
|
---|
231 | 'valinux' => 'va-release', #
|
---|
232 | 'yellowdog' => 'yellowdog-release', #
|
---|
233 | 'ultrapenguin' => 'ultrapenguin-release', #
|
---|
234 | );
|
---|
235 |
|
---|
236 | # List of files that ambiguously indicates what distro we have
|
---|
237 | my %ambiguous_rel_files = (
|
---|
238 | 'mandrake' => 'mandrake-release', # <= 10.1
|
---|
239 | 'debian' => 'debian_version', # >= 3.1
|
---|
240 | 'suse' => 'SuSE-release', # >= 10.0
|
---|
241 | 'redhat' => 'redhat-release', # >= 7.3
|
---|
242 | 'lsb' => 'lsb-release', # ???
|
---|
243 | );
|
---|
244 |
|
---|
245 | # Should have the same keys as the previous one.
|
---|
246 | # If ambiguity, which other distributions should be checked
|
---|
247 | my %distro_similar = (
|
---|
248 | 'mandrake' => ['mandrake', 'mandrakelinux'],
|
---|
249 | 'debian' => ['debian', 'ubuntu'],
|
---|
250 | 'suse' => ['suse', 'sles', 'opensuse'],
|
---|
251 | 'redhat' => ['redhat', 'rhel', 'centos', 'mandrake', 'vmware'],
|
---|
252 | 'lsb' => ['ubuntu', 'lsb'],
|
---|
253 | );
|
---|
254 |
|
---|
255 | my %distro_match = (
|
---|
256 | # Tested
|
---|
257 | 'gentoo' => '.* version (.+)',
|
---|
258 | 'slackware' => 'S[^ ]* (.+)$',
|
---|
259 | # There should be no ambiguity between potential ambiguous distro
|
---|
260 | 'mandrakelinux' => 'Mandrakelinux release (.+) \(',
|
---|
261 | 'mandrake' => 'Mandr[^ ]* release (.+) \(',
|
---|
262 | 'mandriva' => 'Mandr[^ ]* [^ ]* release (.+) \(',
|
---|
263 | 'fedora' => 'Fedora .*release (\d+) \(',
|
---|
264 | 'vmware' => 'VMware ESX Server (\d+) \(',
|
---|
265 | 'rhel' => 'Red Hat (?:Enterprise Linux|Linux Advanced Server) .*release ([0-9.]+).* \(',
|
---|
266 | 'centos' => '.*CentOS .*release ([0-9]).* ',
|
---|
267 | 'redhat' => 'Red Hat Linux release (.+) \(',
|
---|
268 | 'sles' => 'SUSE .* Enterprise Server (\d+) \(',
|
---|
269 | 'suse' => 'SUSE LINUX (\d.+) \(',
|
---|
270 | 'opensuse' => 'openSUSE (\d.+) \(',
|
---|
271 | 'asianux' => 'Asianux (?:Server|release) ([0-9]).* \(',
|
---|
272 | 'lsb' => '.*[^Ubunt].*\nDISTRIB_RELEASE=(.+)',
|
---|
273 | # Ubuntu includes a /etc/debian_version file that creates an ambiguity with debian
|
---|
274 | # So we need to look at distros in reverse alphabetic order to treat ubuntu always first
|
---|
275 | 'ubuntu' => '.*Ubuntu.*\nDISTRIB_RELEASE=(.+)',
|
---|
276 | 'debian' => '(.+)',
|
---|
277 | # Not tested
|
---|
278 | 'arch' => '.* ([0-9.]+) .*',
|
---|
279 | 'redflag' => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)',
|
---|
280 | );
|
---|
281 |
|
---|
282 | my $release;
|
---|
283 | my $distro;
|
---|
284 |
|
---|
285 | # Begin to test presence of non-ambiguous files
|
---|
286 | # that way we reduce the choice
|
---|
287 | my ($d,$r);
|
---|
288 | while (($d,$r) = each %single_rel_files) {
|
---|
289 | if (-f "$base/$r" && ! -l "$base/$r") {
|
---|
290 | my $tmp=pb_get_content("$base/$r");
|
---|
291 | # Found the only possibility.
|
---|
292 | # Try to get version and return
|
---|
293 | if (defined ($distro_match{$d})) {
|
---|
294 | ($release) = $tmp =~ m/$distro_match{$d}/m;
|
---|
295 | } else {
|
---|
296 | print STDERR "Unable to find $d version in $r\n";
|
---|
297 | print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
|
---|
298 | $release = "unknown";
|
---|
299 | }
|
---|
300 | return($d,$release);
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | # Now look at ambiguous files
|
---|
305 | # Ubuntu includes a /etc/debian_version file that creates an ambiguity with debian
|
---|
306 | # So we need to look at distros in reverse alphabetic order to treat ubuntu always first via lsb
|
---|
307 | foreach $d (reverse keys %ambiguous_rel_files) {
|
---|
308 | $r = $ambiguous_rel_files{$d};
|
---|
309 | if (-f "$base/$r" && !-l "$base/$r") {
|
---|
310 | # Found one possibility.
|
---|
311 | # Get all distros concerned by that file
|
---|
312 | my $tmp=pb_get_content("$base/$r");
|
---|
313 | my $found = 0;
|
---|
314 | my $ptr = $distro_similar{$d};
|
---|
315 | pb_log(2,"amb: ".Dumper($ptr)."\n");
|
---|
316 | $release = "unknown";
|
---|
317 | foreach my $dd (@$ptr) {
|
---|
318 | pb_log(2,"check $dd\n");
|
---|
319 | # Try to check pattern
|
---|
320 | if (defined $distro_match{$dd}) {
|
---|
321 | pb_log(2,"cmp: $distro_match{$dd} - vs - $tmp\n");
|
---|
322 | ($release) = $tmp =~ m/$distro_match{$dd}/m;
|
---|
323 | if ((defined $release) && ($release ne "unknown")) {
|
---|
324 | $distro = $dd;
|
---|
325 | $found = 1;
|
---|
326 | last;
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 | if ($found == 0) {
|
---|
331 | print STDERR "Unable to find $d version in $r\n";
|
---|
332 | print STDERR "Please report to the maintainer bruno_at_project-builder.org\n";
|
---|
333 | $release = "unknown";
|
---|
334 | } else {
|
---|
335 | return($distro,$release);
|
---|
336 | }
|
---|
337 | }
|
---|
338 | }
|
---|
339 | return("unknown","unknown");
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | =over 4
|
---|
344 |
|
---|
345 | =item B<pb_distro_installdeps>
|
---|
346 |
|
---|
347 | This function install the dependencies required to build the package on an RPM based distro
|
---|
348 | dependencies can be passed as a parameter in which case they are not computed
|
---|
349 |
|
---|
350 | =cut
|
---|
351 |
|
---|
352 | sub pb_distro_installdeps {
|
---|
353 |
|
---|
354 | # SPEC file
|
---|
355 | my $f = shift || undef;
|
---|
356 | my $dtype = shift || undef;
|
---|
357 | my $dupd = shift || undef;
|
---|
358 | my $deps = shift || undef;
|
---|
359 |
|
---|
360 | # Protection
|
---|
361 | return if (not defined $dupd);
|
---|
362 |
|
---|
363 | # Get dependecies in the build file if not forced
|
---|
364 | $deps = pb_distro_getdeps("$f", $dtype) if (not defined $deps);
|
---|
365 | pb_log(2,"deps: $deps\n");
|
---|
366 | return if ((not defined $deps) || ($deps =~ /^\s*$/));
|
---|
367 | if ($deps !~ /^[ ]*$/) {
|
---|
368 | pb_system("$dupd $deps","Installing dependencies ($deps)");
|
---|
369 | }
|
---|
370 | }
|
---|
371 |
|
---|
372 | =over 4
|
---|
373 |
|
---|
374 | =item B<pb_distro_getdeps>
|
---|
375 |
|
---|
376 | This function computes the dependencies indicated in the build file and return them as a string of packages to install
|
---|
377 |
|
---|
378 | =cut
|
---|
379 |
|
---|
380 | sub pb_distro_getdeps {
|
---|
381 |
|
---|
382 | my $f = shift || undef;
|
---|
383 | my $dtype = shift || undef;
|
---|
384 |
|
---|
385 | my $regexp = "";
|
---|
386 | my $deps = "";
|
---|
387 | my $sep = $/;
|
---|
388 |
|
---|
389 | pb_log(3,"entering pb_distro_getdeps: $dtype - $f\n");
|
---|
390 | # Protection
|
---|
391 | return("") if (not defined $dtype);
|
---|
392 | if ($dtype eq "rpm") {
|
---|
393 | # In RPM this could include files, but we do not handle them atm.
|
---|
394 | $regexp = '^BuildRequires:(.*)$';
|
---|
395 | } elsif ($dtype eq "deb") {
|
---|
396 | $regexp = '^Build-Depends:(.*)$';
|
---|
397 | } elsif ($dtype eq "ebuild") {
|
---|
398 | $sep = '"'.$/;
|
---|
399 | $regexp = '^DEPEND="(.*)"\n'
|
---|
400 | } else {
|
---|
401 | # No idea
|
---|
402 | return("");
|
---|
403 | }
|
---|
404 | pb_log(2,"regexp: $regexp\n");
|
---|
405 |
|
---|
406 |
|
---|
407 | # Protection
|
---|
408 | return("") if (not defined $f);
|
---|
409 |
|
---|
410 | # Preserve separator before using the one we need
|
---|
411 | my $oldsep = $/;
|
---|
412 | $/ = $sep;
|
---|
413 | open(DESC,"$f") || die "Unable to open $f";
|
---|
414 | while (<DESC>) {
|
---|
415 | pb_log(4,"read: $_\n");
|
---|
416 | next if (! /$regexp/);
|
---|
417 | chomp();
|
---|
418 | # What we found with the regexp is the list of deps.
|
---|
419 | pb_log(2,"found deps: $_\n");
|
---|
420 | s/$regexp/$1/i;
|
---|
421 | # Remove conditions in the middle and at the end for deb
|
---|
422 | s/\(\s*[><=]+.*\)\s*,/,/g;
|
---|
423 | s/\(\s*[><=]+.*$//g;
|
---|
424 | # Same for rpm
|
---|
425 | s/[><=]+.*,/,/g;
|
---|
426 | s/[><=]+.*$//g;
|
---|
427 | # Improve string format (remove , and spaces at start, end and in double
|
---|
428 | s/,/ /g;
|
---|
429 | s/^\s*//;
|
---|
430 | s/\s*$//;
|
---|
431 | s/\s+/ /g;
|
---|
432 | $deps .= " ".$_;
|
---|
433 | }
|
---|
434 | close(DESC);
|
---|
435 | $/ = $oldsep;
|
---|
436 | pb_log(2,"now deps: $deps\n");
|
---|
437 | my $deps2 = pb_distro_only_deps_needed($dtype,$deps);
|
---|
438 | return($deps2);
|
---|
439 | }
|
---|
440 |
|
---|
441 |
|
---|
442 | =over 4
|
---|
443 |
|
---|
444 | =item B<pb_distro_only_deps_needed>
|
---|
445 |
|
---|
446 | This function returns only the dependencies not yet installed
|
---|
447 |
|
---|
448 | =cut
|
---|
449 |
|
---|
450 | sub pb_distro_only_deps_needed {
|
---|
451 |
|
---|
452 | my $dtype = shift || undef;
|
---|
453 | my $deps = shift || undef;
|
---|
454 |
|
---|
455 | return("") if ((not defined $deps) || ($deps =~ /^\s*$/));
|
---|
456 | my $deps2 = "";
|
---|
457 | # Avoid to install what is already there
|
---|
458 | foreach my $p (split(/ /,$deps)) {
|
---|
459 | if ($dtype eq "rpm") {
|
---|
460 | my $res = pb_system("rpm -q --whatprovides --quiet $p","","quiet");
|
---|
461 | next if ($res eq 0);
|
---|
462 | } elsif ($dtype eq "deb") {
|
---|
463 | my $res = pb_system("dpkg -L $p","","quiet");
|
---|
464 | next if ($res eq 0);
|
---|
465 | } elsif ($dtype eq "ebuild") {
|
---|
466 | } else {
|
---|
467 | # Not reached
|
---|
468 | }
|
---|
469 | pb_log(2,"found deps2: $p\n");
|
---|
470 | $deps2 .= " $p";
|
---|
471 | }
|
---|
472 |
|
---|
473 | $deps2 =~ s/^\s*//;
|
---|
474 | pb_log(2,"now deps2: $deps2\n");
|
---|
475 | return($deps2);
|
---|
476 | }
|
---|
477 |
|
---|
478 | =over 4
|
---|
479 |
|
---|
480 | =item B<pb_distro_setuprepo>
|
---|
481 |
|
---|
482 | This function sets up potential additional repository to the build environment
|
---|
483 |
|
---|
484 | =cut
|
---|
485 |
|
---|
486 | sub pb_distro_setuprepo {
|
---|
487 |
|
---|
488 | my $ddir = shift || undef;
|
---|
489 | my $dver = shift;
|
---|
490 | my $darch = shift;
|
---|
491 | my $dtype = shift || undef;
|
---|
492 |
|
---|
493 | my ($addrepo) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","addrepo");
|
---|
494 | return if (not defined $addrepo);
|
---|
495 |
|
---|
496 | my $param = pb_distro_get_param($ddir,$dver,$darch,$addrepo);
|
---|
497 | return if ($param eq "");
|
---|
498 |
|
---|
499 | # Loop on the list of additional repo
|
---|
500 | foreach my $i (split(/,/,$param)) {
|
---|
501 |
|
---|
502 | my ($scheme, $account, $host, $port, $path) = pb_get_uri($i);
|
---|
503 | my $bn = basename($i);
|
---|
504 |
|
---|
505 | # The repo file can be local or remote. download or copy at the right place
|
---|
506 | if (($scheme eq "ftp") || ($scheme eq "http")) {
|
---|
507 | pb_system("wget -O $ENV{'PBTMP'}/$bn $i","Donwloading additional repository file $i");
|
---|
508 | } else {
|
---|
509 | copy($i,$ENV{'PBTMP'}/$bn);
|
---|
510 | }
|
---|
511 |
|
---|
512 | # The repo file can be a real file or a package
|
---|
513 | if ($dtype eq "rpm") {
|
---|
514 | if ($bn =~ /\.rpm$/) {
|
---|
515 | my $pn = $bn;
|
---|
516 | $pn =~ s/\.rpm//;
|
---|
517 | if (pb_system("rpm -q --quiet $pn","","quiet") != 0) {
|
---|
518 | pb_system("sudo rpm -Uvh $ENV{'PBTMP'}/$bn","Adding package to setup repository");
|
---|
519 | }
|
---|
520 | } elsif ($bn =~ /\.repo$/) {
|
---|
521 | # Yum repo
|
---|
522 | pb_system("sudo mv $ENV{'PBTMP'}/$bn /etc/yum.repos.d","Adding yum repository") if (not -f "/etc/yum.repos.d/$bn");
|
---|
523 | } elsif ($bn =~ /\.addmedia/) {
|
---|
524 | # URPMI repo
|
---|
525 | # We should test that it's not already a urpmi repo
|
---|
526 | pb_system("chmod 755 $ENV{'PBTMP'}/$bn ; sudo $ENV{'PBTMP'}/$bn 2>&1 > /dev/null","Adding urpmi repository");
|
---|
527 | } else {
|
---|
528 | pb_log(0,"Unable to deal with repository file $i on rpm distro ! Please report to dev team\n");
|
---|
529 | }
|
---|
530 | } elsif ($dtype eq "deb") {
|
---|
531 | if (($bn =~ /\.sources.list$/) && (not -f "/etc/apt/sources.list.d/$bn")) {
|
---|
532 | pb_system("sudo mv $ENV{'PBTMP'}/$bn /etc/apt/sources.list.d","Adding apt repository");
|
---|
533 | pb_system("sudo apt-get update","Updating apt repository");
|
---|
534 | } else {
|
---|
535 | pb_log(0,"Unable to deal with repository file $i on deb distro ! Please report to dev team\n");
|
---|
536 | }
|
---|
537 | } else {
|
---|
538 | pb_log(0,"Unable to deal with repository file $i on that distro ! Please report to dev team\n");
|
---|
539 | }
|
---|
540 | }
|
---|
541 | return;
|
---|
542 | }
|
---|
543 |
|
---|
544 | =over 4
|
---|
545 |
|
---|
546 | =item B<pb_distro_get_param>
|
---|
547 |
|
---|
548 | This function gets the parameter in the conf file from the most precise tuple up to default
|
---|
549 |
|
---|
550 | =cut
|
---|
551 |
|
---|
552 | sub pb_distro_get_param {
|
---|
553 |
|
---|
554 | my $param = "";
|
---|
555 | my $ddir = shift;
|
---|
556 | my $dver = shift;
|
---|
557 | my $darch = shift;
|
---|
558 | my $opt = shift;
|
---|
559 |
|
---|
560 | if (defined $opt->{"$ddir-$dver-$darch"}) {
|
---|
561 | $param = $opt->{"$ddir-$dver-$darch"};
|
---|
562 | } elsif (defined $opt->{"$ddir-$dver"}) {
|
---|
563 | $param = $opt->{"$ddir-$dver"};
|
---|
564 | } elsif (defined $opt->{"$ddir"}) {
|
---|
565 | $param = $opt->{"$ddir"};
|
---|
566 | } elsif (defined $opt->{"default"}) {
|
---|
567 | $param = $opt->{"default"};
|
---|
568 | } else {
|
---|
569 | $param = "";
|
---|
570 | }
|
---|
571 | return($param);
|
---|
572 |
|
---|
573 | }
|
---|
574 |
|
---|
575 |
|
---|
576 | =back
|
---|
577 |
|
---|
578 | =head1 WEB SITES
|
---|
579 |
|
---|
580 | The 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/>.
|
---|
581 |
|
---|
582 | =head1 USER MAILING LIST
|
---|
583 |
|
---|
584 | None exists for the moment.
|
---|
585 |
|
---|
586 | =head1 AUTHORS
|
---|
587 |
|
---|
588 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
589 |
|
---|
590 | =head1 COPYRIGHT
|
---|
591 |
|
---|
592 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
593 | described in the file C<COPYING> included with the distribution.
|
---|
594 |
|
---|
595 | =cut
|
---|
596 |
|
---|
597 |
|
---|
598 | 1;
|
---|