Class: NativePackageInstaller
- Inherits:
-
Object
- Object
- NativePackageInstaller
- Defined in:
- lib/native-package-installer/version.rb,
lib/native-package-installer.rb,
lib/native-package-installer/platform.rb,
lib/native-package-installer/os-release.rb,
lib/native-package-installer/platform/suse.rb,
lib/native-package-installer/platform/conda.rb,
lib/native-package-installer/platform/msys2.rb,
lib/native-package-installer/platform/debian.rb,
lib/native-package-installer/platform/fedora.rb,
lib/native-package-installer/platform/ubuntu.rb,
lib/native-package-installer/platform/freebsd.rb,
lib/native-package-installer/platform/unknown.rb,
lib/native-package-installer/executable-finder.rb,
lib/native-package-installer/platform/homebrew.rb,
lib/native-package-installer/platform/macports.rb,
lib/native-package-installer/platform/alt-linux.rb,
lib/native-package-installer/platform/pld-linux.rb,
lib/native-package-installer/platform/arch-linux.rb,
lib/native-package-installer/platform/gentoo-linux.rb,
lib/native-package-installer/platform/amazon-linux-2.rb,
lib/native-package-installer/platform/amazon-linux-2023.rb,
lib/native-package-installer/platform/red-hat-enterprise-linux.rb
Overview
Copyright © 2017-2021 Ruby-GNOME Project Team
This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Defined Under Namespace
Modules: Platform Classes: ExecutableFinder, OSRelease
Constant Summary collapse
- VERSION =
"1.1.6"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(spec) ⇒ NativePackageInstaller
constructor
A new instance of NativePackageInstaller.
- #install ⇒ Object
Constructor Details
#initialize(spec) ⇒ NativePackageInstaller
Returns a new instance of NativePackageInstaller.
32 33 34 35 |
# File 'lib/native-package-installer.rb', line 32 def initialize(spec) @spec = spec @platform = Platform.detect end |
Class Method Details
.install(spec) ⇒ Object
27 28 29 |
# File 'lib/native-package-installer.rb', line 27 def install(spec) new(spec).install end |
Instance Method Details
#install ⇒ Object
37 38 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 |
# File 'lib/native-package-installer.rb', line 37 def install package = @platform.package(@spec) return false if package.nil? package_name, * = package package_command_line = [package_name, *].collect do |component| Shellwords.escape(component) end.join(" ") install_command = "#{@platform.install_command} #{package_command_line}" if have_priviledge? sudo = nil else sudo = ExecutableFinder.find("sudo") end = "installing '#{package_name}' native package... " ("%s", ) failed_to_get_super_user_priviledge = false if have_priviledge? succeeded = run_command(install_command) else if sudo prompt = "[sudo] password for %u to install <#{package_name}>: " = "-p #{Shellwords.escape(prompt)}" install_command = "#{sudo} #{} #{install_command}" succeeded = run_command(install_command) else succeeded = false failed_to_get_super_user_priviledge = true end end if failed_to_get_super_user_priviledge = "require super user privilege" else = succeeded ? "succeeded" : "failed" end do "#{}#{}\n" end ("#{}\n") = nil unless succeeded if failed_to_get_super_user_priviledge = <<-MESSAGE '#{package_name}' native package is required. Run the following command as super user to install required native package: \# #{install_command} MESSAGE else = <<-MESSAGE Failed to run '#{install_command}'. MESSAGE end end if ("%s", ) ("%s", ) end ("--------------------\n\n") succeeded end |