kanrisuru 0.16.0 → 0.16.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/lib/kanrisuru/command.rb +2 -3
- data/lib/kanrisuru/core/zypper/commands/add_repo.rb +1 -8
- data/lib/kanrisuru/core/zypper/commands/add_service.rb +4 -2
- data/lib/kanrisuru/core/zypper/commands/info.rb +1 -2
- data/lib/kanrisuru/core/zypper/commands/install.rb +2 -3
- data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +1 -7
- data/lib/kanrisuru/core/zypper/commands/modify_service.rb +3 -1
- data/lib/kanrisuru/core/zypper/commands/remove.rb +1 -2
- data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +3 -3
- data/lib/kanrisuru/core/zypper/commands/remove_service.rb +6 -1
- data/lib/kanrisuru/core/zypper/commands/search.rb +1 -3
- data/lib/kanrisuru/core/zypper/commands/source_install.rb +2 -0
- data/lib/kanrisuru/core/zypper/commands.rb +10 -1
- data/lib/kanrisuru/mode/permission.rb +103 -0
- data/lib/kanrisuru/mode.rb +2 -98
- data/lib/kanrisuru/os_package.rb +2 -0
- data/lib/kanrisuru/remote/fstab/entry.rb +154 -0
- data/lib/kanrisuru/remote/fstab/options.rb +143 -0
- data/lib/kanrisuru/remote/fstab.rb +3 -283
- data/lib/kanrisuru/remote/host.rb +1 -3
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/{ip/ip_address_label_spec.rb → ip_address_label_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_address_spec.rb → ip_address_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_link_spec.rb → ip_link_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_maddress_spec.rb → ip_maddress_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_neighbour_spec.rb → ip_neighbour_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_route_spec.rb → ip_route_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_rule_spec.rb → ip_rule_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_spec.rb → ip_spec.rb} +0 -0
- data/spec/functional/core/zypper_spec.rb +708 -0
- data/spec/helper/stub_network.rb +1 -1
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e33daa1aa8d51a7f8a9e6efb4e77933ef5a71e1ce3e428dabc7f44468bde79b3
|
4
|
+
data.tar.gz: 8cbc4f168fdf88bdd22c8fb237018c65427010356ed8d1bfe9771f2e8ecfc0ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 992f48fbc7c55a67cd2bfa649cba991620ab0ee6aa97d4c49de918d099a1e9963a30dea99aa71fe738ad39982462e731caf4ab121263a0bbf4870a68ae5a1e83
|
7
|
+
data.tar.gz: 208b2389785ed015055a3c67b49b433dae7d5388ee32334af5d74f7a2f94db19900a1dba4396b02edc675987fadead7b90d3f961e3eddb9e5e7c35c946ac28fe
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
## Kanrisuru 0.16.4 (December 25, 2021) ##
|
2
|
+
* Refactor `Kanrisuru::Fstab::Entry` and `Kanrisuru::Fstab::Options` classes into separate files.
|
3
|
+
|
4
|
+
## Kanrisuru 0.16.3 (December 25, 2021) ##
|
5
|
+
* Refactor `Kanrisuru::Mode::Permission` class into separate file.
|
6
|
+
|
7
|
+
## Kanrisuru 0.16.2 (December 19, 2021) ##
|
8
|
+
* Organize functional ip specs
|
9
|
+
* Log in realtime, debug output the stdout from the remote server, as opposed to waiting until after the command is done.
|
10
|
+
* Fix the `opensuse_leap` for the stubnetwork rspec helper.
|
11
|
+
* Refactor and cleanup the `append_array` method for the `Kanrisuru::Command` instance
|
12
|
+
* Move `gpg_opts` for `zypper` command into re-usable method
|
13
|
+
* Add functional test cases for `zypper` command.
|
14
|
+
|
15
|
+
## Kanrisuru 0.16.1 (December 16, 2021) ##
|
16
|
+
* Fix require class for `os_package`.
|
17
|
+
|
1
18
|
## Kanrisuru 0.16.0 (December 14, 2021) ##
|
2
19
|
* Fix `append_array` for the `Kanrisuru::Command` class with negated check on Array type.
|
3
20
|
* Add `to_f` method for `Kanrisuru::Command` and `Kanrisuru::Result` with unit test cases.
|
data/lib/kanrisuru/command.rb
CHANGED
@@ -88,11 +88,10 @@ module Kanrisuru
|
|
88
88
|
append_value("| #{value}")
|
89
89
|
end
|
90
90
|
|
91
|
-
def append_array(value)
|
91
|
+
def append_array(value, separator = ' ')
|
92
92
|
return unless Kanrisuru::Util.present?(value)
|
93
93
|
|
94
|
-
value
|
95
|
-
append_value(value.join(' '))
|
94
|
+
append_value(Kanrisuru::Util.array_join_string(value, separator))
|
96
95
|
end
|
97
96
|
|
98
97
|
def append_value(value)
|
@@ -17,16 +17,9 @@ module Kanrisuru
|
|
17
17
|
command.append_flag('--no-refresh', opts[:no_refresh])
|
18
18
|
command.append_flag('--keep-packages', opts[:keep_packages])
|
19
19
|
command.append_flag('--no-keep-packages', opts[:no_keep_packages])
|
20
|
-
command.append_flag('--gpgcheck', opts[:gpgcheck])
|
21
|
-
command.append_flag('--gpgcheck-strict', opts[:gpgcheck_strict])
|
22
|
-
command.append_flag('--gpgcheck-allow-unsigned', opts[:gpgcheck_allow_unsigned])
|
23
|
-
command.append_flag('--gpgcheck-allow-unsigned-repo', opts[:gpgcheck_allow_unsigned_repo])
|
24
|
-
command.append_flag('--gpgcheck-allow-unsigned-package', opts[:gpgcheck_allow_unsigned_package])
|
25
|
-
command.append_flag('--no-gpgcheck', opts[:no_gpgcheck])
|
26
|
-
command.append_flag('--default-gpgcheck', opts[:default_gpgcheck])
|
27
|
-
|
28
20
|
command.append_arg('--priority', opts[:priority])
|
29
21
|
|
22
|
+
zypper_gpg_opts(command, opts)
|
30
23
|
zypper_repos_opt(command, opts)
|
31
24
|
|
32
25
|
execute_shell(command)
|
@@ -8,14 +8,16 @@ module Kanrisuru
|
|
8
8
|
zypper_global_opts(command, opts)
|
9
9
|
command << 'addservice'
|
10
10
|
|
11
|
-
|
11
|
+
name = ("'#{opts[:name]}'" if Kanrisuru::Util.present?(opts[:name]))
|
12
12
|
|
13
|
+
command.append_arg('--name', name)
|
13
14
|
command.append_flag('--enable', opts[:enable])
|
14
15
|
command.append_flag('--disable', opts[:disable])
|
15
16
|
command.append_flag('--refresh', opts[:refresh])
|
16
17
|
command.append_flag('--no-refresh', opts[:no_refresh])
|
17
18
|
|
18
|
-
command
|
19
|
+
command << opts[:service]
|
20
|
+
command << opts[:alias]
|
19
21
|
|
20
22
|
execute_shell(command)
|
21
23
|
|
@@ -11,8 +11,7 @@ module Kanrisuru
|
|
11
11
|
zypper_repos_opt(command, opts)
|
12
12
|
zypper_package_type_opt(command, opts)
|
13
13
|
|
14
|
-
|
15
|
-
command << packages
|
14
|
+
command.append_array(opts[:packages])
|
16
15
|
|
17
16
|
execute_shell(command)
|
18
17
|
|
@@ -12,7 +12,7 @@ module Kanrisuru
|
|
12
12
|
zypper_package_type_opt(command, opts)
|
13
13
|
|
14
14
|
command.append_arg('-n', opts[:name])
|
15
|
-
command.
|
15
|
+
command.append_flag('-f', opts[:force])
|
16
16
|
command.append_flag('--oldpackage', opts[:oldpackage])
|
17
17
|
command.append_arg('--from', opts[:from])
|
18
18
|
command.append_arg('--capability', opts[:capability])
|
@@ -27,8 +27,7 @@ module Kanrisuru
|
|
27
27
|
zypper_download_and_install_opts(command, opts)
|
28
28
|
zypper_expert_opts(command, opts)
|
29
29
|
|
30
|
-
|
31
|
-
command << packages
|
30
|
+
command.append_array(opts[:packages])
|
32
31
|
|
33
32
|
execute_shell(command)
|
34
33
|
|
@@ -19,13 +19,7 @@ module Kanrisuru
|
|
19
19
|
command.append_flag('--keep-packages', opts[:keep_packages])
|
20
20
|
command.append_flag('--no-keep-packages', opts[:no_keep_packages])
|
21
21
|
|
22
|
-
command
|
23
|
-
command.append_flag('--gpgcheck-strict', opts[:gpgcheck_strict])
|
24
|
-
command.append_flag('--gpgcheck-allow-unsigned', opts[:gpgcheck_allow_unsigned])
|
25
|
-
command.append_flag('--gpgcheck-allow-unsigned-repo', opts[:gpgcheck_allow_unsigned_repo])
|
26
|
-
command.append_flag('--gpgcheck-allow-unsigned-package', opts[:gpgcheck_allow_unsigned_package])
|
27
|
-
command.append_flag('--no-gpgcheck', opts[:no_gpgcheck])
|
28
|
-
command.append_flag('--default-gpgcheck', opts[:default_gpgcheck])
|
22
|
+
zypper_gpg_opts(command, opts)
|
29
23
|
|
30
24
|
command.append_flag('--all', opts[:all])
|
31
25
|
command.append_flag('--local', opts[:local])
|
@@ -8,8 +8,8 @@ module Kanrisuru
|
|
8
8
|
zypper_global_opts(command, opts)
|
9
9
|
|
10
10
|
command << 'modifyservice'
|
11
|
-
command.append_arg('--name', opts[:name])
|
12
11
|
|
12
|
+
command.append_arg('--name', opts[:name])
|
13
13
|
command.append_flag('--enable', opts[:enable])
|
14
14
|
command.append_flag('--disable', opts[:disable])
|
15
15
|
command.append_flag('--refresh', opts[:refresh])
|
@@ -31,6 +31,8 @@ module Kanrisuru
|
|
31
31
|
command.append_arg('--medium-type', opts[:medium_type])
|
32
32
|
end
|
33
33
|
|
34
|
+
command << opts[:service] if Kanrisuru::Util.present?(opts[:service])
|
35
|
+
|
34
36
|
execute_shell(command)
|
35
37
|
|
36
38
|
Kanrisuru::Result.new(command)
|
@@ -15,8 +15,7 @@ module Kanrisuru
|
|
15
15
|
zypper_package_type_opt(command, opts)
|
16
16
|
zypper_solver_opts(command, opts)
|
17
17
|
|
18
|
-
|
19
|
-
command << packages
|
18
|
+
command.append_array(opts[:packages])
|
20
19
|
|
21
20
|
execute_shell(command)
|
22
21
|
Kanrisuru::Result.new(command)
|
@@ -15,10 +15,10 @@ module Kanrisuru
|
|
15
15
|
command.append_flag('--local', opts[:local])
|
16
16
|
command.append_flag('--remote', opts[:remote])
|
17
17
|
|
18
|
-
if Kanrisuru::Util.present?(opts[:
|
19
|
-
raise ArgumentError, 'Invalid media type' unless
|
18
|
+
if Kanrisuru::Util.present?(opts[:medium_type])
|
19
|
+
raise ArgumentError, 'Invalid media type' unless MEDIUM_TYPES.include?(opts[:medium_type])
|
20
20
|
|
21
|
-
command.append_arg('--
|
21
|
+
command.append_arg('--medium-type', opts[:medium_type])
|
22
22
|
end
|
23
23
|
|
24
24
|
command.append_array(opts[:repos])
|
@@ -4,13 +4,18 @@ module Kanrisuru
|
|
4
4
|
module Core
|
5
5
|
module Zypper
|
6
6
|
def zypper_remove_service(opts)
|
7
|
+
service = opts[:service]
|
8
|
+
|
7
9
|
command = Kanrisuru::Command.new('zypper')
|
8
10
|
zypper_global_opts(command, opts)
|
9
11
|
|
10
12
|
command << 'removeservice'
|
11
13
|
command.append_flag('--loose-auth', opts[:loose_auth])
|
12
14
|
command.append_flag('--loose-query', opts[:loose_query])
|
13
|
-
|
15
|
+
|
16
|
+
service = "'#{service}'" if service.match(/\s/)
|
17
|
+
|
18
|
+
command << service
|
14
19
|
|
15
20
|
execute_shell(command)
|
16
21
|
|
@@ -37,9 +37,7 @@ module Kanrisuru
|
|
37
37
|
|
38
38
|
zypper_repos_opt(command, opts)
|
39
39
|
zypper_package_type_opt(command, opts)
|
40
|
-
|
41
|
-
packages = Kanrisuru::Util.array_join_string(opts[:packages], ' ')
|
42
|
-
command << packages
|
40
|
+
command.append_array(opts[:packages])
|
43
41
|
|
44
42
|
execute_shell(command)
|
45
43
|
|
@@ -76,6 +76,16 @@ module Kanrisuru
|
|
76
76
|
command.append_flag('--no-allow-vendor-change', opts[:no_allow_vendor_change])
|
77
77
|
end
|
78
78
|
|
79
|
+
def zypper_gpg_opts(command, opts)
|
80
|
+
command.append_flag('--gpgcheck', opts[:gpgcheck])
|
81
|
+
command.append_flag('--gpgcheck-strict', opts[:gpgcheck_strict])
|
82
|
+
command.append_flag('--gpgcheck-allow-unsigned', opts[:gpgcheck_allow_unsigned])
|
83
|
+
command.append_flag('--gpgcheck-allow-unsigned-repo', opts[:gpgcheck_allow_unsigned_repo])
|
84
|
+
command.append_flag('--gpgcheck-allow-unsigned-package', opts[:gpgcheck_allow_unsigned_package])
|
85
|
+
command.append_flag('--no-gpgcheck', opts[:no_gpgcheck])
|
86
|
+
command.append_flag('--default-gpgcheck', opts[:default_gpgcheck])
|
87
|
+
end
|
88
|
+
|
79
89
|
def zypper_repos_opt(command, opts)
|
80
90
|
zypper_array_opt(command, opts[:repos], '--repo')
|
81
91
|
end
|
@@ -101,7 +111,6 @@ module Kanrisuru
|
|
101
111
|
|
102
112
|
def zypper_package_type_opt(command, opts)
|
103
113
|
type = opts[:type]
|
104
|
-
|
105
114
|
command.append_arg('-t', type) if Kanrisuru::Util.present?(type) && PACKAGE_TYPES.include?(type)
|
106
115
|
end
|
107
116
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
class Mode
|
5
|
+
class Permission
|
6
|
+
attr_reader :symbolic
|
7
|
+
|
8
|
+
def initialize(numeric, symbolic)
|
9
|
+
@numeric = numeric
|
10
|
+
@symbolic = symbolic
|
11
|
+
|
12
|
+
update_symbolic_rwx
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_i
|
16
|
+
numeric.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
symbolic
|
21
|
+
end
|
22
|
+
|
23
|
+
def numeric
|
24
|
+
@numeric.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def all?
|
28
|
+
read? && write? && execute?
|
29
|
+
end
|
30
|
+
|
31
|
+
def symbolic=(symbolic)
|
32
|
+
@symbolic = symbolic
|
33
|
+
|
34
|
+
update_symbolic_rwx
|
35
|
+
update_numeric
|
36
|
+
end
|
37
|
+
|
38
|
+
def numeric=(numeric)
|
39
|
+
@numeric = numeric
|
40
|
+
|
41
|
+
update_numeric_rwx
|
42
|
+
update_symbolic
|
43
|
+
end
|
44
|
+
|
45
|
+
def read=(boolean)
|
46
|
+
@readable = boolean
|
47
|
+
|
48
|
+
update_numeric
|
49
|
+
update_symbolic
|
50
|
+
end
|
51
|
+
|
52
|
+
def write=(boolean)
|
53
|
+
@writeable = boolean
|
54
|
+
|
55
|
+
update_numeric
|
56
|
+
update_symbolic
|
57
|
+
end
|
58
|
+
|
59
|
+
def execute=(boolean)
|
60
|
+
@executable = boolean
|
61
|
+
|
62
|
+
update_numeric
|
63
|
+
update_symbolic
|
64
|
+
end
|
65
|
+
|
66
|
+
def read?
|
67
|
+
@readable
|
68
|
+
end
|
69
|
+
|
70
|
+
def write?
|
71
|
+
@writeable
|
72
|
+
end
|
73
|
+
|
74
|
+
def execute?
|
75
|
+
@executable
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def update_symbolic_rwx
|
81
|
+
@readable = @symbolic.include?('r')
|
82
|
+
@writeable = @symbolic.include?('w')
|
83
|
+
@executable = @symbolic.include?('x')
|
84
|
+
end
|
85
|
+
|
86
|
+
def update_numeric_rwx
|
87
|
+
mode = @numeric.to_i(8)
|
88
|
+
|
89
|
+
@readable = ((mode >> 2) & 0b001) == 1
|
90
|
+
@writeable = ((mode >> 1) & 0b001) == 1
|
91
|
+
@executable = ((mode >> 0) & 0b001) == 1
|
92
|
+
end
|
93
|
+
|
94
|
+
def update_numeric
|
95
|
+
@numeric = (((read? ? 1 : 0) << 2) + ((write? ? 1 : 0) << 1) + (execute? ? 1 : 0)).to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
def update_symbolic
|
99
|
+
@symbolic = "#{read? ? 'r' : '-'}#{write? ? 'w' : '-'}#{execute? ? 'x' : '-'}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/kanrisuru/mode.rb
CHANGED
@@ -1,105 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'mode/permission'
|
4
|
+
|
3
5
|
module Kanrisuru
|
4
6
|
class Mode
|
5
|
-
class Permission
|
6
|
-
attr_reader :symbolic
|
7
|
-
|
8
|
-
def initialize(numeric, symbolic)
|
9
|
-
@numeric = numeric
|
10
|
-
@symbolic = symbolic
|
11
|
-
|
12
|
-
update_symbolic_rwx
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_i
|
16
|
-
numeric.to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
symbolic
|
21
|
-
end
|
22
|
-
|
23
|
-
def numeric
|
24
|
-
@numeric.to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
def all?
|
28
|
-
read? && write? && execute?
|
29
|
-
end
|
30
|
-
|
31
|
-
def symbolic=(symbolic)
|
32
|
-
@symbolic = symbolic
|
33
|
-
|
34
|
-
update_symbolic_rwx
|
35
|
-
update_numeric
|
36
|
-
end
|
37
|
-
|
38
|
-
def numeric=(numeric)
|
39
|
-
@numeric = numeric
|
40
|
-
|
41
|
-
update_numeric_rwx
|
42
|
-
update_symbolic
|
43
|
-
end
|
44
|
-
|
45
|
-
def read=(boolean)
|
46
|
-
@readable = boolean
|
47
|
-
|
48
|
-
update_numeric
|
49
|
-
update_symbolic
|
50
|
-
end
|
51
|
-
|
52
|
-
def write=(boolean)
|
53
|
-
@writeable = boolean
|
54
|
-
|
55
|
-
update_numeric
|
56
|
-
update_symbolic
|
57
|
-
end
|
58
|
-
|
59
|
-
def execute=(boolean)
|
60
|
-
@executable = boolean
|
61
|
-
|
62
|
-
update_numeric
|
63
|
-
update_symbolic
|
64
|
-
end
|
65
|
-
|
66
|
-
def read?
|
67
|
-
@readable
|
68
|
-
end
|
69
|
-
|
70
|
-
def write?
|
71
|
-
@writeable
|
72
|
-
end
|
73
|
-
|
74
|
-
def execute?
|
75
|
-
@executable
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def update_symbolic_rwx
|
81
|
-
@readable = @symbolic.include?('r')
|
82
|
-
@writeable = @symbolic.include?('w')
|
83
|
-
@executable = @symbolic.include?('x')
|
84
|
-
end
|
85
|
-
|
86
|
-
def update_numeric_rwx
|
87
|
-
mode = @numeric.to_i(8)
|
88
|
-
|
89
|
-
@readable = ((mode >> 2) & 0b001) == 1
|
90
|
-
@writeable = ((mode >> 1) & 0b001) == 1
|
91
|
-
@executable = ((mode >> 0) & 0b001) == 1
|
92
|
-
end
|
93
|
-
|
94
|
-
def update_numeric
|
95
|
-
@numeric = (((read? ? 1 : 0) << 2) + ((write? ? 1 : 0) << 1) + (execute? ? 1 : 0)).to_s
|
96
|
-
end
|
97
|
-
|
98
|
-
def update_symbolic
|
99
|
-
@symbolic = "#{read? ? 'r' : '-'}#{write? ? 'w' : '-'}#{execute? ? 'x' : '-'}"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
7
|
attr_reader :owner, :group, :other
|
104
8
|
|
105
9
|
def initialize(mode)
|
data/lib/kanrisuru/os_package.rb
CHANGED
@@ -0,0 +1,154 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Remote
|
5
|
+
class Fstab
|
6
|
+
class Entry
|
7
|
+
attr_reader :device, :uuid, :invalid, :label, :type, :opts, :freq, :passno
|
8
|
+
attr_accessor :mount_point
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
@host = opts[:host]
|
12
|
+
@line = opts[:line]
|
13
|
+
|
14
|
+
@default = nil
|
15
|
+
|
16
|
+
@device = opts[:device] || nil
|
17
|
+
@opts = opts[:opts] || nil
|
18
|
+
@label = opts[:label] || nil
|
19
|
+
@uuid = opts[:uuid] || nil
|
20
|
+
@mount_point = opts[:mount_point] || nil
|
21
|
+
@type = opts[:type] || nil
|
22
|
+
@freq = opts[:freq] || nil
|
23
|
+
@passno = opts[:passno] || nil
|
24
|
+
|
25
|
+
@changed = false
|
26
|
+
|
27
|
+
@ucount = 0
|
28
|
+
@special = false
|
29
|
+
@invalid = false
|
30
|
+
|
31
|
+
if Kanrisuru::Util.present?(@line) && @line.instance_of?(String)
|
32
|
+
parse_line!
|
33
|
+
elsif (Kanrisuru::Util.present?(@opts) && @opts.instance_of?(String)) || @opts.instance_of?(Hash)
|
34
|
+
@opts = Kanrisuru::Remote::Fstab::Options.new(@type, @opts)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
str = '#<Kanrisuru::Remote::Fstab::Entry:0x%<object_id>s ' \
|
40
|
+
'@line=%<line>s @device=%<device>s @label=%<label>s' \
|
41
|
+
'@uuid=%<uuid>s @freq=%<freq>s @pasno=%<passno>s' \
|
42
|
+
'@opts=%<opts>s}>'
|
43
|
+
|
44
|
+
format(
|
45
|
+
str,
|
46
|
+
object_id: object_id,
|
47
|
+
line: @line,
|
48
|
+
device: @device,
|
49
|
+
label: @label,
|
50
|
+
uuid: @uuid,
|
51
|
+
freq: @freq,
|
52
|
+
passno: @passno,
|
53
|
+
opts: @opts.inspect
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def valid?
|
58
|
+
!@invalid
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s(override = nil)
|
62
|
+
mode = override || @default
|
63
|
+
|
64
|
+
case mode
|
65
|
+
when 'uuid'
|
66
|
+
"UUID=#{@uuid} #{@mount_point} #{@type} #{@opts} #{@freq} #{@passno}"
|
67
|
+
when 'label'
|
68
|
+
"LABEL=#{@label} #{@mount_point} #{@type} #{@opts} #{@freq} #{@passno}"
|
69
|
+
else
|
70
|
+
"#{@device} #{@mount_point} #{@type} #{@opts} #{@freq} #{@passno}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def parse_line!
|
77
|
+
fsline, mp, @type, opts, freq, passno = @line.split
|
78
|
+
|
79
|
+
@mount_point = mp
|
80
|
+
@freq = freq || '0'
|
81
|
+
@passno = passno || '0'
|
82
|
+
|
83
|
+
@opts = Fstab::Options.new(@type, opts)
|
84
|
+
|
85
|
+
case @line
|
86
|
+
when /^\s*LABEL=/
|
87
|
+
@default = 'label'
|
88
|
+
parse_label(fsline)
|
89
|
+
when /^\s*UUID=/
|
90
|
+
@default = 'uuid'
|
91
|
+
parse_uuid(fsline)
|
92
|
+
when %r{^\s*/dev}
|
93
|
+
@default = 'dev'
|
94
|
+
parse_dev(fsline)
|
95
|
+
else
|
96
|
+
# TODO: somewhat risky to assume that everything else
|
97
|
+
# can be considered a special device, but validating this
|
98
|
+
# is really tricky.
|
99
|
+
@special = true
|
100
|
+
@device = fsline
|
101
|
+
end
|
102
|
+
|
103
|
+
# Fstab entries not matching real devices have device unknown
|
104
|
+
@invalid = (@line.split.count != 6) # invalid entry if < 6 columns
|
105
|
+
|
106
|
+
if (@uuid.nil? && @label.nil? && !@special) ||
|
107
|
+
@device =~ /^unknown_/ ||
|
108
|
+
(!@host.inode?(@device) && !@special)
|
109
|
+
@invalid = true
|
110
|
+
@ucount += 1
|
111
|
+
end
|
112
|
+
|
113
|
+
@invalid = true unless @freq =~ /0|1|2/ && @passno =~ /0|1|2/
|
114
|
+
end
|
115
|
+
|
116
|
+
def parse_label(fsline)
|
117
|
+
@label = fsline.split('=').last.strip.chomp
|
118
|
+
path = @host.realpath("/dev/disk/by-label/#{@label}").path
|
119
|
+
|
120
|
+
@device = begin
|
121
|
+
"/dev/#{path.split('/').last}"
|
122
|
+
rescue StandardError
|
123
|
+
"unknown_#{@ucount}"
|
124
|
+
end
|
125
|
+
|
126
|
+
result = @host.blkid(device: @device)
|
127
|
+
@uuid = result.success? ? result[0].uuid : nil
|
128
|
+
end
|
129
|
+
|
130
|
+
def parse_uuid(fsline)
|
131
|
+
@uuid = fsline.split('=').last.strip.chomp
|
132
|
+
path = @host.realpath("/dev/disk/by-uuid/#{uuid}").path
|
133
|
+
|
134
|
+
@device = begin
|
135
|
+
"/dev/#{path.split('/').last}"
|
136
|
+
rescue StandardError
|
137
|
+
"unknown_#{@ucount}"
|
138
|
+
end
|
139
|
+
|
140
|
+
result = @host.blkid(device: @device)
|
141
|
+
@label = result.success? ? result[0].label : nil
|
142
|
+
end
|
143
|
+
|
144
|
+
def parse_dev(fsline)
|
145
|
+
@device = fsline
|
146
|
+
result = @host.blkid(device: @device)
|
147
|
+
|
148
|
+
@label = result.success? ? result[0].label : nil
|
149
|
+
@uuid = result.success? ? result[0].uuid : nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|