chef 11.14.0.alpha.2-x86-mingw32 → 11.14.0.alpha.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/chef-service-manager +1 -1
- data/lib/chef/application.rb +8 -2
- data/lib/chef/chef_fs/command_line.rb +4 -4
- data/lib/chef/chef_fs/file_system.rb +3 -3
- data/lib/chef/chef_fs/parallelizer.rb +66 -90
- data/lib/chef/chef_fs/parallelizer/flatten_enumerable.rb +35 -0
- data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +279 -0
- data/lib/chef/config.rb +36 -2
- data/lib/chef/cookbook/cookbook_version_loader.rb +0 -1
- data/lib/chef/cookbook/synchronizer.rb +64 -42
- data/lib/chef/cookbook_uploader.rb +4 -25
- data/lib/chef/cookbook_version.rb +12 -11
- data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +18 -1
- data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -3
- data/lib/chef/knife/bootstrap.rb +23 -1
- data/lib/chef/knife/bootstrap/chef-aix.erb +58 -0
- data/lib/chef/knife/bootstrap/chef-full.erb +16 -13
- data/lib/chef/knife/core/bootstrap_context.rb +25 -1
- data/lib/chef/knife/list.rb +9 -8
- data/lib/chef/knife/serve.rb +44 -0
- data/lib/chef/knife/show.rb +2 -3
- data/lib/chef/knife/ssh.rb +1 -0
- data/lib/chef/mixin/create_path.rb +20 -4
- data/lib/chef/node.rb +19 -3
- data/lib/chef/platform/provider_mapping.rb +0 -1
- data/lib/chef/platform/query_helpers.rb +4 -3
- data/lib/chef/provider/env/windows.rb +10 -3
- data/lib/chef/provider/file.rb +1 -1
- data/lib/chef/provider/mount.rb +84 -42
- data/lib/chef/provider/package/freebsd/base.rb +92 -0
- data/lib/chef/provider/package/freebsd/pkg.rb +113 -0
- data/lib/chef/provider/package/freebsd/pkgng.rb +80 -0
- data/lib/chef/provider/package/freebsd/port.rb +70 -0
- data/lib/chef/providers.rb +3 -1
- data/lib/chef/resource/chef_gem.rb +2 -1
- data/lib/chef/resource/freebsd_package.rb +39 -3
- data/lib/chef/resource/lwrp_base.rb +2 -2
- data/lib/chef/resource/mount.rb +9 -9
- data/lib/chef/util/threaded_job_queue.rb +61 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version/platform.rb +2 -0
- data/lib/chef/whitelist.rb +82 -0
- data/lib/chef/win32/registry.rb +0 -1
- data/lib/chef/win32/version.rb +4 -3
- data/spec/functional/win32/versions_spec.rb +4 -4
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/knife/chef_fs_data_store_spec.rb +1 -1
- data/spec/integration/knife/chef_repo_path_spec.rb +4 -1
- data/spec/integration/knife/common_options_spec.rb +9 -9
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
- data/spec/integration/knife/deps_spec.rb +3 -0
- data/spec/integration/knife/list_spec.rb +3 -0
- data/spec/integration/knife/raw_spec.rb +5 -2
- data/spec/integration/knife/redirection_spec.rb +4 -1
- data/spec/integration/knife/serve_spec.rb +57 -0
- data/spec/integration/knife/show_spec.rb +3 -0
- data/spec/support/pedant/run_pedant.rb +1 -0
- data/spec/support/platform_helpers.rb +7 -5
- data/spec/support/shared/context/config.rb +21 -0
- data/spec/support/shared/functional/file_resource.rb +52 -0
- data/spec/unit/chef_fs/parallelizer.rb +482 -0
- data/spec/unit/client_spec.rb +4 -2
- data/spec/unit/config_spec.rb +66 -12
- data/spec/unit/knife/bootstrap_spec.rb +6 -0
- data/spec/unit/knife/core/bootstrap_context_spec.rb +31 -1
- data/spec/unit/node_spec.rb +73 -3
- data/spec/unit/provider/mount_spec.rb +102 -79
- data/spec/unit/provider/package/{freebsd_spec.rb → freebsd/pkg_spec.rb} +19 -32
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +155 -0
- data/spec/unit/provider/package/freebsd/port_spec.rb +160 -0
- data/spec/unit/resource/chef_gem_spec.rb +5 -0
- data/spec/unit/resource/freebsd_package_spec.rb +63 -11
- data/spec/unit/resource/mount_spec.rb +11 -0
- data/spec/unit/role_spec.rb +5 -1
- data/spec/unit/run_lock_spec.rb +2 -0
- data/spec/unit/util/threaded_job_queue_spec.rb +51 -0
- data/spec/unit/version/platform_spec.rb +1 -1
- metadata +176 -161
- data/lib/chef/provider/package/freebsd.rb +0 -149
@@ -0,0 +1,92 @@
|
|
1
|
+
#
|
2
|
+
# Authors:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Matthew Landauer (matthew@openaustralia.org)
|
4
|
+
# Richard Manyanza (liseki@nyikacraftsmen.com)
|
5
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan, Matthew Landauer
|
6
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'chef/resource/package'
|
23
|
+
require 'chef/provider/package'
|
24
|
+
require 'chef/mixin/shell_out'
|
25
|
+
require 'chef/mixin/get_source_from_package'
|
26
|
+
|
27
|
+
class Chef
|
28
|
+
class Provider
|
29
|
+
class Package
|
30
|
+
module Freebsd
|
31
|
+
|
32
|
+
module PortsHelper
|
33
|
+
def supports_ports?
|
34
|
+
::File.exist?("/usr/ports/Makefile")
|
35
|
+
end
|
36
|
+
|
37
|
+
def port_dir(port)
|
38
|
+
case port
|
39
|
+
|
40
|
+
# When the package name starts with a '/' treat it as the full path to the ports directory.
|
41
|
+
when /^\//
|
42
|
+
port
|
43
|
+
|
44
|
+
# Otherwise if the package name contains a '/' not at the start (like 'www/wordpress') treat
|
45
|
+
# as a relative path from /usr/ports.
|
46
|
+
when /\//
|
47
|
+
"/usr/ports/#{port}"
|
48
|
+
|
49
|
+
# Otherwise look up the path to the ports directory using 'whereis'
|
50
|
+
else
|
51
|
+
whereis = shell_out!("whereis -s #{port}", :env => nil)
|
52
|
+
unless _path = whereis.stdout[/^#{Regexp.escape(port)}:\s+(.+)$/, 1]
|
53
|
+
raise Chef::Exceptions::Package, "Could not find port with the name #{port}"
|
54
|
+
end
|
55
|
+
_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def makefile_variable_value(variable, dir = nil)
|
60
|
+
options = dir ? { :cwd => dir } : {}
|
61
|
+
make_v = shell_out!("make -V #{variable}", options.merge!(:env => nil, :returns => [0,1]))
|
62
|
+
make_v.exitstatus.zero? ? make_v.stdout.strip.split($\).first : nil # $\ is the line separator, i.e. newline.
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
class Base < Chef::Provider::Package
|
68
|
+
include Chef::Mixin::ShellOut
|
69
|
+
include Chef::Mixin::GetSourceFromPackage
|
70
|
+
|
71
|
+
def initialize(*args)
|
72
|
+
super
|
73
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_current_resource
|
77
|
+
@current_resource.package_name(@new_resource.package_name)
|
78
|
+
|
79
|
+
@current_resource.version(current_installed_version)
|
80
|
+
Chef::Log.debug("#{@new_resource} current version is #{@current_resource.version}") if @current_resource.version
|
81
|
+
|
82
|
+
@candidate_version = candidate_version
|
83
|
+
Chef::Log.debug("#{@new_resource} candidate version is #{@candidate_version}") if @candidate_version
|
84
|
+
|
85
|
+
@current_resource
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#
|
2
|
+
# Authors:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Matthew Landauer (matthew@openaustralia.org)
|
4
|
+
# Richard Manyanza (liseki@nyikacraftsmen.com)
|
5
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan, Matthew Landauer
|
6
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza
|
7
|
+
# License:: Apache License, Version 2.0
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'chef/provider/package/freebsd/base'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Provider
|
26
|
+
class Package
|
27
|
+
module Freebsd
|
28
|
+
class Pkg < Base
|
29
|
+
include PortsHelper
|
30
|
+
|
31
|
+
def install_package(name, version)
|
32
|
+
unless @current_resource.version
|
33
|
+
case @new_resource.source
|
34
|
+
when /^http/, /^ftp/
|
35
|
+
if @new_resource.source =~ /\/$/
|
36
|
+
shell_out!("pkg_add -r #{package_name}", :env => { "PACKAGESITE" => @new_resource.source, 'LC_ALL' => nil }).status
|
37
|
+
else
|
38
|
+
shell_out!("pkg_add -r #{package_name}", :env => { "PACKAGEROOT" => @new_resource.source, 'LC_ALL' => nil }).status
|
39
|
+
end
|
40
|
+
Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
|
41
|
+
|
42
|
+
when /^\//
|
43
|
+
shell_out!("pkg_add #{file_candidate_version_path}", :env => { "PKG_PATH" => @new_resource.source , 'LC_ALL'=>nil}).status
|
44
|
+
Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
|
45
|
+
|
46
|
+
else
|
47
|
+
shell_out!("pkg_add -r #{latest_link_name}", :env => nil).status
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def remove_package(name, version)
|
53
|
+
shell_out!("pkg_delete #{package_name}-#{version || @current_resource.version}", :env => nil).status
|
54
|
+
end
|
55
|
+
|
56
|
+
# The name of the package (without the version number) as understood by pkg_add and pkg_info.
|
57
|
+
def package_name
|
58
|
+
if supports_ports?
|
59
|
+
if makefile_variable_value("PKGNAME", port_path) =~ /^(.+)-[^-]+$/
|
60
|
+
$1
|
61
|
+
else
|
62
|
+
raise Chef::Exceptions::Package, "Unexpected form for PKGNAME variable in #{port_path}/Makefile"
|
63
|
+
end
|
64
|
+
else
|
65
|
+
@new_resource.package_name
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def latest_link_name
|
70
|
+
makefile_variable_value("LATEST_LINK", port_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
def current_installed_version
|
74
|
+
pkg_info = shell_out!("pkg_info -E \"#{package_name}*\"", :env => nil, :returns => [0,1])
|
75
|
+
pkg_info.stdout[/^#{Regexp.escape(package_name)}-(.+)/, 1]
|
76
|
+
end
|
77
|
+
|
78
|
+
def candidate_version
|
79
|
+
case @new_resource.source
|
80
|
+
when /^http/, /^ftp/
|
81
|
+
repo_candidate_version
|
82
|
+
when /^\//
|
83
|
+
file_candidate_version
|
84
|
+
else
|
85
|
+
ports_candidate_version
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def file_candidate_version_path
|
90
|
+
Dir["#{@new_resource.source}/#{@current_resource.package_name}*"][-1].to_s
|
91
|
+
end
|
92
|
+
|
93
|
+
def file_candidate_version
|
94
|
+
file_candidate_version_path.split(/-/).last.split(/.tbz/).first
|
95
|
+
end
|
96
|
+
|
97
|
+
def repo_candidate_version
|
98
|
+
"0.0.0"
|
99
|
+
end
|
100
|
+
|
101
|
+
def ports_candidate_version
|
102
|
+
makefile_variable_value("PORTVERSION", port_path)
|
103
|
+
end
|
104
|
+
|
105
|
+
def port_path
|
106
|
+
port_dir @new_resource.package_name
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#
|
2
|
+
# Authors:: Richard Manyanza (liseki@nyikacraftsmen.com)
|
3
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/package/freebsd/base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Provider
|
23
|
+
class Package
|
24
|
+
module Freebsd
|
25
|
+
class Pkgng < Base
|
26
|
+
|
27
|
+
def install_package(name, version)
|
28
|
+
unless @current_resource.version
|
29
|
+
case @new_resource.source
|
30
|
+
when /^(http|ftp|\/)/
|
31
|
+
shell_out!("pkg add#{expand_options(@new_resource.options)} #{@new_resource.source}", :env => { 'LC_ALL' => nil }).status
|
32
|
+
Chef::Log.debug("#{@new_resource} installed from: #{@new_resource.source}")
|
33
|
+
|
34
|
+
else
|
35
|
+
shell_out!("pkg install -y#{expand_options(@new_resource.options)} #{name}", :env => { 'LC_ALL' => nil }).status
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_package(name, version)
|
41
|
+
options = @new_resource.options && @new_resource.options.sub(repo_regex, '')
|
42
|
+
options && !options.empty? || options = nil
|
43
|
+
shell_out!("pkg delete -y#{expand_options(options)} #{name}#{version ? '-' + version : ''}", :env => nil).status
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_installed_version
|
47
|
+
pkg_info = shell_out!("pkg info \"#{@new_resource.package_name}\"", :env => nil, :returns => [0,70])
|
48
|
+
pkg_info.stdout[/^#{Regexp.escape(@new_resource.package_name)}-(.+)/, 1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def candidate_version
|
52
|
+
@new_resource.source ? file_candidate_version : repo_candidate_version
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def file_candidate_version
|
60
|
+
@new_resource.source[/#{Regexp.escape(@new_resource.package_name)}-(.+)\.txz/, 1]
|
61
|
+
end
|
62
|
+
|
63
|
+
def repo_candidate_version
|
64
|
+
if @new_resource.options && @new_resource.options.match(repo_regex)
|
65
|
+
options = $1
|
66
|
+
end
|
67
|
+
|
68
|
+
pkg_query = shell_out!("pkg rquery#{expand_options(options)} '%v' #{@new_resource.package_name}", :env => nil)
|
69
|
+
pkg_query.exitstatus.zero? ? pkg_query.stdout.strip.split(/\n/).last : nil
|
70
|
+
end
|
71
|
+
|
72
|
+
def repo_regex
|
73
|
+
/(-r\s?\S+)\b/
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#
|
2
|
+
# Authors:: Richard Manyanza (liseki@nyikacraftsmen.com)
|
3
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/package/freebsd/base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Provider
|
23
|
+
class Package
|
24
|
+
module Freebsd
|
25
|
+
class Port < Base
|
26
|
+
include PortsHelper
|
27
|
+
|
28
|
+
def install_package(name, version)
|
29
|
+
shell_out!("make -DBATCH install clean", :timeout => 1800, :env => nil, :cwd => port_dir).status
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_package(name, version)
|
33
|
+
shell_out!("make deinstall", :timeout => 300, :env => nil, :cwd => port_dir).status
|
34
|
+
end
|
35
|
+
|
36
|
+
def current_installed_version
|
37
|
+
pkg_info = if supports_pkgng?
|
38
|
+
shell_out!("pkg info \"#{@new_resource.package_name}\"", :env => nil, :returns => [0,70])
|
39
|
+
else
|
40
|
+
shell_out!("pkg_info -E \"#{@new_resource.package_name}*\"", :env => nil, :returns => [0,1])
|
41
|
+
end
|
42
|
+
pkg_info.stdout[/^#{Regexp.escape(@new_resource.package_name)}-(.+)/, 1]
|
43
|
+
end
|
44
|
+
|
45
|
+
def candidate_version
|
46
|
+
if supports_ports?
|
47
|
+
makefile_variable_value("PORTVERSION", port_dir)
|
48
|
+
else
|
49
|
+
raise Chef::Exceptions::Package, "Ports collection could not be found"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def port_dir
|
54
|
+
super(@new_resource.package_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def supports_pkgng?
|
62
|
+
with_pkgng = makefile_variable_value('WITH_PKGNG')
|
63
|
+
with_pkgng && with_pkgng =~ /yes/i
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/chef/providers.rb
CHANGED
@@ -55,7 +55,9 @@ require 'chef/provider/env/windows'
|
|
55
55
|
require 'chef/provider/package/apt'
|
56
56
|
require 'chef/provider/package/dpkg'
|
57
57
|
require 'chef/provider/package/easy_install'
|
58
|
-
require 'chef/provider/package/freebsd'
|
58
|
+
require 'chef/provider/package/freebsd/port'
|
59
|
+
require 'chef/provider/package/freebsd/pkg'
|
60
|
+
require 'chef/provider/package/freebsd/pkgng'
|
59
61
|
require 'chef/provider/package/ips'
|
60
62
|
require 'chef/provider/package/macports'
|
61
63
|
require 'chef/provider/package/pacman'
|
@@ -28,6 +28,7 @@ class Chef
|
|
28
28
|
def initialize(name, run_context=nil)
|
29
29
|
super
|
30
30
|
@resource_name = :chef_gem
|
31
|
+
@gem_binary = RbConfig::CONFIG['bindir'] + "/gem"
|
31
32
|
@provider = Chef::Provider::Package::Rubygems
|
32
33
|
end
|
33
34
|
|
@@ -37,7 +38,7 @@ class Chef
|
|
37
38
|
raise ArgumentError, "The chef_gem resource is restricted to the current gem environment, use gem_package to install to other environments."
|
38
39
|
end
|
39
40
|
|
40
|
-
|
41
|
+
@gem_binary
|
41
42
|
end
|
42
43
|
|
43
44
|
def after_created
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#
|
2
|
-
#
|
2
|
+
# Authors:: AJ Christensen (<aj@opscode.com>)
|
3
|
+
# Richard Manyanza (<liseki@nyikacraftsmen.com>)
|
3
4
|
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# Copyright:: Copyright (c) 2014 Richard Manyanza.
|
4
6
|
# License:: Apache License, Version 2.0
|
5
7
|
#
|
6
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,16 +19,50 @@
|
|
17
19
|
#
|
18
20
|
|
19
21
|
require 'chef/resource/package'
|
20
|
-
require 'chef/provider/package/freebsd'
|
22
|
+
require 'chef/provider/package/freebsd/port'
|
23
|
+
require 'chef/provider/package/freebsd/pkg'
|
24
|
+
require 'chef/provider/package/freebsd/pkgng'
|
25
|
+
require 'chef/mixin/shell_out'
|
21
26
|
|
22
27
|
class Chef
|
23
28
|
class Resource
|
24
29
|
class FreebsdPackage < Chef::Resource::Package
|
30
|
+
include Chef::Mixin::ShellOut
|
31
|
+
|
32
|
+
provides :package, :on_platforms => ["freebsd"]
|
33
|
+
|
25
34
|
|
26
35
|
def initialize(name, run_context=nil)
|
27
36
|
super
|
28
37
|
@resource_name = :freebsd_package
|
29
|
-
|
38
|
+
end
|
39
|
+
|
40
|
+
def after_created
|
41
|
+
assign_provider
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def assign_provider
|
49
|
+
@provider = if @source.to_s =~ /^ports$/i
|
50
|
+
Chef::Provider::Package::Freebsd::Port
|
51
|
+
elsif ships_with_pkgng? || supports_pkgng?
|
52
|
+
Chef::Provider::Package::Freebsd::Pkgng
|
53
|
+
else
|
54
|
+
Chef::Provider::Package::Freebsd::Pkg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def ships_with_pkgng?
|
59
|
+
# It was not until __FreeBSD_version 1000017 that pkgng became
|
60
|
+
# the default binary package manager. See '/usr/ports/Mk/bsd.port.mk'.
|
61
|
+
node[:os_version].to_i >= 1000017
|
62
|
+
end
|
63
|
+
|
64
|
+
def supports_pkgng?
|
65
|
+
!!shell_out!("make -V WITH_PKGNG", :env => nil).stdout.match(/yes/i)
|
30
66
|
end
|
31
67
|
|
32
68
|
end
|