support/install_command.ps1 in mixlib-install-2.1.8 vs support/install_command.ps1 in mixlib-install-2.1.9

- old
+ new

@@ -41,14 +41,20 @@ Log "Downloading package from $url" Get-WebContent $url $dst Log "Download complete." if ($sha256 -eq $null) { Log "Skipping sha256 verification" } - elseif (($dsha256 = Get-SHA256 $dst) -eq $sha256) { Log "Successfully verified $dst" } - else { throw "SHA256 for $dst $dsha256 does not match $sha256" } + elseif (Verify-SHA256 $dst $sha256) { Log "Successfully verified $dst" } + else { throw "SHA256 for $dst does not match $sha256" } } +Function Verify-SHA256($path, $sha256) { + if ($sha256 -eq $null) { return $false } + elseif (($dsha256 = Get-SHA256 $path) -eq $sha256) { return $true } + else { return $false } +} + Function Install-Chef($msi, $chef_omnibus_root) { Log "Installing Chef Omnibus package $msi" $installingChef = $True $installAttempts = 0 while ($installingChef) { @@ -61,11 +67,10 @@ $result = Install-ChefMsi $msi } if(!$result) { continue } $installingChef = $False } - Remove-Item $msi -Force Log "Installation complete" } Function Install-ChefMsi($msi) { $p = Start-Process -FilePath "msiexec.exe" -ArgumentList "/qn /i $msi" -Passthru -Wait @@ -183,12 +188,16 @@ $url, $sha256 = Get-ChefMetadata "$chef_metadata_url" } else { $url = $chef_msi_url $sha256 = $null } - $msi = Join-Path $env:temp "$url".Split("/")[-1] + $msi = Join-Path $download_directory "$url".Split("/")[-1] $msi = Unresolve-Path $msi - Download-Chef "$url" $sha256 $msi + if (Verify-SHA256 $msi $sha256) { + Log "Skipping package download; found a matching package at $msi" + } else { + Download-Chef "$url" $sha256 $msi + } Install-Chef $msi $chef_omnibus_root } else { Write-Host "-----> Chef Omnibus installation detected ($pretty_version)" }