diff --git a/.gemfile b/.gemfile index c9713f0..45a6e84 100644 --- a/.gemfile +++ b/.gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['~> 3.2.0'] +puppetversion = ENV.key?('PUPPET_VERSION') ? "#{ENV['PUPPET_VERSION']}" : ['~> 3.7.0'] gem 'puppet', puppetversion diff --git a/.gitignore b/.gitignore index 008b417..d8fe4fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -/metadata.json /.project diff --git a/Modulefile b/Modulefile deleted file mode 100644 index ea4c0b0..0000000 --- a/Modulefile +++ /dev/null @@ -1,8 +0,0 @@ -name 'gini-archive' -version '0.2.0' -author 'Jochen Schalanda' -license 'Apache 2.0' -project_page 'https://github.com/gini/puppet-archive' -source 'https://github.com/gini/puppet-archive' -summary 'Puppet module to download and extract tar and zip archives' -description 'This module downloads archives (tar.{gz,bz2,xz} and zip) using curl and extracts them to a given directory.' diff --git a/manifests/extract.pp b/manifests/extract.pp index fec7335..ab6b674 100644 --- a/manifests/extract.pp +++ b/manifests/extract.pp @@ -32,20 +32,36 @@ $ensure = present, $src_target = '/usr/src', $root_dir = '', + $nested_dir = undef, $extension = 'tar.gz', $timeout = 120, $strip_components = 0, $exec_path = ['/usr/local/bin', '/usr/bin', '/bin']) { - if $root_dir != '' { - $extract_dir = "${target}/${root_dir}" - } else { - $extract_dir = "${target}/${name}" - } - case $ensure { present: { + if $extension != 'zip' and $nested_dir { + fail("Param nested_dir just allowed in combination with unzip") + } + + if $strip_components > 0 and $extension !~ /(tar.gz|tgz|tar.xz|txz|tar.bz2|tbz|tbz2)/ { + fail('Param strip_components just allowed in combination with tar') + } + + if $extension == 'zip' and $nested_dir { + $extract_dir = $target + $creates_dir = "${target}/${name}" + + } else { + if $root_dir != '' { + $extract_dir = "${target}/${root_dir}" + } else { + $extract_dir = "${target}/${name}" + } + $creates_dir = $extract_dir + } + $extract_zip = "unzip -o ${src_target}/${name}.${extension} -d ${extract_dir}" $extract_targz = "tar --no-same-owner --no-same-permissions --strip-components=${strip_components} -xzf ${src_target}/${name}.${extension} -C ${extract_dir}" $extract_tarxz = "tar --no-same-owner --no-same-permissions --strip-components=${strip_components} -xJf ${src_target}/${name}.${extension} -C ${extract_dir}" @@ -66,7 +82,7 @@ exec {"Unpack ${name}": command => $unpack_command, path => $exec_path, - creates => $extract_dir, + creates => $creates_dir, timeout => $timeout } } diff --git a/manifests/init.pp b/manifests/init.pp index 948011b..37a18f7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -20,7 +20,6 @@ # - *$username: set basic auth username # - *$password: set basic auth password # - *$proxy: HTTP proxy in the form of "hostname:port"; e.g. "myproxy:8080" -# - *$dependency_class: Puppet class which installs the required programs (curl, tar, unzip) # - *$exec_path: Path being searched for all Exec resources, default: ['/usr/local/bin', '/usr/bin', '/bin'] # # Example usage: @@ -48,6 +47,7 @@ $digest_type = 'md5', $timeout = 120, $root_dir = '', + $nested_dir = undef, $extension = 'tar.gz', $src_target = '/usr/src', $allow_insecure = false, @@ -56,9 +56,14 @@ $username = undef, $password = undef, $proxy = undef, - $dependency_class = Class['archive::prerequisites'], $exec_path = ['/usr/local/bin', '/usr/bin', '/bin']) { + # list of packages needed for download and extraction + $packages = [ 'curl', 'unzip', 'tar' ] + + # install additional packages if missing + ensure_packages($packages) + archive::download {"${name}.${extension}": ensure => $ensure, url => $url, @@ -73,7 +78,7 @@ username => $username, password => $password, proxy => $proxy, - require => $dependency_class, + require => Package[$packages], exec_path => $exec_path, } @@ -82,6 +87,7 @@ target => $target, src_target => $src_target, root_dir => $root_dir, + nested_dir => $nested_dir, extension => $extension, timeout => $timeout, strip_components => $strip_components, diff --git a/manifests/prerequisites.pp b/manifests/prerequisites.pp deleted file mode 100644 index e7ca18a..0000000 --- a/manifests/prerequisites.pp +++ /dev/null @@ -1,18 +0,0 @@ -# == Class: prerequisites -# -# Ensure any required dependencies for archive download and extraction are present. -# -# Parameters: -# -# None -# -class archive::prerequisites { - - # list of packages needed for download and extraction - $packages = [ 'curl', 'unzip', 'tar', ] - - # install additional packages if missing - package { $packages: - ensure => installed, - } -} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..ba8425b --- /dev/null +++ b/metadata.json @@ -0,0 +1,33 @@ +{ + "name": "gini-archive", + "version": "0.2.0", + "author": "Jochen Schalanda", + "summary": "Puppet module to download and extract tar and zip archives", + "license": "Apache 2.0", + "source": "https://github.com/gini/puppet-archive", + "project_page": "https://github.com/gini/puppet-archive", + "issues_url": "https://github.com/gini/puppet-archive/issues", + "tags": [ + "tar", "curl", "unzip", "download", "extract", "archive" + ], + "operatingsystem_support": [ + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "7.6" + ] + } + ], + "requirements": [ + { + "name": "puppet", + "version_requirement": "3.7" + } + ], + "dependencies": [ + { + "name": "puppetlabs-stdlib", + "version_requirement": ">= 4.0.0" + } + ] +}