Update cookbooks and add wordpress cookbook

This commit is contained in:
Greg Karékinian
2016-02-19 18:09:49 +01:00
parent 9ba973e3ac
commit 820b0ab3f8
606 changed files with 22421 additions and 14084 deletions

View File

@@ -1,234 +1,113 @@
# libs
require_relative 'platform_specific_builders'
require_relative 'resource_deprecations'
require_relative 'resource_defaults'
require_relative 'sevenzip_command_builder'
require_relative 'unzip_command_builder'
require_relative 'tar_command_builder'
require_relative 'general_owner'
require_relative 'windows_owner'
module Opscode
module Ark
module ProviderHelpers
private
module Ark
module ProviderHelpers
extend ::Ark::PlatformSpecificBuilders
def unpack_type
case parse_file_extension
when /tar.gz|tgz/ then "tar_xzf"
when /tar.bz2|tbz/ then "tar_xjf"
when /tar.xz|txz/ then "tar_xJf"
when /zip|war|jar/ then "unzip"
else fail "Don't know how to expand #{new_resource.url}"
end
end
generates_archive_commands_for :seven_zip,
when_the: -> { node['platform_family'] == 'windows' },
with_klass: ::Ark::SevenZipCommandBuilder
def parse_file_extension
if new_resource.extension.nil?
# purge any trailing redirect
url = new_resource.url.clone
url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip)(\/.*\/)}
url.gsub!(Regexp.last_match(2), '') unless Regexp.last_match(2).nil?
# remove tailing 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)(\?.*)?/
Chef::Log.debug("DEBUG: file_extension is #{Regexp.last_match(2)}")
new_resource.extension = Regexp.last_match(2)
end
new_resource.extension
end
generates_archive_commands_for :unzip,
when_the: -> { new_resource.extension =~ /zip|war|jar/ },
with_klass: ::Ark::UnzipCommandBuilder
def unpack_command
if node['platform_family'] === 'windows'
cmd = sevenzip_command
else
case unpack_type
when "tar_xzf"
cmd = tar_command("xzf")
when "tar_xjf"
cmd = tar_command("xjf")
when "tar_xJf"
cmd = tar_command("xJf")
when "unzip"
cmd = unzip_command
end
end
Chef::Log.debug("DEBUG: cmd: #{cmd}")
cmd
end
generates_archive_commands_for :tar,
when_the: -> { true },
with_klass: ::Ark::TarCommandBuilder
def tar_command(tar_args)
cmd = node['ark']['tar']
cmd += " #{tar_args} "
cmd += new_resource.release_file
cmd += tar_strip_args
cmd
end
generates_owner_commands_for :windows,
when_the: -> { node['platform_family'] == 'windows' },
with_klass: ::Ark::WindowsOwner
def unzip_command
if new_resource.strip_components > 0
require 'tmpdir'
tmpdir = Dir.mktmpdir
strip_dir = '*/' * new_resource.strip_components
cmd = "unzip -q -u -o #{new_resource.release_file} -d #{tmpdir}"
cmd += " && rsync -a #{tmpdir}/#{strip_dir} #{new_resource.path}"
cmd += " && rm -rf #{tmpdir}"
cmd
else
"unzip -q -u -o #{new_resource.release_file} -d #{new_resource.path}"
end
end
generates_owner_commands_for :all_other_platforms,
when_the: -> { true },
with_klass: ::Ark::GeneralOwner
def sevenzip_command
if new_resource.strip_components > 0
require 'tmpdir'
tmpdir = Dir.mktmpdir
cmd = sevenzip_command_builder(tmpdir,'e')
cmd += " && "
currdir = tmpdir
var = 0
while var < new_resource.strip_components do
var += 1
cmd += "for /f %#{var} in ('dir /ad /b \"#{currdir.gsub! '/', '\\'}\"') do "
currdir += "\\%#{var}"
end
cmd += "xcopy \"#{currdir}\" \"#{new_resource.home_dir}\" /s /e"
else
cmd = sevenzip_command_builder(new_resource.path,'x')
end
cmd
end
def deprecations
::Ark::ResourceDeprecations.on(new_resource)
end
def sevenzip_command_builder(dir, command)
cmd = "#{node['ark']['tar']} #{command} \"";
cmd += new_resource.release_file
cmd += "\" "
case parse_file_extension
when /tar.gz|tgz|tar.bz2|tbz|tar.xz|txz/
cmd += " -so | #{node['ark']['tar']} x -aoa -si -ttar"
end
cmd += " -o\"#{dir}\" -uy"
cmd
end
def show_deprecations
deprecations.each { |message| Chef::Log.warn("DEPRECATED: #{message}") }
end
def dump_command
if node['platform_family'] === 'windows'
cmd = sevenzip_command_builder(new_resource.path,'e')
else
case unpack_type
when "tar_xzf", "tar_xjf", "tar_xJf"
cmd = "tar -mxf \"#{new_resource.release_file}\" -C \"#{new_resource.path}\""
when "unzip"
cmd = "unzip -j -q -u -o \"#{new_resource.release_file}\" -d \"#{new_resource.path}\""
end
end
Chef::Log.debug("DEBUG: cmd: #{cmd}")
cmd
end
def defaults
@resource_defaults ||= ::Ark::ResourceDefaults.new(new_resource)
end
def cherry_pick_command
if node['platform_family'] === 'windows'
cmd = sevenzip_command_builder(new_resource.path,'e')
cmd += " -r #{new_resource.creates}"
else
case unpack_type
when "tar_xzf"
cmd = cherry_pick_tar_command("xzf")
when "tar_xjf"
cmd = cherry_pick_tar_command("xjf")
when "tar_xJf"
cmd = cherry_pick_tar_command("xJf")
when "unzip"
cmd = "unzip -t #{new_resource.release_file} \"*/#{new_resource.creates}\" ; stat=$? ;"
cmd += "if [ $stat -eq 11 ] ; then "
cmd += "unzip -j -o #{new_resource.release_file} \"#{new_resource.creates}\" -d #{new_resource.path} ;"
cmd += "elif [ $stat -ne 0 ] ; then false ;"
cmd += "else "
cmd += "unzip -j -o #{new_resource.release_file} \"*/#{new_resource.creates}\" -d #{new_resource.path} ;"
cmd += "fi"
end
end
Chef::Log.debug("DEBUG: cmd: #{cmd}")
cmd
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
def cherry_pick_tar_command(tar_args)
cmd = node['ark']['tar']
cmd += " #{tar_args}"
cmd += " #{new_resource.release_file}"
cmd += " -C"
cmd += " #{new_resource.path}"
cmd += " #{new_resource.creates}"
cmd += tar_strip_args
cmd
end
# TODO: what happens when the path is already set --
# with the current logic we overwrite it
# if you are in windows we overwrite it
# otherwise we overwrite it with the root/name-version
new_resource.path = defaults.path
new_resource.release_file = defaults.release_file
end
# rubocop:enable Metrics/AbcSize
def set_paths
release_ext = parse_file_extension
prefix_bin = new_resource.prefix_bin.nil? ? new_resource.run_context.node['ark']['prefix_bin'] : new_resource.prefix_bin
prefix_root = new_resource.prefix_root.nil? ? new_resource.run_context.node['ark']['prefix_root'] : new_resource.prefix_root
if new_resource.prefix_home.nil?
default_home_dir = ::File.join(new_resource.run_context.node['ark']['prefix_home'], new_resource.name)
else
default_home_dir = ::File.join(new_resource.prefix_home, new_resource.name)
end
# set effective paths
new_resource.prefix_bin = prefix_bin
new_resource.version ||= "1" # initialize to one if nil
new_resource.home_dir ||= default_home_dir
if node['platform_family'] === 'windows'
new_resource.path = new_resource.win_install_dir
else
new_resource.path = ::File.join(prefix_root, "#{new_resource.name}-#{new_resource.version}")
end
Chef::Log.debug("path is #{new_resource.path}")
new_resource.release_file = ::File.join(Chef::Config[:file_cache_path], "#{new_resource.name}-#{new_resource.version}.#{release_ext}")
end
def set_put_paths
new_resource.extension = defaults.extension
def set_put_paths
release_ext = parse_file_extension
path = new_resource.path.nil? ? new_resource.run_context.node['ark']['prefix_root'] : new_resource.path
new_resource.path = ::File.join(path, new_resource.name)
Chef::Log.debug("DEBUG: path is #{new_resource.path}")
new_resource.release_file = ::File.join(Chef::Config[:file_cache_path], "#{new_resource.name}.#{release_ext}")
end
# TODO: Should we be setting the prefix_root -
# as the prefix_root could be used in the path_with_version
# new_resource.prefix_root = default.prefix_root
new_resource.path = defaults.path_without_version
new_resource.release_file = defaults.release_file_without_version
end
def set_dump_paths
release_ext = parse_file_extension
new_resource.release_file = ::File.join(Chef::Config[:file_cache_path], "#{new_resource.name}.#{release_ext}")
end
def set_dump_paths
new_resource.extension = defaults.extension
new_resource.release_file = defaults.release_file_without_version
end
def tar_strip_args
new_resource.strip_components > 0 ? " --strip-components=#{new_resource.strip_components}" : ""
end
def unpack_command
archive_application.unpack
end
def show_deprecations
if [true, false].include?(new_resource.strip_leading_dir)
Chef::Log.warn("DEPRECATED: strip_leading_dir attribute was deprecated. Use strip_components instead.")
end
end
def dump_command
archive_application.dump
end
def owner_command
if node['platform_family'] === 'windows'
cmd = "icacls #{new_resource.path}\\* /setowner #{new_resource.owner}"
else
cmd = "chown -R #{new_resource.owner}:#{new_resource.group} #{new_resource.path}"
end
cmd
end
def cherry_pick_command
archive_application.cherry_pick
end
# def unpacked?(path)
# if new_resource.creates
# full_path = ::File.join(new_resource.path, new_resource.creates)
# else
# full_path = path
# end
# if ::File.directory? full_path
# if ::File.stat(full_path).nlink == 2
# false
# else
# true
# end
# elsif ::File.exists? full_path
# true
# else
# false
# end
# end
def unzip_command
archive_application.unpack
end
def owner_command
owner_builder_klass.new(new_resource).command
end
private
def archive_application
@archive_application ||= archive_builder_klass.new(new_resource)
end
def archive_builder_klass
new_resource.extension ||= defaults.extension
Ark::ProviderHelpers.archive_command_generators.find { |condition, _klass| instance_exec(&condition) }.last
end
def owner_builder_klass
Ark::ProviderHelpers.owner_command_generators.find { |condition, _klass| instance_exec(&condition) }.last
end
end
end

