add update script for cloud backup
This commit is contained in:
+31
-28
@@ -1,30 +1,34 @@
|
||||
$DNSHelper = $Global:ToolsDirectory + '\ekdns.exe'
|
||||
|
||||
$DNSHelperRequiredVersion = '2.3.0'
|
||||
$DownloadRequired = $false
|
||||
|
||||
If (Test-Path $DNSHelper) {
|
||||
$versionOutput = (& $DNSHelper 2>&1 | Select-Object -First 1)
|
||||
If ($versionOutput -match 'v(\d+\.\d+\.\d+)') {
|
||||
If ($Matches[1] -ne $DNSHelperRequiredVersion) {
|
||||
$DownloadRequired = $true
|
||||
}
|
||||
} Else {
|
||||
$DownloadRequired = $true
|
||||
}
|
||||
# SHA-256 of ekdns.exe from each v2.3.0 Windows release archive.
|
||||
If ([Environment]::Is64BitOperatingSystem) {
|
||||
$DNSHelperURL = 'https://xfer.emberkom.com/shares/tools/folders/9b9988fb-c53a-4833-a4ad-68d01a3021bb/files/ekdns-x64-exe/download/ekdns-x64.exe'
|
||||
$DNSHelperHash = '308E36680C0E4AD7CE802F4B1D8C38E89B0D8E24BBCE4F33550721C78BA2224C'
|
||||
} Else {
|
||||
$DownloadRequired = $true
|
||||
$DNSHelperURL = 'https://xfer.emberkom.com/shares/tools/folders/9b9988fb-c53a-4833-a4ad-68d01a3021bb/files/ekdns-x86-exe/download/ekdns-x86.exe'
|
||||
$DNSHelperHash = 'F987E75D8FFB87B587B57D2394131B072957C0E3EB6B73B4FB784E9B0D65277B'
|
||||
}
|
||||
|
||||
# Download the latest version of ekDNSHelper
|
||||
If ($DownloadRequired) {
|
||||
$DNSHelperURL = 'https://xfer.emberkom.com/shares/tools/folders/9b9988fb-c53a-4833-a4ad-68d01a3021bb/files/ekdns-x64-exe/download/ekdns-x64.exe'
|
||||
If (!(Test-Path ${Env:ProgramFiles(x86)})) {
|
||||
$DNSHelperURL = 'https://xfer.emberkom.com/shares/tools/folders/9b9988fb-c53a-4833-a4ad-68d01a3021bb/files/ekdns-x86-exe/download/ekdns-x86.exe'
|
||||
$InstalledHash = (Get-FileHash -LiteralPath $DNSHelper -Algorithm SHA256 -ErrorAction SilentlyContinue).Hash
|
||||
If ($InstalledHash -ne $DNSHelperHash) {
|
||||
$StagedHelper = $DNSHelper + '.' + [guid]::NewGuid().ToString('N') + '.tmp'
|
||||
Try {
|
||||
Write-Output "Downloading latest version of ekDNSHelper"
|
||||
$null = Download-File -URL $DNSHelperURL -File $StagedHelper
|
||||
If ((Get-FileHash -LiteralPath $StagedHelper -Algorithm SHA256 -ErrorAction Stop).Hash -ne $DNSHelperHash) {
|
||||
Throw 'Downloaded ekdns.exe failed SHA-256 verification.'
|
||||
}
|
||||
If ([IO.File]::Exists($DNSHelper)) {
|
||||
[IO.File]::Replace($StagedHelper, $DNSHelper, [NullString]::Value)
|
||||
} Else {
|
||||
[IO.File]::Move($StagedHelper, $DNSHelper)
|
||||
}
|
||||
} Catch {
|
||||
Write-Error $_.Exception.Message
|
||||
Exit 1
|
||||
} Finally {
|
||||
Remove-Item -LiteralPath $StagedHelper -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
If (Test-Path $DNSHelper) { Remove-Item -Path $DNSHelper -Force -ErrorAction SilentlyContinue }
|
||||
Write-Output "Downloading latest version of ekDNSHelper"
|
||||
Download-File -URL $DNSHelperURL -File $DNSHelper
|
||||
}
|
||||
|
||||
# Delete the old version of ekDNSHelper if it exists
|
||||
@@ -62,15 +66,14 @@ If ( Test-Path $DNSHelper ) {
|
||||
$commandString = """${DNSHelper}"" add -host ${HostString}"
|
||||
$content = $RefreshScriptHeader + $commandString
|
||||
Write-Output "Creating latest refresh script"
|
||||
If ( Test-Path $RefreshScript ) { Remove-Item -Path $RefreshScript -Force }
|
||||
Try {
|
||||
New-Item -Path $RefreshScript -ItemType File -Force | Out-Null
|
||||
Set-Content -Path $RefreshScript -Value $content
|
||||
Set-Content -LiteralPath $RefreshScript -Value $content -Force -ErrorAction Stop
|
||||
Write-Output "Updating local hosts file with name-to-IP mappings for the following host(s): ${HostString}"
|
||||
& "${RefreshScript}"
|
||||
If ($LASTEXITCODE -ne 0) { Exit $LASTEXITCODE }
|
||||
}
|
||||
Catch { Write-Error $_.Exception.Message }
|
||||
|
||||
Write-Output "Updating local hosts file with name-to-IP mappings for the following host(s): ${HostString}"
|
||||
& "${RefreshScript}"
|
||||
Catch { Write-Error $_.Exception.Message ; Exit 1 }
|
||||
} Else {
|
||||
Write-Error "Cannot find the DNS Helper executable: ""${DNSHelper}"""
|
||||
Exit 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user