diff options
author | Maciej Blizinski <maciej@opencsw.org> | 2010-07-22 12:48:53 +0200 |
---|---|---|
committer | Maciej Blizinski <maciej@opencsw.org> | 2010-07-22 12:48:53 +0200 |
commit | fc1859119b8fad1edaabdbce48545e1583bfa24c (patch) | |
tree | abfe62e98ede3be4beb9eb84ed29b76396c2f5aa /lib | |
parent | a0a63c3735f53cbf895a9e30e6a2c1dfd2ae4c4e (diff) | |
download | puppet-fc1859119b8fad1edaabdbce48545e1583bfa24c.tar.gz puppet-fc1859119b8fad1edaabdbce48545e1583bfa24c.tar.xz puppet-fc1859119b8fad1edaabdbce48545e1583bfa24c.zip |
Adding pkgutil support.
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/puppet/provider/package/pkgutil.rb | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/puppet/provider/package/pkgutil.rb b/lib/puppet/provider/package/pkgutil.rb new file mode 100755 index 000000000..cde7482f2 --- /dev/null +++ b/lib/puppet/provider/package/pkgutil.rb @@ -0,0 +1,111 @@ +# Packaging using pkgutil from http://pkgutil.wikidot.com/ +Puppet::Type.type(:package).provide :pkgutil, :parent => :sun, :source => :sun do + desc "Package management using ``pkgutil`` command on Solaris." + pkgutil = "pkgutil" + if FileTest.executable?("/opt/csw/bin/pkgutil") + pkgutil = "/opt/csw/bin/pkgutil" + end + + confine :operatingsystem => :solaris + + commands :pkgutil => pkgutil + + # This is so stupid, but then, so is Solaris. + ENV["PAGER"] = "/usr/bin/cat" + + def self.extended(mod) + unless command(:pkgutil) != "pkgutil" + raise Puppet::Error, + "The pkgutil command is missing; pkgutil packaging unavailable" + end + end + + def self.instances(hash = {}) + blastlist(hash).collect do |bhash| + bhash.delete(:avail) + new(bhash) + end + end + + # Turn our pkgutil listing into a bunch of hashes. + def self.blastlist(hash) + command = ["-c"] + + if hash[:justme] + command << hash[:justme] + end + + output = pkgutil command + + list = output.split("\n").collect do |line| + next if line =~ /^#/ + next if line =~ /^WARNING/ + next if line =~ /localrev\s+remoterev/ + + blastsplit(line) + end.reject { |h| h.nil? } + + if hash[:justme] + return list[0] + else + list.reject! { |h| + h[:ensure] == :absent + } + return list + end + + end + + # Split the different lines into hashes. + def self.blastsplit(line) + if line =~ /\s*(\S+)\s+((\[Not installed\])|(\S+))\s+(\S+)/ + hash = {} + hash[:name] = $1 + hash[:ensure] = if $2 == "[Not installed]" + :absent + else + $2 + end + hash[:avail] = $5 + + 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 + pkgutil "-y", "--install", @resource[:name] + end + + # Retrieve the version from the current package file. + def latest + hash = self.class.blastlist(:justme => @resource[:name]) + hash[:avail] + end + + def query + if hash = self.class.blastlist(:justme => @resource[:name]) + hash + else + {:ensure => :absent} + end + end + + # Remove the old package, and install the new one + def update + pkgutil "-y", "--upgrade", @resource[:name] + end + + def uninstall + pkgutil "-y", "--remove", @resource[:name] + end +end |