1
require 'puppet/provider/package'
3
Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Package do
4
desc "Support for the Package Manager Utility (pacman) used in Archlinux."
6
commands :pacman => "/usr/bin/pacman"
7
defaultfor :operatingsystem => :archlinux
8
confine :operatingsystem => :archlinux
9
has_feature :upgradeable
11
# Install a package using 'pacman'.
12
# Installs quietly, without confirmation or progressbar, updates package
13
# list from servers defined in pacman.conf.
15
pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]
18
raise Puppet::ExecutionFailure.new("Could not find package %s" % self.name)
23
[command(:pacman), " -Q"]
26
# Fetch the list of packages currently installed on the system.
30
execpipe(listcmd()) do |process|
31
# pacman -Q output is 'packagename version-rel'
32
regex = %r{^(\S+)\s(\S+)}
33
fields = [:name, :ensure]
36
process.each_line { |line|
37
if match = regex.match(line)
38
fields.zip(match.captures) { |field,value|
43
hash[:provider] = self.name
48
warning("Failed to match line %s" % line)
52
rescue Puppet::ExecutionFailure
58
# Because Archlinux is a rolling release based distro, installing a package
59
# should always result in the newest release.
61
# Install in pacman can be used for update, too
67
output = pacman "-Sp", "--print-format", "%v", @resource[:name]
71
# Querys the pacman master list for information about the package.
74
output = pacman("-Qi", @resource[:name])
76
if output =~ /Version.*:\s(.+)/
77
return { :ensure => $1 }
79
rescue Puppet::ExecutionFailure
83
:name => @resource[:name],
90
# Removes a package from the system.
92
pacman "--noconfirm", "--noprogressbar", "-R", @resource[:name]