~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to lib/puppet/provider/package/pacman.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'puppet/provider/package'
 
2
 
 
3
Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Package do
 
4
  desc "Support for the Package Manager Utility (pacman) used in Archlinux."
 
5
 
 
6
  commands :pacman => "/usr/bin/pacman"
 
7
  defaultfor :operatingsystem => :archlinux
 
8
  confine    :operatingsystem => :archlinux
 
9
  has_feature :upgradeable
 
10
 
 
11
  # Install a package using 'pacman'.
 
12
  # Installs quietly, without confirmation or progressbar, updates package
 
13
  # list from servers defined in pacman.conf.
 
14
  def install
 
15
    pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]
 
16
 
 
17
    unless self.query
 
18
      raise Puppet::ExecutionFailure.new("Could not find package %s" % self.name)
 
19
    end
 
20
  end
 
21
 
 
22
  def self.listcmd
 
23
    [command(:pacman), " -Q"]
 
24
  end
 
25
 
 
26
  # Fetch the list of packages currently installed on the system.
 
27
  def self.instances
 
28
    packages = []
 
29
    begin
 
30
      execpipe(listcmd()) do |process|
 
31
        # pacman -Q output is 'packagename version-rel'
 
32
        regex = %r{^(\S+)\s(\S+)}
 
33
        fields = [:name, :ensure]
 
34
        hash = {}
 
35
 
 
36
        process.each_line { |line|
 
37
          if match = regex.match(line)
 
38
            fields.zip(match.captures) { |field,value|
 
39
              hash[field] = value
 
40
            }
 
41
 
 
42
            name = hash[:name]
 
43
            hash[:provider] = self.name
 
44
 
 
45
            packages << new(hash)
 
46
            hash = {}
 
47
          else
 
48
            warning("Failed to match line %s" % line)
 
49
          end
 
50
        }
 
51
      end
 
52
    rescue Puppet::ExecutionFailure
 
53
      return nil
 
54
    end
 
55
    packages
 
56
  end
 
57
 
 
58
  # Because Archlinux is a rolling release based distro, installing a package
 
59
  # should always result in the newest release.
 
60
  def update
 
61
    # Install in pacman can be used for update, too
 
62
    self.install
 
63
  end
 
64
 
 
65
  def latest
 
66
    pacman "-Sy"
 
67
    output = pacman "-Sp", "--print-format", "%v", @resource[:name]
 
68
    output.chomp
 
69
  end
 
70
 
 
71
  # Querys the pacman master list for information about the package.
 
72
  def query
 
73
    begin
 
74
      output = pacman("-Qi", @resource[:name])
 
75
 
 
76
      if output =~ /Version.*:\s(.+)/
 
77
        return { :ensure => $1 }
 
78
      end
 
79
    rescue Puppet::ExecutionFailure
 
80
      return {
 
81
        :ensure => :purged,
 
82
        :status => 'missing',
 
83
        :name => @resource[:name],
 
84
        :error => 'ok',
 
85
      }
 
86
    end
 
87
    nil
 
88
  end
 
89
 
 
90
  # Removes a package from the system.
 
91
  def uninstall
 
92
    pacman "--noconfirm", "--noprogressbar", "-R", @resource[:name]
 
93
  end
 
94
end