Class: Sysutil::Package

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

Class Method Summary collapse

Class Method Details

.autoremove!Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sysutil/package.rb', line 54

def self.autoremove!

  autoremove_command = case linux_variant[:family]
                       when 'Debian'
                         'apt-get autoremove -y'
                       when 'Redhat'
                         'yum autoremove'
                       when 'Solaris'
                         'pkg-delete -a'
                       end

  autoremove_command = conditional_sudo + autoremove_command
  out, err, status = Open3.capture3(autoremove_command)

  if status.success?
    {success: true, message: out}
  else
    {success: true, output: "Error: #{err}"}
  end
  
end

.install!(*packages) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sysutil/package.rb', line 8

def self.install!(*packages)

  packages = packages.join(' ')

  install_command = case linux_variant[:family]
                    when 'Debian'
                      'apt-get install -y'
                    when 'Redhat'
                      'yum install -y'
                    when 'Solaris'
                      'pkg install'
                    end

  install_command = conditional_sudo + install_command
  out, err, status = Open3.capture3(install_command)

  if status.success?
    {success: true, output: out}
  else
    {success: false, output: "Error: #{err}"}
  end
  
end

.remove!(*packages) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sysutil/package.rb', line 32

def self.remove!(*packages)

  remove_command = case linux_variant[:family]
                       when 'Debian'
                         'apt-get remove -y'
                       when 'Redhat'
                         'yum remove -y'
                       when 'Solaris'
                         'pkg-delete'
                       end

  remove_command = conditional_sudo + remove_command
  out, err, status = Open3.capture3(remove_command)

  if status.success?
    {success: true, output: out}
  else
    {success: false, output: "Error: #{err}"}
  end
  
end