Class: Yast::InstUpdateInstaller

Inherits:
Object
  • Object
show all
Includes:
I18n, Logger
Defined in:
src/lib/installation/clients/inst_update_installer.rb

Constant Summary collapse

UPDATED_FLAG_FILENAME =
"installer_updated".freeze
PROFILE_FORBIDDEN_SCHEMES =
["label"].freeze
REGISTRATION_DATA_PATH =
"/var/lib/YaST2/inst_update_installer.yaml".freeze

Instance Method Summary collapse

Constructor Details

#initializeInstUpdateInstaller

Returns a new instance of InstUpdateInstaller.



52
53
54
# File 'src/lib/installation/clients/inst_update_installer.rb', line 52

def initialize
  textdomain "installation"
end

Instance Method Details

#add_repository(repo) ⇒ Boolean (protected)

Add a repository to the updates manager

Parameters:

  • repo (UpdateRepository)

    Update repository to add

Returns:

  • (Boolean)

    true if the repository was added; false otherwise.



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
# File 'src/lib/installation/clients/inst_update_installer.rb', line 223

def add_repository(repo)
  log.info("Adding update from #{repo.inspect}")
  updates_manager.add_repository(repo.uri)
rescue ::Installation::UpdatesManager::NotValidRepo
  if repo.user_defined?
    # TRANSLATORS: %s is an URL
    Report.Error(format(_("A valid update could not be found at\n%s.\n\n"), repo.uri))
  end
  false
rescue ::Installation::UpdatesManager::CouldNotFetchUpdateFromRepo
  if repo.user_defined?
    # TRANSLATORS: %s is an URL
    Report.Error(format(_("Could not fetch update from\n%s.\n\n"), repo.uri))
  end
  false
rescue ::Installation::UpdatesManager::CouldNotProbeRepo
  return false unless repo.user_defined?

  msg = could_not_probe_repo_msg(repo.uri)
  if Mode.auto
    Report.Warning(msg)
  elsif repo.remote? && configure_network?(msg)
    retry
  end
  false
end

#configure_network?(reason) ⇒ Boolean (protected)

Launch the network configuration client on users' demand

Ask the user about checking network configuration. If she/he accepts, the inst_lan client will be launched.

Parameters:

  • reason (String)

    reason why user want to check his network configuration

Returns:

  • (Boolean)

    true if the network configuration client was launched; false if the network is not configured.



258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'src/lib/installation/clients/inst_update_installer.rb', line 258

def configure_network?(reason)
  msg = reason + _("\nWould you like to check your network configuration\n" \
                   "and try installing the updates again?")

  if Popup.YesNo(msg)
    Yast::WFM.CallFunction(
      "inst_lan",
      [{ "skip_detection" => true, "hide_abort_button" => true }]
    )
    true
  else
    false
  end
end

#could_not_probe_repo_msg(url) ⇒ String (protected)

Return a message to be shown when the updates repo could not be probed

Parameters:

  • url (URI, String)

    Repository URI

Returns:

  • (String)

    Message including the repository URL

See Also:

  • #self_update_url


296
297
298
299
300
301
302
303
304
305
306
307
# File 'src/lib/installation/clients/inst_update_installer.rb', line 296

def could_not_probe_repo_msg(url)
  # NOTE: the proxy cannot be configured in the YaST installer yet,
  # it needs to be set via the "proxy" boot option.
  # TRANSLATORS: %s is an URL
  format(_("Downloading the optional installer updates from \n%s\nfailed.\n" \
           "\n" \
           "You can continue the installation without applying the updates.\n" \
           "However, some potentially important bug fixes might be missing.\n" \
           "\n" \
           "If you need a proxy server to access the update repository\n" \
           "then use the \"proxy\" boot parameter.\n"), url.to_s)
end

#disabled_in_linuxrc?Boolean (protected)

disabled via Linuxrc ?

Returns:

  • (Boolean)

    true if self update has been disabled by "self_update=0" boot option



166
167
168
# File 'src/lib/installation/clients/inst_update_installer.rb', line 166

def disabled_in_linuxrc?
  Linuxrc.InstallInf("SelfUpdate") == "0"
end

#disabled_in_profile?Boolean (protected)

Determines whether self-update feature is disabled via AutoYaST profile

Returns:

  • (Boolean)

    true if self update has been disabled by AutoYaST profile



173
174
175
# File 'src/lib/installation/clients/inst_update_installer.rb', line 173

def disabled_in_profile?
  AutoinstGeneral.self_update == false
end

#finish_packagerObject (protected)

delete all added installation repositories to make sure there is no leftover which could affect the installation later



378
379
380
381
382
383
384
385
386
# File 'src/lib/installation/clients/inst_update_installer.rb', line 378

