# Installs the latest Seqora for Windows. # # irm https://seqora.dev/install.ps1 | iex # # Reads the release catalog, downloads the newest Windows installer, checks # it against the SHA-256 the catalog publishes, and runs it silently (/S), the # way winget does, so there is no wizard to click through, then opens Seqora # (not in CI or a -NonInteractive session). The installer is # per-user, so it needs no administrator rights. A file fetched here carries # no Mark of the Web, so SmartScreen does not stop it the way it stops a # browser download of the same (unsigned) installer. # # Works in Windows PowerShell 5.1 and PowerShell 7. Keep this file ASCII: # Windows PowerShell 5.1 reads a script without a BOM as the ANSI code page. & { $ErrorActionPreference = 'Stop' # Windows PowerShell 5.1 redraws its progress bar for every chunk, which # makes a large download many times slower. $ProgressPreference = 'SilentlyContinue' $catalogUrl = 'https://releases.seqora.dev/channels/tester/catalog.json' # Lets the release site count installs made with this command apart from # browser downloads. It carries nothing about this computer. $userAgent = "Seqora-Install/1 PowerShell/$($PSVersionTable.PSVersion)" # Where the per-user installer registers itself (docs/WINGET.md). $uninstallKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Seqora' # Each failure returns from this block rather than calling exit, which # would close the window the command was pasted into. function Write-Failure([string] $message) { Write-Host "Seqora was not installed: $message" -ForegroundColor Red } # The installed copy, or $null when none is registered or its files are gone. function Get-InstalledSeqora { $entry = Get-ItemProperty -LiteralPath $uninstallKey -ErrorAction SilentlyContinue if (-not $entry -or -not $entry.DisplayIcon) { return $null } # The installer writes the app's own path, in quotes, as its icon. $exe = ([string] $entry.DisplayIcon).Trim('"') if (-not (Test-Path -LiteralPath $exe)) { return $null } [pscustomobject] @{ Version = [string] $entry.DisplayVersion; Exe = $exe } } # A dropped connection or a busy server gets two more tries. function Invoke-WithRetry([scriptblock] $action) { for ($attempt = 1; ; $attempt++) { try { return (& $action) } catch { if ($attempt -ge 3) { throw } Start-Sleep -Seconds (2 * $attempt) } } } if ($env:OS -ne 'Windows_NT') { Write-Failure 'this script is for Windows. Download Seqora from https://seqora.dev/' return } # AppLocker and WDAC put PowerShell in Constrained Language Mode, which # blocks the calls below. The same policy would block the unsigned app. if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') { Write-Failure 'this computer restricts PowerShell (Constrained Language Mode). Ask whoever manages it to install Seqora.' return } # WebView2, which Seqora draws its window with, needs Windows 10 or later. if ([Environment]::OSVersion.Version.Major -lt 10) { Write-Failure 'Seqora needs Windows 10 or later.' return } if (-not [Environment]::Is64BitOperatingSystem) { Write-Failure 'Seqora needs 64-bit Windows.' return } # The installer is x64. Windows 11 on ARM runs x64 apps; Windows 10 on ARM # does not. The registry names the real processor even when this # PowerShell itself runs emulated. $machineArch = (Get-ItemProperty -LiteralPath 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -ErrorAction SilentlyContinue).PROCESSOR_ARCHITECTURE if ($machineArch -eq 'ARM64' -and [Environment]::OSVersion.Version.Build -lt 22000) { Write-Failure 'on ARM, Seqora needs Windows 11, which can run x64 apps.' return } # Windows PowerShell 5.1 can default to TLS 1.0, which the release host refuses. try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch {} # A proxy that asks for sign-in gets the Windows account, as a browser # would, instead of a 407. The first line is for Windows PowerShell 5.1, # the second for PowerShell 7. try { [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials } catch {} try { [Net.Http.HttpClient]::DefaultProxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials } catch {} Write-Host 'Finding the latest Seqora release...' try { $catalog = Invoke-WithRetry { Invoke-RestMethod -Uri $catalogUrl -UserAgent $userAgent -UseBasicParsing } } catch { Write-Failure "could not read the release catalog ($($_.Exception.Message))." return } # A captive portal or a filtering proxy answers with a web page instead. if (-not $catalog.releases) { Write-Failure "the release catalog did not come back as expected. Check that this computer can open $catalogUrl" return } $release = $null $installer = $null foreach ($candidate in $catalog.releases) { $file = $candidate.downloads.windows.x86_64.primary if ($file.url -and $file.sha256) { $release = $candidate $installer = $file break } } if (-not $installer) { Write-Failure 'no Windows release is published yet.' return } $installed = Get-InstalledSeqora if ($installed) { if ($installed.Version -eq $release.version) { Write-Host "Seqora $($release.version) is already installed and up to date." -ForegroundColor Green return } # The installer refuses to downgrade, so say so here instead. $newer = $false try { $newer = [version] $installed.Version -gt [version] $release.version } catch {} if ($newer) { Write-Host "Seqora $($installed.Version) is installed, which is newer than the latest release ($($release.version))." -ForegroundColor Green return } # A silent install closes a running Seqora without asking, which would # lose unsaved work. Leave that to the person. $processName = [IO.Path]::GetFileNameWithoutExtension($installed.Exe) if (Get-Process -Name $processName -ErrorAction SilentlyContinue) { Write-Failure "Seqora is open. Quit it, then run this command again to update to $($release.version)." return } } # A folder of its own, so a file left locked by an earlier run or a virus # scan cannot get in the way. $workDir = Join-Path ([IO.Path]::GetTempPath()) ('seqora-install-' + [Guid]::NewGuid().ToString('N')) $fileName = [IO.Path]::GetFileName([string] $installer.filename) if (-not $fileName) { $fileName = 'Seqora-setup.exe' } $target = Join-Path $workDir $fileName try { try { $null = New-Item -ItemType Directory -Path $workDir } catch { Write-Failure "could not create a folder in $([IO.Path]::GetTempPath()) ($($_.Exception.Message))." return } Write-Host "Downloading Seqora $($release.version)..." try { Invoke-WithRetry { Invoke-WebRequest -Uri $installer.url -OutFile $target -UserAgent $userAgent -UseBasicParsing } } catch { Write-Failure "the download failed ($($_.Exception.Message))." return } $actual = $null try { $actual = (Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash } catch {} if (-not $actual) { Write-Failure 'the downloaded installer disappeared. Antivirus software may have removed it.' return } if ($actual -ne ([string] $installer.sha256).Trim()) { Write-Failure 'the download does not match its published SHA-256, so it was deleted.' return } Write-Host "Installing Seqora $($release.version)..." try { $process = Start-Process -FilePath $target -ArgumentList '/S' -PassThru # Windows PowerShell 5.1 loses the exit code unless the handle is read # before the process ends. $null = $process.Handle # Wait for the installer alone. Start-Process -Wait in PowerShell 7 also # waits for anything the installer leaves running. $process.WaitForExit() } catch { Write-Failure "Windows would not run the installer ($($_.Exception.Message)). Smart App Control, where it is on, blocks unsigned apps however they are downloaded." return } } finally { Remove-Item -LiteralPath $workDir -Recurse -Force -ErrorAction SilentlyContinue } $now = Get-InstalledSeqora if ($process.ExitCode -eq 0 -and $now -and $now.Version -eq $release.version) { # One word in Seqora's data folder, so its usage counts can tell installs # made with this command apart. Nothing else is written, and a failure # here never fails the install. try { $dataDir = Join-Path $env:APPDATA 'com.seqora.app' $null = New-Item -ItemType Directory -Force -Path $dataDir [IO.File]::WriteAllText((Join-Path $dataDir 'install-source'), 'script') } catch {} Write-Host "Seqora $($release.version) is installed." -ForegroundColor Green # Open the app for the person who pasted the command. A CI job, a # service or a -NonInteractive run has nobody to see a window, so it # only gets the line. A failure to start never fails the install. $interactive = [Environment]::UserInteractive -and -not $env:CI -and -not ([Environment]::GetCommandLineArgs() -match '^-NonI') $started = $false if ($interactive) { try { $null = Start-Process -FilePath $now.Exe $started = $true } catch {} } if ($started) { Write-Host 'Opening Seqora...' } else { Write-Host 'Open it from the Start menu or the desktop shortcut.' } } elseif ($process.ExitCode -eq 0) { Write-Failure "the installer finished, but Seqora $($release.version) is not registered. Try again, or download the installer from https://seqora.dev/" } else { # In silent mode the installer prints its own reason, in red, above this. Write-Failure "the installer stopped (exit code $($process.ExitCode))." } }