forked from ddurieux/fusioninventory-agent-task-snmpquery
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.PL
134 lines (107 loc) · 4.17 KB
/
Makefile.PL
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use inc::Module::Install;
use English qw(-no_match_vars);
name 'FusionInventory-Agent-Task-NetInventory';
include 'Module::AutoInstall';
abstract 'FusionInventory Agent Network Inventory task';
version_from 'lib/FusionInventory/Agent/Task/NetInventory.pm';
license 'gpl';
perl_version '5.008';
eval {
# check for fusioninventory-agent setup
require File::Which;
my $agent = File::Which::which('fusioninventory-agent');
die "fusioninventory-agent not found in PATH\n" unless $agent;
my $command = 'fusioninventory-agent --setup 2>/dev/null';
open (my $handle, '-|', $command) or die "can't run $command: $ERRNO";
while (my $line = <$handle>) {
chomp $line;
next unless $line =~ /(\S+): (\S+)/;
$MY::setup{uc($1)} = $2;
}
close $handle;
die "agent too old (minimal version 2.2.0 required)\n" if $CHILD_ERROR;
# add agent lib directory to @INC;
unshift @INC, "$MY::setup{DATADIR}/lib";
};
warn "unable to check fusioninventory-agent setup: $EVAL_ERROR" if $EVAL_ERROR;
# mandatory dependencies
requires 'threads' => undef;
requires 'Net::IP' => undef;
requires 'Net::SNMP' => undef;
requires 'XML::TreePP' => '0.26';
requires 'FusionInventory::Agent::SNMP' => '1.1';
requires 'FusionInventory::Agent::Threads' => undef;
install_script 'fusioninventory-netinventory';
WriteAll;
# substitute prefix everywhere
$MY::variables{DATADIR} =~ s/\$\(PREFIX\)/$MY::variables{PREFIX}/;
print <<EOF;
Installation summary
--------------------
prefix: $MY::variables{PREFIX}
constant data installation directory: $MY::variables{DATADIR}
EOF
package MY;
use English qw(-no_match_vars);
our %setup;
our %variables;
# force a perl-independant prefix for everything but perl modules
sub constants {
my ($self) = @_;
# for some reason, initialising variables from the global scope doesn't work
%variables = (
PREFIX => '/usr/local',
INSTALLSCRIPT => '$(PREFIX)/bin',
INSTALLSITESCRIPT => '$(PREFIX)/bin',
INSTALLVENDORSCRIPT => '$(PREFIX)/bin',
INSTALLLIB => '$(DATADIR)/lib',
INSTALLSITELIB => '$(DATADIR)/lib',
INSTALLVENDORLIB => '$(DATADIR)/lib',
INSTALLMAN1DIR => '$(PREFIX)/share/man/man1',
INSTALLSITEMAN1DIR => '$(PREFIX)/share/man/man1',
INSTALLVENDORMAN1DIR => '$(PREFIX)/share/man/man1',
INSTALLMAN3DIR => '$(PREFIX)/share/man/man3',
INSTALLSITEMAN3DIR => '$(PREFIX)/share/man/man3',
INSTALLVENDORMAN3DIR => '$(PREFIX)/share/man/man3',
DATADIR => '$(PREFIX)/share/fusioninventory',
FULLPERLRUN => '$(FULLPERL) -I$(DATADIR)/lib'
);
# allow variables detected from agent setup to override defaults
foreach my $name (keys %variables) {
$variables{$name} = $setup{$name} if $setup{$name};
}
# allow variables defined on command line to override defaults
foreach my $name (keys %variables) {
$variables{$name} = $self->{ARGS}->{$name} if $self->{ARGS}->{$name};
}
# get all standard MM variables definitions, and override them if needed
my @code = split(/\n/, $self->SUPER::constants(@_));
foreach my $line (@code) {
# Skip comments
next if $line =~ /^\s*#/;
# Skip everything which isn't a var assignment.
next unless $line =~ /^([A-Z0-9_]+) =/;
my $name = $1;
# skip variables we're not interested
next unless $variables{$name};
$line = "$name = $variables{$name}";
}
# add out own variables
foreach my $name (qw/DATADIR/) {
push @code, "$name = $variables{$name}";
}
return join("\n", @code);
}
# ensure binaries get modified to use configured directories (on Unix only)
sub installbin {
my ($self) = @_;
my $installbin = $self->SUPER::installbin(@_);
return $installbin if $OSNAME eq 'MSWin32';
$installbin =~ s|\t\$\(FIXIN\) (.*)\n|\t\$(FIXIN) $1\n\t\$(FINALIZE) $1\n|g;
$installbin .= <<'EOF';
FINALIZE = $(ABSPERLRUN) -pi \
-e 's|use lib .*|use lib "$(DATADIR)/lib";|;' \
--
EOF
return $installbin;
}