From 0f2d3ce686f7e706537e03ebb2166478fa55f649 Mon Sep 17 00:00:00 2001 From: Rein Henrichs Date: Tue, 13 Apr 2010 14:20:48 -0700 Subject: Fixes #1223 Add Zypper support for SuSE machines Zypper is the replacement for `rug' from earlier SuSE releases. Zypper is backward compatible with the rug command (mostly) and supports most of the same commands that rug does. This version fixes a number of bugs in the original: * when installing with a specified version, fix bug where the package name was being doubled ("foo" became "foofoo"). * fix bug where package name and version were separated by a "=" when it should have been a "-". * Update specs to reflect the implementation's use of the "-l" flag as recommended in http://groups.google.com/group/puppet-dev/msg/d86416c079bd3faf Signed-off-by: Rein Henrichs --- lib/puppet/provider/package/zypper.rb | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/puppet/provider/package/zypper.rb (limited to 'lib') diff --git a/lib/puppet/provider/package/zypper.rb b/lib/puppet/provider/package/zypper.rb new file mode 100644 index 000000000..2a9c2b391 --- /dev/null +++ b/lib/puppet/provider/package/zypper.rb @@ -0,0 +1,52 @@ +Puppet::Type.type(:package).provide :zypper, :parent => :rpm do + desc "Support for SuSE ``zypper`` package manager. Found in SLES10sp2+ and SLES11" + + has_feature :versionable + + commands :rug => "/usr/bin/zypper" + commands :rpm => "rpm" + + confine :operatingsystem => [:suse, :sles, :sled, :opensuse] + + # Install a package using 'zypper'. + def install + should = @resource.should(:ensure) + self.debug "Ensuring => #{should}" + wanted = @resource[:name] + + # XXX: We don't actually deal with epochs here. + case should + when true, false, Symbol + # pass + else + # Add the package version + wanted = "%s-%s" % [wanted, should] + end + output = zypper "--quiet", :install, "-l", "-y", wanted + + unless self.query + raise Puppet::ExecutionFailure.new( + "Could not find package %s" % self.name + ) + end + end + + # What's the latest package version available? + def latest + #zypper can only get a list of *all* available packages? + output = zypper "list-updates" + + if output =~ /#{Regexp.escape @resource[:name]}\s*\|\s*([^\s\|]+)/ + return $1 + else + # rug didn't find updates, pretend the current + # version is the latest + return @property_hash[:ensure] + end + end + + def update + # rug install can be used for update, too + self.install + end +end -- cgit