kanrisuru 0.16.1 → 0.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/lib/kanrisuru/command.rb +2 -3
  4. data/lib/kanrisuru/core/dmi/parsers/dmi.rb +14 -10
  5. data/lib/kanrisuru/core/zypper/commands/add_repo.rb +1 -8
  6. data/lib/kanrisuru/core/zypper/commands/add_service.rb +4 -2
  7. data/lib/kanrisuru/core/zypper/commands/info.rb +1 -2
  8. data/lib/kanrisuru/core/zypper/commands/install.rb +2 -3
  9. data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +1 -7
  10. data/lib/kanrisuru/core/zypper/commands/modify_service.rb +3 -1
  11. data/lib/kanrisuru/core/zypper/commands/remove.rb +1 -2
  12. data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +3 -3
  13. data/lib/kanrisuru/core/zypper/commands/remove_service.rb +6 -1
  14. data/lib/kanrisuru/core/zypper/commands/search.rb +1 -3
  15. data/lib/kanrisuru/core/zypper/commands/source_install.rb +2 -0
  16. data/lib/kanrisuru/core/zypper/commands.rb +10 -1
  17. data/lib/kanrisuru/mode/permission.rb +103 -0
  18. data/lib/kanrisuru/mode.rb +2 -98
  19. data/lib/kanrisuru/remote/fstab/entry.rb +154 -0
  20. data/lib/kanrisuru/remote/fstab/options.rb +143 -0
  21. data/lib/kanrisuru/remote/fstab.rb +3 -283
  22. data/lib/kanrisuru/remote/host.rb +1 -3
  23. data/lib/kanrisuru/version.rb +1 -1
  24. data/spec/functional/core/{ip/ip_address_label_spec.rb → ip_address_label_spec.rb} +0 -0
  25. data/spec/functional/core/{ip/ip_address_spec.rb → ip_address_spec.rb} +0 -0
  26. data/spec/functional/core/{ip/ip_link_spec.rb → ip_link_spec.rb} +0 -0
  27. data/spec/functional/core/{ip/ip_maddress_spec.rb → ip_maddress_spec.rb} +0 -0
  28. data/spec/functional/core/{ip/ip_neighbour_spec.rb → ip_neighbour_spec.rb} +0 -0
  29. data/spec/functional/core/{ip/ip_route_spec.rb → ip_route_spec.rb} +0 -0
  30. data/spec/functional/core/{ip/ip_rule_spec.rb → ip_rule_spec.rb} +0 -0
  31. data/spec/functional/core/{ip/ip_spec.rb → ip_spec.rb} +0 -0
  32. data/spec/functional/core/zypper_spec.rb +708 -0
  33. data/spec/helper/stub_network.rb +1 -1
  34. metadata +14 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd7661452984fde76a67c205c6de2fc65ef6dd4eca517ff207677ddac0adfe25
4
- data.tar.gz: 0ff31a1685bb616fb4039da422544944ba3b713a00a3941ccb8a4fa03d753def
3
+ metadata.gz: 44eda2d0bb8165ff1df3d763531ffdb64a442b390e6e97ccda473105ddd8b04b
4
+ data.tar.gz: 14967498be11e552b7f546984173abf279387649da8fc9d45a98b42ed06aaa4f
5
5
  SHA512:
