Added util::extract::tar.

This commit is contained in:
Ossi Salmi 2010-10-26 11:47:11 +03:00 committed by Timo Mkinen
parent 543c4db28c
commit 365483adff

42
util/manifests/init.pp Normal file
View file

@ -0,0 +1,42 @@
# Extract tar package.
#
# === Parameters
#
# $name:
# Destination directory.
# $source:
# File to extract.
# $strip:
# Remove the specified number of leading path elements.
# Defaults to 0.
#
# === Sample usage
#
#util::extract::tar { "/usr/local/src/moin-1.8.8":
# strip => 1,
# source => "/usr/local/src/moin-1.8.8.tar.gz",
#}
#
define util::extract::tar($source, $strip=0) {
file { "${name}":
ensure => directory,
mode => 0755,
owner => root,
group => root,
}
case regsubst($source, '.*\.([^.]+)$', '\1') {
tar: { $cat = "cat" }
gz,tgz: { $cat = "zcat" }
bz2, tbz: { $cat = "bzcat" }
}
exec { "extract-tar-${name}":
path => "/bin:/usr/bin:/sbin:/usr/sbin",
command => "${cat} ${source} | tar xf - --strip-components=${strip} -C ${name}",
require => [ File["${name}"], File["${source}"], ],
unless => "test -n \"$(ls -A ${name})\"",
}
}