File: Deb.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 (70 lines) | stat: -rw-r--r-- 2,298 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package Ocsinventory::Agent::Backend::OS::Generic::Packaging::Deb;

use strict;
use warnings;
use File::Basename;
use File::stat;


sub check { 
    my $params = shift;
    my $common = $params->{common};
    $common->can_run("dpkg") }

sub run {
    my $params = shift;
    my $common = $params->{common};
    my $logger = $params->{logger};
    my $size;
    my $key;
    my $value;
    my %statinfo;
    my @infos;

    # List of files from which installation date will be extracted
    my @listfile=glob('"/var/lib/dpkg/info/*.list"');

    foreach my $file_list (@listfile){
        my $stat=stat($file_list);
        my ($year,$month,$day,$hour,$min,$sec)=(localtime($stat->mtime))[5,4,3,2,1,0];
        $value=sprintf "%02d/%02d/%02d %02d:%02d:%02d",($year+1900),$month,$day,$hour,$min,$sec;
        $key=fileparse($file_list, ".list");
        $key =~ s/(\s+):.+/$1/;
        $statinfo{$key}=$value;
    }
  
    # Use binary:Package to see all packages (amd64,deb) with dpkg > 1162
    my $ver=`dpkg --list dpkg | tail -n 1 | cut -d" " -f14`;
    $ver=~chomp($ver);
    my $vers=$common->convertVersion($ver,4);

    if ($vers > 1162 ){
        @infos=`dpkg-query --show --showformat='\${binary:Package}---\${Architecture}---\${Version}---\${Installed-Size}---\${Status}---\${Homepage}---\${Description}\n'`;
    } else {
        @infos=`dpkg-query --show --showformat='\${Package}---\${Architecture}---\${Version}---\${Installed-Size}---\${Status}---\${Homepage}---\${Description}\n'`;
    }
    foreach my $line (@infos) {
        next if $line =~ /^ /;
        chomp $line;
        my @deb=split("---",$line);
        if ($deb[4] && $deb[4] !~ / installed/) {
            $logger->debug("Skipping $deb[0] package as not installed, status='$deb[4]'");
            next;
        }
        $key=$deb[0];
        if (exists $statinfo{$key}) {
            $common->addSoftware ({
                'NAME'          => $deb[0],
                'ARCHITECTURE'  => $deb[1],
                'VERSION'       => $deb[2],
                'FILESIZE'      => ( $deb[3] || 0 ) * 1024,
                'PUBLISHER'     => $deb[5],
                'INSTALLDATE'   => $statinfo{$key},
                'COMMENTS'      => $deb[6],
                'FROM'          => 'deb'
            });
        }
    }
}

1;