From 3c816a18f65c43eb5d65f4ee3a06cdc7055036aa Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Tue, 23 Apr 2019 15:52:22 +0200
Subject: [PATCH] Allow for specifying updater config, make script
 location-agnostic

---
 Scripts/Deploy-NewBuild.ps1 | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/Scripts/Deploy-NewBuild.ps1 b/Scripts/Deploy-NewBuild.ps1
index a65e157..8963a71 100644
--- a/Scripts/Deploy-NewBuild.ps1
+++ b/Scripts/Deploy-NewBuild.ps1
@@ -1,6 +1,29 @@
-$UpdaterSettings = "C:\Tools\AutoTx-Updater\UpdaterConfig.inc.ps1"
+# Helper script to facilitate the package-deploy-update cycle. Its purpose is to
+# automate reading the updater config (optionally just using the default
+# location) and subsequently call the `Make-Package.ps1` and
+# `Provide-UpdaterPackage.ps1` scripts followed by a removal of the update
+# marker file for the local computer, all using the parameters collected from
+# the configuration file.
 
-. $UpdaterSettings
+[CmdletBinding()]
+Param(
+    [String] $UpdaterSettings = "C:\Tools\AutoTx-Updater\UpdaterConfig.inc.ps1"
+)
+
+$ErrorActionPreference = "Stop"
+
+try {
+    . $UpdaterSettings
+}
+catch {
+    $ex = $_.Exception.Message
+    Write-Host "Error reading settings file: '$($UpdaterSettings)' [$($ex)]"
+    Exit
+}
+
+# Make sure to run from the directory containing the script itself:
+$BaseDir = $(Split-Path $MyInvocation.MyCommand.Path)
+Push-Location $BaseDir
 
 .\Make-Package.ps1
 .\Provide-UpdaterPackage.ps1 -UpdaterSettings $UpdaterSettings
@@ -8,4 +31,6 @@ $UpdaterSettings = "C:\Tools\AutoTx-Updater\UpdaterConfig.inc.ps1"
 $Marker = "$($UpdateSourcePath)\Service\UpdateMarkers\$($env:COMPUTERNAME)"
 if (Test-Path $Marker) {
     Remove-Item -Force -Verbose $Marker
-}
\ No newline at end of file
+}
+
+Pop-Location
\ No newline at end of file
-- 
GitLab