line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::GMOD::Admin::Update; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
26916
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
9
|
use vars qw/@ISA $AUTOLOAD/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
129
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
892
|
use Bio::GMOD; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
62
|
|
7
|
2
|
|
|
2
|
|
1396
|
use Bio::GMOD::Util::Mirror; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
81
|
|
8
|
2
|
|
|
2
|
|
2461
|
use Bio::GMOD::Util::CheckVersions; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Bio::GMOD::Util::Rearrange; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw/Bio::GMOD Bio::GMOD::Util::CheckVersions/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Currently, there is no generic update method. Bio::GMOD::Admin::Update |
14
|
|
|
|
|
|
|
# must be subclassed for your particular MOD |
15
|
|
|
|
|
|
|
sub update { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
my $adaptor = $self->adaptor; |
18
|
|
|
|
|
|
|
my $name = $adaptor->name; |
19
|
|
|
|
|
|
|
$self->logit("$name does not currently support automated updates at this time. Please ask the administrators of $name to add this functionality.", |
20
|
|
|
|
|
|
|
-die => 1); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# MORE TWEAKS NEEDED - configuration, verbosity, etc |
25
|
|
|
|
|
|
|
sub mirror { |
26
|
|
|
|
|
|
|
my ($self,@p) = @_; |
27
|
|
|
|
|
|
|
my ($remote_path,$local_path,$is_optional) |
28
|
|
|
|
|
|
|
= rearrange([qw/REMOTE_PATH LOCAL_PATH IS_OPTIONAL/],@p); |
29
|
|
|
|
|
|
|
my $adaptor = $self->adaptor; |
30
|
|
|
|
|
|
|
$local_path ||= $adaptor->tmp_path; |
31
|
|
|
|
|
|
|
$self->logit(-msg => "Must supply a local path in which to download files", |
32
|
|
|
|
|
|
|
-die => 1) unless $local_path; |
33
|
|
|
|
|
|
|
my $ftp = Bio::GMOD::Util::Mirror->new(-host => $adaptor->ftp_site, |
34
|
|
|
|
|
|
|
-path => $remote_path, |
35
|
|
|
|
|
|
|
-localpath => $local_path, |
36
|
|
|
|
|
|
|
-verbose => 1); |
37
|
|
|
|
|
|
|
my $result = $ftp->mirror(); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# TODO: Clear out the local directory if mirroring fails |
40
|
|
|
|
|
|
|
# TODO: Resumable downloads. |
41
|
|
|
|
|
|
|
if ($result) { |
42
|
|
|
|
|
|
|
$self->logit(-msg => "$remote_path successfully downloaded"); |
43
|
|
|
|
|
|
|
} else { |
44
|
|
|
|
|
|
|
if ($is_optional) { |
45
|
|
|
|
|
|
|
$self->logit(-msg => "$remote_path failed to download, installation is optional: $!"); |
46
|
|
|
|
|
|
|
} else { |
47
|
|
|
|
|
|
|
$self->logit(-msg => "$remote_path failed to download: $!", |
48
|
|
|
|
|
|
|
-die => 1); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
######################################################### |
57
|
|
|
|
|
|
|
# Rsync tasks |
58
|
|
|
|
|
|
|
######################################################### |
59
|
|
|
|
|
|
|
sub rsync_software { |
60
|
|
|
|
|
|
|
my ($self,@p) = @_; |
61
|
|
|
|
|
|
|
my ($rsync_module,$exclude,$install_root) = rearrange([qw/MODULE EXCLUDE INSTALL_ROOT/],@p); |
62
|
|
|
|
|
|
|
$self->logit(-msg=>"Rsync'ing software",-emphasis=>1); |
63
|
|
|
|
|
|
|
my $adaptor = $self->adaptor; |
64
|
|
|
|
|
|
|
$adaptor->parse_params(@p); |
65
|
|
|
|
|
|
|
$install_root ||= $adaptor->install_root; |
66
|
|
|
|
|
|
|
$rsync_module .= '/' unless ($rsync_module =~ /\/$/); # Add trailing slash |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $rsync_url = $adaptor->rsync_url; |
69
|
|
|
|
|
|
|
$rsync_module ||= $adaptor->rsync_module; |
70
|
|
|
|
|
|
|
my $rsync_path = $rsync_url . ($rsync_module ? "/$rsync_module" : ''); |
71
|
|
|
|
|
|
|
# print "$install_root $rsync_module $exclude $rsync_path\n"; |
72
|
|
|
|
|
|
|
my $result = system("rsync -rztpovl $exclude $rsync_path $install_root"); |
73
|
|
|
|
|
|
|
$self->test_for_error($result,"Rsync'ing the mirror site"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
######################################################### |
78
|
|
|
|
|
|
|
# Housecleaning: checking for diskspace, etc |
79
|
|
|
|
|
|
|
######################################################### |
80
|
|
|
|
|
|
|
sub check_disk_space { |
81
|
|
|
|
|
|
|
my ($self,@p) = @_; |
82
|
|
|
|
|
|
|
my ($path,$required,$component) = rearrange([qw/PATH REQUIRED COMPONENT/],@p); |
83
|
|
|
|
|
|
|
my ($mount_point,$available) = $self->get_available_space($path); # calculated in GB |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if ($available >= $required) { |
86
|
|
|
|
|
|
|
$self->logit(-msg=>"Sufficient space to install $component ($required GB required; $available GB available)"); |
87
|
|
|
|
|
|
|
} else { |
88
|
|
|
|
|
|
|
$self->logit(-msg=>"Insufficient space to install $component ($required GB required; $available GB available)",-die=>1); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
return 1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_available_space { |
94
|
|
|
|
|
|
|
my ($self,$path) = @_; |
95
|
|
|
|
|
|
|
return unless $path; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $cmd = "df -k $path"; |
98
|
|
|
|
|
|
|
open (IN, "$cmd |") or $self->logit(-msg =>"get_available_space: Cannot run df command ($cmd): $!",-die=>1); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my ($mount_point, $available_space); |
101
|
|
|
|
|
|
|
my $counter; |
102
|
|
|
|
|
|
|
while () { |
103
|
|
|
|
|
|
|
next unless /^\//; |
104
|
|
|
|
|
|
|
my ($filesystem, $blocks, $used, $available, $use_percent, $mounted_on) = split(/\s+/); |
105
|
|
|
|
|
|
|
$mount_point = $mounted_on; |
106
|
|
|
|
|
|
|
$available_space = sprintf("%.2f", $available/1048576); |
107
|
|
|
|
|
|
|
$counter++; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
unless ($mount_point && $available_space) { |
111
|
|
|
|
|
|
|
$self->logit("get_available_space: Internal error: Cannot parse df cmd ($cmd)",-die=>1); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
return ($mount_point,$available_space); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub prepare_tmp_dir { |
117
|
|
|
|
|
|
|
my ($self,@p) = @_; |
118
|
|
|
|
|
|
|
my ($tmp_path,$sync_to) = rearrange([qw/TMP_PATH SYNC_TO/],@p); |
119
|
|
|
|
|
|
|
my $adaptor = $self->adaptor; |
120
|
|
|
|
|
|
|
$adaptor->{defaults}->{tmp_path} = $tmp_path if $tmp_path; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $method = $sync_to . "_version"; |
123
|
|
|
|
|
|
|
my $version = $self->$method || 'unknown_version'; |
124
|
|
|
|
|
|
|
$tmp_path ||= $adaptor->tmp_path; |
125
|
|
|
|
|
|
|
my $full_path = "$tmp_path/$version"; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
unless (-e "$full_path") { |
128
|
|
|
|
|
|
|
$self->logit(-msg => "Creating temporary directory at $full_path"); |
129
|
|
|
|
|
|
|
my $command = <
|
130
|
|
|
|
|
|
|
mkdir -p $full_path |
131
|
|
|
|
|
|
|
chmod -R 0775 $full_path |
132
|
|
|
|
|
|
|
END |
133
|
|
|
|
|
|
|
; |
134
|
|
|
|
|
|
|
my $result = system($command); |
135
|
|
|
|
|
|
|
if ($result == 0) { |
136
|
|
|
|
|
|
|
$self->logit(-msg => "Successfully created temporary directory"); |
137
|
|
|
|
|
|
|
} else { |
138
|
|
|
|
|
|
|
$self->logit(-msg => "Cannot make temporary directory: $!", |
139
|
|
|
|
|
|
|
-die => 1); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
return 1; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub cleanup { |
146
|
|
|
|
|
|
|
my ($self,@p) = @_; |
147
|
|
|
|
|
|
|
my $tmp = $self->tmp_path; |
148
|
|
|
|
|
|
|
$self->logit(-msg => "Cleaning up $tmp"); |
149
|
|
|
|
|
|
|
system("rm -rf $tmp/*"); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |