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