d-installer 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +29 -0
  3. data/Gemfile.lock +75 -0
  4. data/bin/d-installer +74 -0
  5. data/etc/d-installer.yaml +284 -0
  6. data/lib/dinstaller/can_ask_question.rb +48 -0
  7. data/lib/dinstaller/cmdline_args.rb +80 -0
  8. data/lib/dinstaller/cockpit_manager.rb +176 -0
  9. data/lib/dinstaller/config.rb +128 -0
  10. data/lib/dinstaller/config_reader.rb +164 -0
  11. data/lib/dinstaller/dbus/base_object.rb +58 -0
  12. data/lib/dinstaller/dbus/clients/base.rb +71 -0
  13. data/lib/dinstaller/dbus/clients/language.rb +86 -0
  14. data/lib/dinstaller/dbus/clients/manager.rb +76 -0
  15. data/lib/dinstaller/dbus/clients/software.rb +185 -0
  16. data/lib/dinstaller/dbus/clients/users.rb +112 -0
  17. data/lib/dinstaller/dbus/clients/with_progress.rb +56 -0
  18. data/lib/dinstaller/dbus/clients/with_service_status.rb +75 -0
  19. data/lib/dinstaller/dbus/clients.rb +34 -0
  20. data/lib/dinstaller/dbus/interfaces/progress.rb +113 -0
  21. data/lib/dinstaller/dbus/interfaces/service_status.rb +89 -0
  22. data/lib/dinstaller/dbus/language.rb +93 -0
  23. data/lib/dinstaller/dbus/language_service.rb +92 -0
  24. data/lib/dinstaller/dbus/manager.rb +147 -0
  25. data/lib/dinstaller/dbus/manager_service.rb +132 -0
  26. data/lib/dinstaller/dbus/question.rb +176 -0
  27. data/lib/dinstaller/dbus/questions.rb +124 -0
  28. data/lib/dinstaller/dbus/service_runner.rb +97 -0
  29. data/lib/dinstaller/dbus/service_status.rb +87 -0
  30. data/lib/dinstaller/dbus/software/manager.rb +131 -0
  31. data/lib/dinstaller/dbus/software/proposal.rb +82 -0
  32. data/lib/dinstaller/dbus/software.rb +31 -0
  33. data/lib/dinstaller/dbus/software_service.rb +86 -0
  34. data/lib/dinstaller/dbus/storage/proposal.rb +170 -0
  35. data/lib/dinstaller/dbus/storage.rb +30 -0
  36. data/lib/dinstaller/dbus/users.rb +132 -0
  37. data/lib/dinstaller/dbus/users_service.rb +92 -0
  38. data/lib/dinstaller/dbus/with_service_status.rb +48 -0
  39. data/lib/dinstaller/dbus/y2dir/manager/modules/Package.rb +51 -0
  40. data/lib/dinstaller/dbus/y2dir/manager/modules/PackagesProposal.rb +62 -0
  41. data/lib/dinstaller/dbus/y2dir/modules/Autologin.rb +214 -0
  42. data/lib/dinstaller/dbus/y2dir/software/modules/SpaceCalculation.rb +44 -0
  43. data/lib/dinstaller/dbus.rb +11 -0
  44. data/lib/dinstaller/errors.rb +28 -0
  45. data/lib/dinstaller/installation_phase.rb +106 -0
  46. data/lib/dinstaller/language.rb +73 -0
  47. data/lib/dinstaller/luks_activation_question.rb +92 -0
  48. data/lib/dinstaller/manager.rb +261 -0
  49. data/lib/dinstaller/network.rb +53 -0
  50. data/lib/dinstaller/package_callbacks.rb +69 -0
  51. data/lib/dinstaller/progress.rb +149 -0
  52. data/lib/dinstaller/question.rb +103 -0
  53. data/lib/dinstaller/questions_manager.rb +145 -0
  54. data/lib/dinstaller/security.rb +96 -0
  55. data/lib/dinstaller/service_status_recorder.rb +58 -0
  56. data/lib/dinstaller/software.rb +232 -0
  57. data/lib/dinstaller/storage/actions.rb +90 -0
  58. data/lib/dinstaller/storage/callbacks/activate.rb +93 -0
  59. data/lib/dinstaller/storage/callbacks/activate_luks.rb +93 -0
  60. data/lib/dinstaller/storage/callbacks/activate_multipath.rb +77 -0
  61. data/lib/dinstaller/storage/callbacks.rb +30 -0
  62. data/lib/dinstaller/storage/manager.rb +104 -0
  63. data/lib/dinstaller/storage/proposal.rb +197 -0
  64. data/lib/dinstaller/storage.rb +30 -0
  65. data/lib/dinstaller/users.rb +156 -0
  66. data/lib/dinstaller/with_progress.rb +63 -0
  67. data/lib/dinstaller.rb +5 -0
  68. data/share/dbus.conf +38 -0
  69. data/share/dbus.service +5 -0
  70. data/share/systemd.service +14 -0
  71. metadata +295 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 253a15d3d68d11b66044b110aff597967e2b1a9cfd39d8d30d2de1e6300519a0
4
+ data.tar.gz: 5cb5c1dc86a5c2849ef73220720001b72a75873d7d37a354ca9fc0ab01c35701
5
+ SHA512:
6
+ metadata.gz: ff631f672cfb779c4662f35fdc0434a6767a43f1f367938ebd7632321e71f9ae89dfcde0f06ac5acca2ce697c792b4b5c5ccdd44b264a6fd0487ff651499f4b7
7
+ data.tar.gz: da4f9bdaf7484c7e259258b417a069f9b0106b25c47555b73ca23273f7662ce0a8488c4d1f4e58a9a5dcbdf6f80a1cc5da3252e0ccf15a78b2f5c1fb96f1f877
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) [2022] SUSE LLC
5
+ #
6
+ # All Rights Reserved.
7
+ #
8
+ # This program is free software; you can redistribute it and/or modify it
9
+ # under the terms of version 2 of the GNU General Public License as published
10
+ # by the Free Software Foundation.
11
+ #
12
+ # This program is distributed in the hope that it will be useful, but WITHOUT
13
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
+ # more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License along
18
+ # with this program; if not, contact SUSE LLC.
19
+ #
20
+ # To contact SUSE LLC about this file by physical or electronic mail, you may
21
+ # find current contact information at www.suse.com.
22
+
23
+ source "https://rubygems.org"
24
+
25
+ gemspec
26
+
27
+ group :development do
28
+ gem "byebug"
29
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ d-installer (0.4.2)
5
+ cfa (~> 1.0.2)
6
+ cfa_grub2 (~> 2.0.0)
7
+ cheetah (~> 1.0.0)
8
+ eventmachine (~> 1.2.7)
9
+ fast_gettext (~> 2.2.0)
10
+ nokogiri (~> 1.13.1)
11
+ rexml (~> 3.2.5)
12
+ ruby-dbus (~> 0.18.1)
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ abstract_method (1.2.1)
18
+ byebug (11.1.3)
19
+ cfa (1.0.2)
20
+ ruby-augeas
21
+ cfa_grub2 (2.0.0)
22
+ cfa (~> 1.0)
23
+ cheetah (1.0.0)
24
+ abstract_method (~> 1.2)
25
+ diff-lcs (1.5.0)
26
+ docile (1.4.0)
27
+ eventmachine (1.2.7)
28
+ fast_gettext (2.2.0)
29
+ mini_portile2 (2.8.0)
30
+ nokogiri (1.13.8)
31
+ mini_portile2 (~> 2.8.0)
32
+ racc (~> 1.4)
33
+ nokogiri (1.13.8-x86_64-linux)
34
+ racc (~> 1.4)
35
+ packaging_rake_tasks (1.5.1)
36
+ rake
37
+ racc (1.6.0)
38
+ rake (13.0.6)
39
+ rexml (3.2.5)
40
+ rspec (3.11.0)
41
+ rspec-core (~> 3.11.0)
42
+ rspec-expectations (~> 3.11.0)
43
+ rspec-mocks (~> 3.11.0)
44
+ rspec-core (3.11.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-expectations (3.11.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-mocks (3.11.1)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.11.0)
52
+ rspec-support (3.11.0)
53
+ ruby-augeas (0.5.0)
54
+ ruby-dbus (0.18.1)
55
+ rexml
56
+ simplecov (0.21.2)
57
+ docile (~> 1.1)
58
+ simplecov-html (~> 0.11)
59
+ simplecov_json_formatter (~> 0.1)
60
+ simplecov-html (0.12.3)
61
+ simplecov-lcov (0.8.0)
62
+ simplecov_json_formatter (0.1.4)
63
+
64
+ PLATFORMS
65
+ ruby
66
+ x86_64-linux
67
+
68
+ DEPENDENCIES
69
+ byebug
70
+ d-installer!
71
+ packaging_rake_tasks (~> 1.5.1)
72
+ rake (~> 13.0.6)
73
+ rspec (~> 3.11.0)
74
+ simplecov (~> 0.21.2)
75
+ simplecov-lcov (~> 0.8.0)
data/bin/d-installer ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # Copyright (c) [2022] SUSE LLC
6
+ #
7
+ # All Rights Reserved.
8
+ #
9
+ # This program is free software; you can redistribute it and/or modify it
10
+ # under the terms of version 2 of the GNU General Public License as published
11
+ # by the Free Software Foundation.
12
+ #
13
+ # This program is distributed in the hope that it will be useful, but WITHOUT
14
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
+ # more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License along
19
+ # with this program; if not, contact SUSE LLC.
20
+ #
21
+ # To contact SUSE LLC about this file by physical or electronic mail, you may
22
+ # find current contact information at www.suse.com.
23
+
24
+ # TEMPORARY overwrite of Y2DIR to use DBus for communication with dependent yast modules
25
+
26
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
27
+
28
+ require "rubygems"
29
+ require "bundler/setup"
30
+ require "dinstaller/dbus/service_runner"
31
+
32
+ # Runs the service with the given name
33
+ #
34
+ # @param name [Symbol] Service name
35
+ # @see ORDERED_SERVICES
36
+ def start_service(name)
37
+ general_y2dir = File.expand_path("../lib/dinstaller/dbus/y2dir", __dir__)
38
+ module_y2dir = File.expand_path("../lib/dinstaller/dbus/y2dir/#{name}", __dir__)
39
+ ENV["Y2DIR"] = "#{module_y2dir}:#{general_y2dir}"
40
+
41
+ logger = Logger.new($stdout, progname: name.to_s)
42
+ service_runner = DInstaller::DBus::ServiceRunner.new(name, logger: logger)
43
+ service_runner.run
44
+ end
45
+
46
+ ORDERED_SERVICES = [:language, :software, :users, :manager].freeze
47
+
48
+ # Starts all the services
49
+ #
50
+ # @return [Array<Integer>] PIDs
51
+ # @see ORDERED_SERVICES
52
+ def start_all_services
53
+ ORDERED_SERVICES.map do |name|
54
+ fork { exec("#{__FILE__} #{name}") }
55
+ # TODO: implement a better mechanism to check whether the service is running
56
+ sleep(1)
57
+ end
58
+ end
59
+
60
+ if ARGV.empty?
61
+ pids = start_all_services
62
+ Signal.trap("SIGINT") do
63
+ puts "Stopping all services..."
64
+ exit
65
+ end
66
+ Process.wait
67
+ else
68
+ name = ARGV[0]
69
+ Signal.trap("SIGINT") do
70
+ puts "Stopping #{name} service..."
71
+ exit
72
+ end
73
+ start_service(name.to_sym)
74
+ end
@@ -0,0 +1,284 @@
1
+ products:
2
+ Tumbleweed:
3
+ name: openSUSE Tumbleweed
4
+ description: 'The Tumbleweed distribution is a pure rolling release version
5
+ of openSUSE containing the latest "stable" versions of all software
6
+ instead of relying on rigid periodic release cycles. The project does
7
+ this for users that want the newest stable software.'
8
+ Leap Micro:
9
+ name: openSUSE Leap Micro 5.2
10
+ description: 'Leap Micro is an ultra-reliable, lightweight operating system
11
+ built for containerized and virtualized workloads. This community version
12
+ is based on SUSE Linux Enterprise Micro, which leverages the enterprise
13
+ hardened security and compliance components of SUSE Linux Enterprise.'
14
+ Leap:
15
+ name: openSUSE Leap 15.4
16
+ description: 'Leap uses source from SUSE Linux Enterprise (SLE), which
17
+ gives Leap a level of stability unmatched by other Linux distributions,
18
+ and combines that with community developments to give users, developers
19
+ and sysadmins the best stable Linux experience available.'
20
+
21
+ web:
22
+ ssl: null
23
+ ssl_cert: null
24
+ ssl_key: null
25
+
26
+
27
+ Tumbleweed:
28
+ software:
29
+ installation_repositories:
30
+ - https://download.opensuse.org/tumbleweed/repo/oss/
31
+ - https://download.opensuse.org/tumbleweed/repo/non-oss/
32
+ - https://download.opensuse.org/update/tumbleweed/
33
+ mandatory_patterns:
34
+ - enhanced_base # only pattern that is shared among all roles on TW
35
+ optional_patterns: null # no optional pattern shared
36
+ base_product: openSUSE
37
+
38
+ security:
39
+ lsm: apparmor
40
+ available_lsms:
41
+ apparmor:
42
+ patterns:
43
+ - apparmor
44
+ selinux:
45
+ patterns:
46
+ - selinux
47
+ policy: permissive
48
+ none:
49
+ patterns: null
50
+
51
+ storage:
52
+ volumes:
53
+ - mount_point: "/"
54
+ fs_type: btrfs
55
+ desired_size: 10 GiB
56
+ min_size: 5 GiB
57
+ max_size: unlimited
58
+ weight: 30
59
+
60
+ # There must always be a root
61
+ proposed_configurable: false
62
+
63
+ snapshots: true
64
+ snapshots_percentage: 250
65
+ snapshots_configurable: true
66
+ # Disable snapshots if there is not enough room
67
+ disable_order: 3
68
+
69
+ btrfs_default_subvolume: "@"
70
+ subvolumes:
71
+ - path: home
72
+ - path: opt
73
+ - path: root
74
+ - path: srv
75
+ - path: usr/local
76
+ # Unified var subvolume - https://lists.opensuse.org/opensuse-packaging/2017-11/msg00017.html
77
+ - path: var
78
+ copy_on_write: false
79
+
80
+ # Architecture specific subvolumes
81
+ - path: boot/grub2/arm64-efi
82
+ archs: aarch64
83
+ - path: boot/grub2/arm-efi
84
+ archs: arm
85
+ - path: boot/grub2/i386-pc
86
+ archs: x86_64
87
+ - path: boot/grub2/powerpc-ieee1275
88
+ archs: ppc,!board_powernv
89
+ - path: boot/grub2/s390x-emu
90
+ archs: s390
91
+ - path: boot/grub2/x86_64-efi
92
+ archs: x86_64
93
+ - path: boot/grub2/riscv64-efi
94
+ archs: riscv64
95
+
96
+ - mount_point: "/home"
97
+ fs_type: xfs
98
+ desired_size: 40 GiB
99
+ min_size: 10 GiB
100
+ max_size: unlimited
101
+ weight: 60
102
+
103
+ proposed: false
104
+ proposed_configurable: true
105
+ disable_order: 1
106
+
107
+ - mount_point: "swap"
108
+ fs_type: swap
109
+ desired_size: 2 GiB
110
+ min_size: 1 GiB
111
+ max_size: 2 GiB
112
+ weight: 10
113
+
114
+ adjust_by_ram: false
115
+ adjust_by_ram_configurable: true
116
+
117
+ proposed_configurable: true
118
+ disable_order: 2
119
+
120
+ Leap:
121
+ software:
122
+ installation_repositories:
123
+ # TODO: support somehow $releasever in URL
124
+ - https://download.opensuse.org/distribution/leap/15.4/repo/oss/
125
+ - https://download.opensuse.org/distribution/leap/15.4/repo/non-oss/
126
+ - https://download.opensuse.org/update/leap/15.4/oss/
127
+ - https://download.opensuse.org/update/leap/15.4/non-oss/
128
+ - https://download.opensuse.org/update/leap/15.4/sle/
129
+ - https://download.opensuse.org/update/leap/15.4/backports/
130
+ mandatory_patterns:
131
+ - enhanced_base # For now lets pick some minimal one
132
+ optional_patterns: null # no optional pattern shared
133
+ base_product: Leap
134
+
135
+ security:
136
+ # TODO: check if skelcd for Leap 15.4 is correct as code is using lsm in globals, but skelcd contain selinux only
137
+ lsm: apparmor
138
+ available_lsms:
139
+ apparmor:
140
+ patterns:
141
+ - apparmor
142
+ selinux:
143
+ patterns:
144
+ - selinux
145
+ policy: disabled
146
+ none:
147
+ patterns: null
148
+
149
+ storage:
150
+ volumes:
151
+ - mount_point: "/"
152
+ fs_type: btrfs
153
+ desired_size: 10 GiB
154
+ min_size: 5 GiB
155
+ max_size: unlimited
156
+ weight: 30
157
+
158
+ # There must always be a root
159
+ proposed_configurable: false
160
+
161
+ snapshots: true
162
+ snapshots_percentage: 250
163
+ snapshots_configurable: true
164
+ # Disable snapshots if there is not enough room
165
+ disable_order: 3
166
+
167
+ btrfs_default_subvolume: "@"
168
+ subvolumes:
169
+ - path: home
170
+ - path: opt
171
+ - path: root
172
+ - path: srv
173
+ - path: usr/local
174
+ # Unified var subvolume - https://lists.opensuse.org/opensuse-packaging/2017-11/msg00017.html
175
+ - path: var
176
+ copy_on_write: false
177
+
178
+ # Architecture specific subvolumes
179
+ - path: boot/grub2/arm64-efi
180
+ archs: aarch64
181
+ - path: boot/grub2/i386-pc
182
+ archs: x86_64
183
+ - path: boot/grub2/powerpc-ieee1275
184
+ archs: ppc,!board_powernv
185
+ - path: boot/grub2/s390x-emu
186
+ archs: s390
187
+ - path: boot/grub2/x86_64-efi
188
+ archs: x86_64
189
+
190
+ - mount_point: "/home"
191
+ fs_type: xfs
192
+ desired_size: 40 GiB
193
+ min_size: 10 GiB
194
+ max_size: unlimited
195
+ weight: 60
196
+
197
+ proposed: false
198
+ proposed_configurable: true
199
+ disable_order: 1
200
+
201
+ - mount_point: "swap"
202
+ fs_type: swap
203
+ desired_size: 2 GiB
204
+ min_size: 1 GiB
205
+ max_size: 2 GiB
206
+ weight: 10
207
+
208
+ adjust_by_ram: false
209
+ adjust_by_ram_configurable: true
210
+
211
+ proposed_configurable: true
212
+ disable_order: 2
213
+
214
+
215
+ Leap Micro:
216
+ software:
217
+ installation_repositories:
218
+ - https://download.opensuse.org/distribution/leap-micro/5.2/product/repo/Leap-Micro-5.2-x86_64-Media/
219
+ mandatory_patterns:
220
+ - microos-base
221
+ - microos-hardware
222
+ - microos-bootloader
223
+ - microos-defaults
224
+ - microos-basesystem
225
+ optional_patterns: null # no optional pattern shared
226
+ base_product: Leap-Micro
227
+
228
+ security:
229
+ lsm: selinux
230
+ available_lsms:
231
+ selinux:
232
+ patterns:
233
+ - microos-selinux
234
+ policy: enforcing
235
+ none:
236
+ patterns: null
237
+
238
+ storage:
239
+ volumes:
240
+ - mount_point: "/"
241
+ fs_type: btrfs
242
+ desired_size: 20 GiB
243
+ min_size: 5 GiB
244
+ max_size: 20 GiB
245
+ fs_types:
246
+ - btrfs
247
+ weight: 20
248
+ snapshots: true
249
+ snapshots_configurable: false
250
+ proposed_configurable: false
251
+ btrfs_default_subvolume: "@"
252
+ btrfs_read_only: true
253
+ subvolumes:
254
+ - path: root
255
+ - path: home
256
+ - path: opt
257
+ - path: srv
258
+ - path: root
259
+ - path: boot/writable
260
+ - path: usr/local
261
+ - path: boot/grub2/arm64-efi
262
+ archs: aarch64
263
+ - path: boot/grub2/i386-pc
264
+ archs: x86_64
265
+ - path: boot/grub2/powerpc-ieee1275
266
+ archs: ppc,!board_powernv
267
+ - path: boot/grub2/s390x-emu
268
+ archs: s390
269
+ - path: boot/grub2/x86_64-efi
270
+ archs: x86_64
271
+ - mount_point: "/var"
272
+ fs_type: btrfs
273
+ fs_types:
274
+ - btrfs
275
+ desired_size: 19 GiB
276
+ min_size: 5 GiB
277
+ max_size: unlimited
278
+ weight: 40
279
+ snapshots: false
280
+ snapshots_configurable: false
281
+ disable_order: 1
282
+ fallback_for_desired_size: "/"
283
+ fallback_for_max_size: "/"
284
+ fallback_for_weight: "/"
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) [2022] SUSE LLC
4
+ #
5
+ # All Rights Reserved.
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify it
8
+ # under the terms of version 2 of the GNU General Public License as published
9
+ # by the Free Software Foundation.
10
+ #
11
+ # This program is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
+ # more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License along
17
+ # with this program; if not, contact SUSE LLC.
18
+ #
19
+ # To contact SUSE LLC about this file by physical or electronic mail, you may
20
+ # find current contact information at www.suse.com.
21
+
22
+ module DInstaller
23
+ # Mixin providing a method to ask a question and wait
24
+ module CanAskQuestion
25
+ # @!method questions_manager
26
+ # @note Classes including this mixin must define a #questions_manager method
27
+ # @return [QuestionsManager]
28
+
29
+ # Asks the given question and waits until the question is answered
30
+ #
31
+ # @example
32
+ # ask(question1) #=> Symbol
33
+ # ask(question2) { |q| q.answer == :yes } #=> Boolean
34
+ #
35
+ # @param question [Question]
36
+ # @yield [Question] Gives the answered question to the block.
37
+ # @return [Symbol, Object] The question answer, or the result of the block in case a block is
38
+ # given.
39
+ def ask(question)
40
+ questions_manager.add(question)
41
+ questions_manager.wait
42
+ result = block_given? ? yield(question) : question.answer
43
+ questions_manager.delete(question)
44
+
45
+ result
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) [2022] SUSE LLC
4
+ #
5
+ # All Rights Reserved.
6
+ #
7
+ # This program is free software; you can redistribute it and/or modify it
8
+ # under the terms of version 2 of the GNU General Public License as published
9
+ # by the Free Software Foundation.
10
+ #
11
+ # This program is distributed in the hope that it will be useful, but WITHOUT
12
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
+ # more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License along
17
+ # with this program; if not, contact SUSE LLC.
18
+ #
19
+ # To contact SUSE LLC about this file by physical or electronic mail, you may
20
+ # find current contact information at www.suse.com.
21
+
22
+ module DInstaller
23
+ # This class is responsible for reading DInstaller kernel cmdline options
24
+ class CmdlineArgs
25
+ CMDLINE_PATH = "/proc/cmdline"
26
+ CMDLINE_PREFIX = "dinst."
27
+
28
+ attr_accessor :config_url
29
+ attr_reader :data
30
+
31
+ # Constructor
32
+ #
33
+ # @param data [Hash]
34
+ def initialize(data = {})
35
+ @data = data
36
+ end
37
+
38
+ # Reads the kernel command line options
39
+ def self.read_from(path)
40
+ options = File.read(path)
41
+ args = new({})
42
+
43
+ options.split.each do |option|
44
+ next unless option.start_with?(CMDLINE_PREFIX)
45
+
46
+ key, value = option.split("=")
47
+ key.gsub!(CMDLINE_PREFIX, "")
48
+ # Omit config_url from Config options
49
+ next args.config_url = value if key == "config_url"
50
+
51
+ # TODO: Add some kind of schema or 'knowledge' of attribute types to convert them properly
52
+ # by now we will just convert Boolean values
53
+ value = normalize(value)
54
+ if key.include?(".")
55
+ section, key = key.split(".")
56
+ args.data[section] = {} unless args.data.keys.include?(section)
57
+ args.data[section][key] = value
58
+ else
59
+ args.data[key.gsub(CMDLINE_PREFIX, "")] = value
60
+ end
61
+ end
62
+
63
+ args
64
+ end
65
+
66
+ # Convenience method to normalize the given value by now it just convert "true" and "false"
67
+ # strings to {Boolean}s
68
+ #
69
+ # @param value [String]
70
+ # @return [Object] normalized value
71
+ def self.normalize(value)
72
+ val = value.to_s.downcase
73
+ return value unless ["false", "true"].include?(val)
74
+
75
+ (val == "true")
76
+ end
77
+
78
+ private_class_method :normalize
79
+ end
80
+ end