line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::Distribution;
|
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
188742
|
use 5.006000;
|
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
242
|
|
4
|
7
|
|
|
7
|
|
32
|
use strict;
|
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
182
|
|
5
|
7
|
|
|
7
|
|
33
|
use warnings;
|
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
7777
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter;
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( distribution_name distribution_version );
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.21';
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $release_files_directory='/etc';
|
16
|
|
|
|
|
|
|
our $standard_release_file = 'lsb-release';
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our %release_files = (
|
19
|
|
|
|
|
|
|
'gentoo-release' => 'gentoo',
|
20
|
|
|
|
|
|
|
'fedora-release' => 'fedora',
|
21
|
|
|
|
|
|
|
'centos-release' => 'centos',
|
22
|
|
|
|
|
|
|
'enterprise-release' => 'oracle enterprise linux',
|
23
|
|
|
|
|
|
|
'turbolinux-release' => 'turbolinux',
|
24
|
|
|
|
|
|
|
'mandrake-release' => 'mandrake',
|
25
|
|
|
|
|
|
|
'mandrakelinux-release' => 'mandrakelinux',
|
26
|
|
|
|
|
|
|
'debian_version' => 'debian',
|
27
|
|
|
|
|
|
|
'debian_release' => 'debian',
|
28
|
|
|
|
|
|
|
'SuSE-release' => 'suse',
|
29
|
|
|
|
|
|
|
'knoppix-version' => 'knoppix',
|
30
|
|
|
|
|
|
|
'yellowdog-release' => 'yellowdog',
|
31
|
|
|
|
|
|
|
'slackware-version' => 'slackware',
|
32
|
|
|
|
|
|
|
'slackware-release' => 'slackware',
|
33
|
|
|
|
|
|
|
'redflag-release' => 'redflag',
|
34
|
|
|
|
|
|
|
'redhat-release' => 'redhat',
|
35
|
|
|
|
|
|
|
'redhat_version' => 'redhat',
|
36
|
|
|
|
|
|
|
'conectiva-release' => 'conectiva',
|
37
|
|
|
|
|
|
|
'immunix-release' => 'immunix',
|
38
|
|
|
|
|
|
|
'tinysofa-release' => 'tinysofa',
|
39
|
|
|
|
|
|
|
'trustix-release' => 'trustix',
|
40
|
|
|
|
|
|
|
'adamantix_version' => 'adamantix',
|
41
|
|
|
|
|
|
|
'yoper-release' => 'yoper',
|
42
|
|
|
|
|
|
|
'arch-release' => 'arch',
|
43
|
|
|
|
|
|
|
'libranet_version' => 'libranet',
|
44
|
|
|
|
|
|
|
'va-release' => 'va-linux',
|
45
|
|
|
|
|
|
|
'pardus-release' => 'pardus',
|
46
|
|
|
|
|
|
|
);
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
our %version_match = (
|
49
|
|
|
|
|
|
|
'gentoo' => 'Gentoo Base System release (.*)',
|
50
|
|
|
|
|
|
|
'debian' => '(.+)',
|
51
|
|
|
|
|
|
|
'suse' => 'VERSION = (.*)',
|
52
|
|
|
|
|
|
|
'fedora' => 'Fedora(?: Core)? release (\d+) \(',
|
53
|
|
|
|
|
|
|
'redflag' => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)',
|
54
|
|
|
|
|
|
|
'redhat' => 'Red Hat(?: Enterprise)? Linux(?: Server)? release (.*) \(',
|
55
|
|
|
|
|
|
|
'oracle enterprise linux' => 'Enterprise Linux Server release (.+) \(',
|
56
|
|
|
|
|
|
|
'slackware' => '^Slackware (.+)$',
|
57
|
|
|
|
|
|
|
'pardus' => '^Pardus (.+)$',
|
58
|
|
|
|
|
|
|
'centos' => '^CentOS(?: Linux)? release (.+)(?:\s\(Final\))',
|
59
|
|
|
|
|
|
|
'scientific' => '^Scientific Linux release (.+) \(',
|
60
|
|
|
|
|
|
|
);
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if ($^O ne 'linux') {
|
64
|
|
|
|
|
|
|
# require Carp;
|
65
|
|
|
|
|
|
|
# Carp::croak('you are trying to use a linux specific module on a different OS');
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub new {
|
69
|
9
|
|
|
9
|
0
|
135
|
my %self = (
|
70
|
|
|
|
|
|
|
'DISTRIB_ID' => '',
|
71
|
|
|
|
|
|
|
'DISTRIB_RELEASE' => '',
|
72
|
|
|
|
|
|
|
'DISTRIB_CODENAME' => '',
|
73
|
|
|
|
|
|
|
'DISTRIB_DESCRIPTION' => '',
|
74
|
|
|
|
|
|
|
'release_file' => '',
|
75
|
|
|
|
|
|
|
'pattern' => ''
|
76
|
|
|
|
|
|
|
);
|
77
|
|
|
|
|
|
|
|
78
|
9
|
|
|
|
|
41
|
return bless \%self;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub distribution_name {
|
82
|
8
|
|
66
|
8
|
0
|
98
|
my $self = shift || new();
|
83
|
8
|
|
|
|
|
15
|
my $distro;
|
84
|
8
|
100
|
|
|
|
47
|
if ($distro = $self->_get_lsb_info()){
|
85
|
2
|
50
|
|
|
|
27
|
return $distro if ($distro);
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
6
|
|
|
|
|
18
|
foreach (qw(enterprise-release fedora-release)) {
|
89
|
11
|
100
|
66
|
|
|
201
|
if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){
|
90
|
2
|
50
|
33
|
|
|
65
|
if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){
|
91
|
2
|
|
|
|
|
10
|
$self->{'DISTRIB_ID'} = $release_files{$_};
|
92
|
2
|
|
|
|
|
6
|
$self->{'release_file'} = $_;
|
93
|
2
|
|
|
|
|
9
|
return $self->{'DISTRIB_ID'};
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
45
|
foreach (keys %release_files) {
|
99
|
64
|
100
|
66
|
|
|
966
|
if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){
|
100
|
4
|
50
|
33
|
|
|
115
|
if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){
|
101
|
4
|
100
|
|
|
|
19
|
if ( $release_files{$_} eq 'redhat' ) {
|
102
|
3
|
|
|
|
|
9
|
foreach my $rhel_deriv ('centos','scientific',) {
|
103
|
5
|
|
|
|
|
17
|
$self->{'pattern'} = $version_match{$rhel_deriv};
|
104
|
5
|
|
|
|
|
9
|
$self->{'release_file'}='redhat-release';
|
105
|
5
|
100
|
|
|
|
18
|
if ( $self->_get_file_info() ) {
|
106
|
2
|
|
|
|
|
5
|
$self->{'DISTRIB_ID'} = $rhel_deriv;
|
107
|
2
|
|
|
|
|
6
|
$self->{'release_file'} = $_;
|
108
|
2
|
|
|
|
|
11
|
return $self->{'DISTRIB_ID'};
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
}
|
111
|
1
|
|
|
|
|
3
|
$self->{'pattern'}='';
|
112
|
|
|
|
|
|
|
}
|
113
|
2
|
|
|
|
|
6
|
$self->{'release_file'} = $_;
|
114
|
2
|
|
|
|
|
5
|
$self->{'DISTRIB_ID'} = $release_files{$_};
|
115
|
2
|
|
|
|
|
9
|
return $self->{'DISTRIB_ID'};
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
}
|
119
|
|
|
|
|
|
|
undef
|
120
|
0
|
|
|
|
|
0
|
}
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub distribution_version {
|
123
|
7
|
|
66
|
7
|
0
|
5208
|
my $self = shift || new();
|
124
|
7
|
|
|
|
|
17
|
my $release;
|
125
|
7
|
100
|
|
|
|
29
|
return $release if ($release = $self->_get_lsb_info('DISTRIB_RELEASE'));
|
126
|
6
|
50
|
|
|
|
1120
|
if (! $self->{'DISTRIB_ID'}){
|
127
|
0
|
0
|
|
|
|
0
|
$self->distribution_name() or die 'No version because no distro.';
|
128
|
|
|
|
|
|
|
}
|
129
|
6
|
|
|
|
|
38
|
$self->{'pattern'} = $version_match{$self->{'DISTRIB_ID'}};
|
130
|
6
|
|
|
|
|
41
|
$release = $self->_get_file_info();
|
131
|
6
|
|
|
|
|
35
|
$self->{'DISTRIB_RELEASE'} = $release;
|
132
|
6
|
|
|
|
|
541
|
return $release;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _get_lsb_info {
|
136
|
15
|
|
|
15
|
|
28
|
my $self = shift;
|
137
|
15
|
|
100
|
|
|
89
|
my $field = shift || 'DISTRIB_ID';
|
138
|
15
|
|
|
|
|
32
|
my $tmp = $self->{'release_file'};
|
139
|
15
|
100
|
|
|
|
300
|
if ( -r "$release_files_directory/" . $standard_release_file ) {
|
140
|
3
|
|
|
|
|
5
|
$self->{'release_file'} = $standard_release_file;
|
141
|
3
|
|
|
|
|
8
|
$self->{'pattern'} = $field . '=(.+)';
|
142
|
3
|
|
|
|
|
10
|
my $info = $self->_get_file_info();
|
143
|
3
|
50
|
|
|
|
17
|
if ($info){
|
144
|
3
|
|
|
|
|
7
|
$self->{$field} = $info;
|
145
|
3
|
|
|
|
|
15
|
return $info
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
}
|
148
|
12
|
|
|
|
|
28
|
$self->{'release_file'} = $tmp;
|
149
|
12
|
|
|
|
|
23
|
$self->{'pattern'} = '';
|
150
|
12
|
|
|
|
|
56
|
undef;
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _get_file_info {
|
154
|
14
|
|
|
14
|
|
25
|
my $self = shift;
|
155
|
14
|
50
|
|
|
|
580
|
open my $fh, '<', "$release_files_directory/" . $self->{'release_file'} or die 'Cannot open file: '.$release_files_directory.'/' . $self->{'release_file'};
|
156
|
14
|
|
|
|
|
29
|
my $info = '';
|
157
|
14
|
|
|
|
|
24
|
local $_;
|
158
|
14
|
|
|
|
|
298
|
while (<$fh>){
|
159
|
17
|
|
|
|
|
40
|
chomp $_;
|
160
|
17
|
|
|
|
|
316
|
($info) = $_ =~ m/$self->{'pattern'}/;
|
161
|
17
|
100
|
|
|
|
289
|
return "\L$info" if $info;
|
162
|
|
|
|
|
|
|
}
|
163
|
3
|
|
|
|
|
40
|
undef;
|
164
|
|
|
|
|
|
|
}
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1;
|
167
|
|
|
|
|
|
|
__END__
|