# Based on MeCodeGood's cli/install.ps1. # Installs the OddsSimply CLI on Windows: https://oddssimply.com/cli # irm https://oddssimply.com/install.ps1 | iex # # It needs Node 20 or newer. It downloads one file from oddssimply.com, checks it against its # published SHA-256 checksum, and puts it with a `oddssimply` command in # %LOCALAPPDATA%\oddssimply. It changes nothing else: if that folder isn't on your PATH, it tells # you the one line to add. $ErrorActionPreference = 'Stop' $Base = if ($env:ODDSSIMPLY_URL) { $env:ODDSSIMPLY_URL } else { 'https://oddssimply.com' } $Dir = if ($env:ODDSSIMPLY_BIN_DIR) { $env:ODDSSIMPLY_BIN_DIR } else { Join-Path $env:LOCALAPPDATA 'oddssimply' } function Fail($Message) { Write-Host "oddssimply install: $Message" -ForegroundColor Red exit 1 } if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Fail "OddsSimply's CLI needs Node 20 or newer, and Node isn't installed. Get the LTS version from https://nodejs.org, then run this again." } $Major = [int](node -p 'process.versions.node.split(".")[0]') if ($Major -lt 20) { Fail "OddsSimply's CLI needs Node 20 or newer; you have $(node -v). Update it from https://nodejs.org, then run this again." } $Temp = Join-Path ([IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString()) New-Item -ItemType Directory -Path $Temp | Out-Null try { $File = Join-Path $Temp 'oddssimply.mjs' try { Invoke-WebRequest -UseBasicParsing -Uri "$Base/cli/oddssimply.mjs" -OutFile $File $Expected = ((Invoke-WebRequest -UseBasicParsing -Uri "$Base/cli/oddssimply.mjs.sha256").Content.ToString().Trim() -split '\s+')[0] } catch { Fail "Couldn't download the CLI from $Base. Check your connection and try again." } $Actual = (Get-FileHash -Algorithm SHA256 -Path $File).Hash.ToLower() if ($Actual -ne $Expected.ToLower()) { Fail "The download didn't match its checksum, so nothing was installed. Try again in a few minutes." } New-Item -ItemType Directory -Force -Path $Dir | Out-Null Copy-Item $File (Join-Path $Dir 'oddssimply.mjs') -Force Set-Content -Path (Join-Path $Dir 'oddssimply.cmd') -Value "@node `"%~dp0oddssimply.mjs`" %*" -Encoding ASCII } finally { Remove-Item -Recurse -Force $Temp -ErrorAction SilentlyContinue } $Version = node (Join-Path $Dir 'oddssimply.mjs') --version Write-Host "Installed oddssimply $Version." $UserPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (($UserPath -split ';') -contains $Dir -or ($env:Path -split ';') -contains $Dir) { Write-Host "`nNext: oddssimply games" } else { Write-Host "`n$Dir isn't on your PATH yet. Add it with this line, then open a new terminal:`n" Write-Host " [Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'User') + ';$Dir', 'User')`n" Write-Host 'Then: oddssimply games' }