Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(scripts) Added helper script for urls without version info
- Loading branch information
1 parent
01513da
commit b781e63
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# NOTE: No documentation will be written for this script. | ||
# This is only a temporary script until a generic version | ||
# have been added to the wormies-au-helpers powershell package | ||
|
||
function Update-OnETagChanged() { | ||
param( | ||
[uri]$execUrl, | ||
[string]$saveFile = ".\info", | ||
[scriptblock]$OnETagChanged, | ||
[scriptblock]$OnUpdated | ||
) | ||
|
||
$request = [System.Net.WebRequest]::CreateDefault($execUrl) | ||
|
||
try { | ||
$response = $request.GetResponse() | ||
$etag = $response.Headers.Get("ETag") | ||
} | ||
finally { | ||
$response.Dispose() | ||
$response = $null | ||
} | ||
|
||
$saveResult = $false | ||
if (!(Test-Path $saveFile) -or ($global:au_Force -eq $true)) { | ||
$result = . $OnETagChanged | ||
$saveResult = $true | ||
} | ||
else { | ||
$existingInfo = (Get-Content $saveFile -Encoding UTF8 -TotalCount 1) -split '\|' | ||
|
||
if ($existingInfo[0] -ne $etag) { | ||
$result = . $OnETagChanged | ||
$saveResult = $true | ||
} | ||
else { | ||
$result = . $OnUpdated | ||
$result["Version"] = $existingInfo[1] | ||
$result["ETAG"] = $existingInfo[0] | ||
$saveResult = $false | ||
} | ||
} | ||
|
||
if ($saveResult) { | ||
$result["ETAG"] = $etag | ||
"$($result["ETAG"])|$($result["Version"])" | Out-File $saveFile -Encoding utf8 -NoNewline | ||
} | ||
|
||
return $result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters