Apache-Logmonster

 view release on metacpan or  search on metacpan

bin/install_deps.pl  view on Meta::CPAN

#!/usr/bin/perl

# by Matt Simerson & Phil Nadeau
# circa 2008, but based in installer in Mail::Toaster dating back to the 20th century

# v1.3 - 2012-10-23
#      - added apt-get support
#      - added app install support

use strict;
use warnings;

our $VERSION = 1.3;

use CPAN;
use English qw( -no_match_vars );

my $deps = {
    'modules' => [
        { module => 'Date::Format'      , info => { port => 'TimeDate' } },
        { module => 'Params::Validate'  , info => {} },
        { module => 'Mail::Send'        , info => { port => 'Mail::Tools' }  },
        { module => 'Regexp::Log'       , info => {} },
#       { module => 'Mail::Toaster'     , info => {} },
#       { module => 'Provision::Unix'   , info => {} },
    ],
    'apps' => [
#        { app => 'expat'         , info => { port => 'expat2',  dport=>'expat2' } },
#        { app => 'gettext'       , info => { port => 'gettext', dport=>'gettext'} },
#        { app => 'gmake'         , info => { port => 'gmake',   dport=>'gmake'  } },
    ]
};

$EUID == 0 or die "You will have better luck if you run me as root.\n";

# this causes problems when CPAN is not configured.
#$ENV{PERL_MM_USE_DEFAULT} = 1;       # supress CPAN prompts

$ENV{FTP_PASSIVE} = 1;        # for FTP behind NAT/firewalls

my @failed;
foreach ( @{ $deps->{apps} } ) {
    my $name = $_->{app} or die 'missing app name';
    install_app( $name, $_->{info} );
};

foreach ( @{ $deps->{modules} } ) {
    my $module = $_->{module} or die 'missing module name';
    my $info   = $_->{info};
    my $version = $info->{version} || '';
    print "checking for $module $version\n";

    eval "use $module $version";
    next if ! $EVAL_ERROR;
    next if $info->{ships_with} && $info->{ships_with} eq 'perl';

    install_module( $module, $info, $version );
    eval "use $module $version";
    if ($EVAL_ERROR) {
        push @failed, $module;
    }
}

if ( scalar @failed > 0 ) {
    print "The following modules failed installation:\n";
    print join( "\n", @failed );
    print "\n";
}

exit;

sub install_app {
    my ( $app, $info) = @_;

    if ( lc($OSNAME) eq 'darwin' ) {
        install_app_darwin($app, $info );
    }
    elsif ( lc($OSNAME) eq 'freebsd' ) {
        install_app_freebsd($app, $info );
    }
    elsif ( lc($OSNAME) eq 'linux' ) {
        install_app_linux( $app, $info );
    };

};

sub install_app_darwin {
    my ($app, $info ) = @_;

    my $port = $info->{dport} || $app;

    if ( ! -x '/opt/local/bin/port' ) {
        print "MacPorts is not installed! Consider installing it.\n";
        return;
    } 

    system "/opt/local/bin/port install $port" 



( run in 0.992 second using v1.01-cache-2.11-cpan-6aa56a78535 )