File: Packages.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 (99 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download | duplicates (4)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Ocsinventory::Agent::Backend::OS::Solaris::Packages;

use strict;
use warnings;

sub check {
      my $params = shift;
     my $common = $params->{common};
      # Do not run an package inventory if there is the --nosoftware parameter
      return if ($params->{config}->{nosoftware});
      $common->can_run("pkginfo") || $common->can_run("pkg");
}

sub run {
     my $params = shift;
     my $common = $params->{common};
     my $chaine ;
     my @tab;

     my $name;
     my $version;
     my $comments;
     my $publisher;

     if ( `uname -r` =~ /5.11/ ) {
     # Solaris 11

     foreach (`pkg info`) {
         if (/^\s*$/) {
             $common->addSoftware({
                 'NAME'          => $name,
                 'VERSION'       => $version,
                 'COMMENTS'      => $comments,
                 'PUBLISHER'     => $publisher,
             });
             $name = '';
             $version = '';
             $comments = '';
             $publisher = '';
         } elsif (/Name:\s+(.+)/) {
             $name = $1;
         } elsif (/Version:\s+(.+)/) {
             $version = $1;
         } elsif (/Publisher:\s+(.+)/) {
             $publisher = $1;
         } elsif (/Summary:\s+(.+)/) {
             $comments = $1;
         }
     }

     } else {
     # Solaris 10 and lower

     foreach (`pkginfo -l`) {
         if (/^\s*$/) {
             $common->addSoftware({
                 'NAME'          => $name,
                 'VERSION'       => $version,
                 'COMMENTS'      => $comments,
                 'PUBLISHER'     => $publisher,
             });
             $name = '';
             $version = '';
             $comments = '';
             $publisher = '';
         } elsif (/PKGINST:\s+(.+)/) {
             $name = $1;
         } elsif (/VERSION:\s+(.+)/) {
             $version = $1;
         } elsif (/VENDOR:\s+(.+)/) {
             $publisher = $1;
         } elsif (/DESC:\s+(.+)/) {
             $comments = $1;
         }
     }
     my $testrep;
     $testrep=0;
     #opendir(DIR,'/var/sis/') || exit ;
     opendir(DIR,'/var/sis/') || ($testrep=1) ;
     if ($testrep==0) {
         foreach (`ls /var/sis/*.SIS`) {
             $chaine= `cat $_` ;
             @tab = split(/;/, $chaine);
             if (/^\/var\/sis\/(\S+).SIS/){
                 $common->addSoftware({
                     'VERSION'       => $tab[2],
                     'NAME'          => $tab[0]." ($1)",
                     'PUBLISHER'     => $tab[1],
                     'COMMENTS'      => $1,
                 });
             }
         }
     }
     closedir(DIR);

     }
}

1;