diff --git a/lib/puppet/provider/package/apple.rb b/lib/puppet/provider/package/apple.rb index fff83617b..4238447a3 100755 --- a/lib/puppet/provider/package/apple.rb +++ b/lib/puppet/provider/package/apple.rb @@ -1,51 +1,51 @@ # OS X Packaging sucks. We can install packages, but that's about it. Puppet::Type.type(:package).provide :apple do desc "Package management based on OS X's builtin packaging system. This is essentially the simplest and least functional package system in existence -- it only supports installation; no deletion or upgrades." confine :exists => "/Library/Receipts" commands :installer => "/usr/sbin/installer" defaultfor :operatingsystem => :darwin def self.listbyname - Dir.entries("/Library/Receipts").find { |f| + Dir.entries("/Library/Receipts").find_all { |f| f =~ /\.pkg$/ }.collect { |f| name = f.sub(/\.pkg/, '') yield name if block_given? name } end def self.list listbyname.collect do |name| Puppet.type(:package).installedpkg( :name => name, :provider => :apple, :ensure => :installed ) end end def query if FileTest.exists?("/Library/Receipts/#{@model[:name]}.pkg") return {:name => @model[:name], :ensure => :present} else return nil end end def install source = nil unless source = @model[:source] self.fail "Mac OS X packages must specify a package source" end installer "-pkg #{source} -target /" end end # $Id$ diff --git a/lib/puppet/provider/package/darwinport.rb b/lib/puppet/provider/package/darwinport.rb index 0dcdcca84..43e9bce5b 100755 --- a/lib/puppet/provider/package/darwinport.rb +++ b/lib/puppet/provider/package/darwinport.rb @@ -1,84 +1,84 @@ Puppet::Type.type(:package).provide :darwinport do desc "Package management using DarwinPorts on OS X." commands :port => "/opt/local/bin/port" confine :operatingsystem => "Darwin" def self.eachpkgashash # list out all of the packages open("| #{command(:port)} list installed") { |process| regex = %r{(\S+)\s+@(\S+)\s+(\S+)} fields = [:name, :ensure, :location] hash = {} # now turn each returned line into a package object process.each { |line| hash.clear if match = regex.match(line) fields.zip(match.captures) { |field,value| hash[field] = value } hash.delete :location yield hash.dup else raise Puppet::DevError, "Failed to match dpkg line %s" % line end } } end def self.list packages = [] eachpkgashash do |hash| pkg = Puppet.type(:package).installedpkg(hash) packages << pkg end return packages end def install - should = @model[:ensure] + should = @model.should(:ensure) # Seems like you can always say 'upgrade' port "upgrade #{@model[:name]}" end def query version = nil self.class.eachpkgashash do |hash| if hash[:name] == @model[:name] return hash end end return nil end def latest info = port "search '^#{@model[:name]}$' 2>/dev/null" if $? != 0 or info =~ /^Error/ return nil end ary = info.split(/\s+/) version = ary[2].sub(/^@/, '') return version end def uninstall port "uninstall #{@model[:name]}" end def update return install() end end # $Id$ diff --git a/lib/puppet/provider/package/freebsd.rb b/lib/puppet/provider/package/freebsd.rb index f630c66b6..5474ad5ca 100755 --- a/lib/puppet/provider/package/freebsd.rb +++ b/lib/puppet/provider/package/freebsd.rb @@ -1,41 +1,41 @@ Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do desc "The specific form of package management on FreeBSD. This is an extremely quirky packaging system, in that it freely mixes between ports and packages. Apparently all of the tools are written in Ruby, so there are plans to rewrite this support to directly use those libraries." commands :pkginfo => "/usr/sbin/pkg_info", :pkgadd => "/usr/sbin/pkg_add", :pkgdelete => "/usr/sbin/pkg_delete" def self.listcmd command(:pkginfo) end def install - should = @model[:ensure] + should = @model.should(:ensure) if @model[:source] return super end pkgadd " -r " + @model[:name] end def query self.class.list if @model.is(:ensure) return :listed else return nil end end def uninstall - pkgdelete "%s-%s" % [@model[:name], @model[:ensure]] + pkgdelete "%s-%s" % [@model[:name], @model.should(:ensure)] end end # $Id$ diff --git a/lib/puppet/provider/package/openbsd.rb b/lib/puppet/provider/package/openbsd.rb index 6012dcc84..b0d5a2277 100755 --- a/lib/puppet/provider/package/openbsd.rb +++ b/lib/puppet/provider/package/openbsd.rb @@ -1,92 +1,92 @@ # Packaging on OpenBSD. Doesn't work anywhere else that I know of. Puppet::Type.type(:package).provide :openbsd do desc "OpenBSD's form of ``pkg_add`` support." commands :pkginfo => "pkg_info", :pkgadd => "pkg_add", :pkgdelete => "pkg_delete" defaultfor :operatingsystem => :openbsd def self.list packages = [] begin execpipe(listcmd()) do |process| # our regex for matching pkg_info output regex = %r{^(\S+)-([^-\s]+)\s+(.+)} fields = [:name, :ensure, :description] hash = {} # now turn each returned line into a package object process.each { |line| hash.clear if match = regex.match(line) fields.zip(match.captures) { |field,value| hash[field] = value } yup = nil name = hash[:name] hash[:provider] = self.name pkg = Puppet.type(:package).installedpkg(hash) packages << pkg else # Print a warning on lines we can't match, but move # on, since it should be non-fatal warning("Failed to match line %s" % line) end } end # Mark as absent any packages we didn't find Puppet.type(:package).each do |pkg| unless packages.include? pkg pkg.is = [:ensure, :absent] end end return packages rescue Puppet::ExecutionFailure return nil end end def self.listcmd "#{command(:info)} -a" end def install - should = @model[:ensure] + should = @model.should(:ensure) unless @model[:source] raise Puppet::Error, "You must specify a package source for BSD packages" end pkgadd @model[:source] end def query hash = {} info = pkginfo @model[:name] # Search for the version info if info =~ /Information for #{@model[:name]}-(\S+)/ hash[:ensure] = $1 else return nil end # And the description if info =~ /Comment:\s*\n(.+)/ hash[:description] = $1 end return hash end def uninstall pkgdelete @model[:name] end end # $Id$ diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb index 199ba8a83..d311009a6 100644 --- a/lib/puppet/provider/package/portage.rb +++ b/lib/puppet/provider/package/portage.rb @@ -1,117 +1,111 @@ Puppet::Type.type(:package).provide :portage do desc "Provides packaging support for Gentoo's portage system." commands :emerge => "/usr/bin/emerge", :eix => "/usr/bin/eix" defaultfor :operatingsystem => :gentoo def self.list search_format = /(\S+) (\S+) \[(.*)\] \[(\S*)\] ([\S]*) (.*)/ result_fields = [:category, :name, :ensure, :version_available, :vendor, :description] command = "#{command(:eix)} --format \"{installedversions} [] [] {}\"" begin search_output = execute( command ) packages = [] search_output.each do |search_result| match = search_format.match( search_result ) if( match ) package = {} result_fields.zip( match.captures ) { |field, value| package[field] = value unless value.empty? } - if self.is_a? Puppet::Type and type = @model[:type] - package[:type] = type - elsif self.is_a? Module and self.respond_to? :name - package[:type] = self.name - else - raise Puppet::DevError, "Cannot determine package type" - end + package[:provider] = :portage package[:ensure] = package[:ensure].split.last packages.push( Puppet.type(:package).installedpkg(package) ) end end return packages rescue Puppet::ExecutionFailure => detail raise Puppet::PackageError.new(detail) end end def install if @model.should( :ensure ) == :present || @model.should( :ensure ) == :latest package_name = "#{@model[:category]}/#{@model[:name]}" else # We must install a specific version package_name = "=#{@model[:category]}/#{@model[:name]}-#{@model.should( :ensure )}" end command = "EMERGE_DEFAULT_OPTS=\"\" #{command(:emerge)} #{package_name}" output = execute( command ) end def uninstall package_name = "#{@model[:category]}/#{@model[:name]}" command ="EMERGE_DEFAULT_OPTS=\"\" #{command(:emerge)} --unmerge #{package_name}" begin output = execute( command ) rescue Puppet::ExecutionFailure => detail raise Puppet::PackageError.new(detail) end end def update self.install end def query search_format = /(\S+) (\S+) \[(.*)\] \[(\S*)\] ([\S]*) (.*)/ result_fields = [:category, :name, :ensure, :version_available, :vendor, :description] search_field = @model[:name].include?( '/' ) ? "--category-name" : "--name" command = "#{command(:eix)} --format \" [] [] \" --exact #{search_field} #{@model[:name]}" begin search_output = execute( command ) packages = [] search_output.each do |search_result| match = search_format.match( search_result ) if( match ) package = {} result_fields.zip( match.captures ) { |field, value| package[field] = value unless value.empty? } if package[:ensure] package[:ensure] = package[:ensure].split.last else package[:ensure] = :absent end packages << package end end case packages.size when 0 raise Puppet::PackageError.new( "No package found with the specified name [#{@model[:name]}]" ) when 1 return packages[0] else raise Puppet::PackageError.new( "More than one package with the specified name [#{@model[:name]}], please use category/name to disambiguate" ) end rescue Puppet::ExecutionFailure => detail raise Puppet::PackageError.new(detail) end end def latest return self.query[:version_available] end def versionable? true end end # $Id$ diff --git a/lib/puppet/provider/package/up2date.rb b/lib/puppet/provider/package/up2date.rb index 1f9fa0ffc..bc3fe0526 100644 --- a/lib/puppet/provider/package/up2date.rb +++ b/lib/puppet/provider/package/up2date.rb @@ -1,45 +1,45 @@ Puppet.type(:package).provide :up2date, :parent => :rpm do desc "Support for Red Hat's proprietary ``up2date`` package update mechanism." commands :up2date => "/usr/sbin/up2date-nox" # Install a package using 'up2date'. def install up2date "-u %s" % @model[:name] #@states[:ensure].retrieve #if @states[:ensure].is == :absent 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 #up2date can only get a list of *all* available packages? #cmd = "/usr/sbib/up2date-nox --show-available %s" % self[:name] output = up2date "--show-available" if output =~ /#{@model[:name]}-(\d+.*)\.\w+/ return $1 else # up2date didn't find updates, pretend the current # version is the latest - return @model[:ensure] + return @model.is(:ensure) end end def update # Install in up2date can be used for update, too self.install end def versionable? false end end # $Id$