pkgng.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #
  2. # Cookbook Name:: pkgng
  3. # Library:: pkgng
  4. #
  5. # Copyright (C) 2013 Douglas Thrift
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. require 'chef/provider/package/freebsd'
  20. require 'chef/platform'
  21. class Chef
  22. class Provider
  23. class Package
  24. class Pkgng < Freebsd
  25. def current_installed_version
  26. pkg_info = shell_out!("pkg info -q #{package_name}", :env => nil, :returns => [0, 70])
  27. pkg_info.stdout[/^#{package_name}-(.*)/, 1]
  28. end
  29. def install_package(name, version)
  30. unless @current_resource.version
  31. case @new_resource.source
  32. when 'ports'
  33. super(name, version)
  34. when /^http/, /^ftp/
  35. if @new_resource.source =~ /\/$/
  36. shell_out!("pkg install -y #{package_name}", :env => {'PACKAGESITE' => @new_resource.source, 'LC_ALL' => nil}).status
  37. else
  38. shell_out!("pkg add #{@new_resource.source}/#{package_name}", :env => {'LC_ALL' => nil}).status
  39. end
  40. Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
  41. when /^\//
  42. shell_out!("pkg add #{file_candidate_version_path}", :env => {'LC_ALL' => nil}).status
  43. Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
  44. else
  45. shell_out!("pkg install -y #{latest_link_name}", :env => nil).status
  46. end
  47. end
  48. end
  49. def remove_package(name, version)
  50. shell_out!("pkg delete -y #{package_name}", :env => nil).status
  51. end
  52. end
  53. end
  54. end
  55. end