Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 rodolico 1
#!/usr/bin/env perl
2
use warnings;
26 rodolico 3
use strict;  
2 rodolico 4
 
37 rodolico 5
# Description: Get software packages installed on IPFire router
20 rodolico 6
 
37 rodolico 7
our $VERSION = '1.3';
8
 
20 rodolico 9
# IPFire software module for sysinfo client
10
# Author: R. W. Rodolico
11
# Date:   2016-04-08
12
 
2 rodolico 13
# gets information on software on systems with dpkg on them (Debian)
14
 
251 rodolico 15
# find our location and use it for searching for libraries
2 rodolico 16
BEGIN {
251 rodolico 17
   use FindBin;
18
   use File::Spec;
19
   use lib File::Spec->catdir($FindBin::Bin);
20
   eval( 'use library;' ); die "Could not find library.pm in the code directory\n" if $@;
21
   eval( 'use Data::Dumper;' );
2 rodolico 22
}
23
 
251 rodolico 24
# check for valid OS. 
25
exit 1 unless &checkOS( { 'linux' => undef );
2 rodolico 26
 
251 rodolico 27
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
28
# script returns a 2
29
#foreach my $command ( 'sysctl', 'df' ) {
30
#   exit 2 unless &validCommandOnSystem( $command );
31
#}
32
 
33
 
34
 
7 rodolico 35
exit unless -d '/opt/pakfire';
2 rodolico 36
my $CATEGORY = 'software';
37
my $pakfireInstallInfo = '/opt/pakfire/db/installed';
38
my $updates = 'meta-core-upgrade-' . `cat /opt/pakfire/db/core/mine`;
39
chomp $updates;
40
 
41
opendir( my $installsDir, $pakfireInstallInfo ) or die "could not open pakFire installs dir $pakfireInstallInfo: $!\n";
42
my @files = grep { ! /^\./ && -f "$pakfireInstallInfo/$_" } readdir( $installsDir );
43
closedir $installsDir;
44
 
45
foreach my $thisPackage ( @files ) {
46
   next if $thisPackage =~ m/meta-core-upgrade/ && $thisPackage ne $updates;
47
   open PACKAGE, "<$pakfireInstallInfo/$thisPackage" or die "could not open package file $pakfireInstallInfo/$thisPackage: $!\n";
48
   my %packageInfo;
28 rodolico 49
   while ( my $line = <PACKAGE> ) {
2 rodolico 50
      next unless $line =~ m/:/;
51
      chomp $line;
52
      my ( $key, $value ) = split( ':', $line );
53
      $packageInfo{$key} = $value;
54
   }
55
   print "$CATEGORY\t$packageInfo{'Name'}\tversion\t$packageInfo{'ProgVersion'}\n";
56
   print "$CATEGORY\t$packageInfo{'Name'}\trelease\t$packageInfo{'Release'}\n";
57
}
58
1;