- Timestamp:
- Jul 31, 2007, 7:24:50 PM (18 years ago)
- Location:
- devel/pb
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb.pl
r22 r23 299 299 300 300 # Get the running distro to build on 301 my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init(); 302 print $LOG "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1); 301 303 302 304 foreach my $pkg (@pkgs) { -
devel/pb/lib/distro.pm
r22 r23 7 7 8 8 use strict; 9 use LinuxDistribution qw (distribution_name distribution_version);10 9 11 10 sub distro_init { 12 11 13 my $ddir = shift ;14 my $dver = shift ;12 my $ddir = shift || undef; 13 my $dver = shift || undef; 15 14 my $dfam = "unknown"; 16 15 my $dtype = "unknown"; … … 18 17 19 18 # If we don't know which distribution we're on, then guess it 20 $ddir = distribution_name() if (not defined $ddir); 21 $dver = distribution_version() if (not defined $dver); 19 ($ddir,$dver) = get_distro() if ((not defined $ddir) || (not defined $dver)); 22 20 23 21 # There shold be unicity of names between ddir dfam and dtype … … 83 81 return($ddir, $dver, $dfam, $dtype, $dsuf); 84 82 } 83 84 sub get_distro { 85 86 # Cf: http://linuxmafia.com/faq/Admin/release-files.html 87 # Ideas taken from 88 # http://search.cpan.org/~kerberus/Linux-Distribution-0.14/lib/Linux/Distribution.pm 89 90 my $base="/etc"; 91 92 # List of files that unambiguously indicates what distro we have 93 my %single_rel_files = ( 94 # Tested 95 'gentoo' => 'gentoo-release', # >= 1.6 96 'debian' => 'debian_version', # >= 3.1 97 'slackware' => 'slackware-version', # >= 10.2 98 'mandriva' => 'mandriva-release', # >=2006.0 99 'fedora' => 'fedora-release', # >= 4 100 'sles' => 'sles-release', # ??? 101 # Untested 102 'knoppix' => 'knoppix_version', # 103 'yellowdog' => 'yellowdog-release', # 104 'esmith' => 'e-smith-release', # 105 'turbolinux' => 'turbolinux-release', # 106 'blackcat' => 'blackcat-release', # 107 'aurox' => 'aurox-release', # 108 'annvix' => 'annvix-release', # 109 'cobalt' => 'cobalt-release', # 110 'redflag' => 'redflag-release', # 111 'ark' => 'ark-release', # 112 'pld' => 'pld-release', # 113 'nld' => 'nld-release', # 114 'lfs' => 'lfs-release', # 115 'mk' => 'mk-release', # 116 'conectiva' => 'conectiva-release', # 117 'immunix' => 'immunix-release', # 118 'tinysofa' => 'tinysofa-release', # 119 'trustix' => 'trustix-release', # 120 'adamantix' => 'adamantix_version', # 121 'yoper' => 'yoper-release', # 122 'arch' => 'arch-release', # 123 'libranet' => 'libranet_version', # 124 'valinux' => 'va-release', # 125 'yellowdog' => 'yellowdog-release', # 126 'ultrapenguin' => 'ultrapenguin-release', # 127 ); 128 129 # List of files that ambiguously indicates what distro we have 130 my %ambiguous_rel_files = ( 131 'mandrake' => 'mandrake-release', # >= 10.1 132 'suse' => 'SuSE-release', # >= 10.0 133 'redhat' => 'redhat-release', # >= 7.3 134 'lsb' => 'lsb-release', # ??? 135 ); 136 137 # Should have the same keys as the previous one. 138 # If ambiguity, which other distributions should be checked 139 my %distro_similar = ( 140 'mandrake' => ('mandrake'), 141 'suse' => ('suse', 'sles'), 142 'redhat' => ('redhat', 'rhel', 'centos', 'mandrake'), 143 'lsb' => ('ubuntu', 'debian', 'lsb') 144 ) 145 146 my %distro_match = ( 147 # Tested 148 'gentoo' => '.* version (.+)', 149 'debian' => '([^/]+)[/]*.*', 150 'slackware' => '[^ ]* (.+) [^ ]*', 151 # There should be no ambiguity between potential ambiguous distro 152 'mandrake' => 'Mandr[^ ]* release (.+) .*', 153 'mandriva' => 'Mandr[^ ]* [^ ]* release (.+) .*', 154 'fedora' => 'Fedora .*release (\d+) .*', 155 'rhel' => '.* Enterprise .*release (.+) \(', 156 'centos' => '.*CentOS .*release (.+) .*', 157 'redhat' => 'Red Hat Linux release (.+) .*', 158 'sles' => '.* Enterprise .*\nVERSION = (.+)', 159 'suse' => '.* [^Enterpis] .*\nVERSION = (.+)', 160 'lsb' => '.*[^Ubunt].*\nDISTRIB_RELEASE=(.+)', 161 'ubuntu' => '.*Ubuntu.*\nDISTRIB_RELEASE=(.+)', 162 # Not tested 163 'arch' => '.* ([0-9.]+) .*', 164 'redflag' => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)', 165 ); 166 167 my $release; 168 my $distro; 169 170 # Begin to test presence of non-amiguous files 171 # that way we reduce the choice 172 while (my ($d,$r) each %single_rel_files) { 173 if (-f "$base/$r" && !-l "$base/$r"){ 174 $release=get_content("$base/$r"); 175 # Found the only possibility. 176 # Try to get version and return 177 if (defined ($distro_match{$d}) { 178 $release =~ m/$distro_match{$d}/m; 179 } else { 180 print STDERR "Unable to find $d's version in $r\n"; 181 print STDERR "Please report to the maintainer bruno_at_project-builder.org\n"; 182 $release = "unknown"; 183 } 184 return($d,$release); 185 } 186 } 187 188 while (my ($d,$r) each %ambiguous_rel_files) { 189 if (-f "$base/$r" && !-l "$base/$r"){ 190 # Found one possibility. 191 # Get all distros concerned by that file 192 $release=get_content("$base/$r"); 193 $found = 0; 194 foreach $dd (@$distro_similar{$d}) { 195 # Try to check pattern 196 if ((defined ($distro_match{$dd}) && ($release =~ /$distro_match{$dd}/m) { 197 $release =~ m/$distro_match{$dd}/m; 198 $distro = $dd; 199 $found = 1; 200 } 201 } 202 if ($found == 0) { 203 print STDERR "Unable to find $d's version in $r\n"; 204 print STDERR "Please report to the maintainer bruno_at_project-builder.org\n"; 205 $release = "unknown"; 206 } else { 207 return($distro,$release); 208 } 209 } 210 } 211 return("unknown","unknown"); 212 213 sub get_content { 214 215 my $file=shift; 216 217 my $bkp = $/; 218 undef $/; 219 open(R,$file) || die "Unable to open $file: $!"; 220 my $content=<R>; 221 close(R); 222 $/ = $bkp; 223 return($content); 224 } 85 225 1;
Note:
See TracChangeset
for help on using the changeset viewer.