From 31dcdb649f606042a4486371be6762d55ebf8752 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Mon, 5 Mar 2018 15:07:33 +0100
Subject: [PATCH] Refuse to update using the Install-Service script.

This has been superseded and is handled much smarter by the updater.

Refers to #13
---
 Scripts/Install-Service.ps1 | 39 ++++++++-----------------------------
 1 file changed, 8 insertions(+), 31 deletions(-)

diff --git a/Scripts/Install-Service.ps1 b/Scripts/Install-Service.ps1
index c099c0e..e79b91b 100644
--- a/Scripts/Install-Service.ps1
+++ b/Scripts/Install-Service.ps1
@@ -1,26 +1,4 @@
-function Stop-MyService {
-    Write-Host -NoNewLine "Checking status of $($ServiceName) service: "
-    try {
-        $Service = Get-Service $ServiceName -ErrorAction Stop
-        Write-Host $Service.Status
-    }
-    catch {
-        Write-Host "[FAILED]" -Fore Red
-        Write-Host "Can't query the service state, stopping."
-        Exit
-    }
 
-    if ($Service.Status -ne "Stopped") {
-        Write-Host -NoNewLine "Stopping service $($ServiceName): "
-        try {
-            Stop-Service $ServiceName -ErrorAction Stop
-            Write-Host "[OK]" -Fore Green
-        }
-        catch {
-            Write-Host "[FAILED]" -Fore Red
-        }
-    }
-}
 
 
 function Start-MyService {
@@ -102,15 +80,14 @@ if (Test-Path $LocalConfiguration) {
 
 $ServiceLog = "$($ServiceDir)\$($ServiceName).log"
 
-try {
-    $Service = Get-Service $ServiceName -ErrorAction Stop
-    Write-Host "Service $($ServiceName) already installed, updating."
-    Stop-MyService
-    Copy-ServiceFiles
-}
-catch {
-    Copy-ServiceFiles
-    Install-Service
+
+$Service = Get-Service $ServiceName -ErrorAction SilentlyContinue
+if ($Service) {
+    Write-Host "Service $($ServiceName) already installed! Please use the" `
+        "Updater to do service updates. Stopping."
+    Exit 1
 }
 
+Copy-ServiceFiles
+Install-Service
 Start-MyService
-- 
GitLab