From 23c0459e8f2b0c71bd6deddfe1c0492585987152 Mon Sep 17 00:00:00 2001 From: Iristyle Date: Sun, 21 Oct 2012 20:54:03 -0400 Subject: [PATCH] Bumped to 0.7.4.1 Overhauled installer -- fixed a number of small bugs Better output during installation Complete uninstaller - removes services, etc --- SABnzbd/SABnzbd.nuspec | 10 +++- SABnzbd/tools/WaitForSuccess.ps1 | 24 ++++++++ SABnzbd/tools/chocolateyInstall.ps1 | 76 +++++++++++++---------- SABnzbd/tools/chocolateyUninstall.ps1 | 86 +++++++++++++++++++++++++++ 4 files changed, 162 insertions(+), 34 deletions(-) create mode 100644 SABnzbd/tools/WaitForSuccess.ps1 create mode 100644 SABnzbd/tools/chocolateyUninstall.ps1 diff --git a/SABnzbd/SABnzbd.nuspec b/SABnzbd/SABnzbd.nuspec index 264ffd0..64f3a89 100644 --- a/SABnzbd/SABnzbd.nuspec +++ b/SABnzbd/SABnzbd.nuspec @@ -3,7 +3,7 @@ SABnzbd SABnzbd+ - 0.7.4 + 0.7.4.1 The SABnzbd+ Team Ethan Brown SABnzbd+ open source binary newsreader @@ -20,7 +20,11 @@ Note that if this is a first time install it will be necessary to configure SABn https://github.com/sabnzbd/sabnzbd/blob/master/LICENSE.txt false https://github.com/Iristyle/ChocolateyPackages/raw/master/SABnzbd/SABnzbd.png - Highlights in 0.7.4 + + 0.7.4.1 - Chocolatey Installer fixes + Can now uninstall + + Highlights in 0.7.4 OSX Mountain Lion: Notification Center support OSX Mountain Lion: improved "keep awake" support @@ -56,4 +60,4 @@ Note that if this is a first time install it will be necessary to configure SABn - \ No newline at end of file + diff --git a/SABnzbd/tools/WaitForSuccess.ps1 b/SABnzbd/tools/WaitForSuccess.ps1 new file mode 100644 index 0000000..45c6ecd --- /dev/null +++ b/SABnzbd/tools/WaitForSuccess.ps1 @@ -0,0 +1,24 @@ +function WaitForSuccess([ScriptBlock] $script, [int]$seconds = 10, + [string]$description = 'operation to complete') +{ + $skip = $false + Write-Host "Waiting up to $($seconds)s for $description..." + $result = 0..($seconds * 2) | + % { + if ($skip) { return $true } + $status = &$script + if ($status -eq $true) + { + $skip = $true + return $true + } + elseif ($service) + { + Start-Sleep -Milliseconds 500 + } + return $false + } | + Select -Last 1 + + return $result +} diff --git a/SABnzbd/tools/chocolateyInstall.ps1 b/SABnzbd/tools/chocolateyInstall.ps1 index 9b1e237..ec47a82 100644 --- a/SABnzbd/tools/chocolateyInstall.ps1 +++ b/SABnzbd/tools/chocolateyInstall.ps1 @@ -1,50 +1,59 @@ -try -{ - $package = 'SABnzbd+' - $upgrade = $false +$package = 'SABnzbd+' +$upgrade = $false +function Get-CurrentDirectory +{ + $thisName = $MyInvocation.MyCommand.Name + [IO.Path]::GetDirectoryName((Get-Content function:$thisName).File) +} + +. (Join-Path (Get-CurrentDirectory) 'WaitForSuccess.ps1') + +try +{ # stop helper services if they're running Get-Service -Include SABnzbd, SABHelper | Stop-Service -Force - - $installPath = (Join-Path "${Env:\ProgramFiles(x86)}" 'sabnzbd'), - (Join-Path 'Env:ProgramFiles' 'sabnzbd') | + + $programFilesPath = "${Env:\ProgramFiles(x86)}", $Env:ProgramFiles | ? { Test-Path $_ } | Select -First 1 $helper = 'SABnzbd-helper.exe' $service = 'SABnzbd-service.exe' - + + $installPath = Join-Path $programFilesPath 'sabnzbd' # already installed, so must call remove on existing exes to be safe - if ($installPath -ne $null) + if (Test-Path $installPath) { $upgrade = $true - $helper, $service | - % { + $helper, $service | + % { $path = Join-Path $installPath $_ if (Test-Path $path) { &$path remove } } } - + #uses NSIS installer Install-ChocolateyPackage 'SABnzbd-0.7.4-win32-setup' 'exe' '/S' ` 'http://sourceforge.net/projects/sabnzbdplus/files/sabnzbdplus/0.7.4/SABnzbd-0.7.4-win32-setup.exe/download' #need to turn on / install services - @("${Env:\ProgramFiles(x86)}", '^%ProgramFiles(x86)^%'), + @("${Env:\ProgramFiles(x86)}", '^%ProgramFiles(x86)^%'), @($Env:ProgramFiles, '^%ProgramFiles^%') | % { $path = Join-Path $_[0] 'sabnzbd' if (Test-Path $path) { + Write-Host "Found SABnzbd installed at $path" $installPath = $path $dosPath = $_[1] - break } } #register file association #http://stackoverflow.com/questions/323426/windows-command-line-non-evaluation-of-environment-variable + Write-Host "Registering SABnzbd+ NZB file associations" cmd /c assoc .nzb=NZBFile $sabPath = "^`"$dosPath\sabnzbd\SABnzbd.exe^`"" cmd /c ftype NZBFile=$sabPath `"%1`" @@ -52,8 +61,9 @@ try Push-Location $installPath $dataDirectory = Join-Path $Env:LOCALAPPDATA 'sabnzbd' - &".\$service" -f $dataDirectory install - &".\$helper" install + Write-Host "Registering SABnzbd+ service with data at $dataDirectory" + &".\$service" -f $dataDirectory install | Out-Null + &".\$helper" install | Out-Null Pop-Location @@ -61,30 +71,34 @@ try sc.exe config SABnzbd start= delayed-auto # configure windows firewall + Write-Host "Registering SABnzbd+ firewall exclusions" netsh advfirewall firewall delete rule name="SABnzbd+" netsh advfirewall firewall add rule name="SABnzbd+" dir=in protocol=tcp localport=8080 action=allow program="$installPath\SABnzbd-service.exe" netsh advfirewall firewall add rule name="SABnzbd+" dir=in protocol=tcp localport=9090 action=allow program="$installPath\SABnzbd-service.exe" + Write-Host "Starting SABnzbd+ service" Start-Service SABnzbd - # no need to use the web UI to configure an upgrade - if ($upgrade) { return } - #wait up to 5 seconds for service to fire up - 0..10 | - % { - if ((Get-Service SABnzbd).Status -eq 'Running') - { - #launch local default browser to configure - [Diagnostics.Process]::Start('http://localhost:8080') - break - } - Start-Sleep -Milliseconds 500 - } - + $msg = 'SABnzbd+ service to start, to launch browser config' + if (WaitForSuccess { (Get-Service SABnzbd).Status -eq 'Running' } 10 $msg) + { + # no need to use the web UI to configure an upgrade + if (!$upgrade) + { + #launch local default browser to configure + [Diagnostics.Process]::Start('http://localhost:8080') + } + } + else + { + Write-ChocolateyFailure 'SABnzbd+ service failed to start!' + return + } + Write-ChocolateySuccess $package } -catch +catch { Write-ChocolateyFailure $package "$($_.Exception.Message)" throw diff --git a/SABnzbd/tools/chocolateyUninstall.ps1 b/SABnzbd/tools/chocolateyUninstall.ps1 new file mode 100644 index 0000000..5ec37b9 --- /dev/null +++ b/SABnzbd/tools/chocolateyUninstall.ps1 @@ -0,0 +1,86 @@ +$package = 'SABnzbd+' + +function Get-CurrentDirectory +{ + $thisName = $MyInvocation.MyCommand.Name + [IO.Path]::GetDirectoryName((Get-Content function:$thisName).File) +} + +. (Join-Path (Get-CurrentDirectory) 'WaitForSuccess.ps1') + +try +{ + # stop helper services if they're running + Get-Service -Include SABnzbd, SABHelper | + Stop-Service -Force + + Write-Host 'Removing Windows Firewall Exclusions' + netsh advfirewall firewall delete rule name="SABnzbd+" + + $installPath = (Join-Path "${Env:\ProgramFiles(x86)}" 'sabnzbd'), + (Join-Path 'Env:ProgramFiles' 'sabnzbd') | + ? { Test-Path $_ } | + Select -First 1 + + $helper = 'SABnzbd-helper.exe' + $service = 'SABnzbd-service.exe' + + # already installed, so must call remove on existing exes to be safe + if ($installPath -ne $null) + { + Write-Host 'Removing SABnzbd+ services' + $upgrade = $true + $helper, $service | + % { + $path = Join-Path $installPath $_ + if (Test-Path $path) { &$path remove } + } + } + + # the above should completely remove existing services, but in case not + 'SABHelper', 'SABnzbd' | + % { if (Get-Service -Include $_) { sc.exe delete $_ } } + + $uninstall = Join-Path $installPath 'Uninstall.exe' + + #uses NSIS installer - http://nsis.sourceforge.net/Docs/Chapter3.html + $uninstallParams = @{ + PackageName = $package; + FileType = 'exe'; + SilentArgs = '/S'; + File = $uninstall; + } + + Uninstall-ChocolateyPackage @uninstallParams + + #remove file association to sabnzbd + #http://stackoverflow.com/questions/323426/windows-command-line-non-evaluation-of-environment-variable + Write-Host 'Removing SABnzbd+ NZB file associations' + $nzbRunner = cmd /c ftype NZBFile + if ($nzbRunner -match 'SABnzbd.exe') + { + cmd /c ftype NZBFile= + } + + $uninstallComplete = { + (Get-Process 'uninstall' -ErrorAction SilentlyContinue) -eq $null + } + if (WaitForSuccess $uninstallComplete 10 'uninstall to complete') + { + $installPath, (Join-Path $Env:LOCALAPPDATA 'sabnzbd') | + % { + $count = (Get-ChildItem $_ -Recurse -ErrorAction SilentlyContinue).Count + if ($count -gt 0) + { + Write-Host "Remove remaining $count files from $_ manually" + } + } + } + + Write-ChocolateySuccess $package +} +catch +{ + Write-ChocolateyFailure $package "$($_.Exception.Message)" + throw +}