File: OSRelease.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (62 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (2)
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;