# Startwell Capture installer for Windows (x64). macOS and Linux: install.sh. # # irm https://capture.startwellventures.com/install.ps1 | iex # # Installs or updates Startwell Capture for the current user (no administrator # rights). Re-run it any time to update in place. What it does, in order: # 1. checks this PC (64-bit Windows 10 or 11) # 2. reads the release feed (latest.yml) and downloads the setup .exe # 3. verifies the download against the feed's SHA-512; nothing runs otherwise # 4. runs the installer silently, per user, into # %LOCALAPPDATA%\Programs\startwell-capture, and opens the app # 5. fetches the Whisper speech models the app would pick for this PC, so # transcription works offline (SHA-256 checked, resumable) # # With options, run it as a script block: # & ([scriptblock]::Create((irm https://capture.startwellventures.com/install.ps1))) -Beta # -Beta the beta channel # -Model |none only that speech model instead of the recommended pair, or none # -Uninstall remove the app, keep your captures and settings # -Uninstall -Purge also remove %APPDATA%\Startwell Capture (asks first) # # Windows PowerShell 5.1 and PowerShell 7. Environment (for testing): # SWC_FEED_URL, SWC_NO_OPEN=1, SWC_MODEL_BASE. param( [switch]$Beta, [string]$Model = '', [switch]$Uninstall, [switch]$Purge ) # ============================================================= speech model # By default the pair the app would pick for this PC (recommendSpeechModels): # one model for recordings, one for live words (the same one on light PCs). # The tables are the app's own registry, generated between the markers. # >>> speech models: generated by apps/desktop/scripts/gen-speech-models-json.mjs from packages/shared/src/speech-models.ts; do not edit # the source (pinned commit), then Startwell's mirror; a file is used only if its SHA-256 matches $script:WhisperBase = 'https://huggingface.co/ggerganov/whisper.cpp/resolve/5359861c739e955e79d9a303bcbc70fb988958b1' $script:WhisperMirror = 'https://capture-updates.startwellventures.com/models/whisper' # file: ggml-.bin $script:WhisperModels = @( @{ Id = 'tiny'; Bytes = 77691713; Sha256 = 'be07e048e1e599ad46341c8d2a135645097a538221678b7acdd1b1919c6e1b21' }, @{ Id = 'tiny.en'; Bytes = 77704715; Sha256 = '921e4cf8686fdd993dcd081a5da5b6c365bfde1162e72b08d75ac75289920b1f' }, @{ Id = 'base'; Bytes = 147951465; Sha256 = '60ed5bc3dd14eea856493d334349b405782ddcaf0028d4b5df4088345fba2efe' }, @{ Id = 'base.en'; Bytes = 147964211; Sha256 = 'a03779c86df3323075f5e796cb2ce5029f00ec8869eee3fdfb897afe36c6d002' }, @{ Id = 'small'; Bytes = 487601967; Sha256 = '1be3a9b2063867b937e64e2ec7483364a79917e157fa98c5d94b5c1fffea987b' }, @{ Id = 'small.en'; Bytes = 487614201; Sha256 = 'c6138d6d58ecc8322097e0f987c32f1be8bb0a18532a3f88f734d1bbf9c41e5d' }, @{ Id = 'small-q5_1'; Bytes = 190085487; Sha256 = 'ae85e4a935d7a567bd102fe55afc16bb595bdb618e11b2fc7591bc08120411bb' }, @{ Id = 'small.en-q5_1'; Bytes = 190098681; Sha256 = 'bfdff4894dcb76bbf647d56263ea2a96645423f1669176f4844a1bf8e478ad30' }, @{ Id = 'medium-q5_0'; Bytes = 539212467; Sha256 = '19fea4b380c3a618ec4723c3eef2eb785ffba0d0538cf43f8f235e7b3b34220f' }, @{ Id = 'medium.en-q5_0'; Bytes = 539225533; Sha256 = '76733e26ad8fe1c7a5bf7531a9d41917b2adc0f20f2e4f5531688a8c6cd88eb0' }, @{ Id = 'large-v3-turbo-q5_0'; Bytes = 574041195; Sha256 = '394221709cd5ad1f40c46e6031ca61bce88931e6e088c188294c6d5a55ffa7e2' }, @{ Id = 'large-v3-turbo'; Bytes = 1624555275; Sha256 = '1fc70f774d38eb169993ac391eea357ef47c88757ef72ee5943879b7e8e2bc69' } ) # memory in tenths of a GB, logical processors; first match wins $script:WhisperTiers = @( @{ MinRamTenths = 150; MinCores = 8; Files = 'large-v3-turbo-q5_0'; Live = 'base' }, @{ MinRamTenths = 70; MinCores = 4; Files = 'small-q5_1'; Live = 'base' }, @{ MinRamTenths = 35; MinCores = 2; Files = 'base'; Live = 'tiny' }, @{ MinRamTenths = 0; MinCores = 0; Files = 'tiny'; Live = 'tiny' } ) # <<< speech models # Logical processors and memory in tenths of a GB, rounded like the app reads # them (Node's os.cpus().length and os.totalmem()), then the first tier this PC # meets. The app also counts a graphics card; the installer doesn't look. function Get-RecommendedModels { $tenths = 0 try { $tenths = [math]::Floor([double](Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory * 10 / 1GB + 0.5) } catch { } Select-SpeechTier -Cores ([Environment]::ProcessorCount) -RamTenths $tenths } # The models to fetch for this many logical processors and this much memory (tenths of a GB). function Select-SpeechTier([int]$Cores, [long]$RamTenths) { foreach ($t in $script:WhisperTiers) { if ($RamTenths -ge $t.MinRamTenths -and $Cores -ge $t.MinCores) { return @($t.Files, $t.Live) | Select-Object -Unique } } } function Install-StartwellCapture { param([switch]$Beta, [string]$Model, [switch]$Uninstall, [switch]$Purge) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest is many times slower with a progress bar in 5.1 [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $Site = 'https://capture.startwellventures.com' if ([Environment]::OSVersion.Platform -ne 'Win32NT') { throw "Error: This installer is for Windows. On macOS or Linux run: curl -fsSL $Site/install.sh | bash" } $AppName = 'Startwell Capture' $ExeName = 'Startwell Capture.exe' $Feed = if ($env:SWC_FEED_URL) { $env:SWC_FEED_URL.TrimEnd('/') } else { 'https://capture-updates.startwellventures.com' } if ($Beta) { $Feed = "$Feed/beta" } $DataDir = Join-Path $env:APPDATA $AppName $DefaultInstallDir = Join-Path $env:LOCALAPPDATA 'Programs\startwell-capture' $WhisperBase = if ($env:SWC_MODEL_BASE) { $env:SWC_MODEL_BASE.TrimEnd('/') } else { $script:WhisperBase } function Step([string]$m) { Write-Host "==> $m" -ForegroundColor White } function Ok([string]$m) { Write-Host " + $m" -ForegroundColor Green } function Note([string]$m) { Write-Host " $m" -ForegroundColor DarkGray } function Fail([string]$m) { throw "Error: $m" } # the uninstall entry electron-builder's installer writes (HKCU, per user) function Get-UninstallEntry { $keys = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' Get-ItemProperty -Path $keys -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -like "$AppName*" } | Select-Object -First 1 } function Get-InstalledExe { $entry = Get-UninstallEntry if ($entry -and $entry.DisplayIcon) { $p = ($entry.DisplayIcon -split ',')[0].Trim('"') if (Test-Path -LiteralPath $p) { return $p } } $p = Join-Path $DefaultInstallDir $ExeName if (Test-Path -LiteralPath $p) { return $p } return $null } function Get-AppProcesses { Get-Process -Name ([IO.Path]::GetFileNameWithoutExtension($ExeName)) -ErrorAction SilentlyContinue } # The installer would force-close a running copy, even mid-recording. Ask instead. function Wait-AppQuit { if (-not (Get-AppProcesses)) { return } Write-Host " $AppName is running. Quit it from its tray icon (right-click, Quit); waiting up to 2 minutes..." -ForegroundColor Yellow for ($i = 0; $i -lt 120; $i++) { if (-not (Get-AppProcesses)) { Ok 'quit'; return } Start-Sleep -Seconds 1 } Fail "$AppName is still running. Quit it and run this again." } function ConvertTo-Base64FromHex([string]$hex) { $bytes = New-Object byte[] ($hex.Length / 2) for ($i = 0; $i -lt $bytes.Length; $i++) { $bytes[$i] = [Convert]::ToByte($hex.Substring($i * 2, 2), 16) } [Convert]::ToBase64String($bytes) } # Parse latest.yml: the first .exe in files:, with its sha512. function Get-FeedInstaller([string]$yml) { $url = $null; $infiles = $false foreach ($line in ($yml -split "`r?`n")) { if ($line -match '^files:') { $infiles = $true; continue } if ($infiles -and $line -match '^\S') { $infiles = $false } if (-not $infiles) { continue } if ($line -match '^\s*-\s*url:\s*(\S+)') { $url = $Matches[1]; continue } if ($url -and $line -match '^\s+sha512:\s*(\S+)') { if ($url -like '*.exe') { return @{ Url = $url; Sha512 = $Matches[1] } } $url = $null } } return $null } # Resumable download into $Path.part, then rename. Windows PowerShell 5.1's # Invoke-WebRequest cannot resume, so this sends the Range header itself. function Get-Resumable([string]$Uri, [string]$Path) { $part = "$Path.part" $have = if (Test-Path -LiteralPath $part) { (Get-Item -LiteralPath $part).Length } else { 0 } $req = [System.Net.HttpWebRequest]::Create($Uri) $req.AllowAutoRedirect = $true $req.UserAgent = 'startwell-capture-installer' if ($have -gt 0) { $req.AddRange([long]$have) } try { $res = $req.GetResponse() } catch [System.Net.WebException] { $r = $_.Exception.Response if ($r -and [int]$r.StatusCode -eq 416) { $r.Close(); return $part } # already complete throw } try { $append = $have -gt 0 -and [int]$res.StatusCode -eq 206 $mode = if ($append) { [IO.FileMode]::Append } else { [IO.FileMode]::Create } $out = [IO.File]::Open($part, $mode, [IO.FileAccess]::Write) try { $res.GetResponseStream().CopyTo($out) } finally { $out.Close() } } finally { $res.Close() } return $part } # One model: never fails the install; a problem is a warning. The mirror if the source fails. function Install-OneModel([string]$Id) { $row = $script:WhisperModels | Where-Object { $_.Id -eq $Id } | Select-Object -First 1 if (-not $row) { Note "speech model $Id is not in this installer's list; get one in the app's Settings."; return } $dir = Join-Path $DataDir 'models\whisper' $file = Join-Path $dir "ggml-$Id.bin" try { New-Item -ItemType Directory -Force -Path $dir | Out-Null if ((Test-Path -LiteralPath $file) -and (Get-Item -LiteralPath $file).Length -eq $row.Bytes -and ((Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash.ToLower() -eq $row.Sha256)) { Ok "speech model $Id is already here"; return } Step ("Downloading the speech model $Id ({0} MB) for transcription on this PC" -f [math]::Floor($row.Bytes / 1e6)) $lastError = $null foreach ($base in @($WhisperBase, $script:WhisperMirror)) { try { $part = Get-Resumable -Uri "$base/ggml-$Id.bin" -Path $file if ((Get-FileHash -LiteralPath $part -Algorithm SHA256).Hash.ToLower() -eq $row.Sha256) { Move-Item -LiteralPath $part -Destination $file -Force Ok "speech model $Id verified (SHA-256)" return } Remove-Item -LiteralPath $part -Force Note "that copy of $Id did not match its SHA-256; trying the next address" } catch { $lastError = $_.Exception.Message } } $why = if ($lastError) { " ($lastError)" } else { '' } Write-Host " The speech model download stopped$why. Run this again to resume it, or get it in the app's Settings." -ForegroundColor Red } catch { Write-Host " The speech model download stopped ($($_.Exception.Message)). Run this again to resume it, or get it in the app's Settings." -ForegroundColor Red } } # The -Model choice, else the pair recommended for this PC. function Install-Model([string]$Id) { if ($Id -eq 'none') { Note "speech model: none (-Model none); get one in the app's Settings"; return } $ids = if ($Id) { @($Id) } else { @(Get-RecommendedModels) } foreach ($one in $ids) { Install-OneModel $one } } # ------------------------------------------------------------- checks if ($Purge -and -not $Uninstall) { Fail '-Purge only goes with -Uninstall.' } if ($Model -and $Model -ne 'none' -and -not ($script:WhisperModels | Where-Object { $_.Id -eq $Model })) { Fail ("Unknown speech model `"$Model`". Use one of: " + (($script:WhisperModels | ForEach-Object { $_.Id }) -join ', ') + ', or none.') } if (-not [Environment]::Is64BitOperatingSystem) { Fail 'Startwell Capture needs 64-bit Windows 10 or 11.' } $arch = $env:PROCESSOR_ARCHITECTURE; if ($env:PROCESSOR_ARCHITEW6432) { $arch = $env:PROCESSOR_ARCHITEW6432 } if ($arch -eq 'ARM64') { Note 'Windows on ARM: the x64 build runs under emulation.' } if ([Environment]::OSVersion.Version.Major -lt 10) { Fail 'Startwell Capture needs Windows 10 or 11.' } # ---------------------------------------------------------- uninstall if ($Uninstall) { if ($Purge) { Write-Host "This removes $AppName and ALL of its data:" Write-Host " $DataDir (captures, topics, settings, speech models)" Write-Host 'Context packs you exported to your Startwell Capture folder are kept.' $answer = Read-Host 'Type "delete" to continue' if ($answer -ne 'delete') { Fail 'Cancelled. Nothing was removed.' } } Wait-AppQuit $entry = Get-UninstallEntry if ($entry -and $entry.QuietUninstallString) { Step "Removing $AppName" $cmd = $entry.QuietUninstallString } elseif ($entry -and $entry.UninstallString) { Step "Removing $AppName" $cmd = "$($entry.UninstallString) /S" } else { $cmd = $null Note "$AppName was not found in this user's installed apps." } if ($cmd) { # "C:\...\Uninstall Startwell Capture.exe" /currentuser /S if ($cmd -match '^"([^"]+)"\s*(.*)$') { $exe = $Matches[1]; $rest = $Matches[2] } else { $exe = $cmd; $rest = '' } $p = Start-Process -FilePath $exe -ArgumentList $rest -PassThru $p.WaitForExit() Ok 'removed the app' } if ($Purge) { if (Test-Path -LiteralPath $DataDir) { Remove-Item -LiteralPath $DataDir -Recurse -Force } Ok 'removed app data' } else { Note "Your captures and settings are kept in $DataDir." } Write-Host "$AppName is uninstalled." -ForegroundColor White return } # ------------------------------------------------------------ install $work = Join-Path ([IO.Path]::GetTempPath()) ("swc-install-" + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $work | Out-Null try { Step 'Checking for the latest release' try { $yml = (Invoke-WebRequest -UseBasicParsing -Uri ("$Feed/latest.yml?t=" + [DateTimeOffset]::UtcNow.ToUnixTimeSeconds())).Content if ($yml -is [byte[]]) { $yml = [Text.Encoding]::UTF8.GetString($yml) } } catch { Fail "Could not reach the release feed at $Feed. Check your connection and try again." } $version = if ($yml -match '(?m)^version:\s*[''"]?([^''"\s]+)') { $Matches[1] } else { '?' } $setup = Get-FeedInstaller $yml if (-not $setup) { Fail 'The release feed lists no Windows installer. Try again later.' } Ok "$AppName $version" $installed = Get-UninstallEntry if ($installed) { Note "installed: $($installed.DisplayVersion)" } Step 'Downloading' $exe = Join-Path $work $setup.Url try { Invoke-WebRequest -UseBasicParsing -Uri "$Feed/$($setup.Url)" -OutFile $exe } catch { Fail "Download failed: $Feed/$($setup.Url)" } $got = ConvertTo-Base64FromHex (Get-FileHash -LiteralPath $exe -Algorithm SHA512).Hash if ($got -ne $setup.Sha512) { Fail "The download does not match the release feed's SHA-512 (got $got). Nothing was installed." } Ok 'SHA-512 verified' Unblock-File -LiteralPath $exe -ErrorAction SilentlyContinue Wait-AppQuit Step "Installing for $env:USERNAME" # not Start-Process -Wait: in 5.1 it also waits for anything the installer starts $p = Start-Process -FilePath $exe -ArgumentList '/S' -PassThru $p.WaitForExit() if ($p.ExitCode -ne 0) { Fail "The installer stopped with code $($p.ExitCode). Nothing else was changed." } $app = Get-InstalledExe if (-not $app) { Fail "The installer finished but $ExeName was not found in $DefaultInstallDir." } Ok "installed to $(Split-Path $app)" # models first: the app resumes any half-done .part it finds as it starts, # and two writers on one file spoil it for both Install-Model $Model if ($env:SWC_NO_OPEN -ne '1') { Step "Opening $AppName" Start-Process -FilePath $app | Out-Null } Write-Host '' Write-Host "$AppName $version is installed." -ForegroundColor White Write-Host '' Write-Host 'What happens next:' Write-Host ' - It lives in the system tray (the ^ by the clock). Windows asks for the' Write-Host ' microphone in Settings > Privacy & security > Microphone if it is off.' Write-Host ' - The app updates itself. To update by hand, run this command again.' Write-Host " - Uninstall: & ([scriptblock]::Create((irm $Site/install.ps1))) -Uninstall" } finally { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue } } # everything above only defines things: a truncated download runs nothing try { Install-StartwellCapture -Beta:$Beta -Model $Model -Uninstall:$Uninstall -Purge:$Purge } catch { Write-Host $_.Exception.Message -ForegroundColor Red # no `exit`: under `irm | iex` it would close the window (or end the caller's script) $global:LASTEXITCODE = 1 }