aboutsummaryrefslogtreecommitdiffstats
path: root/coin/provisioning/common/windows/set-proxy.ps1
blob: f2a89e43becc184b2d2cdebdd2d7737a86a796dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (C) 2017 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

$n = Get-Content "$PSScriptRoot\..\shared\http_proxy.txt"
$n = $n.Split('=')
New-Variable -Name $n[0] -Value $n[1]

if ([string]::IsNullOrEmpty($proxy)) {
    Write-Host "No proxy is defined."
} else {
    Write-Host "Checking proxy @ $proxy"
    $proxy = $proxy -replace '"', ""
    $webclient = New-Object System.Net.WebClient
    $proxy_obj = New-Object System.Net.WebProxy($proxy)
    $webclient.proxy = $proxy_obj
    try {
        $webpage = $webclient.DownloadData("http://proxy.intra.qt.io")
    } catch {
        $ErrorMessage = $_.Exception.Message
        $FailedItem = $_.Exception.ItemName
        $iserror = $true
    }
    if ($iserror -eq $true) {
        Write-Host "Testing download with proxy does not work: $ErrorMessage, $FailedItem. Not setting proxy."
    } else {
        Write-Host "Setting proxy to: $proxy"
        Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -Value "$proxy"
        Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value 1
        Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyOverride -Value 10.215
    }
}