Added util::extract::tar.
This commit is contained in:
parent
543c4db28c
commit
365483adff
1 changed files with 42 additions and 0 deletions
42
util/manifests/init.pp
Normal file
42
util/manifests/init.pp
Normal 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})\"",
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue