Skip to content

Commit

Permalink
adapt to new agent setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Rousse authored and Guillaume Rousse committed Jan 9, 2012
1 parent 3e07b7a commit a18bfdf
Showing 1 changed file with 81 additions and 2 deletions.
83 changes: 81 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

use inc::Module::Install;
use English qw(-no_match_vars);
use File::Which;

name 'FusionInventory-Agent-Task-ESX';
include 'Module::AutoInstall';
Expand All @@ -9,12 +9,91 @@ license 'gpl';
version_from 'lib/FusionInventory/Agent/Task/ESX.pm';
perl_version '5.008';

# check for fusioninventory-agent setup
my $agent = 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;

# mandatory dependencies
requires 'FusionInventory::Agent' => 2.2.0;
requires 'JSON' => undef;

test_requires 'Test::Exception' => undef;

install_script 'fusioninventory-esx';

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;

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',
INSTALLLIB => '$(DATADIR)/lib',
INSTALLSITELIB => '$(DATADIR)/lib',
INSTALLVENDORLIB => '$(DATADIR)/lib',
INSTALLMAN3DIR => '$(PREFIX)/share/man/man3',
INSTALLSITEMAN3DIR => '$(PREFIX)/share/man/man3',
INSTALLVENDORMAN3DIR => '$(PREFIX)/share/man/man3',
DATADIR => '$(PREFIX)/share/fusioninventory'
);

# 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);
}

0 comments on commit a18bfdf

Please sign in to comment.