line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# system::mount Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::System::Mount; |
7
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package Metabrik::File::Text); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
622
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable mtab fstab mount umount system filesystem) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
install => [ ], # Inherited |
20
|
|
|
|
|
|
|
is_device_mounted => [ qw(device) ], |
21
|
|
|
|
|
|
|
is_directory_mounted => [ qw(directory) ], |
22
|
|
|
|
|
|
|
get_device_mounted_directory => [ qw(device) ], |
23
|
|
|
|
|
|
|
umount_directory => [ qw(directory) ], |
24
|
|
|
|
|
|
|
umount_device => [ qw(device) ], |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
require_binaries => { |
27
|
|
|
|
|
|
|
mount => [ ], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
need_packages => { |
30
|
|
|
|
|
|
|
ubuntu => [ qw(mount) ], |
31
|
|
|
|
|
|
|
debian => [ qw(mount) ], |
32
|
|
|
|
|
|
|
kali => [ qw(mount) ], |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub is_device_mounted { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my ($device) = @_; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_device_mounted', $device) or return; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->as_array(1); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
my $lines = $self->read('/etc/mtab') or return; |
46
|
0
|
|
|
|
|
|
return grep {/^\s*$device\s+/} @$lines; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub is_directory_mounted { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my ($directory) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('is_directory_mounted', $directory) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$directory =~ s{/*$}{}g; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->as_array(1); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
my $lines = $self->read('/etc/mtab') or return; |
60
|
0
|
|
|
|
|
|
return grep {/^\s*\S+\s+$directory\s+/} @$lines; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub get_device_mounted_directory { |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my ($device) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('get_device_mounted_directory', $device) or return; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->as_array(1); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
my $lines = $self->read('/etc/mtab') or return; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $directory = ''; |
74
|
0
|
|
|
|
|
|
for (@$lines) { |
75
|
0
|
0
|
|
|
|
|
if (/^\s*$device\s+(\S+)\s+/) { |
76
|
0
|
|
|
|
|
|
$directory = $1; |
77
|
0
|
|
|
|
|
|
last; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$directory =~ s{/*$}{}g; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $directory; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub umount_directory { |
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
my ($directory) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('umount_directory', $directory) or return; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$directory =~ s{/*$}{}g; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $is_mounted = $self->is_directory_mounted($directory); |
95
|
0
|
0
|
|
|
|
|
if (! defined($is_mounted)) { |
96
|
0
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if (! $is_mounted) { |
100
|
0
|
|
|
|
|
|
return $self->log->error("umount_directory: directory [$directory] not mounted"); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $cmd = 'umount '.$directory; |
104
|
0
|
|
|
|
|
|
return $self->sudo_execute($cmd); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub umount_device { |
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my ($device) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('umount_device', $device) or return; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $is_mounted = $self->is_device_mounted($device); |
114
|
0
|
0
|
|
|
|
|
if (! defined($is_mounted)) { |
115
|
0
|
|
|
|
|
|
return; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if (! $is_mounted) { |
119
|
0
|
|
|
|
|
|
return $self->log->error("umount_device: device [$device] not mounted"); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
my $directory = $self->get_device_mounted_directory($device) or return; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $cmd = 'umount '.$directory; |
125
|
0
|
|
|
|
|
|
return $self->sudo_execute($cmd); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |