Class: AutomateIt::PackageManager::APT

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/automateit/package_manager/apt.rb

Overview

PackageManager::APT

The APT driver for the PackageManager provides a way to manage software packages on Debian-style systems using apt-get and dpkg.

Instance Method Summary collapse

Instance Method Details

#install(*packages) ⇒ Object

See AutomateIt::PackageManager#install



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/automateit/package_manager/apt.rb', line 37

def install(*packages)
  return _install_helper(*packages) do |list, opts|
    # apt-get options:
    # -y : yes to all queries
    # -q : no interactive progress bars
    cmd = "export DEBIAN_FRONTEND=noninteractive; apt-get install -y -q "+list.join(" ")+" < /dev/null"
    cmd << " > /dev/null" if opts[:quiet]
    cmd << " 2>&1"

    interpreter.sh(cmd)
  end
end

#installed?(*packages) ⇒ Boolean

See AutomateIt::PackageManager#installed?

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/automateit/package_manager/apt.rb', line 13

def installed?(*packages)
  return _installed_helper?(*packages) do |list, opts|
    ### data = `dpkg --status nomarch apache2 not_a_real_package 2>&1`
    cmd = "dpkg --status "+list.join(" ")+" 2>&1"

    log.debug(PEXEC+cmd)
    data = `#{cmd}`
    matches = data.scan(/^Package: (.+)$\s*^Status: (.+)$/)
    available = matches.inject([]) do |sum, match|
      package, status = match
      sum << package if status.match(/(?:^|\s)installed\b/)
      sum
    end

    available
  end
end

#not_installed?(*packages) ⇒ Boolean

See AutomateIt::PackageManager#not_installed?

Returns:

  • (Boolean)


32
33
34
# File 'lib/automateit/package_manager/apt.rb', line 32

def not_installed?(*packages)
  return _not_installed_helper?(*packages)
end

#suitability(method, *args) ⇒ Object

:nodoc:



8
9
10
# File 'lib/automateit/package_manager/apt.rb', line 8

def suitability(method, *args) # :nodoc:
  return available? ? 1 : 0
end

#uninstall(*packages) ⇒ Object

See AutomateIt::PackageManager#uninstall



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/automateit/package_manager/apt.rb', line 51

def uninstall(*packages)
  return _uninstall_helper(*packages) do |list, opts|
    # apt-get options:
    # -y : yes to all queries
    # -q : no interactive progress bars
    cmd = "export DEBIAN_FRONTEND=noninteractive; apt-get remove -y -q "+list.join(" ")+" < /dev/null"
    cmd << " > /dev/null" if opts[:quiet]
    cmd << " 2>&1"

    interpreter.sh(cmd)
  end
end