1 poldek package manager support
3 https://github.com/chef/chef/pull/7482
5 diff --git a/lib/chef/provider/package/poldek.rb b/lib/chef/provider/package/poldek.rb
7 index 000000000..a4d17ba67
9 +++ b/lib/chef/provider/package/poldek.rb
12 +# Author:: Elan Ruusamäe (glen@pld-linux.org)
13 +# Copyright:: Copyright (c) 2013,2018 Elan Ruusamäe
14 +# License:: Apache License, Version 2.0
16 +# Licensed under the Apache License, Version 2.0 (the "License");
17 +# you may not use this file except in compliance with the License.
18 +# You may obtain a copy of the License at
20 +# http://www.apache.org/licenses/LICENSE-2.0
22 +# Unless required by applicable law or agreed to in writing, software
23 +# distributed under the License is distributed on an "AS IS" BASIS,
24 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 +# See the License for the specific language governing permissions and
26 +# limitations under the License.
30 +require 'chef/provider/package'
31 +require 'chef/mixin/shell_out'
32 +require 'chef/resource/package'
37 + class Poldek < Chef::Provider::Package
38 + include Chef::Mixin::ShellOut
41 + use_multipackage_api
43 + provides :package, platform_family: "pld"
45 + def load_current_resource
46 + logger.debug("#{new_resource} loading current resource")
47 + @current_resource = Chef::Resource::Package.new(new_resource.name)
48 + current_resource.package_name(new_resource.package_name)
49 + current_resource.version(get_current_versions)
53 + def candidate_version
54 + @candidate_version ||= get_candidate_versions
57 + def get_current_versions
58 + names = package_name_array
59 + logger.debug("#{new_resource} checking current version: #{names}")
61 + # rpm works as expected: output is returned in order as input given, even duplicates
62 + cmd = rpm("-q", "--qf", "%{NAME} %{VERSION}\n", names)
63 + versions_from_name_list(cmd.stdout, names)
66 + def get_candidate_versions
67 + names = package_name_array
68 + logger.debug("#{new_resource} check candidate version");
72 + # poldek works unexpectedly: packages that don't exist are printed as errors first, and names are de-duplicated
73 + cmd = poldek(%w{--uniq --skip-installed} + options.to_a + ["--cmd", "ls --qf '%{NAME} %{VERSION}\n'", names])
74 + versions_from_name_list(cmd.stdout, names)
77 + def install_package(names, versions)
78 + logger.trace("#{new_resource} installing package #{names} version #{versions}")
80 + poldek(options, "-u", names)
83 + def upgrade_package(names, versions)
84 + logger.trace("#{new_resource} upgrading package #{names} version #{versions}")
85 + install_package(names, versions)
88 + def remove_package(names, versions)
89 + logger.trace("#{new_resource} removing package #{names} version #{versions}")
90 + poldek(options, "-e", names)
94 + @@updated = Hash.new
96 + def update_indexes()
97 + checksum = Digest::MD5.hexdigest(opts).to_s
99 + if @@updated[checksum]
103 + logger.debug("#{@new_resource} updating package indexe")
104 + poldek("--up", options, :env => nil)
105 + @@updated[checksum] = true
109 + expand_options(options)
112 + def versions_from_name_list(input, names)
113 + packages = extract_packages(input)
114 + versions = match_versions(names, packages)
118 + def extract_packages(output)
120 + output.each_line do |line|
122 + when /^package (.+) is not installed$/
123 + when /(.+): no such package or directory$/
124 + when /^(.+?) (.+)$/
131 + def match_versions(names, packages)
132 + names.map do |name|
138 + shell_out_compact_timeout!("rpm", *args, env: nil, returns: [0, 1])
142 + shell_out_compact_timeout!(%w{poldek -q --noask}, *args, env: nil, returns: [0, 1, 255])
148 diff --git a/lib/chef/providers.rb b/lib/chef/providers.rb
149 index cd265b061..075ffd7e8 100644
150 --- a/lib/chef/providers.rb
151 +++ b/lib/chef/providers.rb
152 @@ -74,6 +74,7 @@ require "chef/provider/package/macports"
153 require "chef/provider/package/openbsd"
154 require "chef/provider/package/pacman"
155 require "chef/provider/package/portage"
156 +require 'chef/provider/package/poldek'
157 require "chef/provider/package/paludis"
158 require "chef/provider/package/rpm"
159 require "chef/provider/package/rubygems"
160 diff --git a/lib/chef/resource/poldek_package.rb b/lib/chef/resource/poldek_package.rb
162 index 000000000..4db9aa824
164 +++ b/lib/chef/resource/poldek_package.rb
167 +# Author:: Elan Ruusamäe (glen@pld-linux.org)
168 +# Copyright:: Copyright (c) 2013,2018 Elan Ruusamäe
169 +# License:: Apache License, Version 2.0
171 +# Licensed under the Apache License, Version 2.0 (the "License");
172 +# you may not use this file except in compliance with the License.
173 +# You may obtain a copy of the License at
175 +# http://www.apache.org/licenses/LICENSE-2.0
177 +# Unless required by applicable law or agreed to in writing, software
178 +# distributed under the License is distributed on an "AS IS" BASIS,
179 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180 +# See the License for the specific language governing permissions and
181 +# limitations under the License.
184 +require 'chef/resource/package'
185 +require 'chef/provider/package/poldek'
189 + class PoldekPackage < Chef::Resource::Package
190 + extend Chef::Mixin::Which
192 + resource_name :poldek_package
194 + provides :package do
198 + provides :poldek_package
200 + description "Use the poldek_package resource to install, upgrade, and remove packages with poldek."
203 + allowed_actions :install, :upgrade, :remove