Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,18 @@ jobs:
with:
persist-credentials: false

# scripts/install.ps1 against fake web and process cmdlets, in both PowerShell editions. It
# needs no toolchain and no package, so it runs first here and does not wait for windows-cross.
- name: Install script regressions (Windows PowerShell 5.1)
timeout-minutes: 2
shell: powershell
run: ./scripts/release/test_install_windows.ps1

- name: Install script regressions (PowerShell 7)
timeout-minutes: 2
shell: pwsh
run: ./scripts/release/test_install_windows.ps1

- name: Rust toolchain (rust-toolchain.toml)
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/acceptance.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/site/guide/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ curl -fsSL https://raw.githubusercontent.com/sunerpy/voltip/main/scripts/install

The script picks the package for the computer and downloads it together with the release's `SHA256SUMS`. Nothing is installed unless the checksum matches.

If a download fails, the script shows the address and the error it received. Check that this computer, or its proxy, can open the [releases page](https://github.com/sunerpy/voltip/releases).

- **Windows**: the per-user installer runs silently, without an administrator prompt, and starts Voltip when it is done.
- **Linux**: the `.deb` is installed through apt where apt is available, which asks for your password; otherwise the AppImage goes to `~/.local/bin` with an entry in the applications menu.
- **macOS**: the dmg for the Mac's processor is chosen automatically, also from a Rosetta terminal. The app goes to `/Applications`, or to `~/Applications` when that folder is not writable. Installed this way, it opens without the Gatekeeper prompt.
Expand Down
2 changes: 2 additions & 0 deletions docs/site/zh/guide/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ curl -fsSL https://raw.githubusercontent.com/sunerpy/voltip/main/scripts/install

脚本会为这台电脑选择合适的安装包,并连同发布附带的 `SHA256SUMS` 一起下载。校验不通过时不会安装任何内容。

下载失败时,脚本会显示下载地址和收到的错误。请检查这台电脑或所用代理能否打开[发布页](https://github.com/sunerpy/voltip/releases)。

- **Windows**:静默运行按用户安装的安装器,不需要管理员授权,安装完成后自动启动 Voltip。
- **Linux**:有 apt 的系统通过 apt 安装 `.deb`,会要求输入密码;否则把 AppImage 放到 `~/.local/bin`,并添加到应用菜单。
- **macOS**:自动识别处理器类型(在 Rosetta 终端中同样适用),下载对应的 dmg,把应用放进 `/Applications`;没有写入权限时放进 `~/Applications`。用这种方式安装的应用,打开时不会被 Gatekeeper 拦下。
Expand Down
60 changes: 47 additions & 13 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,49 @@ $Repo = "sunerpy/voltip"
$ChecksumFile = "SHA256SUMS"

function Stop-Install($Message) {
Write-Host "voltip-install: $Message" -ForegroundColor Red
throw "voltip-install: $Message"
}

function Say($Message) {
Write-Host "voltip-install: $Message"
}

# One GET with the parameters Windows PowerShell 5.1 and PowerShell 7 share, up to three times. An
# HTTP 4xx other than 408 and 429 is final; anything else (a 5xx, a timeout, a refused, dropped or
# failed TLS connection) is tried again. A failed request does not mean that the release lacks the
# file, so the last error names the URL and keeps every inner message. -TimeoutSec bounds only the
# wait for the response headers. A download is never cut off for being slow, only when its data
# stops arriving: for 30 s where the cmdlet has -OperationTimeoutSeconds (PowerShell 7.4 and
# later); Windows PowerShell 5.1 gives up on a read after 300 s by itself.
function Invoke-InstallRequest([string]$Uri, [string]$OutFile) {
$Request = @{
Uri = $Uri
UseBasicParsing = $true
TimeoutSec = 30
Headers = @{ "User-Agent" = "voltip-install" }
}
if ((Get-Command Microsoft.PowerShell.Utility\Invoke-WebRequest).Parameters.ContainsKey('OperationTimeoutSeconds')) {
$Request.OperationTimeoutSeconds = 30
}
for ($Attempt = 1; $Attempt -le 3; $Attempt++) {
try {
if ($OutFile) { Invoke-WebRequest @Request -OutFile $OutFile } else { Invoke-RestMethod @Request }
return
} catch {
$Status = $null
$Response = $_.Exception.PSObject.Properties['Response']
if ($Response -and $Response.Value) { $Status = [int]$Response.Value.StatusCode }
$Detail = $_.Exception.Message
for ($Inner = $_.Exception.InnerException; $Inner; $Inner = $Inner.InnerException) { $Detail += " --> " + $Inner.Message }
if ($Status) { $Detail = "HTTP ${Status}: $Detail" }
$Final = $Status -ge 400 -and $Status -lt 500 -and $Status -notin @(408, 429)
if ($Final -or $Attempt -eq 3) { Stop-Install "could not download ${Uri}: $Detail" }
Say "could not download ${Uri} (attempt ${Attempt}/3): $Detail; retrying in 1s"
Start-Sleep -Seconds 1
}
}
}

# Windows PowerShell 5.1 on an older Windows 10 may still offer TLS 1.0 only; GitHub needs 1.2.
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

Expand All @@ -38,9 +73,7 @@ if ($env:VOLTIP_VERSION) {
$Version = $env:VOLTIP_VERSION -replace '^v', ''
} else {
Say "finding the latest release"
$Release = Invoke-RestMethod -UseBasicParsing `
-Uri "https://api.github.com/repos/$Repo/releases/latest" `
-Headers @{ "User-Agent" = "voltip-install" }
$Release = Invoke-InstallRequest -Uri "https://api.github.com/repos/$Repo/releases/latest"
$Version = $Release.tag_name -replace '^v', ''
}
# The version goes into URLs and file names: digits and dots, and an optional pre-release tail.
Expand All @@ -55,20 +88,21 @@ $TempDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP ("voltip-" +
try {
$Installer = Join-Path $TempDir $Asset
$Checksums = Join-Path $TempDir $ChecksumFile
Say "downloading $Asset (Voltip $Version)"
try {
Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/$ChecksumFile" -OutFile $Checksums
} catch {
Stop-Install "release v$Version has no $ChecksumFile (is $Version a Voltip release?)"
}
Say "downloading $ChecksumFile (Voltip $Version)"
Invoke-InstallRequest -Uri "$BaseUrl/$ChecksumFile" -OutFile $Checksums
$Escaped = [Regex]::Escape($Asset)
$Line = Get-Content $Checksums | Where-Object { $_ -match "^[0-9a-fA-F]{64}\s+\*?$Escaped$" } | Select-Object -First 1
if (-not $Line) { Stop-Install "release v$Version has no $Asset" }
Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/$Asset" -OutFile $Installer
if (-not $Line) { Stop-Install "$ChecksumFile has no checksum for $Asset in release v$Version" }
Say "downloading $Asset (Voltip $Version)"
Invoke-InstallRequest -Uri "$BaseUrl/$Asset" -OutFile $Installer

$Expected = ($Line -split '\s+')[0].ToLowerInvariant()
$Actual = (Get-FileHash -Algorithm SHA256 -Path $Installer).Hash.ToLowerInvariant()
if ($Actual -ne $Expected) { Stop-Install "checksum mismatch for ${Asset}: nothing was installed" }
# Windows PowerShell 5.1 can end a download whose connection closes early as if it were complete;
# the size downloaded tells that apart from a changed file.
if ($Actual -ne $Expected) {
Stop-Install "checksum mismatch for $Asset ($((Get-Item -LiteralPath $Installer).Length) bytes downloaded): nothing was installed"
}
Say "SHA-256 matches $ChecksumFile"

# A running Voltip holds its files; the installer would stop at it.
Expand Down
25 changes: 16 additions & 9 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ for arg in "$@"; do
esac
done

# download <url> <file, or - for stdout>. A slow download is never cut off: it ends only when it
# cannot connect or its data stops arriving for 30 s. Timeouts and HTTP 408, 429, 500, 502, 503
# and 504 are tried up to three times (wget also retries a dropped connection); other errors such
# as a 404 stop at once. The tool's own message, TLS and proxy failures included, stays on stderr.
if command -v curl >/dev/null 2>&1; then
download() { curl -fsSL --retry 3 "$1" -o "$2"; }
fetch() { curl -fsSL --retry 3 "$1"; }
download() { curl -fsSL --connect-timeout 15 --speed-limit 1 --speed-time 30 --retry 2 --retry-delay 1 "$1" -o "$2"; }
elif command -v wget >/dev/null 2>&1; then
download() { wget -qO "$2" "$1"; }
fetch() { wget -qO - "$1"; }
# --timeout bounds a stalled DNS lookup, connection or read, not the whole download. Keep its
# diagnostics: -q hides failures, and -nv hides the status of retried HTTP errors.
download() { wget --timeout=30 --tries=3 --waitretry=1 --retry-on-http-error=408,429,500,502,503,504 -O "$2" "$1"; }
else
err "curl or wget is required"
fi
Expand Down Expand Up @@ -93,7 +97,9 @@ if [ -n "${VOLTIP_VERSION:-}" ]; then
version=$(printf '%s' "$VOLTIP_VERSION" | sed 's/^v//')
else
info "finding the latest release"
tag=$(fetch "https://api.github.com/repos/${REPO}/releases/latest" |
latest_url="https://api.github.com/repos/${REPO}/releases/latest"
metadata=$(download "$latest_url" -) || err "could not download $latest_url"
tag=$(printf '%s\n' "$metadata" |
sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
[ -n "$tag" ] || err "could not find the latest release"
version=$(printf '%s' "$tag" | sed 's/^v//')
Expand All @@ -117,16 +123,17 @@ cleanup() {
}
trap cleanup EXIT INT TERM

info "downloading ${asset} (Voltip ${version})"
info "downloading ${CHECKSUM_FILE} (Voltip ${version})"
download "${base_url}/${CHECKSUM_FILE}" "$tmp/$CHECKSUM_FILE" ||
err "release v${version} has no ${CHECKSUM_FILE} (is ${version} a Voltip release?)"
err "could not download ${base_url}/${CHECKSUM_FILE}"
expected=$(awk -v name="$asset" '{
file = $2
sub(/^\*/, "", file)
if (file == name) { print $1; exit }
}' "$tmp/$CHECKSUM_FILE")
[ -n "$expected" ] || err "release v${version} has no ${asset}"
download "${base_url}/${asset}" "$tmp/$asset" || err "could not download ${asset}"
[ -n "$expected" ] || err "${CHECKSUM_FILE} has no checksum for ${asset}"
info "downloading ${asset} (Voltip ${version})"
download "${base_url}/${asset}" "$tmp/$asset" || err "could not download ${base_url}/${asset}"

if command -v sha256sum >/dev/null 2>&1; then
actual=$(sha256sum "$tmp/$asset" | awk '{print $1}')
Expand Down
Loading