1 # Define resource to extract files from staging directories to target directories.
2 define staging::extract (
3 $target, #: the target extraction directory
4 $source = undef, #: the source compression file, supports tar, tar.gz, zip, war
5 $creates = undef, #: the file created after extraction. if unspecified defaults ${staging::path}/${caller_module_name}/${name} ${target}/${name}
6 $unless = undef, #: alternative way to conditionally check whether to extract file.
7 $onlyif = undef, #: alternative way to conditionally check whether to extract file.
8 $user = undef, #: extract file as this user.
9 $group = undef, #: extract file as this group.
10 $environment = undef, #: environment variables.
11 $strip = undef, #: extract file with the --strip=X option. Only works with GNU tar.
12 $subdir = $caller_module_name #: subdir per module in staging directory.
18 $source_path = $source
20 $source_path = "${staging::path}/${subdir}/${name}"
23 # Use user supplied creates path, set default value if creates, unless or
24 # onlyif is not supplied.
26 $creates_path = $creates
27 } elsif ! ($unless or $onlyif) {
28 if $name =~ /.tar.gz$/ {
29 $folder = staging_parse($name, 'basename', '.tar.gz')
30 } elsif $name =~ /.tar.bz2$/ {
31 $folder = staging_parse($name, 'basename', '.tar.bz2')
33 $folder = staging_parse($name, 'basename')
35 $creates_path = "${target}/${folder}"
40 if scope_defaults('Exec','path') {
45 environment => $environment,
46 creates => $creates_path,
49 logoutput => on_failure,
57 environment => $environment,
58 creates => $creates_path,
61 logoutput => on_failure,
66 if $::osfamily == 'Solaris' or $name !~ /(.tar|.tgz|.tar.gz|.tar.bz2)$/ {
67 warning('strip is only supported with GNU tar, ignoring the parameter')
70 $strip_opt = " --strip=${strip}"
78 $command = "tar xf ${source_path}${strip_opt}"
82 if $::osfamily == 'Solaris' {
83 $command = "gunzip -dc < ${source_path} | tar xf - "
85 $command = "tar xzf ${source_path}${strip_opt}"
90 $command = "tar xjf ${source_path}${strip_opt}"
94 $command = "unzip ${source_path}"
98 $command = "jar xf ${source_path}"
102 fail("staging::extract: unsupported file format ${name}.")
106 exec { "extract ${name}":