Here is my attempt at supporting Solaris "pkg" packages (works locally for me):
— package.rb 2010-02-26 15:19:04.956006337 -0500
+++ chef/chef/lib/chef/resource/package.rb 2009-11-20 10:28:49.219605036 -0500
@@ -29,7 +29,6 @@
@version = nil
@candidate_version = nil
@response_file = nil
- @admin_file = nil
@source = nil
@action = "install"
@options = nil
@@ -52,14 +51,6 @@
)
end
— package.rb 2010-02-26 15:20:37.826017504 -0500
+++ chef/chef/lib/chef/provider/package.rb 2009-11-20 10:28:49.209605192 -0500
@@ -52,10 +52,6 @@
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
- if @new_resource.admin_file
- admin_package(@new_resource.package_name, install_version)
- end
-
# We need to make sure we handle the preseed file
if @new_resource.response_file
preseed_package(@new_resource.package_name, install_version)
@@ -81,9 +77,6 @@
def action_remove
if should_remove_package(@current_resource.version, @new_resource.version)
Chef::Log.info("Removing #{@new_resource}")
- if @new_resource.admin_file
- admin_package(@new_resource.package_name, install_version)
- end
remove_package(@current_resource.package_name, @new_resource.version)
@new_resource.updated = true
end
@@ -131,10 +124,6 @@
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
end
- def admin_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support an admin file - don't ask it to!"
- end
-
def get_preseed_file(name, version)
full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"
Plus an entirely new provider chef/provider/package/pkg.rb:
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
class Chef
class Provider
class Package
class Pkg < Chef::Provider::Package
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
@new_resource.version(nil)
if @new_resource.source
unless ::File.exists?(@new_resource.source)
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
end
Chef::Log.debug("Checking pkg status for #{@new_resource.package_name}")
status = popen4("pkginfo -d #{@new_resource.source} -l") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
when /PKGINST:\s+(.+)/
@current_resource.package_name($1)
when /VERSION:\s+(.+)/
@new_resource.version($1)
end
end
end
else
if @new_resource.action.include?(:install)
raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
end
end
Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
status = popen4("pkginfo -i -l #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
when /VERSION:\s+(.+)/
Chef::Log.debug("Current version is #{$1}")
@current_resource.version($1)
end
end
end
unless status.exitstatus == 0 || status.exitstatus == 1
raise Chef::Exceptions::Package, "pkginfo failed - #{status.inspect}!"
end
@current_resource
end
def install_package(name, version)
admin_file = admin_file_argument
run_command_with_systems_locale(
:command => "pkgadd#{admin_file} -G -n -d #{@new_resource.source} all"
)
end
def remove_package(name, version)
admin_file = admin_file_argument
run_command_with_systems_locale(
:command => "pkgrm#{admin_file} -n #{name}"
)
end
def admin_file_argument()
admin_file = ''
if (@new_resource.admin_file)
admin_file = " -a #{@new_resource.admin_file}"
else
Chef::Log.info("attempting action without an admin file; probably will not complete!")
end
return admin_file
end
def admin_package(name, version)
# if we have a system-wide admin file already, use it
solaris_admin_dir = '/var/sadm/install/admin'
if ::File.exists?("#{solaris_admin_dir}/#{@new_resource.admin_file}")
Chef::Log.debug("Using existing admin file: #{solaris_admin_dir}/#{@new_resource.admin_file}")
# otherwise, assume it's a local file and download it
else
cache_sub_path = "admin/#{@new_resource.cookbook_name}"
cache_full_path = Chef::FileCache.create_cache_path(cache_sub_path)
cache_file = "#{name}-#{version}"
Chef::Log.debug("Fetching admin file to #{cache_full_path}/#{cache_file}")
remote_file = Chef::Resource::RemoteFile.new(
"#{cache_full_path}/#{cache_file}",
nil,
@node
)
remote_file.cookbook_name = @new_resource.cookbook_name
remote_file.source(@new_resource.admin_file)
remote_file.backup(false)
rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
rf_provider.load_current_resource
rf_provider.action_create
if remote_file.updated
Chef::FileCache.load("#{cache_sub_path}/#{cache_file}", false)
Chef::Log.debug("Setting up admin file before installing #{@new_resource}.")
end
@new_resource.admin_file("#{cache_full_path}/#{cache_file}")
end
end
end
end
end
end
Here is my attempt at supporting Solaris "pkg" packages (works locally for me):
— package.rb 2010-02-26 15:19:04.956006337 -0500
+++ chef/chef/lib/chef/resource/package.rb 2009-11-20 10:28:49.219605036 -0500
@@ -29,7 +29,6 @@
@version = nil
@candidate_version = nil
@response_file = nil
@source = nil
@action = "install"
@options = nil
@@ -52,14 +51,6 @@
)
end
def response_file(arg=nil)
set_or_return(
:response_file,
— package.rb 2010-02-26 15:20:37.826017504 -0500
+++ chef/chef/lib/chef/provider/package.rb 2009-11-20 10:28:49.209605192 -0500
@@ -52,10 +52,6 @@
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
- if @new_resource.admin_file
- admin_package(@new_resource.package_name, install_version)
- end
-
# We need to make sure we handle the preseed file
if @new_resource.response_file
preseed_package(@new_resource.package_name, install_version)
@@ -81,9 +77,6 @@
def action_remove
if should_remove_package(@current_resource.version, @new_resource.version)
Chef::Log.info("Removing #{@new_resource}")
remove_package(@current_resource.package_name, @new_resource.version)
@new_resource.updated = true
end
@@ -131,10 +124,6 @@
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
end
- def admin_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support an admin file - don't ask it to!"
def get_preseed_file(name, version)
full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"
Plus an entirely new provider chef/provider/package/pkg.rb:
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
class Chef
class Provider
class Package
class Pkg < Chef::Provider::Package
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
@new_resource.version(nil)
if @new_resource.source
unless ::File.exists?(@new_resource.source)
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
end
Chef::Log.debug("Checking pkg status for #{@new_resource.package_name}")
status = popen4("pkginfo -d #{@new_resource.source} -l") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
when /PKGINST:\s+(.+)/
@current_resource.package_name($1)
when /VERSION:\s+(.+)/
@new_resource.version($1)
end
end
end
else
if @new_resource.action.include?(:install)
raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
end
end
Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
status = popen4("pkginfo -i -l #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
when /VERSION:\s+(.+)/
Chef::Log.debug("Current version is #{$1}")
@current_resource.version($1)
end
end
end
unless status.exitstatus == 0 || status.exitstatus == 1
raise Chef::Exceptions::Package, "pkginfo failed - #{status.inspect}!"
end
@current_resource
end
def install_package(name, version)
admin_file = admin_file_argument
run_command_with_systems_locale(
:command => "pkgadd#{admin_file} -G -n -d #{@new_resource.source} all"
)
end
def remove_package(name, version)
admin_file = admin_file_argument
run_command_with_systems_locale(
:command => "pkgrm#{admin_file} -n #{name}"
)
end
def admin_file_argument()
admin_file = ''
if (@new_resource.admin_file)
admin_file = " -a #{@new_resource.admin_file}"
else
Chef::Log.info("attempting action without an admin file; probably will not complete!")
end
return admin_file
end
def admin_package(name, version)
# if we have a system-wide admin file already, use it
solaris_admin_dir = '/var/sadm/install/admin'
if ::File.exists?("#{solaris_admin_dir}/#{@new_resource.admin_file}")
Chef::Log.debug("Using existing admin file: #{solaris_admin_dir}/#{@new_resource.admin_file}")
# otherwise, assume it's a local file and download it
else
cache_sub_path = "admin/#{@new_resource.cookbook_name}"
cache_full_path = Chef::FileCache.create_cache_path(cache_sub_path)
cache_file = "#{name}-#{version}"
Chef::Log.debug("Fetching admin file to #{cache_full_path}/#{cache_file}")
remote_file = Chef::Resource::RemoteFile.new(
"#{cache_full_path}/#{cache_file}",
nil,
@node
)
remote_file.cookbook_name = @new_resource.cookbook_name
remote_file.source(@new_resource.admin_file)
remote_file.backup(false)
rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
rf_provider.load_current_resource
rf_provider.action_create
if remote_file.updated
Chef::FileCache.load("#{cache_sub_path}/#{cache_file}", false)
Chef::Log.debug("Setting up admin file before installing #{@new_resource}.")
end
@new_resource.admin_file("#{cache_full_path}/#{cache_file}")
end
end
end
end
end
end
- def admin_file(arg=nil)
- set_or_return(
- :admin_file,
- arg,
- :kind_of => [ String ]
- )
- end
-
def response_file(arg=nil)
set_or_return(
:response_file,
— package.rb 2010-02-26 15:20:37.826017504 -0500 +++ chef/chef/lib/chef/provider/package.rb 2009-11-20 10:28:49.209605192 -0500 @@ -52,10 +52,6 @@ Chef::Log.info("Installing #{@new_resource} version #{install_version}") - if @new_resource.admin_file - admin_package(@new_resource.package_name, install_version) - end - # We need to make sure we handle the preseed file if @new_resource.response_file preseed_package(@new_resource.package_name, install_version) @@ -81,9 +77,6 @@ def action_remove if should_remove_package(@current_resource.version, @new_resource.version) Chef::Log.info("Removing #{@new_resource}")- if @new_resource.admin_file
- admin_package(@new_resource.package_name, install_version)
- end
remove_package(@current_resource.package_name, @new_resource.version)
@new_resource.updated = true
end
@@ -131,10 +124,6 @@
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
end
- def admin_package(name, version)
- raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support an admin file - don't ask it to!"
- end
-
def get_preseed_file(name, version)
full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"
Plus an entirely new provider chef/provider/package/pkg.rb:
require 'chef/provider/package'
require 'chef/mixin/command'
require 'chef/resource/package'
class Chef
class Provider
class Package
class Pkg < Chef::Provider::Package
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
@new_resource.version(nil)
if @new_resource.source
unless ::File.exists?(@new_resource.source)
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
end
Chef::Log.debug("Checking pkg status for #{@new_resource.package_name}")
status = popen4("pkginfo -d #{@new_resource.source} -l") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
when /PKGINST:\s+(.+)/
@current_resource.package_name($1)
when /VERSION:\s+(.+)/
@new_resource.version($1)
end
end
end
else
if @new_resource.action.include?(:install)
raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
end
end
Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
status = popen4("pkginfo -i -l #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
stdout.each do |line|
case line
when /VERSION:\s+(.+)/
Chef::Log.debug("Current version is #{$1}")
@current_resource.version($1)
end
end
end
unless status.exitstatus == 0 || status.exitstatus == 1
raise Chef::Exceptions::Package, "pkginfo failed - #{status.inspect}!"
end
@current_resource
end
def install_package(name, version)
admin_file = admin_file_argument
run_command_with_systems_locale(
:command => "pkgadd#{admin_file} -G -n -d #{@new_resource.source} all"
)
end
def remove_package(name, version)
admin_file = admin_file_argument
run_command_with_systems_locale(
:command => "pkgrm#{admin_file} -n #{name}"
)
end
def admin_file_argument()
admin_file = ''
if (@new_resource.admin_file)
admin_file = " -a #{@new_resource.admin_file}"
else
Chef::Log.info("attempting action without an admin file; probably will not complete!")
end
return admin_file
end
def admin_package(name, version)
# if we have a system-wide admin file already, use it
solaris_admin_dir = '/var/sadm/install/admin'
if ::File.exists?("#{solaris_admin_dir}/#{@new_resource.admin_file}")
Chef::Log.debug("Using existing admin file: #{solaris_admin_dir}/#{@new_resource.admin_file}")
# otherwise, assume it's a local file and download it
else
cache_sub_path = "admin/#{@new_resource.cookbook_name}"
cache_full_path = Chef::FileCache.create_cache_path(cache_sub_path)
cache_file = "#{name}-#{version}"
Chef::Log.debug("Fetching admin file to #{cache_full_path}/#{cache_file}") remote_file = Chef::Resource::RemoteFile.new( "#{cache_full_path}/#{cache_file}", nil, @node ) remote_file.cookbook_name = @new_resource.cookbook_name remote_file.source(@new_resource.admin_file) remote_file.backup(false) rf_provider = Chef::Platform.provider_for_node(@node, remote_file) rf_provider.load_current_resource rf_provider.action_create if remote_file.updated Chef::FileCache.load("#{cache_sub_path}/#{cache_file}", false) Chef::Log.debug("Setting up admin file before installing #{@new_resource}.") end @new_resource.admin_file("#{cache_full_path}/#{cache_file}") end end end end end end