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