vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
|
31560d91
Keenan Nemetz
2d ago
|
1 | <# |
| 2 | .SYNOPSIS | |
| 3 | Install Vole on Windows. | |
| 4 | ||
| 5 | .DESCRIPTION | |
| 6 | The release publishes this file as install.ps1 and serves it at | |
| 7 | /<repository>/channels/<channel>/install.ps1. It downloads the release's MSI, | |
| 8 | checks it against the release's SHA256SUMS, and hands it to the Windows | |
| 9 | Installer, which installs the binary and registers the Vole service. | |
| 10 | ||
| 11 | Run it from an elevated PowerShell. The MSI is not Authenticode-signed yet, | |
| 12 | so the strongest check available here is the checksum list fetched from the | |
| 13 | same HTTPS origin as the MSI. | |
| 14 | ||
| 15 | .PARAMETER Channel | |
| 16 | Release channel to follow. Default: stable. | |
| 17 | ||
| 18 | .PARAMETER Version | |
| 19 | Install a pinned release instead of following a channel, for example v0.2.0. | |
| 20 | ||
| 21 | .PARAMETER BaseUrl | |
| 22 | Origin that serves the release. Default: https://rodent.software/vole. | |
| 23 | ||
| 24 | .PARAMETER LogPath | |
| 25 | Write the Windows Installer log to this file instead of a temporary one. | |
| 26 | ||
| 27 | .PARAMETER DryRun | |
| 28 | Print the plan and exit without downloading or installing anything. | |
| 29 | ||
| 30 | .EXAMPLE | |
| 31 | Invoke-WebRequest https://rodent.software/vole/channels/stable/install.ps1 -OutFile install.ps1 | |
| 32 | .\install.ps1 | |
| 33 | ||
| 34 | .EXAMPLE | |
| 35 | .\install.ps1 -Version v0.2.0 -DryRun | |
| 36 | #> | |
| 37 | [CmdletBinding()] | |
| 38 | param( | |
| 39 | [string] $Channel = 'stable', | |
| 40 | [string] $Version, | |
| 41 | [string] $BaseUrl = 'https://rodent.software/vole', | |
| 42 | [string] $LogPath, | |
| 43 | [switch] $DryRun, | |
| 44 | [switch] $Help | |
| 45 | ) | |
| 46 | ||
| 47 | $ErrorActionPreference = 'Stop' | |
| 48 | $ProgressPreference = 'SilentlyContinue' | |
| 49 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
| 50 | ||
| 51 | $MsiName = 'vole-windows-amd64.msi' | |
| 52 | ||
| 53 | function Stop-WithError([string] $Message) { | |
| 54 | [Console]::Error.WriteLine("vole-install: $Message") | |
| 55 | exit 1 | |
| 56 | } | |
| 57 | ||
| 58 | function Show-Usage { | |
| 59 | @' | |
| 60 | Install Vole on Windows. | |
| 61 | ||
| 62 | Usage: install.ps1 [options] | |
| 63 | ||
| 64 | Options: | |
| 65 | -Channel <name> follow this release channel (default: stable) | |
| 66 | -Version <tag> install a pinned release, for example v0.2.0 | |
| 67 | -BaseUrl <url> origin that serves the release | |
| 68 | (default: https://rodent.software/vole) | |
| 69 | -LogPath <file> write the Windows Installer log here | |
| 70 | -DryRun print the plan, change nothing | |
| 71 | -Help show this help | |
| 72 | ||
| 73 | The script needs an elevated PowerShell. It downloads the release's MSI, checks | |
| 74 | it against the release's SHA256SUMS, and lets the Windows Installer install the | |
| 75 | binary and register the Vole service. `vole service install` writes the | |
| 76 | configuration on first use, and neither the configuration nor the instance's data | |
| 77 | is part of the package, so uninstalling leaves both in place. | |
| 78 | '@ | Write-Output | |
| 79 | } | |
| 80 | ||
| 81 | if ($Help) { | |
| 82 | Show-Usage | |
| 83 | exit 0 | |
| 84 | } | |
| 85 | ||
| 86 | if ($Version) { | |
| 87 | $tag = $Version | |
| 88 | if (-not $tag.StartsWith('v')) { | |
| 89 | $tag = "v$tag" | |
| 90 | } | |
| 91 | $base = "$BaseUrl/releases/$tag/artifacts" | |
| 92 | } | |
| 93 | else { | |
| 94 | $base = "$BaseUrl/channels/$Channel" | |
| 95 | } | |
| 96 | ||
| 97 | if ($DryRun) { | |
| 98 | Write-Output "would install from $base" | |
| 99 | Write-Output "would check $MsiName against $base/SHA256SUMS" | |
| 100 | Write-Output "would run: msiexec /i $MsiName /qn /norestart" | |
| 101 | exit 0 | |
| 102 | } | |
| 103 | ||
| 104 | $principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | |
| 105 | if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
| 106 | Stop-WithError 'run this from an elevated PowerShell (Run as administrator)' | |
| 107 | } | |
| 108 | ||
| 109 | $work = Join-Path ([IO.Path]::GetTempPath()) ("vole-install-" + [Guid]::NewGuid().ToString('N')) | |
| 110 | New-Item -ItemType Directory -Path $work | Out-Null | |
| 111 | $keepWork = $false | |
| 112 | $installerLog = $LogPath | |
| 113 | if (-not $installerLog) { | |
| 114 | $installerLog = Join-Path $work 'install.log' | |
| 115 | } | |
| 116 | ||
| 117 | try { | |
| 118 | Write-Output "installing Vole from $base" | |
| 119 | ||
| 120 | $sums = Join-Path $work 'SHA256SUMS' | |
| 121 | try { | |
| 122 | Invoke-WebRequest -Uri "$base/SHA256SUMS" -OutFile $sums -UseBasicParsing | |
| 123 | } | |
| 124 | catch { | |
| 125 | Stop-WithError "cannot download `"$base/SHA256SUMS`": $($_.Exception.Message)" | |
| 126 | } | |
| 127 | ||
| 128 | # SHA256SUMS is `<sha256> <name>`. Finding the MSI's line instead of guessing | |
| 129 | # its name means a release that stopped shipping one fails here, with the | |
| 130 | # reason, rather than as a 404 below. | |
| 131 | $pattern = '^\s*([0-9a-fA-F]{64})\s+\*?' + [regex]::Escape($MsiName) + '\s*$' | |
| 132 | $entry = Select-String -Path $sums -Pattern $pattern | Select-Object -First 1 | |
| 133 | if (-not $entry) { | |
| 134 | $message = "$base publishes no $MsiName." + [Environment]::NewLine + | |
| 135 | 'Pre-release releases have no MSI yet; install the binary from the release instead:' + [Environment]::NewLine + | |
| 136 | " $base/vole-windows-amd64.exe" | |
| 137 | Stop-WithError $message | |
| 138 | } | |
| 139 | $expected = $entry.Matches[0].Groups[1].Value.ToLowerInvariant() | |
| 140 | ||
| 141 | $msi = Join-Path $work $MsiName | |
| 142 | try { | |
| 143 | Invoke-WebRequest -Uri "$base/$MsiName" -OutFile $msi -UseBasicParsing | |
| 144 | } | |
| 145 | catch { | |
| 146 | Stop-WithError "cannot download `"$base/$MsiName`": $($_.Exception.Message)" | |
| 147 | } | |
| 148 | ||
| 149 | $actual = (Get-FileHash -Path $msi -Algorithm SHA256).Hash.ToLowerInvariant() | |
| 150 | if ($actual -ne $expected) { | |
| 151 | Stop-WithError "checksum mismatch for ${MsiName}: expected $expected, got $actual" | |
| 152 | } | |
| 153 | ||
| 154 | $arguments = @('/i', "`"$msi`"", '/qn', '/norestart', '/l*v', "`"$installerLog`"") | |
| 155 | $installer = Start-Process -FilePath msiexec.exe -ArgumentList $arguments -Wait -PassThru | |
| 156 | switch ($installer.ExitCode) { | |
| 157 | 0 { $keepWork = $false } | |
| 158 | 3010 { $keepWork = $false; Write-Output 'installed; a restart is required to finish' } | |
| 159 | 1641 { $keepWork = $false; Write-Output 'installed; Windows is restarting' } | |
| 160 | default { | |
| 161 | $keepWork = $true | |
| 162 | Stop-WithError "the installer failed with exit code $($installer.ExitCode); log: $installerLog" | |
| 163 | } | |
| 164 | } | |
| 165 | ||
| 166 | Write-Output '' | |
| 167 | Write-Output 'Vole is installed as the Vole service.' | |
| 168 | Write-Output 'It starts automatically after a short delay, and restarts after a failure.' | |
| 169 | Write-Output '' | |
| 170 | Write-Output 'next:' | |
| 171 | Write-Output ' & "C:\Program Files\Vole\vole.exe" service status' | |
| 172 | $config = Join-Path $env:ProgramData 'Vole\vole.toml' | |
| 173 | Write-Output (' edit "' + $config + '" to set public_url and HTTPS') | |
| 174 | Write-Output (' & "C:\Program Files\Vole\vole.exe" admin --config "' + $config + '" account invite <name>') | |
| 175 | Write-Output ' open 80, 443, and 2222 in Windows Firewall as needed; see docs/deploy/windows.md' | |
| 176 | } | |
| 177 | finally { | |
| 178 | if (-not $keepWork -and -not $LogPath) { | |
| 179 | Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue | |
| 180 | } | |
| 181 | } |