def finish_packager
  return unless @packager_initialized

  # false = all repositories, even the disabled ones
  Pkg.SourceGetCurrent(false).each { |r| Pkg.SourceDelete(r) }
  Pkg.SourceSaveAll
  Pkg.SourceFinishAll
  Pkg.TargetFinish
end

#finish_progressObject (protected)

Finish the self update progress



425
426
427
428
429
430
# File 'src/lib/installation/clients/inst_update_installer.rb', line 425

def finish_progress
  return unless @wizard_open

  Yast::Progress.Finish
  Yast::Wizard.CloseDialog
end

#initialize_packagerObject (protected)

Initialize the package management so we can download the updates from the update repository.



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'src/lib/installation/clients/inst_update_installer.rb', line 351

def initialize_packager
  return if @packager_initialized

  log.info "Initializing the package management..."

  # Add the initial installation repository.
  # Unfortunately the Packages.InitializeCatalogs call cannot be used here
  # as is does too much (adds y2update.tgz, selects the product, selects
  # the default patterns, looks for the addon product files...).

  # initialize package callbacks to show a progress while downloading the files
  PackageCallbacks.InitPackageCallbacks

  # set the language for the package manager (mainly error messages)
  Pkg.SetTextLocale(Language.language)

  # set the target to inst-sys otherwise libzypp complains in the GPG check
  Pkg.TargetInitialize("/")

  # load the GPG keys (*.gpg files) from inst-sys
  Packages.ImportGPGKeys

  @packager_initialized = true
end

#initialize_progressObject (protected)

Show global self update progress



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'src/lib/installation/clients/inst_update_installer.rb', line 389

def initialize_progress
  stages = [
    # TRANSLATORS: progress label
    _("Add Update Repository"),
    _("Download the Packages"),
    _("Copy the Add-on Packages"),
    _("Apply the Packages"),
    _("Restart")
  ]

  # open a new wizard dialog with title on the top
  # (the default dialog with title on the left looks ugly with the
  # Progress dialog)
  Yast::Wizard.CreateDialog
  @wizard_open = true

  Yast::Progress.New(
    # TRANSLATORS: dialog title
    _("Updating the Installer..."),
    # TRANSLATORS: progress title
    _("Updating the Installer..."),
    # max is 100%
    100,
    # stages
    stages,
    # steps
    [],
    # help text
    ""
  )

  # mark the first stage active
  Yast::Progress.NextStage
end

#installer_updated?Boolean (protected)

Check if installer was updated

It checks if a file UPDATED_FLAG_FILENAME exists in Directory.vardir

Returns:

  • (Boolean)

    true if it exists; false otherwise.



200
201
202
203
204
205
206
207
208
# File 'src/lib/installation/clients/inst_update_installer.rb', line 200

def installer_updated?
  if File.exist?(update_flag_file)
    log.info("#{update_flag_file} exists")
    true
  else
    log.info("#{update_flag_file} does not exist")
    false
  end
end

#load_registration_urlBoolean (protected)

Load URL of registration server to be used by inst_scc client

Returns:

  • (Boolean)

    true if data was loaded; false otherwise.



340
341
342
343
344
345
346
347
# File 'src/lib/installation/clients/inst_update_installer.rb', line 340

def load_registration_url
  return false unless File.exist?(REGISTRATION_DATA_PATH) && require_registration_libraries

  data = YAML.safe_load(File.read(REGISTRATION_DATA_PATH))
  Registration::Storage::InstallationOptions.instance.custom_url = data["custom_url"]
  ::FileUtils.rm_rf(REGISTRATION_DATA_PATH)
  true
end

#mainObject



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
# File 'src/lib/installation/clients/inst_update_installer.rb', line 56

def main
  return :back if GetInstArgs.going_back

  require_registration_libraries

  if Installation.restarting?
    load_registration_url
    Installation.finish_restarting!
  end

  # shortcut - already updated, disabled via boot option or network not running
  if installer_updated? || disabled_in_linuxrc? || !NetworkService.isNetworkRunning
    log.info "Self update not needed, skipping"
    return :next
  end

  if Mode.auto
    process_profile
    return :next if disabled_in_profile?
  end

  initialize_progress
  initialize_packager

  # self-update not possible, the repo URL is not defined
  return :next unless try_to_update?

  log.info("Trying installer update")
  installer_updated = update_installer

  store_registration_url # Registration URL could be set by UpdateRepositoriesFinder

  if installer_updated
    # Indicates that the installer was updated.
    ::FileUtils.touch(update_flag_file)
    Yast::Progress.NextStage
    Installation.restart!
  else
    :next
  end
ensure
  finish_packager
  finish_progress
