Bumped to 0.7.4.1
Overhauled installer -- fixed a number of small bugs Better output during installation Complete uninstaller - removes services, etc
This commit is contained in:
24
SABnzbd/tools/WaitForSuccess.ps1
Normal file
24
SABnzbd/tools/WaitForSuccess.ps1
Normal file
@@ -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
|
||||
}
|
@@ -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
|
||||
|
86
SABnzbd/tools/chocolateyUninstall.ps1
Normal file
86
SABnzbd/tools/chocolateyUninstall.ps1
Normal file
@@ -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
|
||||
}
|
Reference in New Issue
Block a user