summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/package/openbsd.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/provider/package/openbsd.rb')
-rwxr-xr-xlib/puppet/provider/package/openbsd.rb198
1 files changed, 99 insertions, 99 deletions
diff --git a/lib/puppet/provider/package/openbsd.rb b/lib/puppet/provider/package/openbsd.rb
index f6005efa7..ca477e56a 100755
--- a/lib/puppet/provider/package/openbsd.rb
+++ b/lib/puppet/provider/package/openbsd.rb
@@ -2,119 +2,119 @@ require 'puppet/provider/package'
# Packaging on OpenBSD. Doesn't work anywhere else that I know of.
Puppet::Type.type(:package).provide :openbsd, :parent => Puppet::Provider::Package do
- include Puppet::Util::Execution
- desc "OpenBSD's form of ``pkg_add`` support."
-
- commands :pkginfo => "pkg_info", :pkgadd => "pkg_add", :pkgdelete => "pkg_delete"
-
- defaultfor :operatingsystem => :openbsd
- confine :operatingsystem => :openbsd
-
- has_feature :versionable
-
- def self.instances
- packages = []
-
- begin
- execpipe(listcmd) do |process|
- # our regex for matching pkg_info output
- regex = /^(.*)-(\d[^-]*)[-]?(\D*)(.*)$/
- fields = [:name, :ensure, :flavor ]
- hash = {}
-
- # now turn each returned line into a package object
- process.each { |line|
- if match = regex.match(line.split[0])
- fields.zip(match.captures) { |field,value|
- hash[field] = value
- }
- yup = nil
- name = hash[:name]
-
- hash[:provider] = self.name
-
- packages << new(hash)
- hash = {}
- else
- # Print a warning on lines we can't match, but move
- # on, since it should be non-fatal
- warning("Failed to match line #{line}")
- end
- }
- end
-
- return packages
- rescue Puppet::ExecutionFailure
- return nil
- end
- end
+ include Puppet::Util::Execution
+ desc "OpenBSD's form of ``pkg_add`` support."
- def self.listcmd
- [command(:pkginfo), " -a"]
- end
+ commands :pkginfo => "pkg_info", :pkgadd => "pkg_add", :pkgdelete => "pkg_delete"
- def install
- should = @resource.should(:ensure)
+ defaultfor :operatingsystem => :openbsd
+ confine :operatingsystem => :openbsd
- unless @resource[:source]
- raise Puppet::Error,
- "You must specify a package source for BSD packages"
- end
+ has_feature :versionable
- old_ensure = @resource[:ensure]
+ def self.instances
+ packages = []
- if @resource[:source] =~ /\/$/
- withenv :PKG_PATH => @resource[:source] do
- @resource[:ensure] = old_ensure if (@resource[:ensure] = get_version) == nil
- full_name = [ @resource[:name], @resource[:ensure], @resource[:flavor] ]
- pkgadd full_name.join('-').chomp('-')
- end
- else
- pkgadd @resource[:source]
- end
+ begin
+ execpipe(listcmd) do |process|
+ # our regex for matching pkg_info output
+ regex = /^(.*)-(\d[^-]*)[-]?(\D*)(.*)$/
+ fields = [:name, :ensure, :flavor ]
+ hash = {}
+ # now turn each returned line into a package object
+ process.each { |line|
+ if match = regex.match(line.split[0])
+ fields.zip(match.captures) { |field,value|
+ hash[field] = value
+ }
+ yup = nil
+ name = hash[:name]
+
+ hash[:provider] = self.name
+
+ packages << new(hash)
+ hash = {}
+ else
+ # Print a warning on lines we can't match, but move
+ # on, since it should be non-fatal
+ warning("Failed to match line #{line}")
+ end
+ }
+ end
+
+ return packages
+ rescue Puppet::ExecutionFailure
+ return nil
end
+ end
- def get_version
- execpipe([command(:pkginfo), " -I ", @resource[:name]]) do |process|
- # our regex for matching pkg_info output
- regex = /^(.*)-(\d[^-]*)[-]?(\D*)(.*)$/
- fields = [ :name, :version, :flavor ]
- master_version = 0
-
- process.each do |line|
- if match = regex.match(line.split[0])
- # now we return the first version, unless ensure is latest
- version = match.captures[1]
- return version unless @resource[:ensure] == "latest"
-
- master_version = version unless master_version > version
- end
- end
-
- return master_version unless master_version == 0
- raise Puppet::Error, "#{version} is not available for this package"
- end
- rescue Puppet::ExecutionFailure
- return nil
+ def self.listcmd
+ [command(:pkginfo), " -a"]
+ end
+
+ def install
+ should = @resource.should(:ensure)
+
+ unless @resource[:source]
+ raise Puppet::Error,
+ "You must specify a package source for BSD packages"
end
- def query
- hash = {}
- info = pkginfo @resource[:name]
+ old_ensure = @resource[:ensure]
+
+ if @resource[:source] =~ /\/$/
+ withenv :PKG_PATH => @resource[:source] do
+ @resource[:ensure] = old_ensure if (@resource[:ensure] = get_version) == nil
+ full_name = [ @resource[:name], @resource[:ensure], @resource[:flavor] ]
+ pkgadd full_name.join('-').chomp('-')
+ end
+ else
+ pkgadd @resource[:source]
+ end
+
+ end
- # Search for the version info
- if info =~ /Information for (inst:)?#{@resource[:name]}-(\S+)/
- hash[:ensure] = $2
- else
- return nil
+ def get_version
+ execpipe([command(:pkginfo), " -I ", @resource[:name]]) do |process|
+ # our regex for matching pkg_info output
+ regex = /^(.*)-(\d[^-]*)[-]?(\D*)(.*)$/
+ fields = [ :name, :version, :flavor ]
+ master_version = 0
+
+ process.each do |line|
+ if match = regex.match(line.split[0])
+ # now we return the first version, unless ensure is latest
+ version = match.captures[1]
+ return version unless @resource[:ensure] == "latest"
+
+ master_version = version unless master_version > version
+ end
end
- hash
+ return master_version unless master_version == 0
+ raise Puppet::Error, "#{version} is not available for this package"
+ end
+ rescue Puppet::ExecutionFailure
+ return nil
+ end
+
+ def query
+ hash = {}
+ info = pkginfo @resource[:name]
+
+ # Search for the version info
+ if info =~ /Information for (inst:)?#{@resource[:name]}-(\S+)/
+ hash[:ensure] = $2
+ else
+ return nil
end
- def uninstall
- pkgdelete @resource[:name]
- end
+ hash
+ end
+
+ def uninstall
+ pkgdelete @resource[:name]
+ end
end