Class: Chef::Provider::Package::Apt

Inherits:
Chef::Provider::Package show all
Defined in:
lib/chef/provider/package/apt.rb

Direct Known Subclasses

Dpkg

Instance Attribute Summary

Attributes inherited from Chef::Provider::Package

#candidate_version

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods inherited from Chef::Provider::Package

#action_install, #action_purge, #action_remove, #action_upgrade, #expand_options, #get_preseed_file, #initialize, #should_remove_package

Methods included from Mixin::Command

handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #initialize

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #filename_to_qualified_string

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Constructor Details

This class inherits a constructor from Chef::Provider::Package

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#install_package(name, version) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/chef/provider/package/apt.rb', line 63

def install_package(name, version)
  run_command_with_systems_locale(
    :command => "apt-get -q -y#{expand_options(@new_resource.options)} install #{name}=#{version}",
    :environment => {
      "DEBIAN_FRONTEND" => "noninteractive"
    }
  )
end

#load_current_resourceObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/provider/package/apt.rb', line 28

def load_current_resource
  @current_resource = Chef::Resource::Package.new(@new_resource.name)
  @current_resource.package_name(@new_resource.package_name)

  Chef::Log.debug("Checking apt-cache policy for #{@new_resource.package_name}")
  status = popen4("apt-cache policy #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
    stdout.each do |line|
      case line
      when /^\s{2}Installed: (.+)$/
        installed_version = $1
        if installed_version == '(none)'
          Chef::Log.debug("Current version is nil")
          @current_resource.version(nil)
        else
          Chef::Log.debug("Current version is #{installed_version}")
          @current_resource.version(installed_version)
        end
      when /^\s{2}Candidate: (.+)$/
        Chef::Log.debug("Current version is #{$1}")                
        @candidate_version = $1
      end
    end
  end

  unless status.exitstatus == 0
    raise Chef::Exceptions::Package, "apt-cache failed - #{status.inspect}!"
  end
  
  if @candidate_version == "(none)"
    raise Chef::Exceptions::Package, "apt does not have a version of package #{@new_resource.package_name}"
  end

  @current_resource
end

#preseed_package(name, version) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/chef/provider/package/apt.rb', line 94

def preseed_package(name, version)
  preseed_file = get_preseed_file(name, version)
  if preseed_file
    Chef::Log.info("Pre-seeding #{@new_resource} with package installation instructions.")
    run_command_with_systems_locale(
      :command => "debconf-set-selections #{preseed_file}",
      :environment => {
        "DEBIAN_FRONTEND" => "noninteractive"
      }
    )
  end
end

#purge_package(name, version) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/chef/provider/package/apt.rb', line 85

def purge_package(name, version)
  run_command_with_systems_locale(
    :command => "apt-get -q -y#{expand_options(@new_resource.options)} purge #{@new_resource.package_name}",
    :environment => {
      "DEBIAN_FRONTEND" => "noninteractive"
    }
  )
end

#remove_package(name, version) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/chef/provider/package/apt.rb', line 76

def remove_package(name, version)
  run_command_with_systems_locale(
    :command => "apt-get -q -y#{expand_options(@new_resource.options)} remove #{@new_resource.package_name}",
    :environment => {
      "DEBIAN_FRONTEND" => "noninteractive"
    }
  )
end

#upgrade_package(name, version) ⇒ Object



72
73
74
# File 'lib/chef/provider/package/apt.rb', line 72

def upgrade_package(name, version)
  install_package(name, version)
end