Signed-off-by: Nicolas Szalay <[email protected]>
---
 lib/puppet/provider/package/pkgin.rb |   67 ++++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)
 create mode 100644 lib/puppet/provider/package/pkgin.rb

diff --git a/lib/puppet/provider/package/pkgin.rb 
b/lib/puppet/provider/package/pkgin.rb
new file mode 100644
index 0000000..50f1825
--- /dev/null
+++ b/lib/puppet/provider/package/pkgin.rb
@@ -0,0 +1,67 @@
+require 'puppet/provider/package'
+
+# Puppet provider for iMil's pkgin (binary pkgsrc). Based on openbsd provider
+# This is not bug free, feel free to improve
+#
+# Nicolas Szalay <[email protected]>
+#
+Puppet::Type.type(:package).provide :pkgin, :parent => 
Puppet::Provider::Package do
+    include Puppet::Util::Execution
+    desc "pkgin provider"
+
+       # add typical pkgsrc dirs to the PATH
+       ENV["PATH"] = 
ENV["PATH"]+":/opt/pkg/bin:/usr/pkg/bin/opt/pkg/sbin:/usr/pkg/sbin"
+
+    commands :pkgin => "pkgin"
+
+       def self.instances
+               packages = []
+               # we rely on pkg_info to know which packages are installed
+               cmd="pkg_info -a"
+
+               begin
+                       Puppet.debug "Running '%s'" % cmd
+            execpipe(cmd) { |pkglist|
+                packages = pkglist.grep(/(\S+)-(.*?)\s+(.*)/) { new(
+                        :name => $1,
+                        :version => $2,
+                        :description => $3 ) }
+               rescue Puppet::ExecutionFailure
+                       return nil
+               end
+
+               return packages
+       end
+
+    def install
+               should = @resource[:ensure]
+               pkgin ["-y", "in", @resource[:name] ]
+    end
+
+       def uninstall 
+               pkgin ["-y", "rm", @resource[:name] ]
+       end
+
+    def query
+        hash = {}
+               hash[:ensure] = :absent
+               regex=%r{(\S+)(-)(.*?)(\s+)(.*)}
+
+               begin
+                       cmd = "pkgin ls"
+                       execpipe(cmd) { |process|
+                               process.each { |line|
+                                       if match = regex.match(line)
+                                               if match[1] == @resource[:name]
+                                                       Puppet.debug " %s is 
present" % @resource[:name]
+                                                       hash[:ensure] = :present
+                                               end
+                                       end
+                               }
+                       }
+               end
+
+               return hash
+    end
+
+end
-- 
1.7.0

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to