class PoiseArchive::ArchiveProviders::GnuTar

The `gnu_tar` provider class for `poise_archive` to install from TAR archives using GNU's tar executable.

@see PoiseArchive::Resources::PoiseArchive::Resource @provides poise_archive

Public Class Methods

provides?(node, _resource) click to toggle source

Only use this if we are on Linux. Everyone else gets the slow Ruby code.

@api private

# File lib/poise_archive/archive_providers/gnu_tar.rb, line 36
def self.provides?(node, _resource)
  super && node['os'] == 'linux'
end

Private Instance Methods

install_prereqs() click to toggle source

Install any needed prereqs.

@return [void]

# File lib/poise_archive/archive_providers/gnu_tar.rb, line 52
def install_prereqs
  utils = ['tar']
  utils << 'bzip2' if new_resource.absolute_path =~ /\.t?bz/
  if new_resource.absolute_path =~ /\.t?xz/
    xz_package = node.value_for_platform_family(
      debian: 'xz-utils',
      rhel: 'xz',
    )
    utils << xz_package if xz_package
  end
  # This is a resource.
  package utils
end
unpack_archive() click to toggle source
# File lib/poise_archive/archive_providers/gnu_tar.rb, line 42
def unpack_archive
  notifying_block do
    install_prereqs
  end
  unpack_tar
end
unpack_tar() click to toggle source

Unpack the archive and process `strip_components`.

@return [void]

# File lib/poise_archive/archive_providers/gnu_tar.rb, line 69
def unpack_tar
  # Build the tar command.
  cmd = %w{tar}
  cmd << "--strip-components=#{new_resource.strip_components}" if new_resource.strip_components && new_resource.strip_components > 0
  cmd << if new_resource.absolute_path =~ /\.t?gz/
    '-xzvf'
  elsif new_resource.absolute_path =~ /\.t?bz/
    '-xjvf'
  elsif new_resource.absolute_path =~ /\.t?xz/
    '-xJvf'
  else
    '-xvf'
  end
  cmd << new_resource.absolute_path
  poise_shell_out!(cmd, cwd: new_resource.destination, group: new_resource.group, user: new_resource.user)
end