-
Notifications
You must be signed in to change notification settings - Fork 19
/
inst_scc.rb
352 lines (296 loc) · 11.3 KB
/
inst_scc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# encoding: utf-8
# ------------------------------------------------------------------------------
# Copyright (c) 2013 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
#
# Summary: Ask user for the SCC credentials
#
# use external rubygem for SCC communication
require "yast/suse_connect"
require "cgi"
require "registration/addon"
require "registration/exceptions"
require "registration/helpers"
require "registration/connect_helpers"
require "registration/sw_mgmt"
require "registration/storage"
require "registration/url_helpers"
require "registration/registration"
require "registration/registration_ui"
require "registration/ui/addon_eula_dialog"
require "registration/ui/addon_selection_registration_dialog"
require "registration/ui/addon_reg_codes_dialog"
require "registration/ui/registered_system_dialog"
require "registration/ui/base_system_registration_dialog"
require "registration/ui/registration_update_dialog"
require "registration/ui/media_addon_workflow"
# TODO: move to the "Registration" name space
module Yast
class InstSccClient < Client
include Yast::Logger
extend Yast::I18n
# popup message
CONTACTING_MESSAGE = N_("Contacting the Registration Server")
def main
textdomain "registration"
import_modules
first_run
@selected_addons = ::Registration::Storage::InstallationOptions.instance.selected_addons
initialize_regcodes
# FIXME: Add a separate client, changing the behavior completely acording to
# the passed parameters is not nice
media_workflow? ? ::Registration::UI::MediaAddonWorkflow.run(WFM.Args[1]) : start_workflow
end
private
def import_modules
Yast.import "UI"
Yast.import "Popup"
Yast.import "GetInstArgs"
Yast.import "Wizard"
Yast.import "Mode"
Yast.import "Stage"
Yast.import "Label"
Yast.import "Sequencer"
Yast.import "Installation"
end
# started from the add-on module?
# @return [Boolean] true if the media add-on worklow should be started
def media_workflow?
return false if WFM.Args[0] != "register_media_addon"
return true if WFM.Args[1].is_a?(Fixnum)
log.warn "Invalid argument: #{WFM.Args[1].inspect}, a Fixnum is expected"
log.warn "Starting the standard workflow"
false
end
# initialize known reg. codes
def initialize_regcodes
@known_reg_codes = ::Registration::Storage::RegCodes.instance.reg_codes
if @known_reg_codes
log.info "Known reg codes for #{@known_reg_codes.keys.inspect}"
return
end
@known_reg_codes = {}
# cache the values
::Registration::Storage::RegCodes.instance.reg_codes = @known_reg_codes
end
# run the dialog for registering the base system
# @return [Symbol] the user action
def register_base_system
base_reg_dialog = ::Registration::UI::BaseSystemRegistrationDialog.new
ret = base_reg_dialog.run
# remember the created registration object for later use
@registration = base_reg_dialog.registration if ret == :next
# tell #registration_check whether the user wants to go back (bnc#940915)
@back_from_register = (ret == :back)
ret
end
# run the dialog for updating the registration
# @return [Symbol] the user action
def update_registration
update_dialog = ::Registration::UI::RegistrationUpdateDialog.new
ret = update_dialog.run
# remeber the user Registration object to reuse it if needed
@registration = update_dialog.registration
ret
end
# run the addon selection dialog
def select_addons
# FIXME: available_addons is called just to fill cache with popup
return :cancel if get_available_addons == :cancel
# FIXME: workaround to reference between old way and new storage in Addon metaclass
@selected_addons = Registration::Addon.selected
::Registration::Storage::InstallationOptions.instance.selected_addons = @selected_addons
Registration::UI::AddonSelectionRegistrationDialog.run(@registration)
end
# load available addons from SCC server
# the result is cached to avoid reloading when going back and forth in the
# installation workflow
def get_available_addons
# cache the available addons
return :cancel if init_registration == :cancel
if !Registration::SwMgmt.find_base_product
Registration::Helpers.report_no_base_product
return :cancel
end
addons_loaded = Registration::ConnectHelpers.catch_registration_errors do
registration_ui.get_available_addons
end
return :cancel unless addons_loaded
@addons_registered_orig = Registration::Addon.registered.dup
end
# register all selected addons
# back returns directly to the extensions selection
def register_addons
return false if init_registration == :cancel
addons = Registration::Addon.selected + Registration::Addon.auto_selected
addons = Registration::Addon.registration_order(addons)
ret = registration_ui.register_addons(addons, @known_reg_codes)
ret = :extensions if ret == :back
ret
end
# do some sanity checks and decide which workflow will be used
# return [Symbol] :update
def registration_check
# Go back if the user clicked 'back' in the registration dialog
return :back if @back_from_register
# check the base product at start to avoid problems later
if ::Registration::SwMgmt.find_base_product.nil?
::Registration::Helpers.report_no_base_product
return Mode.normal ? :abort : :auto
end
if Mode.update
Wizard.SetContents(
_("Registration"),
Empty(),
# no help text needed, the dialog displays just a progress message
"",
false,
false
)
::Registration::SwMgmt.copy_old_credentials(Installation.destdir)
if File.exist?(SUSE::Connect::YaST::GLOBAL_CREDENTIALS_FILE)
# update the registration using the old credentials
return :update
end
end
return :register unless ::Registration::Registration.is_registered?
log.info "The system is already registered, displaying registered dialog"
::Registration::UI::RegisteredSystemDialog.run
end
# display EULAs for the selected addons
def addon_eula
new_addons = Registration::Addon.selected + Registration::Addon.auto_selected
::Registration::UI::AddonEulaDialog.run(new_addons)
end
# remember the user entered values so they can be stored to the AutoYast
# profile generated at the end of installation
def update_autoyast_config
options = ::Registration::Storage::InstallationOptions.instance
return :next unless Mode.installation && options.base_registered
log.info "Updating Autoyast config"
config = ::Registration::Storage::Config.instance
config.import(::Registration::Helpers.collect_autoyast_config(@known_reg_codes))
config.modified = true
:next
end
# preselect the addon products and in installed system run the package manager
def pkg_manager
::Registration::SwMgmt.select_addon_products
# run the package manager only in installed system and if a new addon was registered
if Mode.normal && Registration::Addon.registered != @addons_registered_orig
WFM.call("sw_single")
else
:next
end
end
def registration_ui
::Registration::RegistrationUI.new(@registration)
end
# define Sequencer aliases
def workflow_aliases
{
# skip this when going back
"check" => ->() { registration_check },
"register" => ->() { register_base_system },
"select_addons" => ->() { select_addons },
"update" => [->() { update_registration }, true],
"addon_eula" => ->() { addon_eula },
"register_addons" => ->() { register_addons },
"update_autoyast_config" => ->() { update_autoyast_config },
"pkg_manager" => ->() { pkg_manager }
}
end
# define the Sequence workflow
def start_workflow
sequence = {
"ws_start" => workflow_start,
"check" => {
auto: :auto,
abort: :abort,
cancel: :abort,
register: "register",
extensions: "select_addons",
update: "update",
next: :next
},
"update" => {
abort: :abort,
cancel: :abort,
next: "select_addons",
register: "register"
},
"register" => {
abort: :abort,
cancel: :abort,
skip: :next,
next: "select_addons"
},
"select_addons" => {
abort: :abort,
skip: "update_autoyast_config",
cancel: "check",
next: "addon_eula"
},
"addon_eula" => {
abort: :abort,
next: "register_addons"
},
"register_addons" => {
abort: :abort,
extensions: "select_addons",
next: "update_autoyast_config"
},
"update_autoyast_config" => {
abort: :abort,
next: "pkg_manager"
},
"pkg_manager" => {
abort: :abort,
next: :next
}
}
log.info "Starting scc sequence"
Sequencer.Run(workflow_aliases, sequence)
end
# which dialog should be displayed at start
def workflow_start
log.debug "WFM.Args: #{WFM.Args}"
if WFM.Args.include?("select_extensions") && Registration::Registration.is_registered?
"select_addons"
else
"check"
end
end
# initialize the Registration object
# @return [Symbol, nil] returns :cancel if the URL selection was canceled
def init_registration
return if @registration
url = ::Registration::UrlHelpers.registration_url
return :cancel if url == :cancel
log.info "Initializing registration with URL: #{url.inspect}"
@registration = ::Registration::Registration.new(url)
end
# do some additional initialization at the first run
def first_run
return unless ::Registration::Storage::Cache.instance.first_run
::Registration::Storage::Cache.instance.first_run = false
return unless Stage.initial && ::Registration::Registration.is_registered?
::Registration::Helpers.reset_registration_status
end
end
end