Class: Yast::InstExtensionImageClass
- Inherits:
-
Module
- Object
- Module
- Yast::InstExtensionImageClass
- Defined in:
- library/control/src/modules/InstExtensionImage.rb
Instance Method Summary collapse
-
#CutLastDirOrFile(url) ⇒ Object
Removes the last url item.
- #DesintegrateExtension(_extension) ⇒ Object
- #DisintegrateAllExtensions ⇒ Object
- #DownloadAndIntegrateExtension(extension) ⇒ Object
- #IsURLRelative(url) ⇒ Object
-
#LazyInit ⇒ Object
Every global function should call LazyInit in the beginning.
-
#LoadExtension(package, message) ⇒ Object
Load a rpm package from the media into the inst-sys the package is expected in the /boot/
/ directory of the media. - #main ⇒ Object
-
#MergeURLs(url_base, url_with_modifs) ⇒ String
Merges two URLs into one and removes parameters from both.
-
#MergeURLsParams(base_url, url_with_modifs) ⇒ String
Merges two different URLs, repspectively their parameters to one string with parameters.
-
#UnLoadExtension(package, message) ⇒ Object
Remove given package from the inst-sys the package is expected in the /boot/
/ directory of the media. -
#with_extension(package) { ... } ⇒ Object
Load a rpm package from the media into the inst-sys and ensure its unloading after end of block.
Instance Method Details
#CutLastDirOrFile(url) ⇒ Object
Removes the last url item.
211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 211 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 |
#DesintegrateExtension(_extension) ⇒ Object
435 436 437 438 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 435 def DesintegrateExtension(_extension) Builtins.y2warning("Function is empty, see BNC #376870") true end |
#DisintegrateAllExtensions ⇒ Object
440 441 442 443 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 440 def DisintegrateAllExtensions Builtins.y2warning("Function is empty, see BNC #376870") true end |
#DownloadAndIntegrateExtension(extension) ⇒ Object
431 432 433 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 431 def DownloadAndIntegrateExtension(extension) LoadExtension(extension, "") end |
#IsURLRelative(url) ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 146 def IsURLRelative(url) return nil if url.nil? # "http://..." -> not-relative # "cd:/" -> not relative # "boot/i386/root -> relative !Builtins.regexpmatch(url, "^[[:alpha:]]+:/") end |
#LazyInit ⇒ Object
Every global function should call LazyInit in the beginning.
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 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 276 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 |
#LoadExtension(package, message) ⇒ Object
Load a rpm package from the media into the inst-sys
the package is expected in the /boot/
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 358 def LoadExtension(package, ) Builtins.y2error("This module should be used in Stage::initial only!") if !Stage.initial 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("/bin/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 @integrated_extensions = Builtins.add(@integrated_extensions, package) else Builtins.y2error("'extend' failed!") ret = false end Popup.ClearFeedback if != "" && !.nil? ret end |
#main ⇒ Object
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 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 39 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 |
#MergeURLs(url_base, url_with_modifs) ⇒ String
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).
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 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 242 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 return CutLastDirOrFile(url_with_modifs_onlyurl) if !IsURLRelative(url_with_modifs_onlyurl) # base URL url_base_pos = Builtins.search(url_base, "?") url_base_onlyurl = url_base url_base_onlyurl = Builtins.substring(url_base, 0, url_base_pos) if !url_base_pos.nil? && Ops.greater_or_equal(url_base_pos, 0) url_base_onlyurl = Ops.add(url_base_onlyurl, "/") if !Builtins.regexpmatch(url_base_onlyurl, "/$") CutLastDirOrFile(Ops.add(url_base_onlyurl, url_with_modifs_onlyurl)) end |
#MergeURLsParams(base_url, url_with_modifs) ⇒ String
Merges two different URLs, repspectively their parameters to one string with parameters. See the example.
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 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 168 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 = "" base_params = Builtins.substring(base_url, Ops.add(base_params_pos, 1)) if !base_params_pos.nil? && Ops.greater_or_equal(base_params_pos, 0) # 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 |
#UnLoadExtension(package, message) ⇒ Object
Remove given package from the inst-sys
the package is expected in the /boot/
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 423 424 425 426 427 428 429 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 396 def UnLoadExtension(package, ) Builtins.y2error("This module should be used in Stage::initial only!") if !Stage.initial 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("/bin/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 @integrated_extensions = Builtins.filter(@integrated_extensions) do |p| p != package end else Builtins.y2error("'extend' failed!") ret = false end Popup.ClearFeedback if != "" && !.nil? ret end |
#with_extension(package) { ... } ⇒ Object
Load a rpm package from the media into the inst-sys and ensure its unloading after end of block.
341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'library/control/src/modules/InstExtensionImage.rb', line 341 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 |