Ignore:
Timestamp:
Oct 21, 2009, 2:11:13 PM (15 years ago)
Author:
Bruno Cornec
Message:
  • function pb_distro_get now also uses the external pb.conf conf file. Nothing is hard coded anymore in the Distribution.pm which will make porting and adaptations by users much easier.
File:
1 edited

Legend:

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

    r867 r869  
    6767Mandriva, Open SuSE and Fedora have all the same "rpm" type of build system. Ubuntu ad Debian have the same "deb" type of build system.
    6868And "fc" is the extension generated for all Fedora packages (Version will be added by pb).
     69All these information are stored in an external configuration file typically at /etc/pb/pb.conf
    6970
    7071When 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.
     
    8889my $drmdot = "false";
    8990
    90 # If we don't know which distribution we're on, then guess it
    91 ($ddir,$dver) = pb_distro_get() if ((not defined $ddir) || (not defined $dver));
    92 
    93 # Initialize arch
    94 $darch=pb_get_arch() if (not defined $darch);
    95 
    9691# Adds conf file for distribution description
    9792# the location of the conf file is finalyzed at install time
    9893# depending whether we deal with package install or tar file install
    9994pb_conf_add("CCCC/pb.conf");
     95
     96# If we don't know which distribution we're on, then guess it
     97($ddir,$dver) = pb_distro_get() if ((not defined $ddir) || (not defined $dver));
     98
     99# Initialize arch
     100$darch=pb_get_arch() if (not defined $darch);
     101
    100102my ($osfamily,$ostype,$osupd,$ossuffix,$osnover,$osremovedotinver) = pb_conf_get("osfamily","ostype","osupd","ossuffix","osnover","osremovedotinver");
    101103
     
    138140sub pb_distro_get {
    139141
    140 my $base="/etc";
    141 
    142 # List of files that unambiguously indicates what distro we have
    143 my %single_rel_files = (
    144 # Tested
    145     'gentoo'            =>  'gentoo-release',       # >= 1.6
    146     'slackware'         =>  'slackware-version',    # >= 10.2
    147     'mandriva'          =>  'mandriva-release',     # >=2006.0
    148     'mandrakelinux'     =>  'mandrakelinux-release',# = 10.2
    149     'fedora'            =>  'fedora-release',       # >= 4
    150     'vmware'            =>  'vmware-release',       # >= 3
    151     'sles'              =>  'sles-release',         # Doesn't exist as of 10
    152     'asianux'           =>  'asianux-release',      # >= 2.2
    153 # Untested
    154     'knoppix'           =>  'knoppix_version',      #
    155     'yellowdog'         =>  'yellowdog-release',    #
    156     'esmith'            =>  'e-smith-release',      #
    157     'turbolinux'        =>  'turbolinux-release',   #
    158     'blackcat'          =>  'blackcat-release',     #
    159     'aurox'             =>  'aurox-release',        #
    160     'annvix'            =>  'annvix-release',       #
    161     'cobalt'            =>  'cobalt-release',       #
    162     'redflag'           =>  'redflag-release',      #
    163     'ark'               =>  'ark-release',          #
    164     'pld'               =>  'pld-release',          #
    165     'nld'               =>  'nld-release',          #
    166     'lfs'               =>  'lfs-release',          #
    167     'mk'                =>  'mk-release',           #
    168     'conectiva'         =>  'conectiva-release',    #
    169     'immunix'           =>  'immunix-release',      #
    170     'tinysofa'          =>  'tinysofa-release',     #
    171     'trustix'           =>  'trustix-release',      #
    172     'adamantix'         =>  'adamantix_version',    #
    173     'yoper'             =>  'yoper-release',        #
    174     'arch'              =>  'arch-release',         #
    175     'libranet'          =>  'libranet_version',     #
    176     'valinux'           =>  'va-release',           #
    177     'yellowdog'         =>  'yellowdog-release',    #
    178     'ultrapenguin'      =>  'ultrapenguin-release', #
    179     );
    180 
    181 # List of files that ambiguously indicates what distro we have
    182 my %ambiguous_rel_files = (
    183     'mandrake'          =>  'mandrake-release',     # <= 10.1
    184     'debian'            =>  'debian_version',       # >= 3.1
    185     'suse'              =>  'SuSE-release',         # >= 10.0
    186     'redhat'            =>  'redhat-release',       # >= 7.3
    187     'lsb'               =>  'lsb-release',          # ???
    188     );
    189 
    190 # Should have the same keys as the previous one.
    191 # If ambiguity, which other distributions should be checked
    192 my %distro_similar = (
    193     'mandrake'          => ['mandrake', 'mandrakelinux'],
    194     'debian'            => ['debian', 'ubuntu'],
    195     'suse'              => ['suse', 'sles', 'opensuse'],
    196     'redhat'            => ['redhat', 'rhel', 'centos', 'mandrake', 'vmware'],
    197     'lsb'               => ['ubuntu', 'lsb'],
    198     );
    199 
    200 my %distro_match = (
    201 # Tested
    202     'gentoo'                => '.* version (.+)',
    203     'slackware'             => 'S[^ ]* (.+)$',
    204 # There should be no ambiguity between potential ambiguous distro
    205     'mandrakelinux'         => 'Mandrakelinux release (.+) \(',
    206     'mandrake'              => 'Mandr[^ ]* release (.+) \(',
    207     'mandriva'              => 'Mandr[^ ]* [^ ]* release (.+) \(',
    208     'fedora'                => 'Fedora .*release (\d+) \(',
    209     'vmware'                => 'VMware ESX Server (\d+) \(',
    210     'rhel'                  => 'Red Hat (?:Enterprise Linux|Linux Advanced Server) .*release ([0-9.]+).* \(',
    211     'centos'                => '.*CentOS .*release ([0-9]).* ',
    212     'redhat'                => 'Red Hat Linux release (.+) \(',
    213     'sles'                  => 'SUSE .* Enterprise Server (\d+) \(',
    214     'suse'                  => 'SUSE LINUX (\d.+) \(',
    215     'opensuse'              => 'openSUSE (\d.+) \(',
    216     'asianux'               => 'Asianux (?:Server|release) ([0-9]).* \(',
    217     'lsb'                   => '.*[^Ubunt].*\nDISTRIB_RELEASE=(.+)',
    218 # Ubuntu includes a /etc/debian_version file that creates an ambiguity with debian
    219 # So we need to look at distros in reverse alphabetic order to treat ubuntu always first
    220     'ubuntu'                => '.*Ubuntu.*\nDISTRIB_RELEASE=(.+)',
    221     'debian'                => '(.+)',
    222 # Not tested
    223     'arch'                  => '.* ([0-9.]+) .*',
    224     'redflag'               => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)',
    225 );
     142# 1: List of files that unambiguously indicates what distro we have
     143# 2: List of files that ambiguously indicates what distro we have
     144# 3: Should have the same keys as the previous one. If ambiguity, which other distributions should be checked
     145# 4: Matching Rg. Expr to detect distribution and version
     146my ($single_rel_files, $ambiguous_rel_files,$distro_similar,$distro_match) = pb_conf_get("osrelfile","osrelambfile","osambiguous","osrelexpr");
    226147
    227148my $release;
     
    231152# that way we reduce the choice
    232153my ($d,$r);
    233 while (($d,$r) = each %single_rel_files) {
    234     if (-f "$base/$r" && ! -l "$base/$r") {
    235         my $tmp=pb_get_content("$base/$r");
     154while (($d,$r) = each %$single_rel_files) {
     155    if (-f "$r" && ! -l "$r") {
     156        my $tmp=pb_get_content("$r");
    236157        # Found the only possibility.
    237158        # Try to get version and return
    238         if (defined ($distro_match{$d})) {
    239             ($release) = $tmp =~ m/$distro_match{$d}/m;
     159        if (defined ($distro_match->{$d})) {
     160            ($release) = $tmp =~ m/$distro_match->{$d}/m;
    240161        } else {
    241162            print STDERR "Unable to find $d version in $r\n";
     
    250171# Ubuntu includes a /etc/debian_version file that creates an ambiguity with debian
    251172# So we need to look at distros in reverse alphabetic order to treat ubuntu always first via lsb
    252 foreach $d (reverse keys %ambiguous_rel_files) {
    253     $r = $ambiguous_rel_files{$d};
    254     if (-f "$base/$r" && !-l "$base/$r") {
     173foreach $d (reverse keys %$ambiguous_rel_files) {
     174    $r = $ambiguous_rel_files->{$d};
     175    if (-f "$r" && !-l "$r") {
    255176        # Found one possibility.
    256177        # Get all distros concerned by that file
    257         my $tmp=pb_get_content("$base/$r");
     178        my $tmp=pb_get_content("$r");
    258179        my $found = 0;
    259         my $ptr = $distro_similar{$d};
     180        my $ptr = $distro_similar->{$d};
    260181        pb_log(2,"amb: ".Dumper($ptr)."\n");
    261182        $release = "unknown";
    262         foreach my $dd (@$ptr) {
     183        foreach my $dd (split(/,/,$ptr)) {
    263184            pb_log(2,"check $dd\n");
    264185            # Try to check pattern
    265             if (defined $distro_match{$dd}) {
    266                 pb_log(2,"cmp: $distro_match{$dd} - vs - $tmp\n");
    267                 ($release) = $tmp =~ m/$distro_match{$dd}/m;
     186            if (defined $distro_match->{$dd}) {
     187                pb_log(2,"cmp: $distro_match->{$dd} - vs - $tmp\n");
     188                ($release) = $tmp =~ m/$distro_match->{$dd}/m;
    268189                if ((defined $release) && ($release ne "unknown")) {
    269190                    $distro = $dd;
Note: See TracChangeset for help on using the changeset viewer.