Skip to content

Instantly share code, notes, and snippets.

@anl
Created January 19, 2011 19:46
Show Gist options
  • Save anl/786719 to your computer and use it in GitHub Desktop.
Save anl/786719 to your computer and use it in GitHub Desktop.
# Small define to expand a tarball at a location; assumes File[$title]
# definition of tarball and installation of pax:
define baselayout::drop_tarball($dest, $dir_name, $dir_sub='') {
# $dest: cwd in which expansion is done
# $dir_name: name of top level directory created in $dest
# $dir_sub: regexp to -s for pax - not supported for .zip archives
if ($dir_sub) {
$regexp = "-s $dir_sub"
} else {
$regexp = ''
}
# CentOS' pax doesn't support "-j" flag; therefore, run pax after
# bzcat in a pipeline. Twiddle path to bzcat as distro-appropriate:
case $operatingsystem {
CentOS: {
$bzcat = "/usr/bin/bzcat"
}
Ubuntu: {
$bzcat = "/bin/bzcat"
}
}
# Choose expansion method based on file suffix:
if (($title =~ /\.tar.gz$/) or ($title =~ /\.tgz$/)) {
$expand = "/usr/bin/pax -rz $regexp < $title"
} elsif (($title =~ /\.tar.bz2$/) or ($title =~ /\.tbz$/)) {
$expand = "$bzcat $title | /usr/bin/pax -r $regexp"
} elsif ( $title =~ /\.zip$/ ) {
$expand = '/usr/bin/unzip $title'
}
exec { "drop_tarball $title":
command => $expand,
cwd => $dest,
creates => "${dest}/${dir_name}",
require => File[$title],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment