Update golang cookbook
This commit is contained in:
@@ -1,29 +1,92 @@
|
||||
#
|
||||
# Author:: Shawn Neal (<sneal@sneal.net>)
|
||||
# Cookbook:: seven_zip
|
||||
# Resource:: archive
|
||||
#
|
||||
# Copyright:: 2013-2017, Daptiv Solutions LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
unified_mode true
|
||||
|
||||
default_action :extract
|
||||
property :path,
|
||||
String,
|
||||
name_property: true,
|
||||
description: 'Path to extract the archive.'
|
||||
|
||||
actions :extract
|
||||
property :source,
|
||||
String,
|
||||
description: 'Source archive location.'
|
||||
|
||||
attribute :path, kind_of: String, name_attribute: true
|
||||
attribute :source, kind_of: String
|
||||
attribute :overwrite, kind_of: [TrueClass, FalseClass], default: false
|
||||
attribute :checksum, kind_of: String
|
||||
attribute :timeout, kind_of: Integer
|
||||
property :overwrite,
|
||||
[true, false],
|
||||
default: false,
|
||||
description: 'Whether to overwrite the destination files.'
|
||||
|
||||
property :checksum,
|
||||
String,
|
||||
description: 'The checksum for the downloaded file.'
|
||||
|
||||
property :timeout,
|
||||
Integer,
|
||||
default: 600,
|
||||
description: 'Extract timeout in seconds.'
|
||||
|
||||
action :extract do
|
||||
directory new_resource.path
|
||||
|
||||
local_source = cached_file(new_resource.source, new_resource.checksum)
|
||||
|
||||
overwrite_file = new_resource.overwrite ? ' -y' : ' -aos'
|
||||
|
||||
cmd = "\"#{seven_zip_exe}\" x"
|
||||
cmd << overwrite_file
|
||||
cmd << " -o\"#{Chef::Util::PathHelper.cleanpath(new_resource.path)}\""
|
||||
cmd << " \"#{local_source}\""
|
||||
|
||||
Chef::Log.debug(cmd)
|
||||
|
||||
execute "extracting #{new_resource.source}" do
|
||||
command cmd
|
||||
timeout new_resource.timeout
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
# require 'chef/mixin/shell_out'
|
||||
# include Chef::Mixin::ShellOut
|
||||
|
||||
def seven_zip_exe
|
||||
path = seven_zip_exe_from_registry
|
||||
Chef::Log.debug("Using 7-zip home: #{path}")
|
||||
Chef::Util::PathHelper.cleanpath(::File.join(path, '7z.exe'))
|
||||
end
|
||||
|
||||
def seven_zip_exe_from_registry
|
||||
require 'win32/registry'
|
||||
# Read path from recommended Windows App Paths registry location
|
||||
# docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
|
||||
::Win32::Registry::HKEY_LOCAL_MACHINE.open(
|
||||
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe',
|
||||
::Win32::Registry::KEY_READ
|
||||
).read_s('Path')
|
||||
end
|
||||
|
||||
# if a file is local it returns a windows friendly path version
|
||||
# if a file is remote it caches it locally
|
||||
def cached_file(source, checksum = nil)
|
||||
if source =~ %r{^(file|ftp|http|https):\/\/}
|
||||
uri = as_uri(source)
|
||||
cache_file_path = "#{Chef::Config[:file_cache_path]}/#{::File.basename(::CGI.unescape(uri.path))}"
|
||||
Chef::Log.debug("Caching a copy of file #{source} at #{cache_file_path}")
|
||||
|
||||
remote_file cache_file_path do
|
||||
source source
|
||||
backup false
|
||||
checksum checksum unless checksum.nil?
|
||||
end
|
||||
else
|
||||
cache_file_path = source
|
||||
end
|
||||
|
||||
Chef::Util::PathHelper.cleanpath(cache_file_path)
|
||||
end
|
||||
|
||||
def as_uri(source)
|
||||
URI.parse(source)
|
||||
rescue URI::InvalidURIError
|
||||
Chef::Log.warn("#{source} was an invalid URI. Trying to escape invalid characters")
|
||||
URI.parse(URI.escape(source))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
#
|
||||
# Author:: Annih (<b.courtois@criteo.com>)
|
||||
# Cookbook:: seven_zip
|
||||
# Resource:: tool
|
||||
#
|
||||
# Copyright:: 2018, Baptiste Courtois
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
property :package, ::String, default: lazy { node['seven_zip']['package_name'] }
|
||||
property :source, ::String, default: lazy { node['seven_zip']['url'] }
|
||||
property :checksum, [::NilClass, ::String], default: lazy { node['seven_zip']['checksum'] }
|
||||
property :path, [::NilClass, ::String], default: lazy { node['seven_zip']['home'] }
|
||||
unified_mode true
|
||||
|
||||
property :package,
|
||||
String,
|
||||
description: 'Name of the package to install.',
|
||||
default: node['kernel']['machine'] == 'x86_64' ? '7-Zip 19.00 (x64 edition)' : '7-Zip 19.00'
|
||||
|
||||
property :source,
|
||||
String,
|
||||
description: 'Source URL of the package to install.',
|
||||
default: node['kernel']['machine'] == 'x86_64' ? 'https://www.7-zip.org/a/7z1900-x64.msi' : 'https://www.7-zip.org/a/7z1900.msi'
|
||||
|
||||
property :checksum,
|
||||
String,
|
||||
description: 'Checksum for the downloaded pacakge.',
|
||||
default: node['kernel']['machine'] == 'x86_64' ? 'a7803233eedb6a4b59b3024ccf9292a6fffb94507dc998aa67c5b745d197a5dc' : 'b49d55a52bc0eab14947c8982c413d9be141c337da1368a24aa0484cbb5e89cd'
|
||||
|
||||
property :path,
|
||||
String,
|
||||
description: 'Optional: path to install 7zip to.'
|
||||
|
||||
action :install do
|
||||
windows_package new_resource.package do
|
||||
@@ -38,6 +35,12 @@ action :add_to_path do
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
windows_package new_resource.package do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
REG_PATH = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe'.freeze
|
||||
|
||||
|
||||
Reference in New Issue
Block a user