# Copyright (c) 2013-2015 SUSE LLC # # This program is free software; you can redistribute it and/or # modify it under the terms of version 3 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 SUSE LLC. # # To contact SUSE about this file by physical or electronic mail, # you may find current contact information at www.suse.com class LocalSystem < System @@os = nil class << self def os if !@@os description = SystemDescription.new("localhost", SystemDescriptionMemoryStore.new) inspector = OsInspector.new(System.for("localhost"), description) inspector.inspect(nil) @@os = description.os end @@os end def validate_existence_of_package(package) validate_existence_of_packages([package]) end def validate_existence_of_packages(packages) missing_packages = [] needed_modules = [] packages.each do |package| begin Cheetah.run("rpm", "-q", package) rescue Cheetah::ExecutionFailed missing_packages << package needed_module = os.module_required_by_package(package) if needed_module needed_modules << package if needed_module output = <<-EOF You need the package '#{package}' from module '#{needed_module}'. You can install it as follows: If you haven't selected the module '#{needed_module}' before, run `yast2 scc` and choose 'Select Extensions' and activate '#{needed_module}'. Run `zypper install #{package}` to install the package. EOF raise(Machinery::Errors::MissingRequirement.new(output)) end end end end if !missing_packages.empty? count = missing_packages.count error_string = <<-EOF You need the #{Machinery::pluralize(count, "package")} '#{missing_packages.join("\',\'")}'. You can install it by running `zypper install #{missing_packages.join(" ")}`. EOF raise(Machinery::Errors::MissingRequirement.new(error_string)) end end def validate_machinery_compatibility return if !Machinery::Config.new.perform_support_check || os.can_run_machinery? supported_oses = Os.supported_host_systems.map { |o| o.canonical_name }.sort.join(", ") message = < e raise Machinery::Errors::RsyncFailed.new( "Could not rsync files from localhost. \n" \ "Error: #{e}\n" \ "If you lack read permissions on some files you may want to retry as user root or specify\n" \ "the fully qualified host name instead of localhost in order to connect as root via ssh." ) end end # Reads a file from the System. Returns nil if it does not exist. def read_file(file) File.read(file) rescue Errno::ENOENT # File not found, return nil return end end