-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.pl
executable file
·53 lines (43 loc) · 1.34 KB
/
install.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw/$Bin/;
my $path_splitter = $ENV{PATH} =~ /;/ ? qr/[;]/ : qr/[:]/;
my @paths = split /$path_splitter/, $ENV[PATH];
# do we have a make command?
my $make = executable('make');
my $cpanm = executable('cpanm');
my $wget = executable('wget');
my $curl = executable('curl');
my $sudo = executable('sudo') || '';
if ($make) {
# should be able to install this module
exec $cpanm ? "$sudo $cpanm ."
: $wget ? "$wget -O- http://cpanmin.us | $sudo perl - ."
: $curl ? "$curl -L http://cpanmin.us | $sudo perl - ."
: "perl Makefile.PL; make; make install";
}
else {
# no make assume the user can't install Perl modules (eg in git-bash environment)
my ($local) = grep {$_ eq "$ENV{HOME}/bin"} @path;
if ($local) {
# have ~/bin
mkdir $local if !-d $local;
# git-bash has File::Copy (as does Perl 5.8) module assume it's existence
require File::Copy;
File::Copy->import('copy');
opendir my $dirh, "$Bin/bin";
my @bin = grep {/^git/} readdir $dirh;
for my $file (@bin) {
copy("$Bin/bin/$file", "$local/$file");
}
}
}
sub executable {
my ($program) = @_;
for my $dir (@paths) {
next if !-e "$dir/$program";
return "$dir/$program";
}
return;
}