line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# perl package |
2
|
|
|
|
|
|
|
# R binary installation routine |
3
|
|
|
|
|
|
|
# it assumes: R-version.tar.gz is available in local directory |
4
|
|
|
|
|
|
|
# it does: build, test and install |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright (C) 2015, Snehasis Sinha |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package R::Setup::Bootstrap; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
23980
|
use 5.010001; |
|
2
|
|
|
|
|
8
|
|
12
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
13
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
72
|
|
14
|
2
|
|
|
2
|
|
1573
|
use POSIX; |
|
2
|
|
|
|
|
15920
|
|
|
2
|
|
|
|
|
11
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Preloaded methods go here. |
22
|
2
|
|
|
2
|
|
9757
|
BEGIN { $| = 1 } # flush buffer |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
26
|
0
|
|
|
|
|
|
my %params = (@_); |
27
|
|
|
|
|
|
|
my $self = { |
28
|
|
|
|
|
|
|
_tarball => $params{'tarball'} || 'R-3.1.2.tar.gz', |
29
|
0
|
|
|
0
|
|
|
_extract => sub { $a=qx(which tar); chomp $a; return $a.' -xzf'; }->() || undef, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
_builddir=> undef, |
31
|
|
|
|
|
|
|
_config => './configure --prefix=/usr --with-x=no --enable-R-shlib', |
32
|
0
|
|
|
0
|
|
|
_make => sub { $a=qx(which make); chomp $a; return $a; }->() || undef, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
_rtest => 'R -q --no-save', # R query command |
34
|
0
|
0
|
0
|
|
|
|
_verbose => (defined $params{'verbose'} ? $params{'verbose'} : 1 ), # default: yes |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
35
|
|
|
|
|
|
|
}; |
36
|
0
|
|
|
|
|
|
bless $self, $class; |
37
|
0
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub p_pwd { |
41
|
0
|
|
|
0
|
0
|
|
my ($self, $root) = (@_); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return getcwd(); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub p_delete { |
47
|
0
|
|
|
0
|
0
|
|
my ($self, $root) = (@_); |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
unless ( -d $root ) { |
50
|
0
|
|
|
|
|
|
unlink $root; |
51
|
|
|
|
|
|
|
#print "rm ".$root."\n" if $self->{'_verbose'}; |
52
|
0
|
|
|
|
|
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
opendir DIR, $root or die $!; |
56
|
0
|
|
|
|
|
|
my @entries = readdir DIR; |
57
|
0
|
|
|
|
|
|
chomp @entries; |
58
|
0
|
|
|
|
|
|
closedir DIR; |
59
|
0
|
|
|
|
|
|
@entries = grep { !/^\.{1,2}$/ } @entries; |
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
foreach ( @entries ) { |
62
|
0
|
|
|
|
|
|
$self->p_delete ( $root.'/'.$_ ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
rmdir $root; |
66
|
|
|
|
|
|
|
#print $root." removed with content\n" if $self->{'_verbose'}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub p_builddir { |
70
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
71
|
0
|
|
|
|
|
|
my $dir = $self->{'_tarball'}; |
72
|
0
|
|
|
|
|
|
$dir =~ s/\.tar\.gz//g; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$self->{'_builddir'} = $self->p_pwd.'/'.$dir; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub p_exec { |
78
|
0
|
|
|
0
|
0
|
|
my ($self, $cmd) = (@_); |
79
|
0
|
|
|
|
|
|
my $i = 0; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
open CMD, $cmd.' 2>&1 |' or die $!; |
82
|
0
|
|
|
|
|
|
while ( ) { |
83
|
0
|
0
|
|
|
|
|
if ( $self->{'_verbose'} gt 1 ) { print $_; } |
|
0
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
else { print '.' unless ($i++ % 20); } |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
close CMD; |
87
|
0
|
|
|
|
|
|
print "\n"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# extract from package list (persistency) |
91
|
|
|
|
|
|
|
sub p_extract { |
92
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
93
|
0
|
|
|
|
|
|
my $builddir; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
unless ( -f $self->{'_tarball'} ) { |
96
|
0
|
|
|
|
|
|
print $self->{'_tarball'}." is not available!\n"; |
97
|
0
|
|
|
|
|
|
exit (1); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$builddir = $self->{'_builddir'}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# check if directory exists |
103
|
0
|
0
|
|
|
|
|
if ( -d $self->{'_builddir'} ) { # remove it |
104
|
0
|
0
|
|
|
|
|
print $self->{'_builddir'}." removing...\n" if $self->{'_verbose'}; |
105
|
0
|
|
|
|
|
|
$self->p_delete ( $self->{'_builddir'} ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# extract |
109
|
0
|
|
|
|
|
|
my $cmd = $self->{'_extract'}.' '.$self->{'_tarball'}; |
110
|
0
|
0
|
|
|
|
|
print $self->{'_tarball'}." extracting ...\n" if $self->{'_verbose'}; |
111
|
0
|
|
|
|
|
|
qx($cmd); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub p_configure { |
115
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
unless ( defined $self->{'_config'} ) { |
118
|
0
|
0
|
|
|
|
|
print "problem configuring!\n" if $self->{'_verbose'}; |
119
|
0
|
|
|
|
|
|
exit (1); |
120
|
|
|
|
|
|
|
} |
121
|
0
|
0
|
|
|
|
|
print "configuring " if $self->{'_verbose'}; |
122
|
0
|
|
|
|
|
|
$self->p_exec ( $self->{'_config'} ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub p_make { |
126
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
unless ( defined $self->{'_make'} ) { |
129
|
0
|
0
|
|
|
|
|
print "problem building!\n" if $self->{'_verbose'}; |
130
|
0
|
|
|
|
|
|
exit (1); |
131
|
|
|
|
|
|
|
} |
132
|
0
|
0
|
|
|
|
|
print "building " if $self->{'_verbose'}; |
133
|
0
|
|
|
|
|
|
$self->p_exec ( $self->{'_make'} ); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub p_uninstall { |
137
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
unless ( defined $self->{'_make'} ) { |
140
|
0
|
0
|
|
|
|
|
print "problem uninstalling!\n" if $self->{'_verbose'}; |
141
|
0
|
|
|
|
|
|
exit (1); |
142
|
|
|
|
|
|
|
} |
143
|
0
|
0
|
|
|
|
|
print "uninstalling " if $self->{'_verbose'}; |
144
|
0
|
|
|
|
|
|
$self->p_exec ( $self->{'_make'}.' uninstall' ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub p_install { |
148
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
149
|
|
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
unless ( defined $self->{'_make'} ) { |
151
|
0
|
0
|
|
|
|
|
print "problem installing!\n" if $self->{'_verbose'}; |
152
|
0
|
|
|
|
|
|
exit (1); |
153
|
|
|
|
|
|
|
} |
154
|
0
|
0
|
|
|
|
|
print "installing " if $self->{'_verbose'}; |
155
|
0
|
|
|
|
|
|
$self->p_exec ( $self->{'_make'}.' install' ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub p_chdir { |
159
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
160
|
0
|
|
|
|
|
|
my $dir = $self->{'_builddir'}; |
161
|
0
|
0
|
|
|
|
|
chdir $dir if -d $dir; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub p_check_R { |
165
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
166
|
0
|
|
|
|
|
|
my $cmd = 'R'; |
167
|
0
|
|
|
|
|
|
my $out = qx(whereis $cmd); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$out =~ s/$cmd://g; |
170
|
0
|
|
|
|
|
|
$out =~ s/^\s+|\s+$//g; |
171
|
0
|
|
|
|
|
|
$out =~ s/\/usr\/lib64\/R//g; |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if($out ne "") { |
174
|
0
|
|
|
|
|
|
return 0; |
175
|
|
|
|
|
|
|
} |
176
|
0
|
|
|
|
|
|
return 1; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub build { |
180
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$self->p_builddir; |
183
|
0
|
|
|
|
|
|
$self->p_extract; |
184
|
0
|
|
|
|
|
|
$self->p_chdir; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
$self->p_configure; |
187
|
0
|
|
|
|
|
|
$self->p_make; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# gets package id |
191
|
|
|
|
|
|
|
sub install { |
192
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
193
|
|
|
|
|
|
|
|
194
|
0
|
0
|
|
|
|
|
unless ( $self->p_check_R ) { |
195
|
0
|
0
|
|
|
|
|
print "R is already available\n" if $self->{'_verbose'}; |
196
|
0
|
|
|
|
|
|
exit (1); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
if ( getuid() ne 0 ) { |
200
|
0
|
0
|
|
|
|
|
print "requires root (sudo) access\n" if $self->{'_verbose'}; |
201
|
0
|
|
|
|
|
|
exit (1); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
print "installing \n"; |
205
|
0
|
|
|
|
|
|
$self->p_builddir; |
206
|
0
|
|
|
|
|
|
$self->p_chdir; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
$self->p_install; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub uninstall { |
212
|
0
|
|
|
0
|
0
|
|
my ($self) = (@_); |
213
|
|
|
|
|
|
|
|
214
|
0
|
0
|
|
|
|
|
if ( $self->p_check_R ) { |
215
|
0
|
0
|
|
|
|
|
print "R is missing\n" if $self->{'_verbose'}; |
216
|
0
|
|
|
|
|
|
exit (1); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
0
|
0
|
|
|
|
|
if ( getuid() ne 0 ) { |
220
|
0
|
0
|
|
|
|
|
print "requires root (sudo) access\n" if $self->{'_verbose'}; |
221
|
0
|
|
|
|
|
|
exit (1); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# clean up packages first |
225
|
|
|
|
|
|
|
# todo |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
print "removing \n"; |
228
|
0
|
|
|
|
|
|
$self->p_builddir; |
229
|
0
|
|
|
|
|
|
$self->p_chdir; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# uninstall binary |
232
|
0
|
|
|
|
|
|
$self->p_uninstall; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
1; |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
__END__ |