Ignore:
Timestamp:
Feb 19, 2009, 4:42:22 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • new function pb_distro_setuprepo (addition of repository on the fly at build time)
  • pb_get_dist_param => pb_distro_get_param and placed in Distribution
  • removal of last locale issue
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb-modules/lib/ProjectBuilder/Distribution.pm

    r698 r702  
    1111use Data::Dumper;
    1212use ProjectBuilder::Base;
     13use ProjectBuilder::Conf;
     14use File::Basename;
     15use File::Copy;
    1316
    1417# Inherit from the "Exporter" module which handles exporting functions.
     
    2023 
    2124our @ISA = qw(Exporter);
    22 our @EXPORT = qw(pb_distro_init pb_distro_get pb_distro_installdeps pb_distro_getdeps pb_distro_only_deps_needed);
     25our @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);
    2326
    2427=pod
     
    469472}
    470473
     474=over 4
     475
     476=item B<pb_distro_setuprepo>
     477
     478This function sets up potential additional repository to the build environment
     479
     480=cut
     481
     482sub pb_distro_setuprepo {
     483
     484my $ddir = shift || undef;
     485my $dver = shift;
     486my $darch = shift;
     487my $dtype = shift || undef;
     488
     489my ($addrepo) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","addrepo");
     490return if (not defined $addrepo);
     491
     492my $param = pb_distro_get_param($ddir,$dver,$darch,$addrepo);
     493return if ($param eq "");
     494
     495# Loop on the list of additional repo
     496foreach my $i (split(/,/,$param)) {
     497
     498    my ($scheme, $account, $host, $port, $path) = pb_get_uri($i);
     499    my $bn = basename($i);
     500
     501    # The repo file can be local or remote. download or copy at the right place
     502    if (($scheme eq "ftp") || ($scheme eq "http")) {
     503        pb_system("wget -O $ENV{'PBTMP'}/$bn $i","Donwloading additional repository file $i");
     504    } else {
     505        copy($i,$ENV{'PBTMP'}/$bn);
     506    }
     507
     508    # The repo file can be a real file or a package
     509    if ($dtype eq "rpm") {
     510        if ($bn =~ /\.rpm$/) {
     511        pb_system("sudo rpm -Uvh $ENV{'PBTMP'}/$bn","Adding package to setup repostory");
     512    } elsif ($bn =~ /\.repo$/) {
     513            # Yum repo
     514            pb_system("sudo mv $ENV{'PBTMP'}/$bn /etc/yum.repo.d","Adding yum repository");
     515        } elsif ($bn =~ /\.addmedia/) {
     516            # URPMI repo
     517            pb_system("chmod 755 $ENV{'PBTMP'}/$bn ; sudo $ENV{'PBTMP'}/$bn 2>&1 > /dev/null","Adding urpmi repository");
     518        } else {
     519            pb_log(0,"Unable to deal with repository file $i on rpm distro ! Please report to dev team\n");
     520        }
     521    } elsif ($dtype eq "deb") {
     522        if ($bn =~ /\.sources.list$/) {
     523            my $aptrepo = "";
     524            open(REPO,"$ENV{'PBTMP'}/$bn") || die "Unable to open $ENV{'PBTMP'}/$bn";
     525            while (my $repo=<REPO>) {
     526                my $found = 0;
     527                open(APT,"/etc/apt/sources.list") || die "Unable to open /etc/apt/sources.list";
     528                while (my $apt=<APT>) {
     529                    $found++ if ($apt =~ /$repo/);
     530                }
     531                close(APT);
     532                $aptrepo .= "$repo\n" if ($found == 0);
     533            }
     534            close(REPO);
     535            if ($aptrepo ne "") {
     536                pb_system("sudo echo # Added by project-builder.org >> /etc/apt/sources.list");
     537                pb_system("sudo echo #  >> /etc/apt/sources.list");
     538                pb_system("sudo echo \'$aptrepo\' >> /etc/apt/sources.list");
     539            }
     540            pb_system("sudo apt-get update","Adding apt repository");
     541        } else {
     542            pb_log(0,"Unable to deal with repository file $i on deb distro ! Please report to dev team\n");
     543        }
     544    } else {
     545        pb_log(0,"Unable to deal with repository file $i on that distro ! Please report to dev team\n");
     546    }
     547}
     548return;
     549}
     550
     551=over 4
     552
     553=item B<pb_distro_get_param>
     554
     555This function gets the parameter in the conf file from the most precise tuple up to default
     556
     557=cut
     558
     559sub pb_distro_get_param {
     560
     561my $param = "";
     562my $ddir = shift;
     563my $dver = shift;
     564my $darch = shift;
     565my $opt = shift;
     566
     567if (defined $opt->{"$ddir-$dver-$darch"}) {
     568    $param = $opt->{"$ddir-$dver-$darch"};
     569} elsif (defined $opt->{"$ddir-$dver"}) {
     570    $param = $opt->{"$ddir-$dver"};
     571} elsif (defined $opt->{"$ddir"}) {
     572    $param = $opt->{"$ddir"};
     573} elsif (defined $opt->{"default"}) {
     574    $param = $opt->{"default"};
     575} else {
     576    $param = "";
     577}
     578return($param);
     579
     580}
    471581=back
    472582
Note: See TracChangeset for help on using the changeset viewer.