Class: Yast::InstUpdateInstaller

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

Constant Summary

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

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.



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

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.



263
264
265
266
267
268
269
270
271
272
273
# File 'src/lib/installation/clients/inst_update_installer.rb', line 263

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 }])
    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


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

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

#custom_self_update_urlURI (protected)

Return the custom self-update URL

A custom URL can be specified via Linuxrc or in an AutoYaST profile. Only 1 custom self-update URL can be specified.

Returns:

  • (URI)

    self-update URL

See Also:

  • #self_update_url_from_linuxrc
  • #self_update_url_from_profile


194
195
196
# File 'src/lib/installation/clients/inst_update_installer.rb', line 194

def custom_self_update_url
  @custom_self_update_url ||= self_update_url_from_linuxrc || self_update_url_from_profile
end

#disabled_in_linuxrc?Boolean (protected)

disabled via Linuxrc ?

Returns:

  • (Boolean)

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



156
157
158
# File 'src/lib/installation/clients/inst_update_installer.rb', line 156

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



163
164
165
166
# File 'src/lib/installation/clients/inst_update_installer.rb', line 163

def disabled_in_profile?
  profile = Yast::Profile.current
  !profile.fetch("general", {}).fetch("self_update", true)
end

#finish_packagerObject (protected)

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



375
376
377
378
379
380
381
382
# File 'src/lib/installation/clients/inst_update_installer.rb', line 375

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



420
421
422
423
424
425
# File 'src/lib/installation/clients/inst_update_installer.rb', line 420

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.



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

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



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

def initialize_progress
  stages = [
    # TRANSLATORS: progress label
    _("Add Update Repository"),
    _("Download the 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.



203
204
205
206
207
208
209
210
211
# File 'src/lib/installation/clients/inst_update_installer.rb', line 203

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.



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

def load_registration_url
  return false unless File.exist?(REGISTRATION_DATA_PATH) && require_registration_libraries
  data = YAML.load(File.read(REGISTRATION_DATA_PATH))
  Registration::Storage::InstallationOptions.instance.custom_url = data["custom_url"]
  ::FileUtils.rm_rf(REGISTRATION_DATA_PATH)
  true
end

#mainObject



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

def main
  textdomain "installation"

  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



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

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.



144
145
146
147
148
149
150
151
# File 'src/lib/installation/clients/inst_update_installer.rb', line 144

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



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

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:



288
289
290
# File 'src/lib/installation/clients/inst_update_installer.rb', line 288

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:



218
219
220
# File 'src/lib/installation/clients/inst_update_installer.rb', line 218

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.



111
112
113
114
115
116
117
118
119
120
# File 'src/lib/installation/clients/inst_update_installer.rb', line 111

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

  if updated
    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:



174
175
176
177
178
179
180
181
182
183
184
# File 'src/lib/installation/clients/inst_update_installer.rb', line 174

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)



123
124
125
# File 'src/lib/installation/clients/inst_update_installer.rb', line 123

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



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

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