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 (56 lines) | stat: -rw-r--r-- 1,972 bytes parent folder | download | duplicates (3)
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
package Ocsinventory::Agent::Backend::OS::MacOS::Packages;

use strict;
use warnings;

sub check {
    my $params = shift;
    my $common = $params->{common};

    return unless $common->can_load("Mac::SysProfile");
    # Do not run an package inventory if there is the --nosoftware parameter
    return if ($params->{config}->{nosoftware});

    1;
}

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

    my $profile = Mac::SysProfile->new();
    my $data = $profile->gettype('SPApplicationsDataType'); # might need to check version of darwin

    return unless($data && ref($data) eq 'ARRAY');

    # for each app, normalize the information, then add it to the inventory stack
    foreach my $app (@$data){
        #my $a = $apps->{$app};
        my $path = $app->{'path'} ? $app->{'path'} : 'unknown';

        #Exlude from /System/Library/xxx : you can save 150 entries
        if ($path =~ /^\/System\/Library\//) {next;}
        if ($path =~ /\/System\/Library\// and $path =~ /^\/Volumes\//) {next;}
        
        #Exlude from xxx/Library/Printers/xxx : you can save 10 entries because a printer is an app
        if ($path =~ /\/Library\/Printers\//) {next;}

        my $kind = $app->{'runtime_environment'} ? $app->{'runtime_environment'} : 'UNKNOWN';
        my $store = $app->{'app_store'} ? $app->{'app_store'} : 'no';
        my $comments = 'AppStore: '.$store.' - Type: '.$kind.' ';
        my $bits = $app->{'has64BitIntelCode'} ? $app->{'has64BitIntelCode'} : 'unknown';
        if ($bits eq 'yes') {$bits = '64';} else {$bits = '32';}
        
        $common->addSoftware({
            'NAME'        => $app->{'_name'},
            'VERSION'     => $app->{'version'} || 'unknown',
            'COMMENTS'    => $comments,
            'PUBLISHER'   => $app->{'info'} || 'unknown',
            'INSTALLDATE' => $app->{'lastModified'},
            'FOLDER'      => $path,
            'BITSWIDTH'   => $bits,
        });
    }
}

1;