1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
package Ocsinventory::Agent::Backend::OS::Linux::Distro::OSRelease;
use warnings;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read ("/etc/os-release")
}
sub run {
my $name;
my $version;
my $description;
my $params = shift;
my $common = $params->{common};
open V, "/etc/os-release" or warn;
foreach (<V>) {
next if /^#/;
$name = $1 if (/^NAME="?([^"]+)"?/);
$version = $1 if (/^VERSION_ID="?([^"]+)"?/);
$description=$1 if (/^PRETTY_NAME="?([^"]+)"?/);
}
close V;
chomp($name);
# Debian version number is set in/etc/debian_version file
if (-r "/etc/debian_version") {
if (`uname -v` =~ /debian/i) {
open V, "/etc/debian_version" or warn;
foreach (<V>) {
$version = $1 if ($_ =~ /^(\d+.*)/);
}
close V;
chomp($version);
}
}
# CentOS exact version number is set in /etc/centos-release file
if (-r "/etc/centos-release") {
open V, "/etc/centos-release" or warn;
foreach ($description=<V>) {
$version = $1 if ($_ =~ /(\d+\.\d+)./g);
}
close V;
chomp($version);
chomp($description);
}
$common->setHardware({
OSNAME => "$name $version",
OSVERSION => $version,
OSCOMMENTS => $description,
});
}
1;
|