# 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})\"", } } # Apply patch. # # === Parameters # # $name: # Destination directory. # $source: # Patch file. # $strip: # Remove the specified number of leading path elements. # Defaults to 0. # # === Sample usage # # util::patch { "/usr/local/src/moin-1.8.8": # strip => 1, # source => "/usr/local/src/moin.patch", # } # define util::patch($source, $strip=0) { exec { "patch-${name}-${source}": path => "/bin:/usr/bin:/sbin:/usr/sbin", cwd => "${name}", command => "patch -N -t -p${strip} < ${source}", onlyif => "patch --dry-run -N -t -p${strip} < ${source}", require => [ File["${name}"], File["${source}"], ], } }