Skip to content

Instantly share code, notes, and snippets.

@rottenbytes
Created September 5, 2012 08:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rottenbytes/3633306 to your computer and use it in GitHub Desktop.
Save rottenbytes/3633306 to your computer and use it in GitHub Desktop.
chef+pkgng
require 'chef/mixin/shell_out'
require 'chef/platform'
require 'chef'
include Chef::Mixin::ShellOut
class Chef
class Provider
class Package
class Pkgng < Chef::Provider::Package
def initialize(*args)
super
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
@current_resource
end
def check_package_state
pkg_info = shell_out!("pkg info #{package_name}", :env => nil, :returns => [0,70])
version = nil
t = pkg_info.stdout.match(/(.*)-(\d+\.\d+\.\d+(\.\d+.*\s)?)\s+(.*)/)
unless t.nil?
version = t[2].strip
end
return version
end
def load_current_resource
@current_resource.package_name(@new_resource.package_name)
@current_resource.version(self.check_package_state())
@candidate_version = ""
end
def package_name
@new_resource.package_name
end
def install_package(name, version = "")
shell_out!("pkg install -y #{package_name}", :env => nil).status
Chef::Log.debug("PKGNG : #{@new_resource} installed from: #{@new_resource.source}")
end
def remove_package(name, version = nil)
shell_out!("pkg delete -y #{package_name}", :env => nil).status
end
end
end
end
end
Chef::Platform.set({
:platform => :freebsd,
:resource => :package,
:provider => Chef::Provider::Package::Pkgng
})
@douglaswth
Copy link

It would be awesome if this were available as a regular Chef Cookbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment