giraffesoft-chef 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/debian/man/man1/chef-indexer.1 +42 -0
- data/distro/debian/man/man1/chef-server.1 +108 -0
- data/distro/debian/man/man8/chef-client.8 +61 -0
- data/distro/debian/man/man8/chef-solo.8 +58 -0
- data/distro/redhat/etc/chef/client.rb +16 -0
- data/distro/redhat/etc/chef/indexer.rb +10 -0
- data/distro/redhat/etc/chef/server.rb +22 -0
- data/distro/redhat/etc/init.d/chef-client +74 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +77 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +421 -0
- data/lib/chef/compile.rb +170 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +171 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +176 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +386 -0
- data/lib/chef/mixin/convert_to_class_name.rb +48 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +49 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +254 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/cron.rb +187 -0
- data/lib/chef/provider/deploy.rb +281 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/git.rb +198 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +106 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +148 -0
- data/lib/chef/provider/template.rb +143 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +144 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +350 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/scm.rb +129 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +204 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +347 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +293 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
class Chef
|
2
|
+
class Provider
|
3
|
+
class Package
|
4
|
+
class Macports < Chef::Provider::Package
|
5
|
+
def load_current_resource
|
6
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
7
|
+
@current_resource.package_name(@new_resource.package_name)
|
8
|
+
|
9
|
+
@current_resource.version(current_installed_version)
|
10
|
+
Chef::Log.debug("Current version is #{@current_resource.version}") if @current_resource.version
|
11
|
+
|
12
|
+
@candidate_version = macports_candidate_version
|
13
|
+
|
14
|
+
if !@new_resource.version and !@candidate_version
|
15
|
+
raise Chef::Exceptions::Package, "Could not get a candidate version for this package -- #{@new_resource.name} does not seem to be a valid package!"
|
16
|
+
end
|
17
|
+
|
18
|
+
Chef::Log.debug("MacPorts candidate version is #{@candidate_version}") if @candidate_version
|
19
|
+
|
20
|
+
@current_resource
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_installed_version
|
24
|
+
command = "port installed #{@new_resource.package_name}"
|
25
|
+
output = get_response_from_command(command)
|
26
|
+
|
27
|
+
response = nil
|
28
|
+
output.each_line do |line|
|
29
|
+
match = line.match(/^.+ @([^\s]+) \(active\)$/)
|
30
|
+
response = match[1] if match
|
31
|
+
end
|
32
|
+
response
|
33
|
+
end
|
34
|
+
|
35
|
+
def macports_candidate_version
|
36
|
+
command = "port info --version #{@new_resource.package_name}"
|
37
|
+
output = get_response_from_command(command)
|
38
|
+
|
39
|
+
match = output.match(/^version: (.+)$/)
|
40
|
+
|
41
|
+
match ? match[1] : nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def install_package(name, version)
|
45
|
+
unless @current_resource.version == version
|
46
|
+
command = "port install #{name}"
|
47
|
+
command << " @#{version}" if version and !version.empty?
|
48
|
+
run_command_with_systems_locale(
|
49
|
+
:command => command
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def purge_package(name, version)
|
55
|
+
command = "port uninstall #{name}"
|
56
|
+
command << " @#{version}" if version and !version.empty?
|
57
|
+
run_command_with_systems_locale(
|
58
|
+
:command => command
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def remove_package(name, version)
|
63
|
+
command = "port deactivate #{name}"
|
64
|
+
command << " @#{version}" if version and !version.empty?
|
65
|
+
|
66
|
+
run_command_with_systems_locale(
|
67
|
+
:command => command
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def upgrade_package(name, version)
|
72
|
+
# Saving this to a variable -- weird rSpec behavior
|
73
|
+
# happens otherwise...
|
74
|
+
current_version = @current_resource.version
|
75
|
+
|
76
|
+
if current_version.nil? or current_version.empty?
|
77
|
+
# Macports doesn't like when you upgrade a package
|
78
|
+
# that hasn't been installed.
|
79
|
+
install_package(name, version)
|
80
|
+
elsif current_version != version
|
81
|
+
run_command_with_systems_locale(
|
82
|
+
:command => "port upgrade #{name} @#{version}"
|
83
|
+
)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def get_response_from_command(command)
|
89
|
+
output = nil
|
90
|
+
status = popen4(command) do |pid, stdin, stdout, stderr|
|
91
|
+
begin
|
92
|
+
output = stdout.read
|
93
|
+
rescue Exception
|
94
|
+
raise Chef::Exceptions::Package, "Could not read from STDOUT on command: #{command}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
unless status.exitstatus == 0 || status.exitstatus == 1
|
98
|
+
raise Chef::Exceptions::Package, "#{command} failed - #{status.insect}!"
|
99
|
+
end
|
100
|
+
output
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Ezra Zygmuntowicz (<ezra@engineyard.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
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'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/resource/package'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Package
|
26
|
+
class Portage < Chef::Provider::Package
|
27
|
+
|
28
|
+
def load_current_resource
|
29
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
30
|
+
@current_resource.package_name(@new_resource.package_name)
|
31
|
+
|
32
|
+
category = @new_resource.package_name.split('/').first
|
33
|
+
pkg = @new_resource.package_name.split('/').last
|
34
|
+
|
35
|
+
@current_resource.version(nil)
|
36
|
+
|
37
|
+
catdir = "/var/db/pkg/#{category}"
|
38
|
+
|
39
|
+
if( ::File.exists?(catdir) )
|
40
|
+
Dir.entries(catdir).each do |entry|
|
41
|
+
if(entry =~ /^#{Regexp.escape(pkg)}\-(\d[\.\d]*((_(alpha|beta|pre|rc|p)\d*)*)?)/)
|
42
|
+
@current_resource.version($1)
|
43
|
+
Chef::Log.debug("Got current version #{$1}")
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@current_resource
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def parse_emerge(package, txt)
|
54
|
+
available, installed, pkg = nil
|
55
|
+
txt.each do |line|
|
56
|
+
if line =~ /\*(.*)/
|
57
|
+
pkg = $1.strip
|
58
|
+
end
|
59
|
+
if (pkg == package) || (pkg.split('/').last == package rescue false)
|
60
|
+
if line =~ /Latest version available: (.*)/
|
61
|
+
available = $1
|
62
|
+
elsif line =~ /Latest version installed: (.*)/
|
63
|
+
installed = $1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
available = installed unless available
|
68
|
+
[available, installed]
|
69
|
+
end
|
70
|
+
|
71
|
+
def candidate_version
|
72
|
+
return @candidate_version if @candidate_version
|
73
|
+
|
74
|
+
status = popen4("emerge --color n --nospinner --search #{@new_resource.package_name.split('/').last}") do |pid, stdin, stdout, stderr|
|
75
|
+
available, installed = parse_emerge(@new_resource.package_name, stdout.read)
|
76
|
+
@candidate_version = available
|
77
|
+
end
|
78
|
+
|
79
|
+
unless status.exitstatus == 0
|
80
|
+
raise Chef::Exceptions::Package, "emerge --search failed - #{status.inspect}!"
|
81
|
+
end
|
82
|
+
|
83
|
+
@candidate_version
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def install_package(name, version)
|
89
|
+
pkg = "=#{name}-#{version}"
|
90
|
+
|
91
|
+
if(version =~ /^\~(.+)/)
|
92
|
+
# If we start with a tilde
|
93
|
+
pkg = "~#{name}-#{$1}"
|
94
|
+
end
|
95
|
+
|
96
|
+
run_command_with_systems_locale(
|
97
|
+
:command => "emerge -g --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}"
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def upgrade_package(name, version)
|
102
|
+
install_package(name, version)
|
103
|
+
end
|
104
|
+
|
105
|
+
def remove_package(name, version)
|
106
|
+
if(version)
|
107
|
+
pkg = "=#{@new_resource.package_name}-#{version}"
|
108
|
+
else
|
109
|
+
pkg = "#{@new_resource.package_name}"
|
110
|
+
end
|
111
|
+
|
112
|
+
run_command_with_systems_locale(
|
113
|
+
:command => "emerge --unmerge --color n --nospinner --quiet#{expand_options(@new_resource.options)} #{pkg}"
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def purge_package(name, version)
|
118
|
+
remove_package(name, version)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joshua Timberman (<joshua@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
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
|
+
require 'chef/provider/package'
|
19
|
+
require 'chef/mixin/command'
|
20
|
+
require 'chef/resource/package'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Package
|
25
|
+
class Rpm < Chef::Provider::Package
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
29
|
+
@current_resource.package_name(@new_resource.package_name)
|
30
|
+
@new_resource.version(nil)
|
31
|
+
|
32
|
+
if @new_resource.source
|
33
|
+
unless ::File.exists?(@new_resource.source)
|
34
|
+
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
|
35
|
+
end
|
36
|
+
|
37
|
+
Chef::Log.debug("Checking rpm status for #{@new_resource.package_name}")
|
38
|
+
status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
|
39
|
+
stdout.each do |line|
|
40
|
+
case line
|
41
|
+
when /([\w\d_.-]+)\s([\w\d_.-]+)/
|
42
|
+
@current_resource.package_name($1)
|
43
|
+
@new_resource.version($2)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if @new_resource.action.include?(:install)
|
49
|
+
raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
|
54
|
+
status = popen4("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
|
55
|
+
stdout.each do |line|
|
56
|
+
case line
|
57
|
+
when /([\w\d_.-]+)\s([\w\d_.-]+)/
|
58
|
+
Chef::Log.debug("Current version is #{$2}")
|
59
|
+
@current_resource.version($2)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
unless status.exitstatus == 0 || status.exitstatus == 1
|
65
|
+
raise Chef::Exceptions::Package, "rpm failed - #{status.inspect}!"
|
66
|
+
end
|
67
|
+
|
68
|
+
@current_resource
|
69
|
+
end
|
70
|
+
|
71
|
+
def install_package(name, version)
|
72
|
+
run_command_with_systems_locale(
|
73
|
+
:command => "rpm -i #{@new_resource.source}"
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def upgrade_package(name, version)
|
78
|
+
run_command_with_systems_locale(
|
79
|
+
:command => "rpm -U #{@new_resource.source}"
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def remove_package(name, version)
|
84
|
+
if version
|
85
|
+
run_command_with_systems_locale(
|
86
|
+
:command => "rpm -e #{name}-#{version}"
|
87
|
+
)
|
88
|
+
else
|
89
|
+
run_command_with_systems_locale(
|
90
|
+
:command => "rpm -e #{name}"
|
91
|
+
)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
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'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/resource/package'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Package
|
26
|
+
class Rubygems < Chef::Provider::Package
|
27
|
+
|
28
|
+
def gem_list_parse(line)
|
29
|
+
installed_versions = Array.new
|
30
|
+
if line.match("^#{@new_resource.package_name} \\((.+?)\\)$")
|
31
|
+
installed_versions = $1.split(/, /)
|
32
|
+
installed_versions
|
33
|
+
else
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def gem_binary_path
|
39
|
+
path = @new_resource.gem_binary
|
40
|
+
path ? path : 'gem'
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_current_resource
|
44
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
45
|
+
@current_resource.package_name(@new_resource.package_name)
|
46
|
+
@current_resource.version(nil)
|
47
|
+
|
48
|
+
# First, we need to look up whether we have the local gem installed or not
|
49
|
+
status = popen4("#{gem_binary_path} list --local #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
|
50
|
+
stdout.each do |line|
|
51
|
+
installed_versions = gem_list_parse(line)
|
52
|
+
next unless installed_versions
|
53
|
+
# If the version we are asking for is installed, make that our current
|
54
|
+
# version. Otherwise, go ahead and use the highest one, which
|
55
|
+
# happens to come first in the array.
|
56
|
+
if installed_versions.detect { |v| v == @new_resource.version }
|
57
|
+
Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}")
|
58
|
+
@current_resource.version(@new_resource.version)
|
59
|
+
else
|
60
|
+
iv = installed_versions.first
|
61
|
+
Chef::Log.debug("#{@new_resource.package_name} at version #{iv}")
|
62
|
+
@current_resource.version(iv)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
unless status.exitstatus == 0
|
68
|
+
raise Chef::Exceptions::Package, "#{gem_binary_path} list --local failed - #{status.inspect}!"
|
69
|
+
end
|
70
|
+
|
71
|
+
@current_resource
|
72
|
+
end
|
73
|
+
|
74
|
+
def candidate_version
|
75
|
+
return @candidate_version if @candidate_version
|
76
|
+
|
77
|
+
status = popen4("#{gem_binary_path} list --remote #{@new_resource.package_name}#{' --source=' + @new_resource.source if @new_resource.source}") do |pid, stdin, stdout, stderr|
|
78
|
+
stdout.each do |line|
|
79
|
+
installed_versions = gem_list_parse(line)
|
80
|
+
next unless installed_versions
|
81
|
+
Chef::Log.debug("candidate_version: remote rubygem(s) available: #{installed_versions.inspect}")
|
82
|
+
|
83
|
+
unless installed_versions.empty?
|
84
|
+
Chef::Log.debug("candidate_version: setting install candidate version to #{installed_versions.first}")
|
85
|
+
@candidate_version = installed_versions.first
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
unless status.exitstatus == 0
|
92
|
+
raise Chef::Exceptions::Package, "#{gem_binary_path} list --remote failed - #{status.inspect}!"
|
93
|
+
end
|
94
|
+
@candidate_version
|
95
|
+
end
|
96
|
+
|
97
|
+
def install_package(name, version)
|
98
|
+
src = nil
|
99
|
+
if @new_resource.source
|
100
|
+
src = " --source=#{@new_resource.source} --source=http://gems.rubyforge.org"
|
101
|
+
end
|
102
|
+
run_command_with_systems_locale(
|
103
|
+
:command => "#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src}#{opts}"
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def upgrade_package(name, version)
|
108
|
+
install_package(name, version)
|
109
|
+
end
|
110
|
+
|
111
|
+
def remove_package(name, version)
|
112
|
+
if version
|
113
|
+
run_command_with_systems_locale(
|
114
|
+
:command => "#{gem_binary_path} uninstall #{name} -q -v \"#{version}\""
|
115
|
+
)
|
116
|
+
else
|
117
|
+
run_command_with_systems_locale(
|
118
|
+
:command => "#{gem_binary_path} uninstall #{name} -q -a"
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def purge_package(name, version)
|
124
|
+
remove_package(name, version)
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def opts
|
130
|
+
expand_options(@new_resource.options)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|