# Installs the opposable command line tool from getopposable.com on Windows. # # irm https://getopposable.com/install.ps1 | iex # # It downloads the Windows build, checks it against the published SHA-256 sums, puts opposable.exe in # %LOCALAPPDATA%\Opposable\bin and adds that folder to your user PATH. No administrator rights needed. # Settings: $env:OPPOSABLE_INSTALL_DIR to choose the folder, $env:OPPOSABLE_VERSION to pick another version. function Install-Opposable { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $version = if ($env:OPPOSABLE_VERSION) { $env:OPPOSABLE_VERSION } else { '0.3.0-preview.1' } $base = if ($env:OPPOSABLE_BASE_URL) { $env:OPPOSABLE_BASE_URL } else { 'https://getopposable.com' } $dir = if ($env:OPPOSABLE_INSTALL_DIR) { $env:OPPOSABLE_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Opposable\bin' } $arch = $env:PROCESSOR_ARCHITECTURE if ($env:PROCESSOR_ARCHITEW6432) { $arch = $env:PROCESSOR_ARCHITEW6432 } if ($arch -ne 'AMD64' -and $arch -ne 'ARM64') { throw "opposable install: no Windows build for $arch yet" } # Windows on ARM runs the x64 build under emulation. $name = "opposable-$version-windows-x64.zip" $url = if ($env:OPPOSABLE_VERSION) { "$base/download/cli/$name" } else { "$base/get/cli-windows-x64?src=install-ps1" } $tmp = Join-Path ([IO.Path]::GetTempPath()) ("opposable-" + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmp | Out-Null try { Write-Host "Downloading opposable $version for Windows..." $sums = (Invoke-WebRequest -UseBasicParsing -Uri "$base/download/cli/SHA256SUMS").Content if ($sums -is [byte[]]) { $sums = [Text.Encoding]::UTF8.GetString($sums) } $zip = Join-Path $tmp $name Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zip $line = ($sums -split "`n") | Where-Object { $_.Trim().EndsWith(" $name") } | Select-Object -First 1 if (-not $line) { throw "opposable install: $name isn't listed in SHA256SUMS" } $want = ($line.Trim() -split '\s+')[0].ToLower() $got = (Get-FileHash -Algorithm SHA256 -Path $zip).Hash.ToLower() if ($want -ne $got) { throw "opposable install: checksum mismatch for $name (expected $want, got $got). Nothing was installed." } Expand-Archive -Path $zip -DestinationPath (Join-Path $tmp 'x') -Force New-Item -ItemType Directory -Path $dir -Force | Out-Null Copy-Item -Path (Join-Path $tmp 'x\opposable.exe') -Destination (Join-Path $dir 'opposable.exe') -Force Copy-Item -Path (Join-Path $tmp 'x\NOTICES.txt') -Destination (Join-Path $dir 'NOTICES.txt') -Force } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') $parts = @() if ($userPath) { $parts = $userPath -split ';' | Where-Object { $_ } } if ($parts -notcontains $dir) { [Environment]::SetEnvironmentVariable('Path', (($parts + $dir) -join ';'), 'User') Write-Host "Added $dir to your user PATH. Open a new terminal window to use it." } if (($env:Path -split ';') -notcontains $dir) { $env:Path = "$env:Path;$dir" } $v = & (Join-Path $dir 'opposable.exe') --version Write-Host "Installed $v to $dir\opposable.exe" Write-Host "" Write-Host "Next: in the Opposable app on your phone, tap Pair with computer, then run" Write-Host " opposable connect CODE" } Install-Opposable