From a21d0d6cd3c19095eb6301790cbabe69815d2689 Mon Sep 17 00:00:00 2001 From: Miodrag Milic Date: Mon, 22 May 2017 21:23:33 +0200 Subject: [PATCH] added whatif package --- _scripts/whatif.ps1 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 _scripts/whatif.ps1 diff --git a/_scripts/whatif.ps1 b/_scripts/whatif.ps1 new file mode 100644 index 0000000..1f51208 --- /dev/null +++ b/_scripts/whatif.ps1 @@ -0,0 +1,40 @@ +<# +This script implements WhatIf functionality. When you use it, it will + - backup a package prior a call to update + - save updater output to another folder + - restore an original package after update finishes + +Use it by adding a switch parameter to update.ps1 and surrounding update +by backup and restore functions: + + param( [switch]$WhatIf ) + + ... + + backup + update ... + restore + +#> + +function backup() { + if (!$WhatIf) { return } + Write-Warning "WhatIf passed - package files will not be changed" + + $packageName = Split-Path -Leaf $MyInvocation.PSScriptRoot + $d = "$Env:TEMP\au\$packageName" + + rm $d\* -Recurse -ea 0 + cp . $d\_backup -Recurse +} + +function restore() { + $packageName = Split-Path -Leaf $MyInvocation.PSScriptRoot + $d = "$Env:TEMP\au\$packageName" + + cp . $d\_output -Recurse + rm .\* -Recurse + cp $d\_backup\* . -Recurse + + Write-Warning "Package saved to: $d\_output" +} \ No newline at end of file