View File

@@ -0,0 +1,13 @@
module Ark
class GeneralOwner
def initialize(resource)
@resource = resource
end
attr_reader :resource
def command
"chown -R #{resource.owner}:#{resource.group} #{resource.path}"
end
end
end

View File

@@ -0,0 +1,42 @@
if defined?(ChefSpec)
def install_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :install, resource_name)
end
def dump_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :dump, resource_name)
end
def cherry_pick_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :cherry_pick, resource_name)
end
def put_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :put, resource_name)
end
def install_with_make_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :install_with_make, resource_name)
end
def configure_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :configure, resource_name)
end
def setup_py_build_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :setup_py_build, resource_name)
end
def setup_py_install_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :setup_py_install, resource_name)
end
def setup_py_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :setup_py, resource_name)
end
def unzip_ark(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:ark, :unzip, resource_name)
end
end

View File

@@ -0,0 +1,23 @@
module Ark
module PlatformSpecificBuilders
def generates_archive_commands_for(_name, options)
condition = options[:when_the]
builder = options[:with_klass]
archive_command_generators.push [condition, builder]
end
def archive_command_generators
@archive_command_generators ||= []
end
def generates_owner_commands_for(_name, options)
condition = options[:when_the]
builder = options[:with_klass]
owner_command_generators.push [condition, builder]
end
def owner_command_generators
@owner_command_generators ||= []
end
end
end

View File

@@ -0,0 +1,100 @@
module Ark
class ResourceDefaults
def extension
resource.extension || generate_extension_from_url(resource.url.clone)
end
def prefix_bin
resource.prefix_bin || prefix_bin_from_node_in_run_context
end
def prefix_root
resource.prefix_root || prefix_root_from_node_in_run_context
end
def home_dir
if resource.home_dir.nil? || resource.home_dir.empty?
prefix_home = resource.prefix_home || prefix_home_from_node_in_run_context
::File.join(prefix_home, resource.name)
else
resource.home_dir
end
end
def version
resource.version || default_version
end
def path
if windows?
resource.win_install_dir
else
::File.join(resource.prefix_root, "#{resource.name}-#{resource.version}")
end
end
def windows?
node_in_run_context['platform_family'] == 'windows'
end
def path_without_version
partial_path = resource.path || prefix_root_from_node_in_run_context
::File.join(partial_path, resource.name)
end
def release_file
release_filename = "#{resource.name}-#{resource.version}.#{resource.extension}"
::File.join(file_cache_path, release_filename)
end
def release_file_without_version
release_filename = "#{resource.name}.#{resource.extension}"
::File.join(file_cache_path, release_filename)
end
def initialize(resource)
@resource = resource
end
private
attr_reader :resource
def generate_extension_from_url(url)
# purge any trailing redirect
url =~ %r{^https?:\/\/.*(.bin|bz2|gz|jar|tbz|tgz|txz|war|xz|zip)(\/.*\/)}
url.gsub!(Regexp.last_match(2), '') unless Regexp.last_match(2).nil?
# remove tailing 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)(\?.*)?/
Chef::Log.debug("DEBUG: file_extension is #{Regexp.last_match(2)}")
Regexp.last_match(2)
end
def prefix_bin_from_node_in_run_context
node_in_run_context['ark']['prefix_bin']
end
def prefix_root_from_node_in_run_context
node_in_run_context['ark']['prefix_root']
end
def prefix_home_from_node_in_run_context
node_in_run_context['ark']['prefix_home']
end
def default_version
"1"
end
def file_cache_path
Chef::Config[:file_cache_path]
end
def node_in_run_context
resource.run_context.node
end
end
end

View File

@@ -0,0 +1,33 @@
module Ark
class ResourceDeprecations
def self.on(resource)
new(resource).warnings
end
def initialize(resource)
@resource = resource
end
attr_reader :resource
def warnings
applicable_deprecrations.map { |_, message| message }
end
def applicable_deprecrations
deprecations.select { |condition, _| send(condition) }
end
def deprecations
{ strip_leading_dir_feature: strip_leading_dir_feature_message }
end
def strip_leading_dir_feature
[true, false].include?(resource.strip_leading_dir)
end
def strip_leading_dir_feature_message
"strip_leading_dir attribute was deprecated. Use strip_components instead."
end
end
end

View File

@@ -0,0 +1,66 @@
module Ark
class SevenZipCommandBuilder
def unpack
sevenzip_command
end
def dump
sevenzip_command_builder(resource.path, 'e')
end
def cherry_pick
"#{sevenzip_command_builder(resource.path, 'e')} -r #{resource.creates}"
end
def initialize(resource)
@resource = resource
end
private
attr_reader :resource
# rubocop:disable Metrics/AbcSize
def sevenzip_command
if resource.strip_components <= 0
sevenzip_command_builder(resource.path, 'x')
return
end
tmpdir = make_temp_directory
cmd = sevenzip_command_builder(tmpdir, 'e')
cmd += " && "
currdir = tmpdir.tr('/', '\\')
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"
end
# rubocop:enable Metrics/AbcSize
def sevenzip_binary
resource.run_context.node['ark']['tar']
end
def sevenzip_command_builder(dir, command)
"#{sevenzip_binary} #{command} \"#{resource.release_file}\"#{extension_is_tar} -o\"#{dir}\" -uy"
end
def extension_is_tar
if resource.extension =~ /tar.gz|tgz|tar.bz2|tbz|tar.xz|txz/
" -so | #{sevenzip_binary} x -aoa -si -ttar"
else
""
end
end
def make_temp_directory
require 'tmpdir'
Dir.mktmpdir
end
end
end

View File

@@ -0,0 +1,49 @@
module Ark
class TarCommandBuilder
def unpack
"#{tar_binary} #{args} #{resource.release_file}#{strip_args}"
end
def dump
"tar -mxf \"#{resource.release_file}\" -C \"#{resource.path}\""
end
def cherry_pick
"#{tar_binary} #{args} #{resource.release_file} -C #{resource.path} #{resource.creates}#{strip_args}"
end
def initialize(resource)
@resource = resource
end
private
attr_reader :resource
def node
resource.run_context.node
end
def tar_binary
resource.run_context.node['ark']['tar']
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"
else raise unsupported_extension
end
end
def strip_args
resource.strip_components > 0 ? " --strip-components=#{resource.strip_components}" : ""
end
def unsupported_extension
"Don't know how to expand #{resource.url} (extension: #{resource.extension})"
end
end
end

View File

@@ -0,0 +1,50 @@
module Ark
class UnzipCommandBuilder
def unpack
if resource.strip_components > 0
unzip_with_strip_components
else
"unzip -q -o #{resource.release_file} -d #{resource.path}"
end
end
def dump
"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 += "unzip -j -o #{resource.release_file} \"#{resource.creates}\" -d #{resource.path} ;"
cmd += "elif [ $stat -ne 0 ] ; then false ;"
cmd += "else "
cmd += "unzip -j -o #{resource.release_file} \"*/#{resource.creates}\" -d #{resource.path} ;"
cmd += "fi"
cmd
end
# rubocop:enable Metrics/AbcSize
def initialize(resource)
@resource = resource
end
private
attr_reader :resource
def unzip_with_strip_components
tmpdir = make_temp_directory
strip_dir = '*/' * resource.strip_components
cmd = "unzip -q -o #{resource.release_file} -d #{tmpdir}"
cmd += " && rsync -a #{tmpdir}/#{strip_dir} #{resource.path}"
cmd += " && rm -rf #{tmpdir}"
cmd
end
def make_temp_directory
require 'tmpdir'
Dir.mktmpdir
end
end
end

View File

@@ -0,0 +1,13 @@
module Ark
class WindowsOwner
def initialize(resource)
@resource = resource
end
attr_reader :resource
def command
"icacls \"#{resource.path}\\*\" /setowner \"#{resource.owner}\""
end
end
end