Class: Yast::InstExtensionImageClass
- Inherits:
-
Module
- Object
- Module
- Yast::InstExtensionImageClass
- Defined in:
- ../../src/modules/InstExtensionImage.rb
Instance Method Summary (collapse)
-
- (Object) CutLastDirOrFile(url)
Removes the last url item.
- - (Object) DesintegrateExtension(_extension)
- - (Object) DisintegrateAllExtensions
- - (Object) DownloadAndIntegrateExtension(extension)
- - (Object) IsURLRelative(url)
-
- (Object) LazyInit
Every global function should call LazyInit in the beginning.
-
- (Object) LoadExtension(package, message)
Load a rpm package from the media into the inst-sys the package is expected in the /boot// directory of the media.
- - (Object) main
-
- (String) MergeURLs(url_base, url_with_modifs)
Merges two URLs into one and removes parameters from both.
-
- (String) MergeURLsParams(base_url, url_with_modifs)
Merges two different URLs, repspectively their parameters to one string with parameters.
-
- (Object) UnLoadExtension(package, message)
Remove given package from the inst-sys the package is expected in the /boot// directory of the media.
-
- (Object) with_extension(package, &block)
Load a rpm package from the media into the inst-sys and ensure its unloading after end of block.
Instance Method Details
- (Object) CutLastDirOrFile(url)
Removes the last url item.
215 216 217 218 219 220 221 222 223 224 225 226 |
# File '../../src/modules/InstExtensionImage.rb', line 215 def CutLastDirOrFile(url) if url.nil? || url == "" || url == "/" || !Builtins.regexpmatch(url, "/") Builtins.y2error(-1, "Wrong URL: %1", url) return "" end # final "/" is needed for regexp url = Ops.add(url, "/") if !Builtins.regexpmatch(url, "/$") Builtins.regexpsub(url, "^(.*)/[^/]+/$", "\\1/") end |
- (Object) DesintegrateExtension(_extension)
448 449 450 451 |
# File '../../src/modules/InstExtensionImage.rb', line 448 def DesintegrateExtension(_extension) Builtins.y2warning("Function is empty, see BNC #376870") true end |
- (Object) DisintegrateAllExtensions
453 454 455 456 |
# File '../../src/modules/InstExtensionImage.rb', line 453 def DisintegrateAllExtensions Builtins.y2warning("Function is empty, see BNC #376870") true end |
- (Object) DownloadAndIntegrateExtension(extension)
444 445 446 |
# File '../../src/modules/InstExtensionImage.rb', line 444 def DownloadAndIntegrateExtension(extension) LoadExtension(extension, "") end |
- (Object) IsURLRelative(url)
148 149 150 151 152 153 154 155 |
# File '../../src/modules/InstExtensionImage.rb', line 148 def IsURLRelative(url) return nil if url.nil? # "http://..." -> not-relative # "cd:/" -> not relative # "boot/i386/root -> relative !Builtins.regexpmatch(url, "^[[:alpha:]]+:/") end |
- (Object) LazyInit
Every global function should call LazyInit in the beginning.
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 |
# File '../../src/modules/InstExtensionImage.rb', line 286 def LazyInit # already initialized return if @initialized Builtins.y2milestone("Initializing...") @initialized = true # base repo URL repo_url = Linuxrc.InstallInf("RepoURL") # inst-sys URL inst_sys_url = Linuxrc.InstallInf("InstsysURL") # non-relative inst-sys, repo is not taken into account repo_url = "" if !IsURLRelative(inst_sys_url) # final base URL (last file/dir already removed) @base_url = MergeURLs(repo_url, inst_sys_url) Builtins.y2milestone("Base URL: %1", @base_url) # final params @base_url_params = MergeURLsParams(repo_url, inst_sys_url) Builtins.y2milestone("Base URL params: %1", @base_url_params) run = Convert.to_map( WFM.Execute( path(".local.bash_output"), Builtins.sformat("/bin/mkdir -p '%1'", String.Quote(@base_tmpdir)) ) ) if Ops.get_integer(run, "exit", -1) != 0 Builtins.y2error( "Cannot create temporary directory: %1: %2", @base_tmpdir, run ) end run = Convert.to_map( WFM.Execute( path(".local.bash_output"), Builtins.sformat("/bin/mkdir -p '%1'", String.Quote(@base_mounts)) ) ) if Ops.get_integer(run, "exit", -1) != 0 Builtins.y2error( "Cannot create mounts directory: %1: %2", @base_mounts, run ) end nil end |
- (Object) LoadExtension(package, message)
Load a rpm package from the media into the inst-sys the package is expected in the /boot/<arch>/ directory of the media
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File '../../src/modules/InstExtensionImage.rb', line 367 def LoadExtension(package, ) if !Stage.initial Builtins.y2error("This module should be used in Stage::initial only!") end if package.nil? || package == "" Builtins.y2error("Such package name can't work: %1", package) return false end if Builtins.contains(@integrated_extensions, package) Builtins.y2milestone("Package %1 has already been integrated", package) return true end Popup.ShowFeedback("", ) if != "" && !.nil? # See BNC #376870 cmd = Builtins.sformat("extend '%1'", String.Quote(package)) Builtins.y2milestone("Calling: %1", cmd) cmd_out = Convert.to_map(WFM.Execute(path(".local.bash_output"), cmd)) Builtins.y2milestone("Returned: %1", cmd_out) ret = true if Ops.get_integer(cmd_out, "exit", -1) != 0 Builtins.y2error("'extend' failed!") ret = false else @integrated_extensions = Builtins.add(@integrated_extensions, package) end Popup.ClearFeedback if != "" && !.nil? ret end |
- (Object) main
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 |
# File '../../src/modules/InstExtensionImage.rb', line 41 def main textdomain "base" Yast.import "Linuxrc" Yast.import "URL" Yast.import "String" Yast.import "Directory" Yast.import "Popup" Yast.import "Stage" # ** # # Paths where to download inst-sys extension images are taken # from '/etc/install.inf'. An extension image contains the # directory structure and files as it was in inst-sys but # it is a squashfs image of it. # # Inst-sys URL might be absolute or 'relative' to repo URL, # but only if instsys=... parameter wasn't explicitely defined. # # When instsys=... parameter _is not_ used: # * RepoURL: cd:/?device=sr0 # * InstsysURL: boot/<arch>/root # (<arch> is for instance "i386", "x86_64", "ppc") # or # * RepoURL: nfs://server/repo/url/?device=eth0 # * InstsysURL: boot/<arch>/root # # When instsys=... parameter _is_ used: # * RepoURL: nfs://server/repo/url/ # * InstsysURL: http://server/inst-sys/url/ # or # * RepoURL: cd:/?device=sr0 # * InstsysURL: nfs://server/inst-sys/url/?device=eth0 # # Files to download are in the same level (directory) with # inst-sys: # # * RepoURL: cd:/?device=sr0 # * InstsysURL: boot/<arch>/root # -> cd:/boot/<arch>/$extension_file # # * RepoURL: nfs://server/repo/url/?device=eth0 # * InstsysURL: http://server/inst-sys/url/?device=eth0 # -> http://server/inst-sys/$extension_file?device=eth0 # # These files are always squashfs images that need to be: # # * Downloaded: /lbin/wget -v $url $local_filename_path # * Downloaded file needs to be checked against a SHA1 # hash defined in /content file # * Mounted (-o loop) to a directory. # * Directory needs to be merged into inst-sys by using # `/lbin/lndir <image_mountpoint> /` # # This module remembers downloading a file so it does not # download any file twice. # # Additional comments on the "Installation Workflow": # # * When Linuxrc starts loading an initial translation # might already been selected. Linuxrc will download # and merge the pre-selected translation itself. # * Then Linuxrc starts YaST. YaST initializes itself # including translations and displays the language # dialog translated. # * After a different language is selected, YaST downloads # a localization inst-sys extension and merges it. # * Then a different locale is selected and YaST redraws # reruns the current YCP client. # nfs://.../, cd:/, http://.../any/ # always ends with a slash "/" @base_url = "" # if there are any params $url?param1=xx¶m2=... # always only params @base_url_params = "" # Directory used for storing images @base_tmpdir = Builtins.sformat( "%1/%2/", Directory.tmpdir, "instsys_extensions" ) # Directory used for mounting images @base_mounts = Builtins.sformat( "%1/%2/", Directory.tmpdir, "instsys_extmounts" ) @initialized = false # Already downloaded (and mounted and merged) files @already_downloaded_files = [] # All integrated extensions @integrated_extensions = [] # $["extension_name" : "mounted_as_directory", ...] @extensions_mounted_as = {} # $["extension_name" : "downloaded_to_file", ...] @extension_downloaded_as = {} end |
- (String) MergeURLs(url_base, url_with_modifs)
Merges two URLs into one and removes parameters from both. If the second URL is strictly relative, e.g., “boot/i386/root”, it is merged with the first one, otherwise the second one is returned (with params cut).
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 |
# File '../../src/modules/InstExtensionImage.rb', line 246 def MergeURLs(url_base, url_with_modifs) if url_base.nil? || url_with_modifs.nil? Builtins.y2error("Wrong URLs: %1 or %2", url_base, url_with_modifs) return nil end # relative (to base URL) or absolute URL url_with_modifs_pos = Builtins.search(url_with_modifs, "?") url_with_modifs_onlyurl = url_with_modifs if !url_with_modifs_pos.nil? && Ops.greater_or_equal(url_with_modifs_pos, 0) url_with_modifs_onlyurl = Builtins.substring( url_with_modifs, 0, url_with_modifs_pos ) end # Modif URL is not relative, not using the base URL at all if !IsURLRelative(url_with_modifs_onlyurl) return CutLastDirOrFile(url_with_modifs_onlyurl) end # base URL url_base_pos = Builtins.search(url_base, "?") url_base_onlyurl = url_base if !url_base_pos.nil? && Ops.greater_or_equal(url_base_pos, 0) url_base_onlyurl = Builtins.substring(url_base, 0, url_base_pos) end if !Builtins.regexpmatch(url_base_onlyurl, "/$") url_base_onlyurl = Ops.add(url_base_onlyurl, "/") end CutLastDirOrFile(Ops.add(url_base_onlyurl, url_with_modifs_onlyurl)) end |
- (String) MergeURLsParams(base_url, url_with_modifs)
Merges two different URLs, repspectively their parameters to one string with parameters. See the example.
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 |
# File '../../src/modules/InstExtensionImage.rb', line 170 def MergeURLsParams(base_url, url_with_modifs) if base_url.nil? || url_with_modifs.nil? Builtins.y2error("Wrong params: %1 or %2", base_url, url_with_modifs) return nil end # base URL params base_params_pos = Builtins.search(base_url, "?") base_params = "" if !base_params_pos.nil? && Ops.greater_or_equal(base_params_pos, 0) base_params = Builtins.substring(base_url, Ops.add(base_params_pos, 1)) end # URL params with modifications modif_params_pos = Builtins.search(url_with_modifs, "?") modif_params = "" if !modif_params_pos.nil? && Ops.greater_or_equal(modif_params_pos, 0) modif_params = Builtins.substring( url_with_modifs, Ops.add(modif_params_pos, 1) ) end # Nothing to merge return modif_params if base_params == "" return base_params if modif_params == "" base_params_map = URL.MakeMapFromParams(base_params) modif_params_map = URL.MakeMapFromParams(modif_params) final_params_map = Convert.convert( Builtins.union(base_params_map, modif_params_map), from: "map", to: "map <string, string>" ) URL.MakeParamsFromMap(final_params_map) end |
- (Object) UnLoadExtension(package, message)
Remove given package from the inst-sys the package is expected in the /boot/<arch>/ directory of the media
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File '../../src/modules/InstExtensionImage.rb', line 407 def UnLoadExtension(package, ) if !Stage.initial Builtins.y2error("This module should be used in Stage::initial only!") end if package.nil? || package == "" Builtins.y2error("Such package name can't work: %1", package) return false end if !Builtins.contains(@integrated_extensions, package) Builtins.y2milestone("Package %1 wasn't integrated", package) return true end Popup.ShowFeedback("", ) if != "" && !.nil? cmd = Builtins.sformat("extend -r '%1'", String.Quote(package)) Builtins.y2milestone("Calling: %1", cmd) cmd_out = Convert.to_map(WFM.Execute(path(".local.bash_output"), cmd)) Builtins.y2milestone("Returned: %1", cmd_out) ret = true if Ops.get_integer(cmd_out, "exit", -1) != 0 Builtins.y2error("'extend' failed!") ret = false else @integrated_extensions = Builtins.filter(@integrated_extensions) do |p| p != package end end Popup.ClearFeedback if != "" && !.nil? ret end |
- (Object) with_extension(package, &block)
Load a rpm package from the media into the inst-sys and ensure its unloading after end of block.
351 352 353 354 355 356 357 358 359 360 361 |
# File '../../src/modules/InstExtensionImage.rb', line 351 def with_extension(package, &block) loading_msg = format(_("Loading to memory package '%s'"), package) res = LoadExtension(package, loading_msg) raise "Failed to load package. Please check logs." unless res begin block.call ensure unloading_msg = format(_("Removing from memory package '%s'"), package) UnLoadExtension(package, unloading_msg) end end |