| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# $Id$ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# system::os brik |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
package Metabrik::System::Os; |
|
7
|
1
|
|
|
1
|
|
1118
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1410
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
|
13
|
|
|
|
|
|
|
return { |
|
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
|
15
|
|
|
|
|
|
|
tags => [ qw(unstable uname linux freebsd distribution) ], |
|
16
|
|
|
|
|
|
|
author => 'GomoR ', |
|
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
|
18
|
|
|
|
|
|
|
attributes => { |
|
19
|
|
|
|
|
|
|
_uname => [ qw(INTERNAL) ], |
|
20
|
|
|
|
|
|
|
}, |
|
21
|
|
|
|
|
|
|
commands => { |
|
22
|
|
|
|
|
|
|
name => [ ], |
|
23
|
|
|
|
|
|
|
release => [ ], |
|
24
|
|
|
|
|
|
|
version => [ ], |
|
25
|
|
|
|
|
|
|
hostname => [ ], |
|
26
|
|
|
|
|
|
|
arch => [ ], |
|
27
|
|
|
|
|
|
|
distribution => [ ], |
|
28
|
|
|
|
|
|
|
is => [ qw(os) ], |
|
29
|
|
|
|
|
|
|
is_ubuntu => [ ], |
|
30
|
|
|
|
|
|
|
is_debian => [ ], |
|
31
|
|
|
|
|
|
|
is_kali => [ ], |
|
32
|
|
|
|
|
|
|
is_linux => [ ], |
|
33
|
|
|
|
|
|
|
is_freebsd => [ ], |
|
34
|
|
|
|
|
|
|
is_centos => [ ], |
|
35
|
|
|
|
|
|
|
my => [ ], |
|
36
|
|
|
|
|
|
|
}, |
|
37
|
|
|
|
|
|
|
require_modules => { |
|
38
|
|
|
|
|
|
|
'POSIX' => [ ], |
|
39
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub brik_init { |
|
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname(); |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->_uname({ |
|
50
|
|
|
|
|
|
|
name => $sysname, |
|
51
|
|
|
|
|
|
|
hostname => $nodename, |
|
52
|
|
|
|
|
|
|
release => $release, |
|
53
|
|
|
|
|
|
|
version => $version, |
|
54
|
|
|
|
|
|
|
arch => $machine, |
|
55
|
|
|
|
|
|
|
}); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return $self->SUPER::brik_init(@_); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub name { |
|
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self->_uname->{name}; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub release { |
|
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->_uname->{release}; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub version { |
|
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self->_uname->{version}; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub hostname { |
|
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $self->_uname->{hostname}; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub arch { |
|
85
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $x86_64 = [ qw(x86 64) ]; |
|
88
|
0
|
|
|
|
|
|
my $x86_32 = [ qw(x86 32) ]; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Possible other values: |
|
91
|
|
|
|
|
|
|
# ia64, pc98, powerpc, powerpc64, sparc64 |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $arch = $self->_uname->{arch}; |
|
94
|
0
|
0
|
0
|
|
|
|
if ($arch eq 'amd64' || $arch eq 'x86_64') { |
|
|
|
0
|
0
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $x86_64; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
elsif ($arch eq 'i386' || $arch eq 'i685') { |
|
98
|
0
|
|
|
|
|
|
return $x86_32; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
else { |
|
101
|
|
|
|
|
|
|
# We don't know, return raw result |
|
102
|
0
|
|
|
|
|
|
return [ $arch ]; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Error |
|
106
|
0
|
|
|
|
|
|
return; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub distribution { |
|
110
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $name = $self->name; |
|
113
|
0
|
|
|
|
|
|
my $release = $self->release; |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
if ($name eq 'Linux') { |
|
116
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
|
117
|
0
|
|
|
|
|
|
$ft->as_array(1); |
|
118
|
0
|
|
|
|
|
|
$ft->strip_crlf(1); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Ubuntu case |
|
121
|
0
|
0
|
0
|
|
|
|
if (-f '/etc/lsb-release') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
my $lines = $ft->read('/etc/lsb-release') |
|
123
|
|
|
|
|
|
|
or return $self->log->error("distribution: read failed"); |
|
124
|
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my %info = (); |
|
126
|
0
|
|
|
|
|
|
for my $line (@$lines) { |
|
127
|
0
|
|
|
|
|
|
my ($k, $v) = split('\s*=\s*', $line); |
|
128
|
0
|
|
|
|
|
|
$info{$k} = $v; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$info{DISTRIB_DESCRIPTION} =~ s/^"//; |
|
132
|
0
|
|
|
|
|
|
$info{DISTRIB_DESCRIPTION} =~ s/"$//; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
return { |
|
135
|
|
|
|
|
|
|
name => $info{DISTRIB_ID}, # Ubuntu |
|
136
|
|
|
|
|
|
|
release => $info{DISTRIB_RELEASE}, # 14.10 |
|
137
|
|
|
|
|
|
|
codename => $info{DISTRIB_CODENAME}, # utopic |
|
138
|
|
|
|
|
|
|
description => $info{DISTRIB_DESCRIPTION}, # Ubuntu 14.10 |
|
139
|
0
|
|
|
|
|
|
}; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
elsif (-f '/etc/debian_version' && -f '/etc/os-release') { |
|
142
|
0
|
0
|
|
|
|
|
my $lines = $ft->read('/etc/os-release') |
|
143
|
|
|
|
|
|
|
or return $self->log->error("distribution: read failed"); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# /etc/os-release |
|
146
|
|
|
|
|
|
|
# PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)" |
|
147
|
|
|
|
|
|
|
# NAME="Raspbian GNU/Linux" |
|
148
|
|
|
|
|
|
|
# VERSION_ID="8" |
|
149
|
|
|
|
|
|
|
# VERSION="8 (jessie)" |
|
150
|
|
|
|
|
|
|
# ID=raspbian |
|
151
|
|
|
|
|
|
|
# ID_LIKE=debian |
|
152
|
|
|
|
|
|
|
# HOME_URL="http://www.raspbian.org/" |
|
153
|
|
|
|
|
|
|
# SUPPORT_URL="http://www.raspbian.org/RaspbianForums" |
|
154
|
|
|
|
|
|
|
# BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs" |
|
155
|
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my %info = (); |
|
157
|
0
|
|
|
|
|
|
for my $line (@$lines) { |
|
158
|
0
|
|
|
|
|
|
my ($k, $v) = split('\s*=\s*', $line); |
|
159
|
0
|
|
|
|
|
|
$v =~ s{^"*}{}; |
|
160
|
0
|
|
|
|
|
|
$v =~ s{"*$}{}; |
|
161
|
0
|
|
|
|
|
|
$info{$k} = $v; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
$lines = $ft->read('/etc/debian_version') |
|
165
|
|
|
|
|
|
|
or return $self->log->error("distribution: read2 failed"); |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $release = '0.0'; |
|
168
|
0
|
0
|
|
|
|
|
if (@$lines > 0) { |
|
169
|
0
|
|
|
|
|
|
chomp($release = $lines->[0]); |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my ($codename) = $info{VERSION} =~ m{\(([^)]+)\)}; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
return { |
|
175
|
|
|
|
|
|
|
name => 'Debian', # Debian |
|
176
|
|
|
|
|
|
|
full_name => $info{NAME}, # Raspbian GNU/Linux |
|
177
|
|
|
|
|
|
|
release => $release, # 8.0 |
|
178
|
|
|
|
|
|
|
codename => $codename, # jessis |
|
179
|
|
|
|
|
|
|
description => $info{PRETTY_NAME}, # Raspbian GNU/Linux 8 (jessie) |
|
180
|
0
|
|
|
|
|
|
}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
elsif (-f '/etc/centos-release') { |
|
183
|
|
|
|
|
|
|
return { |
|
184
|
0
|
|
|
|
|
|
name => 'CentOS', # CentOS |
|
185
|
|
|
|
|
|
|
}; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
elsif (-f '/etc/redhat-release') { |
|
188
|
|
|
|
|
|
|
return { |
|
189
|
0
|
|
|
|
|
|
name => 'RedHat', # RedHat |
|
190
|
|
|
|
|
|
|
}; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
elsif (-f '/etc/os-release') { |
|
193
|
|
|
|
|
|
|
return { |
|
194
|
0
|
|
|
|
|
|
name => 'OpenSUSE', # OpenSUSE |
|
195
|
|
|
|
|
|
|
}; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
elsif (-f '/etc/arch-release') { |
|
198
|
|
|
|
|
|
|
return { |
|
199
|
0
|
|
|
|
|
|
name => 'ArchLinux', # ArchLinux |
|
200
|
|
|
|
|
|
|
}; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
elsif (-f '/etc/manjaro-release') { |
|
203
|
|
|
|
|
|
|
return { |
|
204
|
0
|
|
|
|
|
|
name => 'Manjaro Linux', # Manjaro Linux |
|
205
|
|
|
|
|
|
|
}; |
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
elsif (-f '/etc/gentoo-release') { |
|
208
|
|
|
|
|
|
|
return { |
|
209
|
0
|
|
|
|
|
|
name => 'Gentoo', # Gentoo |
|
210
|
|
|
|
|
|
|
}; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Default |
|
215
|
|
|
|
|
|
|
return { |
|
216
|
0
|
|
|
|
|
|
name => $name, |
|
217
|
|
|
|
|
|
|
release => $release, |
|
218
|
|
|
|
|
|
|
codename => $name, |
|
219
|
|
|
|
|
|
|
description => "$name $release", |
|
220
|
|
|
|
|
|
|
}; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub is { |
|
224
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
225
|
0
|
|
|
|
|
|
my ($os) = @_; |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is', $os) or return; |
|
228
|
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
$os = lc($os); |
|
230
|
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
my $name = $self->name or return; |
|
232
|
0
|
0
|
|
|
|
|
my $distrib = $self->distribution or return; |
|
233
|
0
|
0
|
|
|
|
|
if (exists($distrib->{name})) { |
|
234
|
0
|
|
|
|
|
|
my $this = lc($distrib->{name}); |
|
235
|
0
|
0
|
|
|
|
|
if ($this eq $os) { |
|
236
|
0
|
|
|
|
|
|
return 1; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
} |
|
239
|
0
|
0
|
|
|
|
|
if (defined($name)) { |
|
240
|
0
|
|
|
|
|
|
my $this = lc($name); |
|
241
|
0
|
0
|
|
|
|
|
if ($this eq $os) { |
|
242
|
0
|
|
|
|
|
|
return 1; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
return 0; |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub is_ubuntu { |
|
250
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
251
|
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
|
return $self->is('ubuntu'); |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub is_debian { |
|
256
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
257
|
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
return $self->is('debian'); |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub is_kali { |
|
262
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
263
|
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
return $self->is('kali'); |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub is_linux { |
|
268
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
269
|
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
|
return $self->is('linux'); |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub is_freebsd { |
|
274
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
275
|
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
return $self->is('freebsd'); |
|
277
|
|
|
|
|
|
|
} |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
sub is_centos { |
|
280
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
281
|
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
return $self->is('centos'); |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
sub my { |
|
286
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
287
|
|
|
|
|
|
|
|
|
288
|
0
|
0
|
|
|
|
|
my $name = $self->name or return; |
|
289
|
0
|
0
|
|
|
|
|
my $distrib = $self->distribution or return; |
|
290
|
0
|
0
|
|
|
|
|
if (exists($distrib->{name})) { |
|
291
|
0
|
|
|
|
|
|
my $this = lc($distrib->{name}); |
|
292
|
0
|
|
|
|
|
|
return $this; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
0
|
0
|
|
|
|
|
if (defined($name)) { |
|
295
|
0
|
|
|
|
|
|
my $this = lc($name); |
|
296
|
0
|
|
|
|
|
|
return $this; |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
|
|
299
|
0
|
|
|
|
|
|
return 'undef'; |
|
300
|
|
|
|
|
|
|
} |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
1; |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
__END__ |