[PATCH/puppet 1/1] Fixed #4258 - Added pkgutil package provider for Solaris

3 views
Skip to first unread message

Dominic Cleal

unread,
Nov 29, 2010, 7:59:26 AM11/29/10
to puppe...@googlegroups.com

Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/4258
lib/puppet/provider/package/pkgutil.rb | 127 ++++++++++++++++++++++++++++++++
1 files changed, 127 insertions(+), 0 deletions(-)
create mode 100755 lib/puppet/provider/package/pkgutil.rb

diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb
new file mode 100755
index 0000000..dacd70a
--- /dev/null
+++ b/lib/puppet/provider/package/pkgutil.rb
@@ -0,0 +1,127 @@
+# Packaging using Peter Bonivart's pkgutil program.
+Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do
+ desc "Package management using Peter Bonivart's ``pkgutil`` command on Solaris."
+ pkguti = "pkgutil"
+ if FileTest.executable?("/opt/csw/bin/pkgutil")
+ pkguti = "/opt/csw/bin/pkgutil"
+ end
+
+ confine :operatingsystem => :solaris
+
+ commands :pkguti => pkguti
+
+ def self.extended(mod)
+ unless command(:pkguti) != "pkgutil"
+ raise Puppet::Error,
+ "The pkgutil command is missing; pkgutil packaging unavailable"
+ end
+
+ unless FileTest.exists?("/var/opt/csw/pkgutil/admin")
+ Puppet.notice "It is highly recommended you create '/var/opt/csw/pkgutil/admin'."
+ Puppet.notice "See /var/opt/csw/pkgutil"
+ end
+ end
+
+ def self.instances(hash = {})
+ pkglist(hash).collect do |bhash|
+ bhash.delete(:avail)
+ new(bhash)
+ end
+ end
+
+ # Turn our pkgutil -c listing into a bunch of hashes.
+ # Supports :justme => packagename, which uses the optimised --single arg
+ def self.pkglist(hash)
+ command = ["-c"]
+
+ if hash[:justme]
+ # The --single option speeds up the execution, because it queries
+ # the package managament system for one package only.
+ command << ["--single"]
+ command << hash[:justme]
+ end
+
+ output = pkguti command
+
+ list = output.split("\n").collect do |line|
+ next if line =~ /^#/
+ next if line =~ /installed\s+catalog/ # header of package list
+ next if line =~ /^Checking integrity / # use_gpg
+ next if line =~ /^gpg: / # gpg verification
+ next if line =~ /^=+> / # catalog fetch
+ next if line =~ /\d+:\d+:\d+ URL:/ # wget without -q
+
+ parsed = pkgsplit(line)
+
+ # When finding one package, ensure we picked up the package line
+ # itself, not any pkgutil noise.
+ next if hash[:justme] and parsed[:name] != hash[:justme]
+
+ parsed
+ end.reject { |h| h.nil? }
+
+ if hash[:justme]
+ return list[-1]
+ else
+ list.reject! { |h|
+ h[:ensure] == :absent
+ }
+ return list
+ end
+
+ end
+
+ # Split the different lines into hashes.
+ def self.pkgsplit(line)
+ if line =~ /\s*(\S+)\s+(\S+)\s+(.*)/
+ hash = {}
+ hash[:name] = $1
+ hash[:ensure] = if $2 == "notinst"
+ :absent
+ else
+ $2
+ end
+ hash[:avail] = $3
+
+ if hash[:avail] == "SAME"
+ hash[:avail] = hash[:ensure]
+ end
+
+ # Use the name method, so it works with subclasses.
+ hash[:provider] = self.name
+
+ return hash
+ else
+ Puppet.warning "Cannot match %s" % line
+ return nil
+ end
+ end
+
+ def install
+ pkguti "-y", "-i", @resource[:name]
+ end
+
+ # Retrieve the version from the current package file.
+ def latest
+ hash = self.class.pkglist(:justme => @resource[:name])
+ hash[:avail]
+ end
+
+ def query
+ if hash = self.class.pkglist(:justme => @resource[:name])
+ hash
+ else
+ {:ensure => :absent}
+ end
+ end
+
+ # Remove the old package, and install the new one
+ def update
+ pkguti "-y", "-i", @resource[:name]
+ end
+
+ def uninstall
+ pkguti "-y", "-r", @resource[:name]
+ end
+end
+
--
1.7.3.2

Dominic Cleal

unread,
Nov 29, 2010, 8:09:19 AM11/29/10
to puppe...@googlegroups.com
On 29/11/10 12:59, Dominic Cleal wrote:
> Fixed #4258 - Added pkgutil package provider for Solaris

This is an attempt to tie up the pkgutil patches from James, Maciej
Bliziński, Rudy Gevaert and me.

There has also been a thread running on puppet-users[1] which includes
the pkgutil author (Peter Bonivart). I don't think the exit code change
for non-existent packages is a requirement and from my limited testing
of installing packages, I'm happy with the provider.

[1]
http://groups.google.com/group/puppet-users/browse_thread/thread/6a0f2de37b515e34/5a985dec36b209d9

--
Dominic Cleal
Red Hat Consulting
m: +44 (0)7818 512168

Reply all
Reply to author
Forward
0 new messages