Update ark cookbook
This commit is contained in:
@@ -43,13 +43,13 @@ module Ark
|
||||
@resource_defaults ||= ::Ark::ResourceDefaults.new(new_resource)
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def set_paths
|
||||
new_resource.extension = defaults.extension
|
||||
new_resource.prefix_bin = defaults.prefix_bin
|
||||
new_resource.prefix_root = defaults.prefix_root
|
||||
new_resource.home_dir = defaults.home_dir
|
||||
new_resource.version = defaults.version
|
||||
new_resource.owner = defaults.owner
|
||||
|
||||
# TODO: what happens when the path is already set --
|
||||
# with the current logic we overwrite it
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
if defined?(ChefSpec)
|
||||
ChefSpec.define_matcher :ark
|
||||
|
||||
def install_ark(resource_name)
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:ark, :install, resource_name)
|
||||
end
|
||||
|
||||
@@ -33,6 +33,10 @@ module Ark
|
||||
end
|
||||
end
|
||||
|
||||
def owner
|
||||
resource.owner || default_owner
|
||||
end
|
||||
|
||||
def windows?
|
||||
node_in_run_context['platform_family'] == 'windows'
|
||||
end
|
||||
@@ -62,13 +66,13 @@ module Ark
|
||||
|
||||
def generate_extension_from_url(url)
|
||||
# purge any trailing redirect
|
||||
url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip)(\/.*\/)}
|
||||
url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip|7z)(\/.*\/)}
|
||||
url.gsub!(Regexp.last_match(2), '') unless Regexp.last_match(2).nil?
|
||||
# remove tailing query string
|
||||
# remove trailing query string
|
||||
release_basename = ::File.basename(url.gsub(/\?.*\z/, '')).gsub(/-bin\b/, '')
|
||||
# (\?.*)? accounts for a trailing querystring
|
||||
Chef::Log.debug("DEBUG: release_basename is #{release_basename}")
|
||||
release_basename =~ /^(.+?)\.(jar|tar\.bz2|tar\.gz|tar\.xz|tbz|tgz|txz|war|zip|tar)(\?.*)?/
|
||||
release_basename =~ /^(.+?)\.(jar|tar\.bz2|tar\.gz|tar\.xz|tbz|tgz|txz|war|zip|tar|7z)(\?.*)?/
|
||||
Chef::Log.debug("DEBUG: file_extension is #{Regexp.last_match(2)}")
|
||||
Regexp.last_match(2)
|
||||
end
|
||||
@@ -86,7 +90,22 @@ module Ark
|
||||
end
|
||||
|
||||
def default_version
|
||||
"1"
|
||||
'1'
|
||||
end
|
||||
|
||||
def default_owner
|
||||
if windows?
|
||||
wmi_property_from_query(:name, "select * from Win32_UserAccount where sid like 'S-1-5-21-%-500' and LocalAccount=True")
|
||||
else
|
||||
'root'
|
||||
end
|
||||
end
|
||||
|
||||
def wmi_property_from_query(wmi_property, wmi_query)
|
||||
@wmi = ::WIN32OLE.connect('winmgmts://')
|
||||
result = @wmi.ExecQuery(wmi_query)
|
||||
return nil unless result.each.count > 0
|
||||
result.each.next.send(wmi_property)
|
||||
end
|
||||
|
||||
def file_cache_path
|
||||
|
||||
@@ -27,7 +27,7 @@ module Ark
|
||||
end
|
||||
|
||||
def strip_leading_dir_feature_message
|
||||
"strip_leading_dir attribute was deprecated. Use strip_components instead."
|
||||
'strip_leading_dir attribute was deprecated. Use strip_components instead.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ module Ark
|
||||
end
|
||||
|
||||
def cherry_pick
|
||||
"#{sevenzip_command_builder(resource.path, 'e')} -r #{resource.creates}"
|
||||
"#{sevenzip_command_builder(resource.path, 'x')} -r #{resource.creates}"
|
||||
end
|
||||
|
||||
def initialize(resource)
|
||||
@@ -20,30 +20,42 @@ module Ark
|
||||
|
||||
attr_reader :resource
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def node
|
||||
resource.run_context.node
|
||||
end
|
||||
|
||||
def sevenzip_command
|
||||
if resource.strip_components <= 0
|
||||
sevenzip_command_builder(resource.path, 'x')
|
||||
return
|
||||
return sevenzip_command_builder(resource.path, 'x')
|
||||
end
|
||||
|
||||
tmpdir = make_temp_directory
|
||||
cmd = sevenzip_command_builder(tmpdir, 'e')
|
||||
tmpdir = make_temp_directory.tr('/', '\\')
|
||||
cmd = sevenzip_command_builder(tmpdir, 'x')
|
||||
|
||||
cmd += " && "
|
||||
currdir = tmpdir.tr('/', '\\')
|
||||
cmd += ' && '
|
||||
currdir = tmpdir
|
||||
|
||||
1.upto(resource.strip_components).each do |count|
|
||||
cmd += "for /f %#{count} in ('dir /ad /b \"#{currdir}\"') do "
|
||||
currdir += "\\%#{count}"
|
||||
end
|
||||
|
||||
cmd += "xcopy \"#{currdir}\" \"#{resource.home_dir}\" /s /e"
|
||||
cmd += "(\"#{ENV.fetch('SystemRoot')}\\System32\\robocopy\" \"#{currdir}\" \"#{resource.path}\" /s /e) ^& IF %ERRORLEVEL% LEQ 3 cmd /c exit 0"
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def sevenzip_binary
|
||||
resource.run_context.node['ark']['tar']
|
||||
@tar_binary ||= "\"#{(node['ark']['sevenzip_binary'] || sevenzip_path_from_registry)}\""
|
||||
end
|
||||
|
||||
def sevenzip_path_from_registry
|
||||
begin
|
||||
basepath = ::Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe').read_s('Path')
|
||||
|
||||
# users like pretty errors
|
||||
rescue ::Win32::Registry::Error
|
||||
raise 'Failed to find the path of 7zip binary by searching checking HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\7zFM.exe\Path. Make sure to install 7zip before using this resource. If 7zip is installed and you still receive this message you can also specify the 7zip binary path by setting node["ark"]["sevenzip_binary"]'
|
||||
end
|
||||
"#{basepath}7z.exe"
|
||||
end
|
||||
|
||||
def sevenzip_command_builder(dir, command)
|
||||
@@ -54,7 +66,7 @@ module Ark
|
||||
if resource.extension =~ /tar.gz|tgz|tar.bz2|tbz|tar.xz|txz/
|
||||
" -so | #{sevenzip_binary} x -aoa -si -ttar"
|
||||
else
|
||||
""
|
||||
' -aoa' # force overwrite, Fixes #164
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -25,21 +25,28 @@ module Ark
|
||||
end
|
||||
|
||||
def tar_binary
|
||||
resource.run_context.node['ark']['tar']
|
||||
@tar_binary ||= node['ark']['tar'] || case node['platform_family']
|
||||
when 'mac_os_x', 'freebsd'
|
||||
'/usr/bin/tar'
|
||||
when 'smartos'
|
||||
'/bin/gtar'
|
||||
else
|
||||
'/bin/tar'
|
||||
end
|
||||
end
|
||||
|
||||
def args
|
||||
case resource.extension
|
||||
when /^(tar)$/ then "xf"
|
||||
when /^(tar.gz|tgz)$/ then "xzf"
|
||||
when /^(tar.bz2|tbz)$/ then "xjf"
|
||||
when /^(tar.xz|txz)$/ then "xJf"
|
||||
when /^(tar)$/ then 'xf'
|
||||
when /^(tar.gz|tgz)$/ then 'xzf'
|
||||
when /^(tar.bz2|tbz)$/ then 'xjf'
|
||||
when /^(tar.xz|txz)$/ then 'xJf'
|
||||
else raise unsupported_extension
|
||||
end
|
||||
end
|
||||
|
||||
def strip_args
|
||||
resource.strip_components > 0 ? " --strip-components=#{resource.strip_components}" : ""
|
||||
resource.strip_components > 0 ? " --strip-components=#{resource.strip_components}" : ''
|
||||
end
|
||||
|
||||
def unsupported_extension
|
||||
|
||||
@@ -12,18 +12,16 @@ module Ark
|
||||
"unzip -j -q -o \"#{resource.release_file}\" -d \"#{resource.path}\""
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def cherry_pick
|
||||
cmd = "unzip -t #{resource.release_file} \"*/#{resource.creates}\" ; stat=$? ;"
|
||||
cmd += "if [ $stat -eq 11 ] ; then "
|
||||
cmd += 'if [ $stat -eq 11 ] ; then '
|
||||
cmd += "unzip -j -o #{resource.release_file} \"#{resource.creates}\" -d #{resource.path} ;"
|
||||
cmd += "elif [ $stat -ne 0 ] ; then false ;"
|
||||
cmd += "else "
|
||||
cmd += 'elif [ $stat -ne 0 ] ; then false ;'
|
||||
cmd += 'else '
|
||||
cmd += "unzip -j -o #{resource.release_file} \"*/#{resource.creates}\" -d #{resource.path} ;"
|
||||
cmd += "fi"
|
||||
cmd += 'fi'
|
||||
cmd
|
||||
end
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def initialize(resource)
|
||||
@resource = resource
|
||||
|
||||
@@ -7,7 +7,7 @@ module Ark
|
||||
attr_reader :resource
|
||||
|
||||
def command
|
||||
"icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\""
|
||||
"#{ENV.fetch('SystemRoot')}\\System32\\icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user