Module: Apt

Defined in:
lib/vmbuilder_plugins/apt.rb

Overview

Purpose

Apt is a Capistrano plugin module providing a set of methods that invoke the apt package manager (as used in Debian and Ubuntu)

Installs within Capistrano as the plugin apt.

Usage

require 'vmbuilder_plugins/apt'

Prefix all calls to the library with apt.

Constant Summary collapse

APT_GET =

Default apt-get command - reduces any interactivity to the minimum.

"DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get"
UPDATE =
{ :has_been_run => false }

Instance Method Summary collapse

Instance Method Details

#autoclean(options = {}) ⇒ Object

Run an apt autoclean



46
47
48
# File 'lib/vmbuilder_plugins/apt.rb', line 46

def autoclean(options={})
  send(run_method, %{sh -c "#{APT_GET} -qy autoclean"}, options)
end

#clean(options = {}) ⇒ Object

Run an apt clean



41
42
43
# File 'lib/vmbuilder_plugins/apt.rb', line 41

def clean(options={})
  send(run_method, %{sh -c "#{APT_GET} -qy clean"}, options)
end

#clear_cache(options = {}) ⇒ Object

Clear the source list and package cache



82
83
84
85
86
# File 'lib/vmbuilder_plugins/apt.rb', line 82

def clear_cache(options={})
  clean
  cmd="rm -f /var/cache/apt/*.bin /var/lib/apt/lists/*_* /var/lib/apt/lists/partial/*"
  send(run_method, cmd, options)
end

#dist_upgrade(options = {}) ⇒ Object

Run an apt distribution upgrade



51
52
53
54
# File 'lib/vmbuilder_plugins/apt.rb', line 51

def dist_upgrade(options={})
  update :once_only => true
  send(run_method, %{sh -c "#{APT_GET} -qy dist-upgrade"}, options)
end

#install(packages, version, options = {}) ⇒ Object

Run the apt install program across the package list in ‘packages’. Select those packages referenced by :base and the version of the distribution you want to use.



32
33
34
35
36
37
38
# File 'lib/vmbuilder_plugins/apt.rb', line 32

def install(packages, version, options={})
  update :once_only => true
  special_options="--allow-unauthenticated" if version != :stable
  send(run_method, %{
    sh -c "#{APT_GET} -qyu --force-yes #{special_options.to_s} install #{package_list(packages, version)}"
  }, options)
end

#rpm_install(packages, options = {}) ⇒ Object

RPM package install via alien



74
75
76
77
78
79
# File 'lib/vmbuilder_plugins/apt.rb', line 74

def rpm_install(packages, options={})
  install({:base => %w(wget alien) }, :base)
  send(run_method, "wget -Ncq #{packages.join(' ')}", options)
  files=packages.collect { |package| File.basename(package) }
  send(run_method, "alien -i #{files.join(' ')}", options)
end

#update(options = {}) ⇒ Object

Run an apt update.



64
65
66
67
68
69
70
71
# File 'lib/vmbuilder_plugins/apt.rb', line 64

def update(options={})
  if options[:once_only] && UPDATE[:has_been_run]
    return false
  else
    send(run_method, %{sh -c "#{APT_GET} -qy update"}, options)
    UPDATE[:has_been_run] = true
  end
end

#upgrade(options = {}) ⇒ Object

Run an apt upgrade. Use dist_upgrade instead if you want to upgrade the critical base packages.



58
59
60
61
# File 'lib/vmbuilder_plugins/apt.rb', line 58

def upgrade(options={})
  update :once_only => true
  send(run_method, %{sh -c "#{APT_GET} -qy upgrade"}, options)
end