Module: VagrantPlugins::Ventriloquist::Cap::Debian::InstallPackages

Defined in:
lib/ventriloquist/cap/utils/debian/install_packages.rb

Class Method Summary collapse

Class Method Details

.install_packages(machine, packages, opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ventriloquist/cap/utils/debian/install_packages.rb', line 6

def self.install_packages(machine, packages, opts = {})
  packages = Array(packages).flatten
  machine.communicate.tap do |comm|
    # Based on http://askubuntu.com/a/17829
    packages_to_install = packages - installed_packages(machine)
    return if packages_to_install.empty?

    unless opts[:silent]
      machine.env.ui.info("Installing #{packages_to_install}")
    end

    if requires_update?(machine)
      comm.sudo("apt-get update -q")
    end
    comm.sudo("apt-get install #{packages_to_install.join(' ')} -y --force-yes -q -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'")
  end
end

.installed_packages(machine) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/ventriloquist/cap/utils/debian/install_packages.rb', line 24

def self.installed_packages(machine)
  pkgs = ""
  cmd  = "dpkg --get-selections | grep -v deinstall | awk '{ print $1 }'"
  machine.communicate.execute cmd do |buffer, output|
    if buffer == :stdout
      pkgs << output.chomp
    end
  end
  pkgs.split("\n")
end

.requires_update?(machine) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/ventriloquist/cap/utils/debian/install_packages.rb', line 35

def self.requires_update?(machine)
  @@_updated_machines ||= {}

  required = !@@_updated_machines[machine]
  @@_updated_machines[machine] = true

  return required
end