Class: Sensible::Package
- Inherits:
-
Object
- Object
- Sensible::Package
- Defined in:
- lib/sensible/package.rb
Instance Attribute Summary collapse
-
#distro ⇒ Object
readonly
Returns the value of attribute distro.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sensible ⇒ Object
readonly
Returns the value of attribute sensible.
Instance Method Summary collapse
-
#do_check ⇒ Object
Check if the package is installed.
-
#do_install ⇒ Object
Install the package.
-
#initialize(packageName, distro, sensible) ⇒ Package
constructor
A new instance of Package.
Constructor Details
#initialize(packageName, distro, sensible) ⇒ Package
Returns a new instance of Package.
12 13 14 15 16 |
# File 'lib/sensible/package.rb', line 12 def initialize(packageName, distro, sensible) @name = packageName @distro = distro @sensible = sensible end |
Instance Attribute Details
#distro ⇒ Object (readonly)
Returns the value of attribute distro.
10 11 12 |
# File 'lib/sensible/package.rb', line 10 def distro @distro end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/sensible/package.rb', line 9 def name @name end |
#sensible ⇒ Object (readonly)
Returns the value of attribute sensible.
8 9 10 |
# File 'lib/sensible/package.rb', line 8 def sensible @sensible end |
Instance Method Details
#do_check ⇒ Object
Check if the package is installed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sensible/package.rb', line 19 def do_check check_command = nil case @distro when "rpm" check_command = "rpm -q #{name}" when "deb" check_command = "dpkg-query -W #{name}" when "aur" check_command = "pacman -Qi #{name}" end if check_command == nil Logger.error("Unknown check command") exit(1) end # Run the shell command shell = Shell.new(@sensible) return shell.run_command(check_command) end |
#do_install ⇒ Object
Install the package
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sensible/package.rb', line 42 def do_install install_command = nil case @distro when "rpm" install_command = "sudo dnf install -y #{name}" when "deb" install_command = "sudo apt get install -y #{name}" when "aur" install_command = "pacman -Syu #{name}" end if install_command == nil Logger.error("Unknown install command") exit(1) end shell = Shell.new(@sensible) return shell.run_command(install_command) end |