| Line 1... |
Line 1... |
| 1 |
#!/usr/bin/env perl
|
1 |
#!/usr/bin/env perl
|
| 2 |
use warnings;
|
2 |
use warnings;
|
| 3 |
use strict;
|
3 |
use strict;
|
| 4 |
|
4 |
|
| 5 |
# Description: Get software packages installed on IPFire router
|
5 |
use version ; our $VERSION = 'v1.0.0';
|
| 6 |
|
6 |
|
| 7 |
our $VERSION = '1.3';
|
- |
|
| 8 |
|
- |
|
| 9 |
# IPFire software module for sysinfo client
|
7 |
# Template for modules to be used in sysinfo
|
| 10 |
# Author: R. W. Rodolico
|
8 |
# Author: R. W. Rodolico
|
| 11 |
# Date: 2016-04-08
|
9 |
# Date: 2025-04-02
|
| 12 |
|
10 |
#
|
| 13 |
# gets information on software on systems with dpkg on them (Debian)
|
11 |
# Enter some information about system here
|
| - |
|
12 |
#
|
| - |
|
13 |
# Revision History
|
| - |
|
14 |
#
|
| - |
|
15 |
# 20250402 v4.0.0 Rodolico
|
| - |
|
16 |
# Modified for v4 of sysinfo_client, using extended tests for modules, files used and operating systems
|
| - |
|
17 |
# Underlying code remains unchanged
|
| - |
|
18 |
#
|
| 14 |
|
19 |
|
| 15 |
# find our location and use it for searching for libraries
|
20 |
# find our location and use it for searching for libraries. library.pm must be in the same directory as the calling script
|
| - |
|
21 |
# or, if run interactively, in the parent of the modules
|
| 16 |
BEGIN {
|
22 |
BEGIN {
|
| 17 |
use FindBin;
|
23 |
use FindBin;
|
| 18 |
use File::Spec;
|
24 |
use File::Spec;
|
| 19 |
use lib File::Spec->catdir($FindBin::Bin);
|
25 |
# prepend the bin directory and its parent
|
| 20 |
eval( 'use library;' ); die "Could not find library.pm in the code directory\n" if $@;
|
26 |
use lib File::Spec->catdir($FindBin::Bin), File::Spec->catdir("$FindBin::Bin/..");
|
| 21 |
eval( 'use Data::Dumper;' );
|
27 |
eval( 'use library;' );
|
| - |
|
28 |
die sprintf( "Could not find library.pm in %s, INC is %s\n", __FILE__, join( "\n", @INC ) ) if $@;
|
| 22 |
}
|
29 |
}
|
| 23 |
|
30 |
|
| - |
|
31 |
#####
|
| 24 |
# check for valid OS.
|
32 |
##### Change these to match your needs
|
| - |
|
33 |
#####
|
| - |
|
34 |
|
| - |
|
35 |
# Make this a list of all the modules we are going to use. You can replace undef with the version you need, if you like
|
| - |
|
36 |
my $modulesList = {
|
| 25 |
exit 1 unless &checkOS( { 'linux' => undef );
|
37 |
'Data::Dumper' => undef,
|
| - |
|
38 |
};
|
| 26 |
|
39 |
|
| 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
|
40 |
# hash of commands that are needed for the system. key is the name of the command and, in some cases, the value will become
|
| 28 |
# script returns a 2
|
41 |
# the full path (from which or where)
|
| 29 |
#foreach my $command ( 'sysctl', 'df' ) {
|
42 |
my $commandsList = {
|
| - |
|
43 |
'dpkg' => undef,
|
| - |
|
44 |
'grep' => undef,
|
| - |
|
45 |
};
|
| - |
|
46 |
|
| 30 |
# exit 2 unless &validCommandOnSystem( $command );
|
47 |
# list of operating systems this module can be used on.
|
| - |
|
48 |
my $osList = {
|
| - |
|
49 |
# 'mswin32' => undef,
|
| - |
|
50 |
# 'freebsd' => undef,
|
| - |
|
51 |
'linux' => undef,
|
| 31 |
#}
|
52 |
};
|
| 32 |
|
53 |
|
| - |
|
54 |
# the category the return data should go into. See sysinfo for a list
|
| - |
|
55 |
my $CATEGORY = 'software';
|
| 33 |
|
56 |
|
| - |
|
57 |
#####
|
| - |
|
58 |
##### End of required
|
| - |
|
59 |
#####
|
| - |
|
60 |
|
| - |
|
61 |
# some variables needed for our system
|
| - |
|
62 |
my $errorPrepend = 'error: in ' . __FILE__; # this is prepended to any error messages
|
| - |
|
63 |
my @out; # temporary location for each line of output
|
| - |
|
64 |
|
| - |
|
65 |
# Try to load the modules we need. If we can not, then make a list of missing modules for error message.
|
| - |
|
66 |
for my $module ( keys %$modulesList ) {
|
| - |
|
67 |
eval ( "use $module;" );
|
| - |
|
68 |
push @out, "$errorPrepend Could not load $module" if $@;
|
| - |
|
69 |
}
|
| 34 |
|
70 |
|
| - |
|
71 |
if ( ! @out && ! checkOS ( $osList ) ) { # check if we are on an acceptible operating system
|
| 35 |
exit unless -d '/opt/pakfire';
|
72 |
push @out, "$errorPrepend Invalid Operating System";
|
| - |
|
73 |
}
|
| - |
|
74 |
if ( !@out && ! validCommandOnSystem ( $commandsList ) ) {
|
| - |
|
75 |
push @out, "$errorPrepend Can not find some commands needed";
|
| - |
|
76 |
}
|
| - |
|
77 |
if ( !@out ) { # we made it, we have everything, so do the processing
|
| - |
|
78 |
#####
|
| - |
|
79 |
##### Your code starts here. Remember to push all output onto @out
|
| - |
|
80 |
#####
|
| - |
|
81 |
|
| 36 |
my $CATEGORY = 'software';
|
82 |
if ( -d '/opt/pakfire' ) {
|
| 37 |
my $pakfireInstallInfo = '/opt/pakfire/db/installed';
|
83 |
my $pakfireInstallInfo = '/opt/pakfire/db/installed';
|
| 38 |
my $updates = 'meta-core-upgrade-' . `cat /opt/pakfire/db/core/mine`;
|
84 |
my $updates = 'meta-core-upgrade-' . `cat /opt/pakfire/db/core/mine`;
|
| 39 |
chomp $updates;
|
85 |
chomp $updates;
|
| 40 |
|
86 |
|
| 41 |
opendir( my $installsDir, $pakfireInstallInfo ) or die "could not open pakFire installs dir $pakfireInstallInfo: $!\n";
|
87 |
opendir( my $installsDir, $pakfireInstallInfo ) or warn "could not open pakFire installs dir $pakfireInstallInfo: $!\n";
|
| 42 |
my @files = grep { ! /^\./ && -f "$pakfireInstallInfo/$_" } readdir( $installsDir );
|
88 |
my @files = grep { ! /^\./ && -f "$pakfireInstallInfo/$_" } readdir( $installsDir );
|
| 43 |
closedir $installsDir;
|
89 |
closedir $installsDir;
|
| 44 |
|
90 |
|
| 45 |
foreach my $thisPackage ( @files ) {
|
91 |
foreach my $thisPackage ( @files ) {
|
| 46 |
next if $thisPackage =~ m/meta-core-upgrade/ && $thisPackage ne $updates;
|
92 |
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";
|
93 |
open PACKAGE, "<$pakfireInstallInfo/$thisPackage" or warn "could not open package file $pakfireInstallInfo/$thisPackage: $!\n";
|
| 48 |
my %packageInfo;
|
94 |
my %packageInfo;
|
| 49 |
while ( my $line = <PACKAGE> ) {
|
95 |
while ( my $line = <PACKAGE> ) {
|
| 50 |
next unless $line =~ m/:/;
|
96 |
next unless $line =~ m/:/;
|
| 51 |
chomp $line;
|
97 |
chomp $line;
|
| 52 |
my ( $key, $value ) = split( ':', $line );
|
98 |
my ( $key, $value ) = split( ':', $line );
|
| 53 |
$packageInfo{$key} = $value;
|
99 |
$packageInfo{$key} = $value;
|
| - |
|
100 |
}
|
| - |
|
101 |
push @out, "$CATEGORY\t$packageInfo{'Name'}\tversion\t$packageInfo{'ProgVersion'}";
|
| - |
|
102 |
push @out, "$CATEGORY\t$packageInfo{'Name'}\trelease\t$packageInfo{'Release'}";
|
| - |
|
103 |
}
|
| 54 |
}
|
104 |
}
|
| 55 |
print "$CATEGORY\t$packageInfo{'Name'}\tversion\t$packageInfo{'ProgVersion'}\n";
|
- |
|
| - |
|
105 |
|
| - |
|
106 |
#####
|
| 56 |
print "$CATEGORY\t$packageInfo{'Name'}\trelease\t$packageInfo{'Release'}\n";
|
107 |
##### Your code ends here.
|
| - |
|
108 |
#####
|
| 57 |
}
|
109 |
}
|
| - |
|
110 |
|
| - |
|
111 |
# If we are testing from the command line (caller is undef), print the results for debugging
|
| - |
|
112 |
print join( "\n", @out ) . "\n" unless caller;
|
| - |
|
113 |
# called by do, which has a value of the last assignment made, so make the assignment. The equivilent of a return
|
| - |
|
114 |
my $return = join( "\n", @out );
|
| 58 |
1;
|
115 |
|