6
- metadata.gz: 7e7ba4e672987e7650c5a0ce288f38fac309514a2670ec705eb7df8880f7b805a45ee3ed961366bed2981d8113a32343fe1d403e3c6cd96a3e77a327a6e3272f
7
- data.tar.gz: 1821f242cd12a8b246d30a2079741988bd36f12df58d2e18551c8f416b6048ed1005cafb48faf33d0741da16a3fd0ccf2487d6c6166b497c54406dcb5aee67cd
6
+ metadata.gz: 5c281ab5f1e6fa063a5f11df3cb7138fe0acd19bb810aaf2e01685b847a1ec7d972420c86e155bc32b23a9d9bf1796077dfa753edfa0c62f7ec671ee81198d09
7
+ data.tar.gz: 7c64b72d543a18e1eee6d8dad9530c7e281a3856003b15d5587bf1351dd55fbbb49a8177e2c8a8cc749549f587e2b42fe76692dd436f0b1d9f57431d9e36cb9e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## Kanrisuru 0.16.5 (December 25, 2021) ##
2
+ * Refactor `dmi_field_translate` to reduce complexity.
3
+
4
+ ## Kanrisuru 0.16.4 (December 25, 2021) ##
5
+ * Refactor `Kanrisuru::Fstab::Entry` and `Kanrisuru::Fstab::Options` classes into separate files.
6
+
7
+ ## Kanrisuru 0.16.3 (December 25, 2021) ##
8
+ * Refactor `Kanrisuru::Mode::Permission` class into separate file.
9
+
10
+ ## Kanrisuru 0.16.2 (December 19, 2021) ##
11
+ * Organize functional ip specs
12
+ * Log in realtime, debug output the stdout from the remote server, as opposed to waiting until after the command is done.
13
+ * Fix the `opensuse_leap` for the stubnetwork rspec helper.
14
+ * Refactor and cleanup the `append_array` method for the `Kanrisuru::Command` instance
15
+ * Move `gpg_opts` for `zypper` command into re-usable method
16
+ * Add functional test cases for `zypper` command.
17
+
1
18
  ## Kanrisuru 0.16.1 (December 16, 2021) ##
2
19
  * Fix require class for `os_package`.
3
20
 
@@ -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 = [value] unless value.instance_of?(Array)
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)
@@ -93,37 +93,41 @@ module Kanrisuru
93
93
  end
94
94
 
95
95
  def dmi_field_translate(struct, field)
96
- field = field.downcase
97
- field = field.gsub(/\s/, '_')
98
- field = field.gsub('-', '_')
99
- field = field.gsub(':', '')
96
+ field = dmi_scrub_field(field)
100
97
 
101
98
  case struct.dmi_type
102
99
  when 'Memory Device'
103
100
  case field
104
101
  when 'size'
105
- return 'mem_size'
102
+ 'mem_size'
106
103
  end
107
104
  when 'System Slots'
108
105
  case field
109
106
  when 'length'
110
- return 'slot_length'
107
+ 'slot_length'
111
108
  end
112
109
  when 'OEM Strings'
113
110
  case field
114
111
  when /^string/
115
- return 'strings'
112
+ 'strings'
116
113
  end
117
114
  when 'Boot Integrity Services'
118
115
  case field
119
116
  when '16_bit_entry_point_address'
120
- return 'sixteen_bit_entry_point_address'
117
+ 'sixteen_bit_entry_point_address'
121
118
  when '32_bit_entry_point_address'
122
- return 'thirty_two_bit_entry_point_address'
119
+ 'thirty_two_bit_entry_point_address'
123
120
  end
121
+ else
122
+ field
124
123
  end
124
+ end
125
125
 
126
- field
126
+ def dmi_scrub_field(field)
127
+ field = field.downcase
128
+ field = field.gsub(/\s/, '_')
129
+ field = field.gsub('-', '_')
130
+ field.gsub(':', '')
127
131
  end
128
132
 
129
133
  def dmi_type_to_struct(type)
@@ -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
- command.append_arg('--name', opts[:name])
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.append_array(opts[:services])
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
- packages = Kanrisuru::Util.array_join_string(opts[:packages], ' ')
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.append_arg('-f', opts[:force])
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
- packages = Kanrisuru::Util.array_join_string(opts[:packages], ' ')
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.append_flag('--gpgcheck', opts[:gpgcheck])
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
- packages = Kanrisuru::Util.array_join_string(opts[:packages], ' ')
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[:media_type])
19
- raise ArgumentError, 'Invalid media type' unless ZYPPER_MEDIA_TYPES.include?(opts[:media_type])
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('--media-type', opts[:media_type])
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
- command.append_array(opts[:services])
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
 
@@ -13,6 +13,8 @@ module Kanrisuru
13
13
  command.append_flag('--no-build-deps', opts[:no_build_deps])
14
14
  command.append_flag('--download-only', opts[:download_only])
15
15
 
16
+ command.append_array(opts[:packages])
17
+
16
18
  execute_shell(command)
17
19
 
18
20
  Kanrisuru::Result.new(command)
@@ -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
@@ -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)
@@ -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