[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 |
|
---|
[757] | 91 | # Initialize arch
|
---|
| 92 | $arch=pb_get_arch() if (not defined $arch);
|
---|
| 93 |
|
---|
[171] | 94 | # There should be unicity of names between ddir dfam and dtype
|
---|
[13] | 95 | # In case of duplicate, bad things can happen
|
---|
[11] | 96 | if (($ddir =~ /debian/) ||
|
---|
| 97 | ($ddir =~ /ubuntu/)) {
|
---|
[13] | 98 | $dfam="du";
|
---|
[11] | 99 | $dtype="deb";
|
---|
| 100 | $dsuf=".$ddir$dver";
|
---|
[622] | 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 ";
|
---|
[11] | 104 | } elsif ($ddir =~ /gentoo/) {
|
---|
[13] | 105 | $dfam="gen";
|
---|
[11] | 106 | $dtype="ebuild";
|
---|
[226] | 107 | $dver="nover";
|
---|
| 108 | $dsuf=".$ddir";
|
---|
[622] | 109 | $dupd="sudo emerge ";
|
---|
[11] | 110 | } elsif ($ddir =~ /slackware/) {
|
---|
[13] | 111 | $dfam="slack";
|
---|
[11] | 112 | $dtype="tgz";
|
---|
| 113 | $dsuf=".$dfam$dver";
|
---|
| 114 | } elsif (($ddir =~ /suse/) ||
|
---|
| 115 | ($ddir =~ /sles/)) {
|
---|
[13] | 116 | $dfam="novell";
|
---|
[11] | 117 | $dtype="rpm";
|
---|
| 118 | $dsuf=".$ddir$dver";
|
---|
[652] | 119 | $dupd="export TERM=linux ; export PATH=\$PATH:/sbin:/usr/sbin ; sudo yast2 -i ";
|
---|
[11] | 120 | } elsif (($ddir =~ /redhat/) ||
|
---|
| 121 | ($ddir =~ /rhel/) ||
|
---|
| 122 | ($ddir =~ /fedora/) ||
|
---|
[146] | 123 | ($ddir =~ /vmware/) ||
|
---|
[714] | 124 | ($ddir =~ /asianux/) ||
|
---|
[11] | 125 | ($ddir =~ /centos/)) {
|
---|
[13] | 126 | $dfam="rh";
|
---|
[11] | 127 | $dtype="rpm";
|
---|
| 128 | my $dver1 = $dver;
|
---|
| 129 | $dver1 =~ s/\.//;
|
---|
[620] | 130 |
|
---|
| 131 | # By defaut propose yum
|
---|
| 132 | my $opt = "";
|
---|
| 133 | if ($arch eq "x86_64") {
|
---|
| 134 | $opt="--exclude=*.i?86";
|
---|
| 135 | }
|
---|
[622] | 136 | $dupd="sudo yum clean all; sudo yum update ; sudo yum -y $opt install ";
|
---|
[11] | 137 | if ($ddir =~ /fedora/) {
|
---|
| 138 | $dsuf=".fc$dver1";
|
---|
| 139 | } elsif ($ddir =~ /redhat/) {
|
---|
| 140 | $dsuf=".rh$dver1";
|
---|
[620] | 141 | $dupd="unknown";
|
---|
[714] | 142 | } elsif ($ddir =~ /asianux/) {
|
---|
| 143 | $dsuf=".asianux$dver1";
|
---|
[146] | 144 | } elsif ($ddir =~ /vmware/) {
|
---|
| 145 | $dsuf=".vwm$dver1";
|
---|
[620] | 146 | $dupd="unknown";
|
---|
[11] | 147 | } else {
|
---|
[683] | 148 | # older versions of rhel ran up2date
|
---|
| 149 | if ((($dver eq "2.1") || ($dver eq "3") || ($dver eq "4")) && ($ddir eq "rhel")) {
|
---|
[622] | 150 | $dupd="sudo up2date -y ";
|
---|
[620] | 151 | }
|
---|
[11] | 152 | $dsuf=".$ddir$dver1";
|
---|
| 153 | }
|
---|
| 154 | } elsif (($ddir =~ /mandrake/) ||
|
---|
[171] | 155 | ($ddir =~ /mandrakelinux/) ||
|
---|
[11] | 156 | ($ddir =~ /mandriva/)) {
|
---|
[13] | 157 | $dfam="md";
|
---|
[11] | 158 | $dtype="rpm";
|
---|
[171] | 159 | if ($ddir =~ /mandrakelinux/) {
|
---|
| 160 | $ddir = "mandrake";
|
---|
| 161 | }
|
---|
[11] | 162 | if ($ddir =~ /mandrake/) {
|
---|
| 163 | my $dver1 = $dver;
|
---|
| 164 | $dver1 =~ s/\.//;
|
---|
| 165 | $dsuf=".mdk$dver1";
|
---|
| 166 | } else {
|
---|
| 167 | $dsuf=".mdv$dver";
|
---|
| 168 | }
|
---|
[622] | 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 ";
|
---|
[11] | 172 | } elsif ($ddir =~ /freebsd/) {
|
---|
[13] | 173 | $dfam="bsd";
|
---|
[11] | 174 | $dtype="port";
|
---|
| 175 | my $dver1 = $dver;
|
---|
| 176 | $dver1 =~ s/\.//;
|
---|
| 177 | $dsuf=".$dfam$dver1";
|
---|
| 178 | } else {
|
---|
| 179 | $dfam="unknown";
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[756] | 182 | return($ddir, $dver, $dfam, $dtype, $dsuf, $dupd, $arch);
|
---|
[11] | 183 | }
|
---|
[23] | 184 |
|
---|
[756] | 185 | =item B<pb_distro_get>
|
---|
[395] | 186 |
|
---|
[756] | 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.
|
---|
[395] | 188 |
|
---|
[756] | 189 | On my home machine it would currently report ("mandriva","2009.0").
|
---|
[395] | 190 |
|
---|
| 191 | =cut
|
---|
| 192 |
|
---|
[622] | 193 | sub pb_distro_get {
|
---|
[23] | 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
|
---|
[171] | 203 | 'mandrakelinux' => 'mandrakelinux-release',# = 10.2
|
---|
[23] | 204 | 'fedora' => 'fedora-release', # >= 4
|
---|
[146] | 205 | 'vmware' => 'vmware-release', # >= 3
|
---|
[181] | 206 | 'sles' => 'sles-release', # Doesn't exist as of 10
|
---|
[714] | 207 | 'asianux' => 'asianux-release', # >= 2.2
|
---|
[23] | 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 = (
|
---|
[171] | 238 | 'mandrake' => 'mandrake-release', # <= 10.1
|
---|
[391] | 239 | 'debian' => 'debian_version', # >= 3.1
|
---|
[23] | 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 = (
|
---|
[171] | 248 | 'mandrake' => ['mandrake', 'mandrakelinux'],
|
---|
[391] | 249 | 'debian' => ['debian', 'ubuntu'],
|
---|
[185] | 250 | 'suse' => ['suse', 'sles', 'opensuse'],
|
---|
[146] | 251 | 'redhat' => ['redhat', 'rhel', 'centos', 'mandrake', 'vmware'],
|
---|
[423] | 252 | 'lsb' => ['ubuntu', 'lsb'],
|
---|
[24] | 253 | );
|
---|
[23] | 254 |
|
---|
| 255 | my %distro_match = (
|
---|
| 256 | # Tested
|
---|
| 257 | 'gentoo' => '.* version (.+)',
|
---|
[24] | 258 | 'slackware' => 'S[^ ]* (.+)$',
|
---|
[23] | 259 | # There should be no ambiguity between potential ambiguous distro
|
---|
[171] | 260 | 'mandrakelinux' => 'Mandrakelinux release (.+) \(',
|
---|
[24] | 261 | 'mandrake' => 'Mandr[^ ]* release (.+) \(',
|
---|
| 262 | 'mandriva' => 'Mandr[^ ]* [^ ]* release (.+) \(',
|
---|
| 263 | 'fedora' => 'Fedora .*release (\d+) \(',
|
---|
[146] | 264 | 'vmware' => 'VMware ESX Server (\d+) \(',
|
---|
[591] | 265 | 'rhel' => 'Red Hat (?:Enterprise Linux|Linux Advanced Server) .*release ([0-9.]+).* \(',
|
---|
[681] | 266 | 'centos' => '.*CentOS .*release ([0-9]).* ',
|
---|
[24] | 267 | 'redhat' => 'Red Hat Linux release (.+) \(',
|
---|
[185] | 268 | 'sles' => 'SUSE .* Enterprise Server (\d+) \(',
|
---|
[188] | 269 | 'suse' => 'SUSE LINUX (\d.+) \(',
|
---|
[185] | 270 | 'opensuse' => 'openSUSE (\d.+) \(',
|
---|
[717] | 271 | 'asianux' => 'Asianux (?:Server|release) ([0-9]).* \(',
|
---|
[23] | 272 | 'lsb' => '.*[^Ubunt].*\nDISTRIB_RELEASE=(.+)',
|
---|
[715] | 273 | # Ubuntu includes a /etc/debian_version file that creates an ambiguity with debian
|
---|
[423] | 274 | # So we need to look at distros in reverse alphabetic order to treat ubuntu always first
|
---|
[23] | 275 | 'ubuntu' => '.*Ubuntu.*\nDISTRIB_RELEASE=(.+)',
|
---|
[391] | 276 | 'debian' => '(.+)',
|
---|
[23] | 277 | # Not tested
|
---|
| 278 | 'arch' => '.* ([0-9.]+) .*',
|
---|
| 279 | 'redflag' => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)',
|
---|
| 280 | );
|
---|
| 281 |
|
---|
| 282 | my $release;
|
---|
| 283 | my $distro;
|
---|
| 284 |
|
---|
[391] | 285 | # Begin to test presence of non-ambiguous files
|
---|
[23] | 286 | # that way we reduce the choice
|
---|
[24] | 287 | my ($d,$r);
|
---|
| 288 | while (($d,$r) = each %single_rel_files) {
|
---|
[171] | 289 | if (-f "$base/$r" && ! -l "$base/$r") {
|
---|
[74] | 290 | my $tmp=pb_get_content("$base/$r");
|
---|
[23] | 291 | # Found the only possibility.
|
---|
| 292 | # Try to get version and return
|
---|
[24] | 293 | if (defined ($distro_match{$d})) {
|
---|
| 294 | ($release) = $tmp =~ m/$distro_match{$d}/m;
|
---|
[23] | 295 | } else {
|
---|
[24] | 296 | print STDERR "Unable to find $d version in $r\n";
|
---|
[23] | 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 |
|
---|
[423] | 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") {
|
---|
[23] | 310 | # Found one possibility.
|
---|
| 311 | # Get all distros concerned by that file
|
---|
[74] | 312 | my $tmp=pb_get_content("$base/$r");
|
---|
[24] | 313 | my $found = 0;
|
---|
| 314 | my $ptr = $distro_similar{$d};
|
---|
[423] | 315 | pb_log(2,"amb: ".Dumper($ptr)."\n");
|
---|
[24] | 316 | $release = "unknown";
|
---|
| 317 | foreach my $dd (@$ptr) {
|
---|
[423] | 318 | pb_log(2,"check $dd\n");
|
---|
[23] | 319 | # Try to check pattern
|
---|
[24] | 320 | if (defined $distro_match{$dd}) {
|
---|
[423] | 321 | pb_log(2,"cmp: $distro_match{$dd} - vs - $tmp\n");
|
---|
[24] | 322 | ($release) = $tmp =~ m/$distro_match{$dd}/m;
|
---|
| 323 | if ((defined $release) && ($release ne "unknown")) {
|
---|
| 324 | $distro = $dd;
|
---|
| 325 | $found = 1;
|
---|
| 326 | last;
|
---|
| 327 | }
|
---|
[23] | 328 | }
|
---|
| 329 | }
|
---|
| 330 | if ($found == 0) {
|
---|
[24] | 331 | print STDERR "Unable to find $d version in $r\n";
|
---|
[23] | 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");
|
---|
[24] | 340 | }
|
---|
[23] | 341 |
|
---|
[621] | 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
|
---|
[756] | 348 | dependencies can be passed as a parameter in which case they are not computed
|
---|
[621] | 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");
|
---|
[623] | 366 | return if ((not defined $deps) || ($deps =~ /^\s*$/));
|
---|
[621] | 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
|
---|
[622] | 391 | return("") if (not defined $dtype);
|
---|
[621] | 392 | if ($dtype eq "rpm") {
|
---|
| 393 | # In RPM this could include files, but we do not handle them atm.
|
---|
| 394 | $regexp = '^BuildRequires:(.*)$';
|
---|
[696] | 395 | } elsif ($dtype eq "deb") {
|
---|
[621] | 396 | $regexp = '^Build-Depends:(.*)$';
|
---|
| 397 | } elsif ($dtype eq "ebuild") {
|
---|
| 398 | $sep = '"'.$/;
|
---|
| 399 | $regexp = '^DEPEND="(.*)"\n'
|
---|
| 400 | } else {
|
---|
| 401 | # No idea
|
---|
[622] | 402 | return("");
|
---|
[621] | 403 | }
|
---|
| 404 | pb_log(2,"regexp: $regexp\n");
|
---|
| 405 |
|
---|
| 406 |
|
---|
| 407 | # Protection
|
---|
[622] | 408 | return("") if (not defined $f);
|
---|
[621] | 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");
|
---|
[681] | 420 | s/$regexp/$1/i;
|
---|
[698] | 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
|
---|
[652] | 425 | s/[><=]+.*,/,/g;
|
---|
| 426 | s/[><=]+.*$//g;
|
---|
[621] | 427 | # Improve string format (remove , and spaces at start, end and in double
|
---|
[652] | 428 | s/,/ /g;
|
---|
[621] | 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");
|
---|
[622] | 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 |
|
---|
[623] | 452 | my $dtype = shift || undef;
|
---|
[622] | 453 | my $deps = shift || undef;
|
---|
| 454 |
|
---|
[623] | 455 | return("") if ((not defined $deps) || ($deps =~ /^\s*$/));
|
---|
[621] | 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);
|
---|
[696] | 462 | } elsif ($dtype eq "deb") {
|
---|
[621] | 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 |
|
---|
[702] | 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$/) {
|
---|
[721] | 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$/) {
|
---|
[702] | 521 | # Yum repo
|
---|
[721] | 522 | pb_system("sudo mv $ENV{'PBTMP'}/$bn /etc/yum.repos.d","Adding yum repository") if (not -f "/etc/yum.repos.d/$bn");
|
---|
[702] | 523 | } elsif ($bn =~ /\.addmedia/) {
|
---|
| 524 | # URPMI repo
|
---|
[721] | 525 | # We should test that it's not already a urpmi repo
|
---|
[702] | 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") {
|
---|
[721] | 531 | if (($bn =~ /\.sources.list$/) && (not -f "/etc/apt/sources.list.d/$bn")) {
|
---|
[711] | 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");
|
---|
[702] | 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 | }
|
---|
[749] | 574 |
|
---|
| 575 |
|
---|
[395] | 576 | =back
|
---|
[23] | 577 |
|
---|
[395] | 578 | =head1 WEB SITES
|
---|
[23] | 579 |
|
---|
[395] | 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 |
|
---|
[11] | 598 | 1;
|
---|