diff options
| author | Max Martin <max@puppetlabs.com> | 2011-05-16 10:29:11 -0700 |
|---|---|---|
| committer | Max Martin <max@puppetlabs.com> | 2011-05-16 10:29:11 -0700 |
| commit | 3b4fd7a2a44873d3dd4afb882a381a2218e8a0e9 (patch) | |
| tree | a86cc3689e1fd33809c2e371fb8fc5d8aaf82e7a /lib | |
| parent | a8e4df735abcbb61915c28378f2fd045bdcdeb42 (diff) | |
| parent | 1dc662a0988fee83c92d2d46462f0662710ce7ad (diff) | |
| download | puppet-3b4fd7a2a44873d3dd4afb882a381a2218e8a0e9.tar.gz puppet-3b4fd7a2a44873d3dd4afb882a381a2218e8a0e9.tar.xz puppet-3b4fd7a2a44873d3dd4afb882a381a2218e8a0e9.zip | |
Merge branch 'ticket/next/1853-pacman-provider' into next
* ticket/next/1853-pacman-provider:
(#1853) Pacman package provider
(#1853) Pacman package provider
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/provider/package/pacman.rb | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb new file mode 100644 index 000000000..6eb7dbe3d --- /dev/null +++ b/lib/puppet/provider/package/pacman.rb @@ -0,0 +1,94 @@ +require 'puppet/provider/package' + +Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Package do + desc "Support for the Package Manager Utility (pacman) used in Archlinux." + + commands :pacman => "/usr/bin/pacman" + defaultfor :operatingsystem => :archlinux + confine :operatingsystem => :archlinux + has_feature :upgradeable + + # Install a package using 'pacman'. + # Installs quietly, without confirmation or progressbar, updates package + # list from servers defined in pacman.conf. + def install + pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name] + + unless self.query + raise Puppet::ExecutionFailure.new("Could not find package %s" % self.name) + end + end + + def self.listcmd + [command(:pacman), " -Q"] + end + + # Fetch the list of packages currently installed on the system. + def self.instances + packages = [] + begin + execpipe(listcmd()) do |process| + # pacman -Q output is 'packagename version-rel' + regex = %r{^(\S+)\s(\S+)} + fields = [:name, :ensure] + hash = {} + + process.each { |line| + if match = regex.match(line) + fields.zip(match.captures) { |field,value| + hash[field] = value + } + + name = hash[:name] + hash[:provider] = self.name + + packages << new(hash) + hash = {} + else + warning("Failed to match line %s" % line) + end + } + end + rescue Puppet::ExecutionFailure + return nil + end + packages + end + + # Because Archlinux is a rolling release based distro, installing a package + # should always result in the newest release. + def update + # Install in pacman can be used for update, too + self.install + end + + def latest + pacman "-Sy" + output = pacman "-Sp", "--print-format", "%v", @resource[:name] + output.chomp + end + + # Querys the pacman master list for information about the package. + def query + begin + output = pacman("-Qi", @resource[:name]) + + if output =~ /Version.*:\s(.+)/ + return { :ensure => $1 } + end + rescue Puppet::ExecutionFailure + return { + :ensure => :purged, + :status => 'missing', + :name => @resource[:name], + :error => 'ok', + } + end + nil + end + + # Removes a package from the system. + def uninstall + pacman "--noconfirm", "--noprogressbar", "-R", @resource[:name] + end +end |
