d-installer-cli 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 48606df15fc96fd4e85ef3c1573754b2d8f241e6e58dcb7d35c8a88e9b42b118
4
+ data.tar.gz: 5d23994c98a7960d50c1601f96883bb6de8c416a2aa46a35131562283e7b5f12
5
+ SHA512:
6
+ metadata.gz: 276c5c9b9be236e8c7c842a26116f7395e1d14ca8edab1cec8b25750567ec22c3e276bdcaa6d2190aa6c725a03cd9c25e022d869ad34f6cb4f83cc5f5b8600c5
7
+ data.tar.gz: 797e746976ede6ebf7c9cb7d069ef49a157eae55089aadcb04ac6ae18fb4b28bb6e555ad6668f3fa1d48c97ede966f4a0145c96aaf4f4c85b9bd9551be693372
data/Gemfile ADDED
@@ -0,0 +1,30 @@
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
+ source "https://rubygems.org"
23
+
24
+ gem "d-installer", path: "../service"
25
+
26
+ gemspec
27
+
28
+ group :development do
29
+ gem "byebug"
30
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: ../service
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
+ PATH
15
+ remote: .
16
+ specs:
17
+ d-installer-cli (0.4.2)
18
+ d-installer (= 0.4.2)
19
+ fast_gettext (~> 2.2.0)
20
+ ruby-dbus (~> 0.18.1)
21
+ thor (~> 1.2, >= 1.2.1)
22
+
23
+ GEM
24
+ remote: https://rubygems.org/
25
+ specs:
26
+ abstract_method (1.2.1)
27
+ byebug (11.1.3)
28
+ cfa (1.0.2)
29
+ ruby-augeas
30
+ cfa_grub2 (2.0.0)
31
+ cfa (~> 1.0)
32
+ cheetah (1.0.0)
33
+ abstract_method (~> 1.2)
34
+ diff-lcs (1.5.0)
35
+ docile (1.4.0)
36
+ eventmachine (1.2.7)
37
+ fast_gettext (2.2.0)
38
+ nokogiri (1.13.8-x86_64-linux)
39
+ racc (~> 1.4)
40
+ packaging_rake_tasks (1.5.1)
41
+ rake
42
+ racc (1.6.0)
43
+ rake (13.0.6)
44
+ rexml (3.2.5)
45
+ rspec (3.11.0)
46
+ rspec-core (~> 3.11.0)
47
+ rspec-expectations (~> 3.11.0)
48
+ rspec-mocks (~> 3.11.0)
49
+ rspec-core (3.11.0)
50
+ rspec-support (~> 3.11.0)
51
+ rspec-expectations (3.11.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.11.0)
54
+ rspec-mocks (3.11.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.11.0)
57
+ rspec-support (3.11.0)
58
+ ruby-augeas (0.5.0)
59
+ ruby-dbus (0.18.1)
60
+ rexml
61
+ simplecov (0.21.2)
62
+ docile (~> 1.1)
63
+ simplecov-html (~> 0.11)
64
+ simplecov_json_formatter (~> 0.1)
65
+ simplecov-html (0.12.3)
66
+ simplecov-lcov (0.8.0)
67
+ simplecov_json_formatter (0.1.4)
68
+ thor (1.2.1)
69
+
70
+ PLATFORMS
71
+ x86_64-linux
72
+
73
+ DEPENDENCIES
74
+ byebug
75
+ d-installer!
76
+ d-installer-cli!
77
+ packaging_rake_tasks (~> 1.5.1)
78
+ rake (~> 13.0.6)
79
+ rspec (~> 3.11.0)
80
+ simplecov (~> 0.21.2)
81
+ simplecov-lcov (~> 0.8.0)
82
+
83
+ BUNDLED WITH
84
+ 2.3.7
data/bin/dinstallerctl ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
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
+ require "dinstaller_cli/commands/main"
25
+
26
+ DInstallerCli::Commands::Main.start(ARGV)
@@ -0,0 +1,73 @@
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
+
24
+ module DInstallerCli
25
+ module Clients
26
+ # D-Bus client for storage configuration
27
+ class Storage < DInstaller::DBus::Clients::Base
28
+ def initialize
29
+ super
30
+
31
+ @dbus_proposal = service.object("/org/opensuse/DInstaller/Storage/Proposal1")
32
+ @dbus_proposal.introspect
33
+ end
34
+
35
+ def service_name
36
+ @service_name ||= "org.opensuse.DInstaller"
37
+ end
38
+
39
+ # Devices available for the installation
40
+ #
41
+ # @return [Array<String>] name of the devices
42
+ def available_devices
43
+ dbus_proposal["org.opensuse.DInstaller.Storage.Proposal1"]["AvailableDevices"].map(&:first)
44
+ end
45
+
46
+ # Devices selected for the installation
47
+ #
48
+ # @return [Array<String>] name of the devices
49
+ def candidate_devices
50
+ dbus_proposal["org.opensuse.DInstaller.Storage.Proposal1"]["CandidateDevices"]
51
+ end
52
+
53
+ # Actions to perform in the storage devices
54
+ #
55
+ # @return [Array<String>]
56
+ def actions
57
+ dbus_proposal["org.opensuse.DInstaller.Storage.Proposal1"]["Actions"].map { |a| a["Text"] }
58
+ end
59
+
60
+ # Calculates the storage proposal with the given devices
61
+ #
62
+ # @param candidate_devices [Array<String>] name of the new candidate devices
63
+ def calculate(candidate_devices)
64
+ dbus_proposal.Calculate({ "CandidateDevices" => candidate_devices })
65
+ end
66
+
67
+ private
68
+
69
+ # @return [::DBus::Object]
70
+ attr_reader :dbus_proposal
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,29 @@
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 DInstallerCli
23
+ # D-Bus clients
24
+ module Clients
25
+ end
26
+ end
27
+
28
+ require "dinstaller_cli/clients/language"
29
+ require "dinstaller_cli/clients/storage"
@@ -0,0 +1,150 @@
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 "thor"
23
+ require "dinstaller_cli/install_config"
24
+ require "dinstaller_cli/install_config_reader"
25
+ require "dinstaller_cli/clients/storage"
26
+ require "dinstaller/dbus/clients/language"
27
+ require "dinstaller/dbus/clients/software"
28
+ require "dinstaller/dbus/clients/users"
29
+
30
+ module DInstallerCli
31
+ module Commands
32
+ # Subcommand to configure the installation
33
+ class Config < Thor
34
+ desc "load <config>", "Load a config file and apply the configuration"
35
+ def load(config_source)
36
+ config = InstallConfigReader.new(config_source).read
37
+ configure_installation(config)
38
+ rescue DInstallerCli::InstallConfigReader::Error
39
+ say_error("error: invalid configuration")
40
+ end
41
+
42
+ desc "dump", "Dump the current installation config to stdout"
43
+ def dump
44
+ say(current_config.dump)
45
+ end
46
+
47
+ private
48
+
49
+ # Configures the installation according to the given config
50
+ #
51
+ # Performs D-Bus calls to configure the proper services.
52
+ #
53
+ # @param config [InstallConfig]
54
+ def configure_installation(config)
55
+ software_client.select_product(config.product) if config.product
56
+ language_client.select_languages(config.languages) if config.languages.any?
57
+ storage_client.calculate(config.disks) if config.disks.any?
58
+
59
+ configure_user(config.user) if config.user
60
+ configure_root(config.root) if config.root
61
+ end
62
+
63
+ # Configures the user
64
+ #
65
+ # Performs D-Bus calls to configure the users service.
66
+ #
67
+ # @param user_config [InstallConfig::User]
68
+ def configure_user(user_config)
69
+ user_name = user_config.name || ""
70
+
71
+ return if user_name.empty?
72
+
73
+ users_client.create_first_user(user_config.name,
74
+ fullname: user_config.fullname,
75
+ password: user_config.password,
76
+ autologin: user_config.autologin)
77
+ end
78
+
79
+ # Configures the root user
80
+ #
81
+ # Performs D-Bus calls to configure the users service.
82
+ #
83
+ # @param root_config [InstallConfig::Root]
84
+ def configure_root(root_config)
85
+ users_client.root_password = root_config.password if root_config.password
86
+ users_client.root_ssh_key = root_config.ssh_key if root_config.ssh_key
87
+ end
88
+
89
+ # Generates an installation config with the current configured values
90
+ #
91
+ # @return [InstallConfig]
92
+ def current_config
93
+ InstallConfig.new.tap do |config|
94
+ product = software_client.selected_product
95
+
96
+ config.product = product unless product.empty?
97
+ config.languages = language_client.selected_languages
98
+ config.disks = storage_client.candidate_devices
99
+
100
+ config.user = current_user_config
101
+ config.root = current_root_config
102
+ end
103
+ end
104
+
105
+ # Generates a user config with the current configured values
106
+ #
107
+ # @note The password is not recovered
108
+ #
109
+ # @return [InstallConfig::User]
110
+ def current_user_config
111
+ fullname, name, autologin = users_client.first_user
112
+
113
+ InstallConfig::User.new.tap do |user|
114
+ user.name = name unless name.empty?
115
+ user.fullname = fullname unless fullname.empty?
116
+ user.autologin = autologin
117
+ end
118
+ end
119
+
120
+ # Generates a root config with the current configured values
121
+ #
122
+ # @note The password is not recovered
123
+ #
124
+ # @return [InstallConfig::Root]
125
+ def current_root_config
126
+ ssh_key = users_client.root_ssh_key
127
+
128
+ InstallConfig::Root.new.tap do |root|
129
+ root.ssh_key = ssh_key unless ssh_key.empty?
130
+ end
131
+ end
132
+
133
+ def language_client
134
+ @language_client ||= DInstaller::DBus::Clients::Language.new
135
+ end
136
+
137
+ def software_client
138
+ @software_client ||= DInstaller::DBus::Clients::Software.new
139
+ end
140
+
141
+ def storage_client
142
+ @storage_client ||= Clients::Storage.new
143
+ end
144
+
145
+ def users_client
146
+ @users_client ||= DInstaller::DBus::Clients::Users.new
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,47 @@
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/installation_phase"
23
+
24
+ module DInstallerCli
25
+ module Commands
26
+ # Mixin that provides methods to ensure a specific installation phase while running code
27
+ #
28
+ # @note Requires a #manager_client method that returns an instance of
29
+ # {DInstaller::DBus::Clients::Manager}.
30
+ module EnsureConfigPhase
31
+ # Ensures the config phase is executed before calling the given block
32
+ #
33
+ # @param block [Proc]
34
+ def ensure_config_phase(&block)
35
+ manager_client.probe unless config_phase?
36
+ block.call
37
+ end
38
+
39
+ # Whether the manager client is in config phase
40
+ #
41
+ # @return [Boolean]
42
+ def config_phase?
43
+ manager_client.current_installation_phase == DInstaller::InstallationPhase::CONFIG
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
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 "thor"
23
+ require "dinstaller/dbus/clients/language"
24
+
25
+ module DInstallerCli
26
+ module Commands
27
+ # Subcommand to manage language settings
28
+ class Language < Thor
29
+ desc "available", "List available languages for the installation"
30
+ def available
31
+ languages = client.available_languages.map { |l| l.join(" - ") }
32
+ languages.each { |l| say(l) }
33
+ end
34
+
35
+ desc "selected [<id>...]", "Select the languages to install in the target system"
36
+ long_desc "Use without arguments to see the currently selected languages."
37
+ def selected(*ids)
38
+ client.select_languages(ids) if ids.any?
39
+ client.selected_languages.each { |l| say(l) }
40
+ end
41
+
42
+ private
43
+
44
+ def client
45
+ @client ||= DInstaller::DBus::Clients::Language.new
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,95 @@
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 "thor"
23
+ require "dinstaller_cli/commands/config"
24
+ require "dinstaller_cli/commands/language"
25
+ require "dinstaller_cli/commands/software"
26
+ require "dinstaller_cli/commands/storage"
27
+ require "dinstaller_cli/commands/root_user"
28
+ require "dinstaller_cli/commands/user"
29
+ require "dinstaller_cli/commands/ensure_config_phase"
30
+ require "dinstaller/dbus/clients/manager"
31
+ require "dinstaller/dbus/clients/software"
32
+
33
+ module DInstallerCli
34
+ module Commands
35
+ # Main command
36
+ class Main < Thor
37
+ include EnsureConfigPhase
38
+
39
+ def self.exit_on_failure?
40
+ true
41
+ end
42
+
43
+ desc "install", "Perform the installation"
44
+ def install
45
+ answer = ask("Do you want to start the installation?", limited_to: ["y", "n"])
46
+ return unless answer == "y"
47
+
48
+ register_callbacks
49
+ ensure_config_phase { manager_client.commit }
50
+ end
51
+
52
+ desc "config SUBCOMMAND", "Manage configuration of the installation"
53
+ subcommand "config", Config
54
+
55
+ desc "language SUBCOMMAND", "Manage language configuration"
56
+ subcommand "language", Language
57
+
58
+ desc "software SUBCOMMAND", "Manage software configuration"
59
+ subcommand "software", Software
60
+
61
+ desc "storage SUBCOMMAND", "Manage storage configuration"
62
+ subcommand "storage", Storage
63
+
64
+ desc "rootuser SUBCOMMAND", "Manage root user configuration"
65
+ subcommand "rootuser", RootUser
66
+
67
+ desc "user SUBCOMMAND", "Manage first user configuration"
68
+ subcommand "user", User
69
+
70
+ private
71
+
72
+ def manager_client
73
+ @manager_client ||= DInstaller::DBus::Clients::Manager.new
74
+ end
75
+
76
+ def software_client
77
+ @software_client ||= DInstaller::DBus::Clients::Software.new
78
+ end
79
+
80
+ # Registers callbacks
81
+ def register_callbacks
82
+ # Callback to show the main progress
83
+ manager_client.on_progress_change do |total_steps, current_step, message, finished|
84
+ feedback = finished ? "Done" : "(#{current_step}/#{total_steps}) #{message}"
85
+ say(feedback)
86
+ end
87
+
88
+ # Callback to show the software progress
89
+ software_client.on_progress_change do |_, _, message, finished|
90
+ say("--> #{message}") unless finished
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,54 @@
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 "thor"
23
+ require "dinstaller/dbus/clients/users"
24
+
25
+ module DInstallerCli
26
+ module Commands
27
+ # Subcommand to manage root user settings
28
+ class RootUser < Thor
29
+ desc "ssh_key [<key>]", "Set the SSH key for root"
30
+ long_desc "Use without arguments to see the current SSH key value."
31
+ def ssh_key(key = nil)
32
+ client.root_ssh_key = key if key
33
+ say(client.root_ssh_key)
34
+ end
35
+
36
+ desc "password [<plain password>]", "Set the root password"
37
+ def password(password = nil)
38
+ client.root_password = password if password
39
+ say("<secret>") if client.root_password?
40
+ end
41
+
42
+ desc "clear", "Clear root configuration"
43
+ def clear
44
+ client.remove_root_info
45
+ end
46
+
47
+ private
48
+
49
+ def client
50
+ @client ||= DInstaller::DBus::Clients::Users.new
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,49 @@
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 "thor"
23
+ require "dinstaller/dbus/clients/software"
24
+
25
+ module DInstallerCli
26
+ module Commands
27
+ # Subcommand to manage software settings
28
+ class Software < Thor
29
+ desc "available_products", "List available products for the installation"
30
+ def available_products
31
+ products = client.available_products.map { |l| l.join(" - ") }
32
+ products.each { |p| say(p) }
33
+ end
34
+
35
+ desc "selected_product [<id>]", "Select the product to install in the target system"
36
+ long_desc "Use without arguments to see the currently selected product."
37
+ def selected_product(id = nil)
38
+ client.select_product(id) if id
39
+ say(client.selected_product)
40
+ end
41
+
42
+ private
43
+
44
+ def client
45
+ @client ||= DInstaller::DBus::Clients::Software.new
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,62 @@
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 "thor"
23
+ require "dinstaller_cli/commands/ensure_config_phase"
24
+ require "dinstaller_cli/clients/storage"
25
+ require "dinstaller/dbus/clients/manager"
26
+
27
+ module DInstallerCli
28
+ module Commands
29
+ # Subcommand to manage storage settings
30
+ class Storage < Thor
31
+ include EnsureConfigPhase
32
+
33
+ desc "available_devices", "List available devices for the installation"
34
+ def available_devices
35
+ storage_client.available_devices.each { |d| say(d) }
36
+ end
37
+
38
+ desc "selected_devices [<device>...]", "Select devices for the installation"
39
+ long_desc "Use without arguments to see the currently selected devices."
40
+ def selected_devices(*devices)
41
+ return storage_client.candidate_devices.each { |d| say(d) } if devices.none?
42
+
43
+ ensure_config_phase { storage_client.calculate(devices) }
44
+ end
45
+
46
+ desc "actions", "List the storage actions to perform"
47
+ def actions
48
+ storage_client.actions.each { |a| say(a) }
49
+ end
50
+
51
+ private
52
+
53
+ def storage_client
54
+ @storage_client ||= Clients::Storage.new
55
+ end
56
+
57
+ def manager_client
58
+ @manager_client ||= DInstaller::DBus::Clients::Manager.new
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,65 @@
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 "thor"
23
+ require "dinstaller/dbus/clients/users"
24
+
25
+ module DInstallerCli
26
+ module Commands
27
+ # Subcommand to manage first user settings
28
+ class User < Thor
29
+ desc "set <name>", "Configure the user that will be created during the installation"
30
+ option :fullname, banner: "<full-name>", desc: "Set the user's full name"
31
+ option :password, banner: "<plain-password>", desc: "Set the user's password"
32
+ option :autologin, type: :boolean, default: false,
33
+ desc: "Enable/disable user autologin (disabled by default)"
34
+ def set(name)
35
+ client.create_first_user(name,
36
+ fullname: options[:fullname],
37
+ password: options[:password],
38
+ autologin: options[:autologin])
39
+ end
40
+
41
+ desc "show", "Show the user configuration"
42
+ def show
43
+ full_name, name, autologin = client.first_user
44
+
45
+ return if name.empty?
46
+
47
+ say("Full Name: #{full_name}\n" \
48
+ "Name: #{name}\n" \
49
+ "Autologin: #{autologin ? "yes" : "no"}\n" \
50
+ "Password: <secret>")
51
+ end
52
+
53
+ desc "clear", "Clear the user configuration"
54
+ def clear
55
+ client.remove_first_user
56
+ end
57
+
58
+ private
59
+
60
+ def client
61
+ @client ||= DInstaller::DBus::Clients::Users.new
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,28 @@
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 DInstallerCli
23
+ # Module containing all commands
24
+ module Commands
25
+ end
26
+ end
27
+
28
+ require "dinstaller_cli/commands/main"
@@ -0,0 +1,148 @@
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 "yaml"
23
+
24
+ module DInstallerCli
25
+ # Class to represent the installation config
26
+ class InstallConfig
27
+ # Product to install
28
+ #
29
+ # @return [String, nil] id of the product (e.g., "Tumbleweed")
30
+ attr_accessor :product
31
+
32
+ # Languages to install
33
+ #
34
+ # @return [Array<String>] ids of the languages (e.g., ["en_UK", "es_ES"])
35
+ attr_accessor :languages
36
+
37
+ # Target devices
38
+ #
39
+ # @return [Array<String>] device names (e.g., ["/dev/vda"])
40
+ attr_accessor :disks
41
+
42
+ # User config
43
+ #
44
+ # @return [InstallConfig::User, nil]
45
+ attr_accessor :user
46
+
47
+ # Root config
48
+ #
49
+ # @return [InstallConfig::Root, nil]
50
+ attr_accessor :root
51
+
52
+ def initialize
53
+ @product = nil
54
+ @languages = []
55
+ @disks = []
56
+ @user = nil
57
+ @root = nil
58
+ end
59
+
60
+ # Dumps the settings in YAML format
61
+ #
62
+ # @return [String]
63
+ def dump
64
+ to_h.to_yaml
65
+ end
66
+
67
+ # Converts the settings to hash
68
+ #
69
+ # @return [Hash]
70
+ def to_h
71
+ {
72
+ "product" => product,
73
+ "languages" => languages,
74
+ "disks" => disks,
75
+ "user" => user&.to_h || {},
76
+ "root" => root&.to_h || {}
77
+ }
78
+ end
79
+
80
+ # Class to represent the user config
81
+ class User
82
+ # @param [String, nil]
83
+ attr_accessor :name
84
+
85
+ # @param [String, nil]
86
+ attr_accessor :fullname
87
+
88
+ # @param [String, nil]
89
+ attr_accessor :password
90
+
91
+ # @param [Boolean]
92
+ attr_accessor :autologin
93
+
94
+ # Constructor
95
+ #
96
+ # @param name [String] user name
97
+ # @param fullname [String, nil] full user name
98
+ # @param password [String, nil] user password
99
+ # @param autologin [Boolean] user autologin option
100
+ def initialize(name: nil, fullname: nil, password: nil, autologin: false)
101
+ @name = name
102
+ @fullname = fullname
103
+ @password = password
104
+ @autologin = autologin
105
+ end
106
+
107
+ # Converts the settings to hash
108
+ #
109
+ # @return [Hash]
110
+ def to_h
111
+ {
112
+ "name" => name,
113
+ "fullname" => fullname,
114
+ "autologin" => autologin,
115
+ "password" => password
116
+ }
117
+ end
118
+ end
119
+
120
+ # Class to represent the root user config
121
+ class Root
122
+ # @return [String, nil]
123
+ attr_accessor :password
124
+
125
+ # @return [String, nil]
126
+ attr_accessor :ssh_key
127
+
128
+ # Constructor
129
+ #
130
+ # @param password [String, nil]
131
+ # @param ssh_key [String, nil]
132
+ def initialize(password: nil, ssh_key: nil)
133
+ @password = password
134
+ @ssh_key = ssh_key
135
+ end
136
+
137
+ # Converts the settings to hash
138
+ #
139
+ # @return [Hash]
140
+ def to_h
141
+ {
142
+ "ssh_key" => ssh_key,
143
+ "password" => password
144
+ }
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,134 @@
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 "yaml"
23
+ require "dinstaller_cli/install_config"
24
+
25
+ module DInstallerCli
26
+ # Class for generating the config of the installation from a YAML file
27
+ #
28
+ # The YAML file has the following structure:
29
+ #
30
+ # product: <product-id>
31
+ #
32
+ # languages:
33
+ # - <language-id>
34
+ # - <language-id>
35
+ #
36
+ # disks:
37
+ # - <device-name>
38
+ # - <device-name>
39
+ #
40
+ # user:
41
+ # name: <name>
42
+ # fullname: <fullname>
43
+ # password: <password>
44
+ # autologin: <autologin>
45
+ #
46
+ # root:
47
+ # password: <password>
48
+ # ssh_key: <key>
49
+ #
50
+ # @example
51
+ # config = InstallConfigReader.new("example.yaml").read
52
+ # config.languages #=> ["en_US", "es_ES"]
53
+ # config.disks #=> ["/dev/vda"]
54
+ # config.user #=> #<InstallConfig::User>
55
+ # config.user.name #=> "john"
56
+ class InstallConfigReader
57
+ # Error reading or loading the config file
58
+ class Error < RuntimeError; end
59
+
60
+ # Constructor
61
+ #
62
+ # @param source [String] path of the config file
63
+ def initialize(source)
64
+ @source = source
65
+ end
66
+
67
+ # Reads the config file and generates an installation config
68
+ #
69
+ # @raise [Error] see {#load_content}
70
+ #
71
+ # @return [InstallConfig]
72
+ def read
73
+ content = load_content
74
+ config_from(content)
75
+ end
76
+
77
+ private
78
+
79
+ # Path to the config file
80
+ #
81
+ # @return [String]
82
+ attr_reader :source
83
+
84
+ # Creates an install config from the content of the YAML config file
85
+ #
86
+ # @param content [Hash] content of the config file
87
+ # @return [InstallConfig]
88
+ def config_from(content)
89
+ InstallConfig.new.tap do |config|
90
+ product = content["product"]
91
+ languages = content["languages"]
92
+ disks = content["disks"]
93
+ user = content["user"]
94
+ root = content["root"]
95
+
96
+ config.product = product if product
97
+ config.languages = languages if languages
98
+ config.disks = disks if disks
99
+ config.user = user_config_from(user) if user
100
+ config.root = root_config_from(root) if root
101
+ end
102
+ end
103
+
104
+ # Generates a user config according to the user section of the YAML config file
105
+ #
106
+ # @param user_content [Hash] user section
107
+ # @return [InstallConfig::User]
108
+ def user_config_from(user_content)
109
+ InstallConfig::User.new(
110
+ name: user_content["name"],
111
+ fullname: user_content["fullname"],
112
+ password: user_content["password"],
113
+ autologin: user_content["autologin"]
114
+ )
115
+ end
116
+
117
+ # Generates a root config according to the root section of the YAML config file
118
+ #
119
+ # @param root_content [Hash] root section
120
+ # @return [InstallConfig::Root]
121
+ def root_config_from(root_content)
122
+ InstallConfig::Root.new(password: root_content["password"], ssh_key: root_content["ssh_key"])
123
+ end
124
+
125
+ # Loads the content of the YAML config file
126
+ #
127
+ # @raise [Error] if the file cannot be loaded
128
+ def load_content
129
+ YAML.load_file(source)
130
+ rescue StandardError => e
131
+ raise Error, e.message
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,26 @@
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
+ # DInstaller CLI module
23
+ module DInstallerCli
24
+ end
25
+
26
+ require "dinstaller_cli/commands"
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: d-installer-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ platform: ruby
6
+ authors:
7
+ - YaST Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: packaging_rake_tasks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.11.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.11.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.21.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.21.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-lcov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: d-installer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: fast_gettext
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.2.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.2.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: ruby-dbus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.18.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.18.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.2'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 1.2.1
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '1.2'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.2.1
145
+ description: Command line interface for D-Installer service
146
+ email: yast-devel@opensuse.org
147
+ executables:
148
+ - dinstallerctl
149
+ extensions: []
150
+ extra_rdoc_files: []
151
+ files:
152
+ - Gemfile
153
+ - Gemfile.lock
154
+ - bin/dinstallerctl
155
+ - lib/dinstaller_cli.rb
156
+ - lib/dinstaller_cli/clients.rb
157
+ - lib/dinstaller_cli/clients/storage.rb
158
+ - lib/dinstaller_cli/commands.rb
159
+ - lib/dinstaller_cli/commands/config.rb
160
+ - lib/dinstaller_cli/commands/ensure_config_phase.rb
161
+ - lib/dinstaller_cli/commands/language.rb
162
+ - lib/dinstaller_cli/commands/main.rb
163
+ - lib/dinstaller_cli/commands/root_user.rb
164
+ - lib/dinstaller_cli/commands/software.rb
165
+ - lib/dinstaller_cli/commands/storage.rb
166
+ - lib/dinstaller_cli/commands/user.rb
167
+ - lib/dinstaller_cli/install_config.rb
168
+ - lib/dinstaller_cli/install_config_reader.rb
169
+ homepage: https://github.com/yast/d-installer
170
+ licenses:
171
+ - GPL-2.0-only
172
+ metadata:
173
+ rubygems_mfa_required: 'true'
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 2.5.0
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubygems_version: 3.3.7
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: D-Installer CLI
193
+ test_files: []