runa-chef 0.8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +201 -0
- data/README.rdoc +136 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/bin/knife +27 -0
- data/bin/shef +45 -0
- data/distro/README +2 -0
- data/distro/common/man/man1/chef-indexer.1 +42 -0
- data/distro/common/man/man1/chef-server.1 +108 -0
- data/distro/common/man/man8/chef-client.8 +61 -0
- data/distro/common/man/man8/chef-solo.8 +58 -0
- data/distro/common/man/man8/knife.8 +359 -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/redhat/etc/init.d/chef-client +78 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +78 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/api_client.rb +269 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +214 -0
- data/lib/chef/application/knife.rb +138 -0
- data/lib/chef/application/server.rb +19 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +323 -0
- data/lib/chef/compile.rb +158 -0
- data/lib/chef/config.rb +195 -0
- data/lib/chef/cookbook.rb +198 -0
- data/lib/chef/cookbook/metadata.rb +487 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +273 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/data_bag.rb +216 -0
- data/lib/chef/data_bag_item.rb +227 -0
- data/lib/chef/exceptions.rb +39 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/knife.rb +300 -0
- data/lib/chef/knife/client_bulk_delete.rb +41 -0
- data/lib/chef/knife/client_create.rb +55 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +84 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +173 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/node_bulk_delete.rb +44 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +45 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +32 -0
- data/lib/chef/mixin/command.rb +390 -0
- data/lib/chef/mixin/convert_to_class_name.rb +57 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +33 -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 +58 -0
- data/lib/chef/mixin/language.rb +107 -0
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
- data/lib/chef/mixin/template.rb +94 -0
- data/lib/chef/nanite.rb +100 -0
- data/lib/chef/node.rb +463 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +268 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +184 -0
- data/lib/chef/provider/deploy.rb +314 -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/erl_call.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +195 -0
- data/lib/chef/provider/git.rb +203 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/dscl.rb +128 -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 +106 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mdadm.rb +88 -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/easy_install.rb +106 -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 +125 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/package/zypper.rb +132 -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 +33 -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 +156 -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 +114 -0
- data/lib/chef/provider/subversion.rb +156 -0
- data/lib/chef/provider/template.rb +175 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/dscl.rb +280 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +108 -0
- data/lib/chef/recipe.rb +105 -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/breakpoint.rb +35 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +359 -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/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -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/mdadm.rb +82 -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 +39 -0
- data/lib/chef/resource/scm.rb +137 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +34 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +101 -0
- data/lib/chef/resource_collection.rb +212 -0
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +298 -0
- data/lib/chef/role.rb +301 -0
- data/lib/chef/run_list.rb +164 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search/query.rb +71 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +185 -0
- data/lib/chef/tasks/chef_repo.rake +245 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- data/lib/chef/webui_user.rb +231 -0
- metadata +398 -0
|
@@ -0,0 +1,110 @@
|
|
|
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 Apt < 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
|
+
Chef::Log.debug("Checking apt-cache policy for #{@new_resource.package_name}")
|
|
33
|
+
status = popen4("apt-cache policy #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
|
|
34
|
+
stdout.each do |line|
|
|
35
|
+
case line
|
|
36
|
+
when /^\s{2}Installed: (.+)$/
|
|
37
|
+
installed_version = $1
|
|
38
|
+
if installed_version == '(none)'
|
|
39
|
+
Chef::Log.debug("Current version is nil")
|
|
40
|
+
@current_resource.version(nil)
|
|
41
|
+
else
|
|
42
|
+
Chef::Log.debug("Current version is #{installed_version}")
|
|
43
|
+
@current_resource.version(installed_version)
|
|
44
|
+
end
|
|
45
|
+
when /^\s{2}Candidate: (.+)$/
|
|
46
|
+
Chef::Log.debug("Current version is #{$1}")
|
|
47
|
+
@candidate_version = $1
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
unless status.exitstatus == 0
|
|
53
|
+
raise Chef::Exceptions::Package, "apt-cache failed - #{status.inspect}!"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if @candidate_version == "(none)"
|
|
57
|
+
raise Chef::Exceptions::Package, "apt does not have a version of package #{@new_resource.package_name}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
@current_resource
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def install_package(name, version)
|
|
64
|
+
run_command_with_systems_locale(
|
|
65
|
+
:command => "apt-get -q -y#{expand_options(@new_resource.options)} install #{name}=#{version}",
|
|
66
|
+
:environment => {
|
|
67
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def upgrade_package(name, version)
|
|
73
|
+
install_package(name, version)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def remove_package(name, version)
|
|
77
|
+
run_command_with_systems_locale(
|
|
78
|
+
:command => "apt-get -q -y#{expand_options(@new_resource.options)} remove #{@new_resource.package_name}",
|
|
79
|
+
:environment => {
|
|
80
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def purge_package(name, version)
|
|
86
|
+
run_command_with_systems_locale(
|
|
87
|
+
:command => "apt-get -q -y#{expand_options(@new_resource.options)} purge #{@new_resource.package_name}",
|
|
88
|
+
:environment => {
|
|
89
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def preseed_package(name, version)
|
|
95
|
+
preseed_file = get_preseed_file(name, version)
|
|
96
|
+
if preseed_file
|
|
97
|
+
Chef::Log.info("Pre-seeding #{@new_resource} with package installation instructions.")
|
|
98
|
+
run_command_with_systems_locale(
|
|
99
|
+
:command => "debconf-set-selections #{preseed_file}",
|
|
100
|
+
:environment => {
|
|
101
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
|
3
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
|
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 Dpkg < Chef::Provider::Package::Apt
|
|
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
|
+
@new_resource.version(nil)
|
|
32
|
+
|
|
33
|
+
# We only -need- source for action install
|
|
34
|
+
if @new_resource.source
|
|
35
|
+
unless ::File.exists?(@new_resource.source)
|
|
36
|
+
raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Get information from the package if supplied
|
|
40
|
+
Chef::Log.debug("Checking dpkg status for #{@new_resource.package_name}")
|
|
41
|
+
status = popen4("dpkg-deb -W #{@new_resource.source}") do |pid, stdin, stdout, stderr|
|
|
42
|
+
stdout.each do |line|
|
|
43
|
+
if pkginfo = /([a-z\d\-\+]+)\t([\w\d.-]+)/.match(line)
|
|
44
|
+
@current_resource.package_name(pkginfo[1])
|
|
45
|
+
@new_resource.version(pkginfo[2])
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
else
|
|
50
|
+
# if the source was not set, and we're installing, fail
|
|
51
|
+
if @new_resource.action.include?(:install)
|
|
52
|
+
raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Check to see if it is installed
|
|
57
|
+
package_installed = nil
|
|
58
|
+
Chef::Log.debug("Checking install state for #{@current_resource.package_name}")
|
|
59
|
+
status = popen4("dpkg -s #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
|
|
60
|
+
stdout.each do |line|
|
|
61
|
+
case line
|
|
62
|
+
when /^Status: install ok installed/
|
|
63
|
+
package_installed = true
|
|
64
|
+
when /^Version: (.+)$/
|
|
65
|
+
if package_installed
|
|
66
|
+
Chef::Log.debug("Current version is #{$1}")
|
|
67
|
+
@current_resource.version($1)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
unless status.exitstatus == 0 || status.exitstatus == 1
|
|
74
|
+
raise Chef::Exceptions::Package, "dpkg failed - #{status.inspect}!"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
@current_resource
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def install_package(name, version)
|
|
81
|
+
run_command_with_systems_locale(
|
|
82
|
+
:command => "dpkg -i#{expand_options(@new_resource.options)} #{@new_resource.source}",
|
|
83
|
+
:environment => {
|
|
84
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def remove_package(name, version)
|
|
90
|
+
run_command_with_systems_locale(
|
|
91
|
+
:command => "dpkg -r#{expand_options(@new_resource.options)} #{@new_resource.package_name}",
|
|
92
|
+
:environment => {
|
|
93
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def purge_package(name, version)
|
|
99
|
+
run_command_with_systems_locale(
|
|
100
|
+
:command => "dpkg -P#{expand_options(@new_resource.options)} #{@new_resource.package_name}",
|
|
101
|
+
:environment => {
|
|
102
|
+
"DEBIAN_FRONTEND" => "noninteractive"
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Joe Williams (<joe@joetify.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2009 Joe Williams
|
|
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
|
+
class Chef
|
|
23
|
+
class Provider
|
|
24
|
+
class Package
|
|
25
|
+
class EasyInstall < Chef::Provider::Package
|
|
26
|
+
|
|
27
|
+
def install_check(name)
|
|
28
|
+
command = "python -c \"import sys; print sys.path\""
|
|
29
|
+
check = false
|
|
30
|
+
status = popen4(command) do |pid, stdin, stdout, stderr|
|
|
31
|
+
stdout.each do |line|
|
|
32
|
+
if line.include? "#{name}"
|
|
33
|
+
check = true
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
check
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def easy_install_binary_path
|
|
41
|
+
path = @new_resource.easy_install_binary
|
|
42
|
+
path ? path : 'easy_install'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def load_current_resource
|
|
46
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
|
47
|
+
@current_resource.package_name(@new_resource.package_name)
|
|
48
|
+
@current_resource.version(nil)
|
|
49
|
+
|
|
50
|
+
# get the currently installed version if installed
|
|
51
|
+
if install_check(@new_resource.package_name)
|
|
52
|
+
command = "python -c \"import #{@new_resource.package_name}; print #{@new_resource.package_name}.__path__\""
|
|
53
|
+
pid, stdin, stdout, stderr = popen4(command)
|
|
54
|
+
install_location = stdout.readline
|
|
55
|
+
install_location[/\S\S(.*)\/(.*)-(.*)-py(.*).egg\S/]
|
|
56
|
+
package_version = $3
|
|
57
|
+
else
|
|
58
|
+
package_version = nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
if package_version == @new_resource.version
|
|
62
|
+
Chef::Log.debug("#{@new_resource.package_name} at version #{@new_resource.version}")
|
|
63
|
+
@current_resource.version(@new_resource.version)
|
|
64
|
+
else
|
|
65
|
+
Chef::Log.debug("#{@new_resource.package_name} at version #{package_version}")
|
|
66
|
+
@current_resource.version(package_version)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@current_resource
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def candidate_version
|
|
73
|
+
return @candidate_version if @candidate_version
|
|
74
|
+
|
|
75
|
+
# do a dry run to get the latest version
|
|
76
|
+
command = "#{easy_install_binary_path} -n #{@new_resource.package_name}"
|
|
77
|
+
pid, stdin, stdout, stderr = popen4(command)
|
|
78
|
+
dry_run_output = ""
|
|
79
|
+
stdout.each do |line|
|
|
80
|
+
dry_run_output << line
|
|
81
|
+
end
|
|
82
|
+
dry_run_output[/(.*)Best match: (.*) (.*)\n/]
|
|
83
|
+
@candidate_version = $3
|
|
84
|
+
@candidate_version
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def install_package(name, version)
|
|
88
|
+
run_command(:command => "#{easy_install_binary_path} \"#{name}==#{version}\"")
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def upgrade_package(name, version)
|
|
92
|
+
install_package(name, version)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def remove_package(name, version)
|
|
96
|
+
run_command(:command => "#{easy_install_binary_path} -m #{name}")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def purge_package(name, version)
|
|
100
|
+
remove_package(name, version)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Authors:: Bryan McLellan (btm@loftninjas.org)
|
|
3
|
+
# Matthew Landauer (matthew@openaustralia.org)
|
|
4
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan, Matthew Landauer
|
|
5
|
+
# License:: Apache License, Version 2.0
|
|
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
|
+
|
|
20
|
+
require 'chef/provider/package'
|
|
21
|
+
require 'chef/mixin/command'
|
|
22
|
+
require 'chef/resource/package'
|
|
23
|
+
|
|
24
|
+
class Chef
|
|
25
|
+
class Provider
|
|
26
|
+
class Package
|
|
27
|
+
class Freebsd < Chef::Provider::Package
|
|
28
|
+
|
|
29
|
+
def current_installed_version
|
|
30
|
+
command = "pkg_info -E \"#{package_name}*\""
|
|
31
|
+
status = popen4(command) do |pid, stdin, stdout, stderr|
|
|
32
|
+
stdout.each do |line|
|
|
33
|
+
case line
|
|
34
|
+
when /^#{package_name}-(.+)/
|
|
35
|
+
return $1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
unless status.exitstatus == 0 || status.exitstatus == 1
|
|
40
|
+
raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}!"
|
|
41
|
+
end
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def port_path
|
|
46
|
+
case @new_resource.package_name
|
|
47
|
+
# When the package name starts with a '/' treat it as the full path to the ports directory
|
|
48
|
+
when /^\//
|
|
49
|
+
@new_resource.package_name
|
|
50
|
+
# Otherwise if the package name contains a '/' not at the start (like 'www/wordpress') treat as a relative
|
|
51
|
+
# path from /usr/ports
|
|
52
|
+
when /\//
|
|
53
|
+
"/usr/ports/#{@new_resource.package_name}"
|
|
54
|
+
# Otherwise look up the path to the ports directory using 'whereis'
|
|
55
|
+
else
|
|
56
|
+
popen4("whereis -s #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
|
|
57
|
+
stdout.each do |line|
|
|
58
|
+
case line
|
|
59
|
+
when /^#{@new_resource.package_name}:\s+(.+)$/
|
|
60
|
+
return $1
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
raise Chef::Exception::Package, "Could not find port with the name #{@new_resource.package_name}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def ports_makefile_variable_value(variable)
|
|
69
|
+
command = "cd #{port_path}; make -V #{variable}"
|
|
70
|
+
status = popen4(command) do |pid, stdin, stdout, stderr|
|
|
71
|
+
return stdout.readline.strip
|
|
72
|
+
end
|
|
73
|
+
unless status.exitstatus == 0 || status.exitstatus == 1
|
|
74
|
+
raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}!"
|
|
75
|
+
end
|
|
76
|
+
nil
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def ports_candidate_version
|
|
80
|
+
ports_makefile_variable_value("PORTVERSION")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def load_current_resource
|
|
84
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
|
85
|
+
@current_resource.package_name(@new_resource.package_name)
|
|
86
|
+
|
|
87
|
+
@current_resource.version(current_installed_version)
|
|
88
|
+
Chef::Log.debug("Current version is #{@current_resource.version}") if @current_resource.version
|
|
89
|
+
|
|
90
|
+
@candidate_version = ports_candidate_version
|
|
91
|
+
Chef::Log.debug("Ports candidate version is #{@candidate_version}") if @candidate_version
|
|
92
|
+
|
|
93
|
+
@current_resource
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def latest_link_name
|
|
97
|
+
ports_makefile_variable_value("LATEST_LINK")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# The name of the package (without the version number) as understood by pkg_add and pkg_info
|
|
101
|
+
def package_name
|
|
102
|
+
if ports_makefile_variable_value("PKGNAME") =~ /^(.+)-[^-]+$/
|
|
103
|
+
$1
|
|
104
|
+
else
|
|
105
|
+
raise Chef::Exception::Package, "Unexpected form for PKGNAME variable in #{port_path}/Makefile"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def install_package(name, version)
|
|
110
|
+
unless @current_resource.version
|
|
111
|
+
case @new_resource.source
|
|
112
|
+
when /^ports$/
|
|
113
|
+
run_command_with_systems_locale(
|
|
114
|
+
:command => "make -DBATCH install",
|
|
115
|
+
:cwd => "#{port_path}"
|
|
116
|
+
)
|
|
117
|
+
when /^http/, /^ftp/
|
|
118
|
+
run_command_with_systems_locale(
|
|
119
|
+
:command => "pkg_add -r #{package_name}",
|
|
120
|
+
:environment => { "PACKAGESITE" => @new_resource.source }
|
|
121
|
+
)
|
|
122
|
+
Chef::Log.info("Installed package #{package_name} from: #{@new_resource.source}")
|
|
123
|
+
when /^\//
|
|
124
|
+
run_command_with_systems_locale(
|
|
125
|
+
:command => "pkg_add #{@new_resource.name}",
|
|
126
|
+
:environment => { "PKG_PATH" => @new_resource.source }
|
|
127
|
+
)
|
|
128
|
+
Chef::Log.info("Installed package #{@new_resource.name} from: #{@new_resource.source}")
|
|
129
|
+
else
|
|
130
|
+
run_command_with_systems_locale(
|
|
131
|
+
:command => "pkg_add -r #{latest_link_name}"
|
|
132
|
+
)
|
|
133
|
+
Chef::Log.info("Installed package #{package_name}")
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def remove_package(name, version)
|
|
139
|
+
# a version is mandatory
|
|
140
|
+
if version
|
|
141
|
+
run_command_with_systems_locale(
|
|
142
|
+
:command => "pkg_delete #{package_name}-#{version}"
|
|
143
|
+
)
|
|
144
|
+
else
|
|
145
|
+
run_command_with_systems_locale(
|
|
146
|
+
:command => "pkg_delete #{package_name}-#{@current_resource.version}"
|
|
147
|
+
)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|