Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing issues when puppet runs as service #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ windows::unzip { 'C:\compressed.zip':
}
```

If you don't have .NET 4.5 installed you can fallback to COM based method but it can fail if puppet runs as service.

```puppet
windows::unzip { 'C:\compressed.zip':
destination => 'C:\dest',
creates => 'C:\dest\uncompressed.txt',
fallback => true,
}
```

This assumes that the file `uncompressed.txt` exists in `C:\compressed.zip`

License
Expand Down
10 changes: 9 additions & 1 deletion manifests/unzip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,29 @@
$zipfile = $name,
$provider = 'powershell',
$options = '20',
$command_template = 'windows/unzip.ps1.erb',
$timeout = 300,
$logoutput = on_failure,
$fallback = false,
) {
validate_absolute_path($destination)

if (! $creates and ! $refreshonly and ! $unless){
fail("Must set one of creates, refreshonly, or unless parameters.\n")
}

if ($fallback){
$command_template = 'windows/unzip.ps1.erb'
} else{
$command_template = 'windows/unzip_dotnet.ps1.erb'
}

exec { "unzip-${name}":
command => template($command_template),
creates => $creates,
refreshonly => $refreshonly,
unless => $unless,
provider => $provider,
timeout => $timeout,
logoutput => $logoutput,
}
}
25 changes: 22 additions & 3 deletions templates/unzip.ps1.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
$shell = New-Object -COMObject Shell.Application;
$zipfile = $shell.NameSpace("<%= @zipfile %>");
foreach($item in $zipfile.Items()){ $shell.NameSpace("<%= @destination %>").CopyHere($item, <%= @options %>) };
$zipFile="<%= @zipfile %>"
$dst="<%= @destination %>"

if ( ! (Test-Path $zipfile) ) {
write-error "ZIP file does not exists: `$zipFile'"
exit 1
}

if ( ! (Test-Path $dst) ) {
write-error "Missing destination folder: `$dst'"
exit 1
}

try {
$shell = New-Object -COMObject Shell.Application;
$zipfile = $shell.NameSpace("<%= @zipfile %>");
foreach($item in $zipfile.Items()){ $shell.NameSpace("<%= @destination %>").CopyHere($item, <%= @options %>) };
}
catch {
write-error $_
exit 1
}
21 changes: 21 additions & 0 deletions templates/unzip_dotnet.ps1.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$zipFile="<%= @zipfile %>"
$dst="<%= @destination %>"

if ( ! (Test-Path $zipfile) ) {
write-error "ZIP file does not exists: ``$zipFile'"
exit 1
}

if ( ! (Test-Path $dst) ) {
write-error "Missing destination folder: ``$dst'"
exit 1
}

try {
Add-Type -A System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $dst)
}
catch {
write-error $_
exit 1
}