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
@@ -0,0 +1,76 @@
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
+ require "dinstaller/dbus/clients/base"
23
+ require "dinstaller/dbus/clients/with_service_status"
24
+ require "dinstaller/dbus/clients/with_progress"
25
+ require "dinstaller/dbus/manager"
26
+ require "dinstaller/installation_phase"
27
+
28
+ module DInstaller
29
+ module DBus
30
+ module Clients
31
+ # D-Bus client for manager service
32
+ class Manager < Base
33
+ include WithServiceStatus
34
+ include WithProgress
35
+
36
+ def initialize
37
+ super
38
+
39
+ @dbus_object = service["/org/opensuse/DInstaller/Manager1"]
40
+ @dbus_object.introspect
41
+ end
42
+
43
+ def service_name
44
+ @service_name ||= "org.opensuse.DInstaller"
45
+ end
46
+
47
+ def probe
48
+ dbus_object.Probe
49
+ end
50
+
51
+ # Starts the installation
52
+ def commit
53
+ dbus_object.Commit
54
+ end
55
+
56
+ def current_installation_phase
57
+ dbus_phase = dbus_object["org.opensuse.DInstaller.Manager1"]["CurrentInstallationPhase"]
58
+
59
+ case dbus_phase
60
+ when DBus::Manager::STARTUP_PHASE
61
+ InstallationPhase::STARTUP
62
+ when DBus::Manager::CONFIG_PHASE
63
+ InstallationPhase::CONFIG
64
+ when DBus::Manager::INSTALL_PHASE
65
+ InstallationPhase::INSTALL
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ # @return [::DBus::Object]
72
+ attr_reader :dbus_object
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,185 @@
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
+ require "dinstaller/dbus/clients/base"
23
+ require "dinstaller/dbus/clients/with_service_status"
24
+ require "dinstaller/dbus/clients/with_progress"
25
+
26
+ module DInstaller
27
+ module DBus
28
+ module Clients
29
+ # D-Bus client for software configuration
30
+ class Software < Base
31
+ include WithServiceStatus
32
+ include WithProgress
33
+
34
+ TYPES = [:package, :pattern].freeze
35
+ private_constant :TYPES
36
+
37
+ def initialize
38
+ super
39
+
40
+ @dbus_object = service["/org/opensuse/DInstaller/Software1"]
41
+ @dbus_object.introspect
42
+
43
+ @dbus_proposal = service["/org/opensuse/DInstaller/Software/Proposal1"]
44
+ @dbus_proposal.introspect
45
+ end
46
+
47
+ # @return [String]
48
+ def service_name
49
+ @service_name ||= "org.opensuse.DInstaller.Software"
50
+ end
51
+
52
+ # Available products for the installation
53
+ #
54
+ # @return [Array<Array<String, String>>] name and display name of each product
55
+ def available_products
56
+ dbus_object["org.opensuse.DInstaller.Software1"]["AvailableBaseProducts"].map do |l|
57
+ l[0..1]
58
+ end
59
+ end
60
+
61
+ # Product selected to install
62
+ #
63
+ # @return [String] name of the product
64
+ def selected_product
65
+ dbus_object["org.opensuse.DInstaller.Software1"]["SelectedBaseProduct"]
66
+ end
67
+
68
+ # Selects the product to install
69
+ #
70
+ # @param name [String]
71
+ def select_product(name)
72
+ dbus_object.SelectProduct(name)
73
+ end
74
+
75
+ # Starts the probing process
76
+ #
77
+ # If a block is given, the method returns immediately and the probing is performed in an
78
+ # asynchronous way.
79
+ #
80
+ # @param done [Proc] Block to execute once the probing is done
81
+ def probe(&done)
82
+ dbus_object.Probe(&done)
83
+ end
84
+
85
+ # Performs the packages installation
86
+ def install
87
+ dbus_object.Install
88
+ end
89
+
90
+ # Makes the software proposal
91
+ def propose
92
+ dbus_object.Propose
93
+ end
94
+
95
+ # Finishes the software installation
96
+ def finish
97
+ dbus_object.Finish
98
+ end
99
+
100
+ # Determine whether the given tag are provided by the selected packages
101
+ #
102
+ # @param tag [String] Tag to search for (package names, requires/provides, or file
103
+ # names)
104
+ # @return [Boolean] true if it is provided; false otherwise
105
+ def provision_selected?(tag)
106
+ dbus_object.ProvisionSelected(tag)
107
+ end
108
+
109
+ # Determine whether the given tags are provided by the selected packages
110
+ #
111
+ # @param tags [Array<String>] Tags to search for (package names, requires/provides, or file
112
+ # names)
113
+ # @return [Array<Boolean>] An array containing whether each tag is selected or not
114
+ def provisions_selected?(tags)
115
+ dbus_object.ProvisionsSelected(tags)
116
+ end
117
+
118
+ # Add the given list of resolvables to the packages proposal
119
+ #
120
+ # @param unique_id [String] Unique identifier for the resolvables list
121
+ # @param type [Symbol] Resolvables type (:package or :pattern)
122
+ # @param resolvables [Array<String>] Resolvables to add
123
+ # @param [Boolean] optional True for optional list, false (the default) for
124
+ # the required list
125
+ def add_resolvables(unique_id, type, resolvables, optional: false)
126
+ dbus_proposal.AddResolvables(unique_id, TYPES.index(type), resolvables, optional)
127
+ end
128
+
129
+ # Returns a list of resolvables
130
+ #
131
+ # @param unique_id [String] Unique identifier for the resolvables list
132
+ # @param type [Symbol] Resolvables type (:package or :pattern)
133
+ # @param [Boolean] optional True for optional list, false (the default) for
134
+ # the required list
135
+ # @return [Array<String>] Resolvables
136
+ def get_resolvables(unique_id, type, optional: false)
137
+ dbus_proposal.GetResolvables(unique_id, TYPES.index(type), optional).first
138
+ end
139
+
140
+ # Replace a list of resolvables in the packages proposal
141
+ #
142
+ # @param unique_id [String] Unique identifier for the resolvables list
143
+ # @param type [Symbol] Resolvables type (:package or :pattern)
144
+ # @param resolvables [Array<String>] List of resolvables
145
+ # @param [Boolean] optional True for optional list, false (the default) for
146
+ # the required list
147
+ def set_resolvables(unique_id, type, resolvables, optional: false)
148
+ dbus_proposal.SetResolvables(unique_id, TYPES.index(type), resolvables, optional)
149
+ end
150
+
151
+ # Remove resolvables from a list
152
+ #
153
+ # @param unique_id [String] Unique identifier for the resolvables list
154
+ # @param type [Symbol] Resolvables type (:package or :pattern)
155
+ # @param resolvables [Array<String>] Resolvables to remove
156
+ # @param [Boolean] optional True for optional list, false (the default) for
157
+ # the required list
158
+ def remove_resolvables(unique_id, type, resolvables, optional: false)
159
+ dbus_proposal.RemoveResolvables(unique_id, TYPES.index(type), resolvables, optional)
160
+ end
161
+
162
+ # Registers a callback to run when the product changes
163
+ #
164
+ # @note Signal subscription is done only once. Otherwise, the latest subscription overrides
165
+ # the previous one.
166
+ #
167
+ # @param block [Proc] Callback to run when a product is selected
168
+ def on_product_selected(&block)
169
+ on_properties_change(dbus_object) do |_, changes, _|
170
+ base_product = changes["SelectedBaseProduct"]
171
+ block.call(base_product) unless base_product.nil?
172
+ end
173
+ end
174
+
175
+ private
176
+
177
+ # @return [::DBus::Object]
178
+ attr_reader :dbus_object
179
+
180
+ # @return [::DBus::Object]
181
+ attr_reader :dbus_proposal
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,112 @@
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
+ require "dinstaller/dbus/clients/base"
23
+ require "dinstaller/dbus/clients/with_service_status"
24
+
25
+ module DInstaller
26
+ module DBus
27
+ module Clients
28
+ # D-Bus client for users configuration
29
+ class Users < Base
30
+ include WithServiceStatus
31
+
32
+ def initialize
33
+ super
34
+
35
+ @dbus_object = service["/org/opensuse/DInstaller/Users1"]
36
+ @dbus_object.introspect
37
+ end
38
+
39
+ # @return [String]
40
+ def service_name
41
+ @service_name ||= "org.opensuse.DInstaller.Users"
42
+ end
43
+
44
+ # Configuration of the first user to create during the installation
45
+ #
46
+ # @return [Array<String, String, Boolean>] full name, name and autologin
47
+ def first_user
48
+ dbus_object["org.opensuse.DInstaller.Users1"]["FirstUser"][0..2]
49
+ end
50
+
51
+ # Configures the first user to create during the installation
52
+ #
53
+ # @param name [String]
54
+ # @param fullname [String, nil]
55
+ # @param password [String, nil]
56
+ # @param autologin [Boolean]
57
+ def create_first_user(name, fullname: nil, password: nil, autologin: false)
58
+ dbus_object.SetFirstUser(fullname.to_s, name, password.to_s, !!autologin, {})
59
+ end
60
+
61
+ # Removes the configuration of the first user
62
+ def remove_first_user
63
+ dbus_object.RemoveFirstUser
64
+ end
65
+
66
+ # SSH key for root
67
+ #
68
+ # @return [String] empty if no SSH key set
69
+ def root_ssh_key
70
+ dbus_object["org.opensuse.DInstaller.Users1"]["RootSSHKey"]
71
+ end
72
+
73
+ # Sets the SSH key for root
74
+ #
75
+ # @param value [String]
76
+ def root_ssh_key=(value)
77
+ dbus_object.SetRootSSHKey(value)
78
+ end
79
+
80
+ # Whether the root password is set
81
+ #
82
+ # @return [Boolean]
83
+ def root_password?
84
+ dbus_object["org.opensuse.DInstaller.Users1"]["RootPasswordSet"]
85
+ end
86
+
87
+ # Sets the root password
88
+ #
89
+ # @param value [String]
90
+ def root_password=(value)
91
+ dbus_object.SetRootPassword(value, false)
92
+ end
93
+
94
+ # Removes the SSH key and password for root
95
+ def remove_root_info
96
+ dbus_object.RemoveRootPassword
97
+ dbus_object.SetRootSSHKey("")
98
+ end
99
+
100
+ # Commit the changes
101
+ def write
102
+ dbus_object.Write
103
+ end
104
+
105
+ private
106
+
107
+ # @return [::DBus::Object]
108
+ attr_reader :dbus_object
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,56 @@
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
+ require "dinstaller/dbus/interfaces/progress"
23
+
24
+ module DInstaller
25
+ module DBus
26
+ module Clients
27
+ # Mixin for clients of services that define the Progress D-Bus interface
28
+ #
29
+ # Provides methods to interact with the API of the Progress interface.
30
+ #
31
+ # @note This mixin is expected to be included in a class inherited from {Clients::Base} and
32
+ # it requires a #dbus_object method that returns a {::DBus::Object} implementing the
33
+ # Progress interface.
34
+ module WithProgress
35
+ # Registers a callback to run when the progress changes
36
+ #
37
+ # @param block [Proc]
38
+ # @yieldparam total_steps [Integer]
39
+ # @yieldparam current_step [Integer]
40
+ # @yieldparam message [String]
41
+ # @yieldparam finished [Boolean]
42
+ def on_progress_change(&block)
43
+ on_properties_change(dbus_object) do |interface, changes, _|
44
+ if interface == Interfaces::Progress::PROGRESS_INTERFACE
45
+ total_steps = changes["TotalSteps"]
46
+ current_step = changes["CurrentStep"][0]
47
+ message = changes["CurrentStep"][1]
48
+ finished = changes["Finished"]
49
+ block.call(total_steps, current_step, message, finished)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,75 @@
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
+ require "dbus"
23
+ require "dinstaller/dbus/service_status"
24
+ require "dinstaller/dbus/interfaces/service_status"
25
+
26
+ module DInstaller
27
+ module DBus
28
+ module Clients
29
+ # Mixin for clients of services that define the ServiceStatus D-Bus interface
30
+ #
31
+ # Provides methods to interact with the API of the ServiceStatus interface.
32
+ #
33
+ # @note This mixin is expected to be included in a class inherited from {Clients::Base} and
34
+ # it requires a #dbus_object method that returns a {::DBus::Object} implementing the
35
+ # ServiceStatus interface.
36
+ module WithServiceStatus
37
+ # Current value of the service status
38
+ #
39
+ # @see Interfaces::ServiceStatus
40
+ #
41
+ # @return [ServiceStatus::IDLE, ServiceStatus::BUSY]
42
+ def service_status
43
+ dbus_status = dbus_object[Interfaces::ServiceStatus::SERVICE_STATUS_INTERFACE]["Current"]
44
+ to_service_status(dbus_status)
45
+ end
46
+
47
+ # Registers a callback to run when the current status property changes
48
+ #
49
+ # @param block [Proc]
50
+ # @yieldparam service_status [ServiceStatus::IDLE, ServiceStatus::BUSY]
51
+ def on_service_status_change(&block)
52
+ on_properties_change(dbus_object) do |interface, changes, _|
53
+ if interface == Interfaces::ServiceStatus::SERVICE_STATUS_INTERFACE
54
+ service_status = to_service_status(changes["Current"])
55
+ block.call(service_status)
56
+ end
57
+ end
58
+ end
59
+
60
+ # Converts the D-Bus status value to the equivalent service status value
61
+ #
62
+ # @param dbus_status [Integer]
63
+ # @return [ServiceStatus::IDLE, ServiceStatus::BUSY]
64
+ def to_service_status(dbus_status)
65
+ case dbus_status
66
+ when Interfaces::ServiceStatus::SERVICE_STATUS_IDLE
67
+ ServiceStatus::IDLE
68
+ when Interfaces::ServiceStatus::SERVICE_STATUS_BUSY
69
+ ServiceStatus::BUSY
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,34 @@
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
+ module DBus
24
+ # Namespace for Clients for DBus API.
25
+ # It provides API to be called from other services.
26
+ # E.g. Users class is used from other services to call Users DBus API.
27
+ module Clients
28
+ end
29
+ end
30
+ end
31
+
32
+ require "dinstaller/dbus/clients/dinstaller"
33
+ require "dinstaller/dbus/clients/software"
34
+ require "dinstaller/dbus/clients/users"
@@ -0,0 +1,113 @@
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
+ require "dbus"
23
+
24
+ module DInstaller
25
+ module DBus
26
+ module Interfaces
27
+ # Mixin to define the Progress D-Bus interface
28
+ #
29
+ # @note This mixin is expected to be included in a class inherited from {DBus::BaseObject}
30
+ # class and it requires a #backend method that returns an instance of a class including the
31
+ # {DInstaller::WithProgress} mixin.
32
+ #
33
+ # @example
34
+ # class Backend
35
+ # include DInstaller::WithProgress
36
+ # end
37
+ #
38
+ # class Demo < DInstaller::DBus::BaseObject
39
+ # include DInstaller::DBus::Interfaces::Progress
40
+ #
41
+ # def initialize
42
+ # super("org.test.Demo")
43
+ # register_progress_callbacks
44
+ # end
45
+ #
46
+ # def backend
47
+ # @backend ||= Backend.new
48
+ # end
49
+ # end
50
+ module Progress
51
+ PROGRESS_INTERFACE = "org.opensuse.DInstaller.Progress1"
52
+
53
+ # Total number of steps of the progress
54
+ #
55
+ # @return [Integer] 0 if no progress defined
56
+ def progress_total_steps
57
+ return 0 unless backend.progress
58
+
59
+ backend.progress.total_steps
60
+ end
61
+
62
+ # Current step data
63
+ #
64
+ # @return [Array(Number,String)] Step id and description
65
+ def progress_current_step
66
+ current_step = backend.progress&.current_step
67
+ return [0, ""] unless current_step
68
+
69
+ [current_step.id, current_step.description]
70
+ end
71
+
72
+ # Whether the progress has finished
73
+ #
74
+ # @return [Boolean]
75
+ def progress_finished
76
+ return true unless backend.progress
77
+
78
+ backend.progress.finished?
79
+ end
80
+
81
+ # D-Bus properties of the Progress interface
82
+ #
83
+ # @return [Hash]
84
+ def progress_properties
85
+ interfaces_and_properties[PROGRESS_INTERFACE]
86
+ end
87
+
88
+ # Registers callbacks to be called when the progress changes or finishes
89
+ #
90
+ # @note This method is expected to be called in the constructor.
91
+ def register_progress_callbacks
92
+ backend.on_progress_change do
93
+ dbus_properties_changed(PROGRESS_INTERFACE, progress_properties, [])
94
+ end
95
+
96
+ backend.on_progress_finish do
97
+ dbus_properties_changed(PROGRESS_INTERFACE, progress_properties, [])
98
+ end
99
+ end
100
+
101
+ def self.included(base)
102
+ base.class_eval do
103
+ dbus_interface PROGRESS_INTERFACE do
104
+ dbus_reader :progress_total_steps, "u", dbus_name: "TotalSteps"
105
+ dbus_reader :progress_current_step, "(us)", dbus_name: "CurrentStep"
106
+ dbus_reader :progress_finished, "b", dbus_name: "Finished"
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end