From 923719447a4cabcb7ef91bbfde4077c2e80278fe Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Tue, 12 Dec 2017 14:31:44 +0100
Subject: [PATCH] Simple script to provide a new package for the automatic
 updater.

Refers to #13
---
 AutoTx-Updater/Update-Service.ps1           |  2 +-
 AutoTx/Resources/Provide-UpdaterPackage.ps1 | 44 +++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 AutoTx/Resources/Provide-UpdaterPackage.ps1

diff --git a/AutoTx-Updater/Update-Service.ps1 b/AutoTx-Updater/Update-Service.ps1
index d08e3b7..db8e71c 100644
--- a/AutoTx-Updater/Update-Service.ps1
+++ b/AutoTx-Updater/Update-Service.ps1
@@ -206,7 +206,7 @@ function Update-Configuration {
 function Copy-ServiceFiles {
     try {
         Copy-Item -Recurse -Force -ErrorAction Stop `
-            -Path "$($UpdateBinariesPath)\*" `
+            -Path "$($UpdateBinariesPath)\$($ServiceName)\*" `
             -Destination "$InstallationPath"
     }
     catch {
diff --git a/AutoTx/Resources/Provide-UpdaterPackage.ps1 b/AutoTx/Resources/Provide-UpdaterPackage.ps1
new file mode 100644
index 0000000..85b20fd
--- /dev/null
+++ b/AutoTx/Resources/Provide-UpdaterPackage.ps1
@@ -0,0 +1,44 @@
+[CmdletBinding()]
+Param(
+    [Parameter(Mandatory=$True)][String] $UpdaterSettings
+)
+
+try {
+    . $UpdaterSettings
+}
+catch {
+    $ex = $_.Exception.Message
+    Write-Host "Error reading settings file: '$($UpdaterSettings)' [$($ex)]"
+    Exit
+}
+
+
+$UpdateBinariesPath = "$($UpdateSourcePath)\Service\Binaries"
+$Pattern = 'build_[0-9]{4}-[0-9]{2}-[0-9]{2}_'
+
+$PackageDir = Get-ChildItem -Directory -Name |
+    Where-Object {$_ -match $Pattern} |
+    Sort-Object |
+    Select-Object -Last 1
+
+if ([string]::IsNullOrEmpty($PackageDir)) {
+    Write-Host "ERROR: couldn't find any directories matching '$($Pattern)'!"
+    Exit
+}
+
+
+try {
+    # exclude some files not be distributed:
+    $Exclude = @("ScriptsConfig.ps1", "Install-Service.ps1")
+    Copy-Item -Recurse -Force -ErrorAction Stop `
+        -Path $PackageDir `
+        -Exclude $Exclude `
+        -Destination $UpdateBinariesPath
+    Write-Host "Copied package [$($PackageDir)] to [$($UpdateBinariesPath)]."
+}
+catch {
+    $ex = $_.Exception.Message
+    Write-Host "Error copying service package: $($ex)"
+    Exit
+}
+
-- 
GitLab