diff --git a/automatic/skype/tools/chocolateyInstall.ps1 b/automatic/skype/tools/chocolateyInstall.ps1 index 6c64dcfaf..350fe4b39 100644 --- a/automatic/skype/tools/chocolateyInstall.ps1 +++ b/automatic/skype/tools/chocolateyInstall.ps1 @@ -7,44 +7,70 @@ function isInstalled() { return Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match 'Skype\u2122 [\d\.]+$'} } -$packageName = 'skype' -$fileType = 'msi' -# http://community.skype.com/t5/Windows-archive/Unattended-install/td-p/184628s -$silentArgs = '/qn /norestart STARTSKYPE=FALSE TRANSFORMS=:RemoveDesktopShortcut.mst TRANSFORMS=:RemoveStartup.mst' +function downloadInstaller { + param( + [string] $packageName, + [alias("installerType")][string] $fileType = 'exe', + [string] $url, + [alias("url64")][string] $url64bit = '', + [string] $checksum = '', + [string] $checksumType = '', + [string] $checksum64 = '', + [string] $checksumType64 = '', + [hashtable] $options = @{Headers=@{}} + ) + $chocTempDir = Join-Path $env:TEMP 'chocolatey' + $tempDir = Join-Path $chocTempDir "$packageName" + if ($env:packageVersion -ne $null) {$tempDir = Join-Path $tempDir "$env:packageVersion"; } + if (![System.IO.Directory]::Exists($tempDir)) { [System.IO.Directory]::CreateDirectory($tempDir) | Out-Null } + $file = Join-Path $tempDir "$($packageName)Install.$fileType" + $filePath = Get-ChocolateyWebFile $packageName $file $url $url64bit -checksum $checksum -checksumType $checksumType -checksum64 $checksum64 -checksumType64 $checksumType64 -options $options -getOriginalFileName -$url = '{{DownloadUrl}}' + $filePath = if ($myval -ne $null) { $filePath } else { $file } + return $filePath +} + +function uninstallExisting($appInstalled, $silentArgs) { + # If Skype (in any version) is already installed on the computer, remove it first, otherwise the + # installation of Skype will fail with an error. + $msiArgs = $('/x' + $appInstalled.IdentifyingNumber + ' ' + $silentArgs) + Write-Host "Uninstalling previous version of Skype, otherwise installing the new version won’t work." + + Start-ChocolateyProcessAsAdmin $msiArgs 'msiexec' -try { + # This loop checks every 5 seconds if Skype is already uninstalled. + # Then it proceeds with the download and installation of the Skype + # version specified in the package. + do { + Start-Sleep -Seconds 5 + $i += 1 - $appInstalled = isInstalled + # Break if too much time passed + if ($i -gt 12) { + Write-Error 'Could not uninstall the previous version of Skype.' + break + } - if ($appInstalled) { - # If Skype (in any version) is already installed on the computer, remove it first, otherwise the - # installation of Skype will fail with an error. - $msiArgs = $('/x' + $appInstalled.IdentifyingNumber + ' ' + $silentArgs) - Write-Host "Uninstalling previous version of Skype, otherwise installing the new version won’t work." - Start-ChocolateyProcessAsAdmin $msiArgs 'msiexec' + } until (-not (isInstalled)) +} + +$packageName = 'skype' +$fileType = 'msi' - # This loop checks every 5 seconds if Skype is already uninstalled. - # Then it proceeds with the download and installation of the Skype - # version specified in the package. - do { - Start-Sleep -Seconds 5 - $i += 1 +# http://community.skype.com/t5/Windows-archive/Unattended-install/td-p/184628s +$updatesilentArgs = '/qn /norestart STARTSKYPE=FALSE TRANSFORMS=:RemoveDesktopShortcut.mst' +$silentArgs = "$updatesilentArgs TRANSFORMS=:RemoveStartup.mst" + +$url = '{{DownloadUrl}}' - # Break if too much time passed - if ($i -gt 12) { - Write-Error 'Could not uninstall the previous version of Skype.' - break - } - } until (-not (isInstalled)) - } +$appInstalled = isInstalled +$filePath = downloadInstaller $packageName $fileType $url - Install-ChocolateyPackage $packageName $fileType $silentArgs $url +if ($appInstalled) { + uninstallExisting $appInstalled $updatesilentArgs -} catch { - Write-ChocolateyFailure $packageName $($_.Exception.Message) - throw + $silentArgs = $updatesilentArgs } +Install-ChocolateyInstallPackage $packageName $fileType $silentArgs $filePath