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,160 @@
|
|
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/mixin/command'
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/file_cache'
|
22
|
+
require 'chef/resource/remote_file'
|
23
|
+
require 'chef/platform'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Provider
|
27
|
+
class Package < Chef::Provider
|
28
|
+
|
29
|
+
include Chef::Mixin::Command
|
30
|
+
|
31
|
+
attr_accessor :candidate_version
|
32
|
+
|
33
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
34
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
35
|
+
@candidate_version = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def action_install
|
39
|
+
# If we specified a version, and it's not the current version, move to the specified version
|
40
|
+
if @new_resource.version != nil && @new_resource.version != @current_resource.version
|
41
|
+
install_version = @new_resource.version
|
42
|
+
# If it's not installed at all, install it
|
43
|
+
elsif @current_resource.version == nil
|
44
|
+
install_version = candidate_version
|
45
|
+
else
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
unless install_version
|
50
|
+
raise(Chef::Exceptions::Package, "No version specified, and no candidate version available!")
|
51
|
+
end
|
52
|
+
|
53
|
+
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
|
54
|
+
|
55
|
+
# We need to make sure we handle the preseed file
|
56
|
+
if @new_resource.response_file
|
57
|
+
preseed_package(@new_resource.package_name, install_version)
|
58
|
+
end
|
59
|
+
|
60
|
+
status = install_package(@new_resource.package_name, install_version)
|
61
|
+
if status
|
62
|
+
@new_resource.updated = true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def action_upgrade
|
67
|
+
if @current_resource.version != candidate_version
|
68
|
+
orig_version = @current_resource.version || "uninstalled"
|
69
|
+
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
|
70
|
+
status = upgrade_package(@new_resource.package_name, candidate_version)
|
71
|
+
if status
|
72
|
+
@new_resource.updated = true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def action_remove
|
78
|
+
if should_remove_package(@current_resource.version, @new_resource.version)
|
79
|
+
Chef::Log.info("Removing #{@new_resource}")
|
80
|
+
remove_package(@current_resource.package_name, @new_resource.version)
|
81
|
+
@new_resource.updated = true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def should_remove_package(current_version, new_version)
|
86
|
+
to_remove_package = false
|
87
|
+
if current_version != nil
|
88
|
+
if new_version != nil
|
89
|
+
if new_version == current_version
|
90
|
+
to_remove_package = true
|
91
|
+
end
|
92
|
+
else
|
93
|
+
to_remove_package = true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
to_remove_package
|
97
|
+
end
|
98
|
+
|
99
|
+
def action_purge
|
100
|
+
if should_remove_package(@current_resource.version, @new_resource.version)
|
101
|
+
Chef::Log.info("Purging #{@new_resource}")
|
102
|
+
purge_package(@current_resource.package_name, @new_resource.version)
|
103
|
+
@new_resource.updated = true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def install_package(name, version)
|
108
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install"
|
109
|
+
end
|
110
|
+
|
111
|
+
def upgrade_package(name, version)
|
112
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :upgrade"
|
113
|
+
end
|
114
|
+
|
115
|
+
def remove_package(name, version)
|
116
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove"
|
117
|
+
end
|
118
|
+
|
119
|
+
def purge_package(name, version)
|
120
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :purge"
|
121
|
+
end
|
122
|
+
|
123
|
+
def preseed_package(name, version, preseed)
|
124
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support pre-seeding package install/upgrade instructions - don't ask it to!"
|
125
|
+
end
|
126
|
+
|
127
|
+
def get_preseed_file(name, version)
|
128
|
+
full_cache_dir = Chef::FileCache.create_cache_path("preseed/#{@new_resource.cookbook_name}")
|
129
|
+
full_cache_file = "#{full_cache_dir}/#{name}-#{version}.seed"
|
130
|
+
cache_path = "preseed/#{@new_resource.cookbook_name}/#{name}-#{version}.seed"
|
131
|
+
|
132
|
+
Chef::Log.debug("Fetching preseed file to #{cache_path}")
|
133
|
+
|
134
|
+
remote_file = Chef::Resource::RemoteFile.new(
|
135
|
+
full_cache_file,
|
136
|
+
nil,
|
137
|
+
@node
|
138
|
+
)
|
139
|
+
remote_file.cookbook_name = @new_resource.cookbook_name
|
140
|
+
remote_file.source(@new_resource.response_file)
|
141
|
+
remote_file.backup(false)
|
142
|
+
|
143
|
+
rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
|
144
|
+
rf_provider.load_current_resource
|
145
|
+
rf_provider.action_create
|
146
|
+
|
147
|
+
if remote_file.updated
|
148
|
+
Chef::FileCache.load(cache_path, false)
|
149
|
+
else
|
150
|
+
false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def expand_options(options)
|
155
|
+
options ? " #{options}" : ""
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -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,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
|