install_deps_from_cpan 3.64 KB
Newer Older
1
#!/usr/bin/perl
Mike Hibler's avatar
Mike Hibler committed
2 3
#
# Copyright (c) 2009 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Mike Hibler's avatar
Mike Hibler committed
23 24
#

25 26 27 28 29
use strict;
use warnings;
use CPAN;

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

32 33 34 35 36 37 38
  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";
  }

39 40 41 42 43 44 45 46 47 48
  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
49 50
   
  $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];
51
  $CPAN::Config->{'prerequisites_policy'} = q[follow];
52
  $CPAN::Config->{'urllist'} = [q[http://cpan.cs.utah.edu ftp://cpan.cs.utah.edu/pub/CPAN/]];
53 54 55 56 57 58 59 60 61 62 63
  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(
64
      Moose
65 66 67 68 69 70 71 72 73 74
      RPC::XML::Client
      RPC::XML
      Test::More
      Time::Local
      TAP::Harness
      Crypt::X509
      Log::Log4perl
      Data::UUID
      IPC::Run3
      Crypt::SSLeay
75
      Test::Exception
76
      Term::ReadKey
77
      );
78
#Test::Class
79 80 81 82 83 84
#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);
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98
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);
}

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
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 {
124 125 126
  if ((grep {$_ eq '--install_deps' } @ARGV)) { install_deps_from_cpan; exit; }
  if ((grep {$_ eq '--install_ext_deps' } @ARGV)) { install_ext_deps_from_cpan; exit;
  }
127 128 129 130
  if (!(grep {$_ eq '--override' } @ARGV) and -e glob("~/.cpan")) {
    die "NOT installing local CPAN ~/.cpan exists, specify --override to ignore check";
  }

131 132
  prep_local_cpan;
  $ENV{PERL5LIB} = glob('~/lib/perl5');
133

134
  if ($ARGV[0] && $ARGV[0] eq 'MI') {
135
    automate_module_install;  #too complicated for fluxers on FreeBSD
136
    #automate_ssh_install;     #too complicated for fluxers on FreeBSD
137 138 139 140
  }
  else {
    install_deps_from_cpan;
  }
141
}
142 143

main;