From c4b60e47a2ba75043ffa2e20af680e56f37efc84 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 4 Mar 2013 20:47:11 +0000 Subject: [PATCH] allow netdisco-deploy to work from git and without localenv --- Netdisco/bin/netdisco-daemon | 3 +-- Netdisco/bin/netdisco-deploy | 37 ++++++++++++++++++++++++++++++------ Netdisco/bin/netdisco-web | 3 +-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Netdisco/bin/netdisco-daemon b/Netdisco/bin/netdisco-daemon index e42bc152..c8426cff 100755 --- a/Netdisco/bin/netdisco-daemon +++ b/Netdisco/bin/netdisco-daemon @@ -5,11 +5,10 @@ use warnings FATAL => 'all'; use FindBin; FindBin::again(); - our $home; -# try really hard to find a localenv if one isn't already in place. BEGIN { + # try really hard to find a localenv if one isn't already in place. $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); eval "use Daemon::Control"; diff --git a/Netdisco/bin/netdisco-deploy b/Netdisco/bin/netdisco-deploy index b76b1def..afc70fac 100755 --- a/Netdisco/bin/netdisco-deploy +++ b/Netdisco/bin/netdisco-deploy @@ -1,11 +1,36 @@ #!/usr/bin/env perl use FindBin; -use lib "$FindBin::Bin/../lib"; -use App::Netdisco; +FindBin::again(); +our $home; +BEGIN { + # try really hard to find a localenv if one isn't already in place. + $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); + eval "use Daemon::Control"; + + if ($@) { + use File::Spec; + my $localenv = File::Spec->catfile($FindBin::RealBin, 'localenv'); + exec($localenv, $0, @ARGV) if -f $localenv; + $localenv = File::Spec->catfile($home, 'perl5', 'bin', 'localenv'); + exec($localenv, $0, @ARGV) if -f $localenv; + die "Sorry, can't find libs required for App::Netdisco.\n"; + } +} + +BEGIN { + # stuff useful locations into @INC + use Path::Class; + unshift @INC, + dir($FindBin::RealBin)->parent->subdir('lib')->stringify, + dir($FindBin::RealBin, 'lib')->stringify; +} + +use App::Netdisco; use Dancer ':script'; use Dancer::Plugin::DBIC 'schema'; +info "App::Netdisco version $App::Netdisco::VERSION loaded."; use 5.010_000; use Term::UI; @@ -14,7 +39,6 @@ use Term::ReadLine; use Archive::Extract; use HTTP::Tiny; use Try::Tiny; -use Path::Class 'file'; =head1 netdisco-deploy @@ -31,7 +55,8 @@ Internet, and update the OUI table in the database. Hence Internet access is required to run the script. Similarly the latest Netdisco MIB bundle is also downloaded, placed into the -user's home directory, and Netdisco reconfigured for its use. +user's home directory (or C<$ENV{NETDISCO_HOME}>), and Netdisco reconfigured +for its use. =cut @@ -109,12 +134,12 @@ sub deploy_oui { sub deploy_mibs { my $url = 'http://downloads.sourceforge.net/project/netdisco/netdisco-mibs/latest-snapshot/netdisco-mibs-snapshot.tar.gz'; - my $file = file($ENV{HOME}, 'netdisco-mibs-snapshot.tar.gz'); + my $file = file($home, 'netdisco-mibs-snapshot.tar.gz'); my $resp = HTTP::Tiny->new->mirror($url, $file); if ($resp->{success}) { my $ae = Archive::Extract->new(archive => $file, type => 'tgz'); - $ae->extract(to => $ENV{HOME}); + $ae->extract(to => $home); unlink $file; } diff --git a/Netdisco/bin/netdisco-web b/Netdisco/bin/netdisco-web index 7b698fed..ee9ebc38 100755 --- a/Netdisco/bin/netdisco-web +++ b/Netdisco/bin/netdisco-web @@ -5,11 +5,10 @@ use warnings FATAL => 'all'; use FindBin; FindBin::again(); - our $home; -# try really hard to find a localenv if one isn't already in place. BEGIN { + # try really hard to find a localenv if one isn't already in place. $home = ($ENV{NETDISCO_HOME} || $ENV{HOME}); eval "use Daemon::Control";