end

#require_registration_librariesObject (protected)

Require registration libraries

Raises:

  • LoadError



312
313
314
315
316
317
318
319
320
321
322
323
# File 'src/lib/installation/clients/inst_update_installer.rb', line 312

def require_registration_libraries
  return @require_registration_libraries unless @require_registration_libraries.nil?

  require "registration/url_helpers"
  require "registration/registration"
  require "registration/ui/regservice_selection_dialog"
  require "registration/exceptions"
  @require_registration_libraries = true
rescue LoadError
  log.info "yast2-registration is not available"
  @require_registration_libraries = false
end

#self_update_enabled?Boolean (protected)

Determines whether self-update feature is enabled

  • Check whether is disabled via Linuxrc
  • Otherwise, it's considered as enabled if some URL is defined.

Returns:

  • (Boolean)

    True if it's enabled; false otherwise.



154
155
156
157
158
159
160
161
# File 'src/lib/installation/clients/inst_update_installer.rb', line 154

def self_update_enabled?
  if disabled_in_linuxrc?
    log.info("self-update was disabled through Linuxrc")
    false
  else
    !update_repositories.empty?
  end
end

#store_registration_urlObject (protected)

Store URL of registration server to be used by inst_scc client



327
328
329
330
331
332
333
334
335
# File 'src/lib/installation/clients/inst_update_installer.rb', line 327

def store_registration_url
  return unless require_registration_libraries

  url = Registration::Storage::InstallationOptions.instance.custom_url
  return if url.nil?

  data = { "custom_url" => url.to_s }
  File.write(REGISTRATION_DATA_PATH, data.to_yaml)
end

#try_to_update?Boolean (protected)

Check whether the update should be performed

The update should be performed when these requeriments are met:

  • Network is up.
  • Installer is not updated yet.
  • Self-update feature is enabled and the repository URL is defined

Returns:

  • (Boolean)

    true if the update should be performed; false otherwise.

See Also:



286
287
288
# File 'src/lib/installation/clients/inst_update_installer.rb', line 286

def try_to_update?
  NetworkService.isNetworkRunning && !installer_updated? && self_update_enabled?
end

#update_flag_fileString (protected)

Returns the path to the "update flag file"

Returns:

  • (String)

    Path to the "update flag file"

See Also:



215
216
217
# File 'src/lib/installation/clients/inst_update_installer.rb', line 215

def update_flag_file
  File.join(Directory.vardir, UPDATED_FLAG_FILENAME)
end

#update_installerBoolean

Tries to update the installer

It also shows feedback to the user in case of error.

Errors handling:

  • A repository is not found: warn the user if she/he is using a custom URL.
  • Could not fetch update from repository: report the user about this error.
  • Repository could not be probed: suggest checking network configuration if URL is remote.

Returns:

  • (Boolean)

    true if installer was updated; false otherwise.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'src/lib/installation/clients/inst_update_installer.rb', line 115

def update_installer
  updated = update_repositories.map { |u| add_repository(u) }.any?

  if updated
    return false unless valid_repositories?

    # copy the addon packages before applying the updates to inst-sys,
    # #apply_all removes the repositories!
    Yast::Progress.NextStage
    copy_addon_packages
    log.info("Applying installer updates")
    Yast::Progress.NextStage
    updates_manager.apply_all
  end
  updated
end

#update_repositoriesArray<URI> (protected)

Return the self-update URLs

Returns:

  • (Array<URI>)

    self-update URLs

See Also:

  • #default_self_update_url
  • #custom_self_update_url


183
184
185
186
187
188
189
190
191
192
193
# File 'src/lib/installation/clients/inst_update_installer.rb', line 183

def update_repositories
  return @update_repositories if @update_repositories

  @update_repositories = update_repositories_finder.updates
  log.info("self-update repositories are #{@update_repositories.inspect}")
  @update_repositories
rescue ::Installation::RegistrationURLError
  Report.Error(_("The registration URL provided is not valid.\n" \
                 "Skipping installer update.\n"))
  @update_repositories = []
end

#update_repositories_finderObject

TODO: convenience method just for testing (to be removed)



133
134
135
# File 'src/lib/installation/clients/inst_update_installer.rb', line 133

def update_repositories_finder
  @update_repositories_finder ||= ::Installation::UpdateRepositoriesFinder.new
end

#updates_managerUpdatesManager (protected)

Instantiates an UpdatesManager to be used by the client

The manager is 'memoized'.

Returns:

  • (UpdatesManager)

    Updates manager to be used by the client



144
145
146
# File 'src/lib/installation/clients/inst_update_installer.rb', line 144

def updates_manager
  @updates_manager ||= ::Installation::UpdatesManager.new
end