install_deps_from_cpan 2.85 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/perl
use strict;
use warnings;
use CPAN;

sub prep_local_cpan {
Kevin Tew's avatar
Kevin Tew committed
7 8
  my $P = shift || "~"; 

9 10 11 12 13 14 15
  print "WARNING installing local CPAN to '~/lib/perl5' -- type yes <ENTER> to continue\n";
  my $response = <STDIN>;
  chomp $response;
  if ($response ne "yes") {
    die "$response does not match yes";
  }

16 17 18 19 20 21 22 23 24 25
  open(FH, "|cpan");
  print FH "no\n";
  print FH "quit\n";
  close(FH);

  mkdir '~/lib/perl5';
  mkdir '~/share/man/man1';
  mkdir '~/share/man/man3';

  CPAN::Config->load;
Kevin Tew's avatar
Kevin Tew committed
26 27
   
  $CPAN::Config->{'makepl_arg'} = qq[PREFIX=$P/ SITELIBEXP=$P/lib/perl5 LIB=$P/lib/perl5 INSTALLMAN1DIR=$P/share/man/man1 INSTALLMAN3DIR=$P/share/man/man3 INSTALLSITEMAN1DIR=$P/share/man/man1 INSTALLSITEMAN3DIR=$P/share/man/man3];
28
  $CPAN::Config->{'prerequisites_policy'} = q[follow];
29
  $CPAN::Config->{'urllist'} = [q[http://cpan.cs.utah.edu ftp://cpan.cs.utah.edu/pub/CPAN/]];
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  CPAN::Config->commit;
}

sub automate_module_install {
  CPAN::Shell->install('Module::Install');
  system("perl Makefile.PL --defaultdeps");
  system("make");
}

sub install_deps_from_cpan {
  my @deps = qw(
      Mouse
      RPC::XML::Client
      RPC::XML
      Test::More
      Time::Local
      TAP::Harness
      Crypt::X509
      Log::Log4perl
      Data::UUID
      IPC::Run3
      Crypt::SSLeay
52
      Test::Exception
53
      Term::ReadKey
54
      );
55
#Test::Class
56 57 58 59 60 61
#Crypt::SSLeay # required for SSL
#Data::UUID requires user input
#Net::Ping #tests fail, default installed version 2.31 is good enough
  CPAN::Shell->install($_) for(@deps);
}

62 63 64 65 66 67 68 69 70 71 72 73 74 75
sub install_ext_deps_from_cpan {
  my @deps = qw(
      Email::Stuff
      Email::Sender
      Email::Send
      IO::All
      );
#Test::Class
#Crypt::SSLeay # required for SSL
#Data::UUID requires user input
#Net::Ping #tests fail, default installed version 2.31 is good enough
  CPAN::Shell->install($_) for(@deps);
}

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
sub automate_ssh_install {
  my @ssh_math_deps = qw(
      bignum
      Math::BigRat
      Math::BigInt::GMP
      );
  
  my @sshdeps = qw(
      Digest::BubbleBabble
      Crypt::RSA
      Convert::PEM
      Data::Buffer
      );

  my @ssh_modules = qw(
      Net::SSH::Perl
      Net::SFTP
      );

  CPAN::Shell->install($_) for(@ssh_math_deps);
  CPAN::Shell->install($_) for(@sshdeps);
  CPAN::Shell->install($_) for(@ssh_modules);
}

sub main {
101 102 103
  if ((grep {$_ eq '--install_deps' } @ARGV)) { install_deps_from_cpan; exit; }
  if ((grep {$_ eq '--install_ext_deps' } @ARGV)) { install_ext_deps_from_cpan; exit;
  }
104 105 106 107
  if (!(grep {$_ eq '--override' } @ARGV) and -e glob("~/.cpan")) {
    die "NOT installing local CPAN ~/.cpan exists, specify --override to ignore check";
  }

108 109
  prep_local_cpan;
  $ENV{PERL5LIB} = glob('~/lib/perl5');
110

111
  if ($ARGV[0] && $ARGV[0] eq 'MI') {
112
    automate_module_install;  #too complicated for fluxers on FreeBSD
113
    #automate_ssh_install;     #too complicated for fluxers on FreeBSD
114 115 116 117
  }
  else {
    install_deps_from_cpan;
  }
118
}
119 120

main;