diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/functions/regsubst.rb | 26 | ||||
-rw-r--r-- | lib/puppet/parser/functions/shellquote.rb | 26 | ||||
-rw-r--r-- | lib/puppet/parser/functions/sprintf.rb | 26 | ||||
-rw-r--r-- | lib/puppet/provider/package/pacman.rb | 94 |
4 files changed, 172 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/regsubst.rb b/lib/puppet/parser/functions/regsubst.rb index b6bb5afcf..397d2b2ee 100644 --- a/lib/puppet/parser/functions/regsubst.rb +++ b/lib/puppet/parser/functions/regsubst.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2009 Thomas Bellman +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Thomas Bellman shall +# not be used in advertising or otherwise to promote the sale, use or +# other dealings in this Software without prior written authorization +# from Thomas Bellman. + module Puppet::Parser::Functions newfunction( diff --git a/lib/puppet/parser/functions/shellquote.rb b/lib/puppet/parser/functions/shellquote.rb index 3ddb988f2..ee070c740 100644 --- a/lib/puppet/parser/functions/shellquote.rb +++ b/lib/puppet/parser/functions/shellquote.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2009 Thomas Bellman +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Thomas Bellman shall +# not be used in advertising or otherwise to promote the sale, use or +# other dealings in this Software without prior written authorization +# from Thomas Bellman. + module Puppet::Parser::Functions Safe = 'a-zA-Z0-9@%_+=:,./-' # Safe unquoted diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb index 5eb4a4f9d..118020412 100644 --- a/lib/puppet/parser/functions/sprintf.rb +++ b/lib/puppet/parser/functions/sprintf.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2009 Thomas Bellman +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Thomas Bellman shall +# not be used in advertising or otherwise to promote the sale, use or +# other dealings in this Software without prior written authorization +# from Thomas Bellman. + module Puppet::Parser::Functions newfunction( diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb new file mode 100644 index 000000000..5e05d147e --- /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 { |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 |