Установка Qt из зеркал с помощью qt-online-installer и MaintenanceTool
Данный способ максимально приближен к "официальному" методу установки Qt с одним лишь отличием, в качестве источников бинарных файлов библиотеки он использует зеркала.
Также данный способ не избавляет от необходимости в VPN в случае установки из РФ, так как и при установке, и при обновлении требуется авторизация на qt.io (а при попытке авторизоваться из РФ выдастся сообщение о запрете установки по IP).
Данный способ может быть полезен тем, у кого адрес VPN сервера заблокирован на download.qt.io.
Использование предельно простое: запустите скрипт и выберите зеркало:
PS > .\QtOnlineInstaller.ps1
============================================
Qt Online Installer
============================================
Select a mirror:
1. https://mirror.yandex.ru/mirrors/qt.io
2. https://ftp.fau.de/qtproject
3. https://mirrors.ukfast.co.uk/sites/qt.io
4. https://mirrors.20i.com/pub/qt.io
5. https://mirror.accum.se/mirror/qt.io/qtproject
6. https://ftp.jaist.ac.jp/pub/qtproject
Mirror number: 1
Selected mirror:
https://mirror.yandex.ru/mirrors/qt.io
Итак, скрипт запуска qt-online-installer с предварительным ручным выбором зеркала. Сам скрипты необходимо положить в каталог с установщиком.
QtOnlineInstaller.ps1
# ============================================================
# Qt Online Installer — mirror selection
# ============================================================
$ErrorActionPreference = "Stop"
# Path to the Qt Online Installer.
# The installer is expected to be located in the same directory
# as this script.
$Installer = Join-Path $PSScriptRoot "qt-online-installer-windows-x64.exe"
# List of mirrors.
# New mirrors can be added here without changing the rest
# of the script.
$Mirrors = @(
"https://mirror.yandex.ru/mirrors/qt.io",
"https://ftp.fau.de/qtproject",
"https://mirrors.ukfast.co.uk/sites/qt.io",
"https://mirrors.20i.com/pub/qt.io",
"https://mirror.accum.se/mirror/qt.io/qtproject",
"https://ftp.jaist.ac.jp/pub/qtproject"
)
# ------------------------------------------------------------
# Check if the installer exists
# ------------------------------------------------------------
if (-not (Test-Path -LiteralPath $Installer)) {
Write-Host ""
Write-Host "ERROR: Qt Online Installer was not found:" -ForegroundColor Red
Write-Host $Installer -ForegroundColor Yellow
Write-Host ""
exit 1
}
# ------------------------------------------------------------
# Display mirror list
# ------------------------------------------------------------
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Qt Online Installer" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Select a mirror:"
Write-Host ""
for ($i = 0; $i -lt $Mirrors.Count; $i++) {
# User-facing numbers start at 1,
# while array indexes start at 0.
Write-Host ("{0}. {1}" -f ($i + 1), $Mirrors[$i])
}
Write-Host ""
$Choice = Read-Host "Mirror number"
# ------------------------------------------------------------
# Validate selection
# ------------------------------------------------------------
# Check that the input is an integer
# and that it is within the available mirror range.
$SelectedIndex = 0
if (-not [int]::TryParse($Choice, [ref]$SelectedIndex)) {
Write-Host ""
Write-Host "ERROR: Please enter a mirror number." -ForegroundColor Red
exit 1
}
if ($SelectedIndex -lt 1 -or $SelectedIndex -gt $Mirrors.Count) {
Write-Host ""
Write-Host "ERROR: No mirror with this number exists." -ForegroundColor Red
Write-Host "Valid range: 1-$($Mirrors.Count)" -ForegroundColor Yellow
exit 1
}
# ------------------------------------------------------------
# Get selected mirror
# ------------------------------------------------------------
$Mirror = $Mirrors[$SelectedIndex - 1]
Write-Host ""
Write-Host "Selected mirror:" -ForegroundColor Cyan
Write-Host $Mirror -ForegroundColor Green
Write-Host ""
# ------------------------------------------------------------
# Start Qt Online Installer
# ------------------------------------------------------------
& $Installer --mirror $Mirror
$ExitCode = $LASTEXITCODE
Write-Host ""
if ($ExitCode -eq 0) {
Write-Host "Qt Online Installer completed successfully." -ForegroundColor Green
}
else {
Write-Host "Qt Online Installer exited with code: $ExitCode" -ForegroundColor Yellow
}
exit $ExitCode
Аналогичный скрипт для обновления и доустановки компонентов, работающий с MaintenanceTool.
QtMaintenance.ps1
# ============================================================
# Qt Maintenance Tool — mirror selection
# ============================================================
$ErrorActionPreference = "Stop"
# Path to MaintenanceTool.exe
$MaintenanceTool = "C:\Qt\MaintenanceTool.exe"
# List of mirrors.
# New mirrors can be added here without changing the rest
# of the script.
$Mirrors = @(
"https://mirror.yandex.ru/mirrors/qt.io",
"https://ftp.fau.de/qtproject",
"https://mirrors.ukfast.co.uk/sites/qt.io",
"https://mirrors.20i.com/pub/qt.io",
"https://mirror.accum.se/mirror/qt.io/qtproject",
"https://ftp.jaist.ac.jp/pub/qtproject"
)
# ------------------------------------------------------------
# Check if MaintenanceTool.exe exists
# ------------------------------------------------------------
if (-not (Test-Path -LiteralPath $MaintenanceTool)) {
Write-Host ""
Write-Host "ERROR: MaintenanceTool.exe was not found:" -ForegroundColor Red
Write-Host $MaintenanceTool -ForegroundColor Yellow
Write-Host ""
exit 1
}
# ------------------------------------------------------------
# Display mirror list
# ------------------------------------------------------------
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Qt Maintenance Tool" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Select a mirror:"
Write-Host ""
for ($i = 0; $i -lt $Mirrors.Count; $i++) {
# User-facing numbers start at 1,
# while array indexes start at 0.
Write-Host ("{0}. {1}" -f ($i + 1), $Mirrors[$i])
}
Write-Host ""
$Choice = Read-Host "Mirror number"
# ------------------------------------------------------------
# Validate selection
# ------------------------------------------------------------
# Check that the input is an integer
# and that it is within the available mirror range.
$SelectedIndex = 0
if (-not [int]::TryParse($Choice, [ref]$SelectedIndex)) {
Write-Host ""
Write-Host "ERROR: Please enter a mirror number." -ForegroundColor Red
exit 1
}
if ($SelectedIndex -lt 1 -or $SelectedIndex -gt $Mirrors.Count) {
Write-Host ""
Write-Host "ERROR: No mirror with this number exists." -ForegroundColor Red
Write-Host "Valid range: 1-$($Mirrors.Count)" -ForegroundColor Yellow
exit 1
}
# ------------------------------------------------------------
# Get selected mirror
# ------------------------------------------------------------
$Mirror = $Mirrors[$SelectedIndex - 1]
Write-Host ""
Write-Host "Selected mirror:" -ForegroundColor Cyan
Write-Host $Mirror -ForegroundColor Green
Write-Host ""
# ------------------------------------------------------------
# Start Maintenance Tool
# ------------------------------------------------------------
& $MaintenanceTool --mirror $Mirror
$ExitCode = $LASTEXITCODE
Write-Host ""
if ($ExitCode -eq 0) {
Write-Host "Maintenance Tool completed successfully." -ForegroundColor Green
}
else {
Write-Host "Maintenance Tool exited with code: $ExitCode" -ForegroundColor Yellow
}
exit $ExitCode
