Class: Sensible::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/sensible/package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#distroObject (readonly)

Returns the value of attribute distro.



10
11
12
# File 'lib/sensible/package.rb', line 10

def distro
  @distro
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/sensible/package.rb', line 9

def name
  @name
end

#sensibleObject (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_checkObject

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_installObject

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