Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ jobs:
else
"$INSTALL_DIR/loops" version
fi

test-ps1:
name: install ps1 (windows)
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- shell: pwsh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$InstallDir = "$env:TEMP\loops-test"
.\install.ps1 -InstallDir $InstallDir
- shell: pwsh
run: |
$InstallDir = "$env:TEMP\loops-test"
& "$InstallDir\loops.exe" version
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ Run `loops --help` to see available commands, or `loops [command] --help` for de
brew install loops-so/tap/loops
```

### Script
### Script for macOS, Linux, Windows via WSL

```bash
curl -fsSL --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/loops-so/cli/main/install.sh | bash
```

To install a specific version or to a custom path, append `-s -- <version> <path>` to `bash` in the command above. The default installation path is `~/.local/bin`.

### Script for Windows PowerShell

```
irm https://raw.githubusercontent.com/Loops-so/cli/main/install.ps1 | iex
```

## Auth

The CLI requires a Loops API key. Get one from [Settings > API](https://app.loops.so/settings?page=api).
Expand Down
88 changes: 88 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# install.ps1
param(
[string]$Tag = "latest",
[string]$InstallDir = "$env:LOCALAPPDATA\Programs\loops"
)

$ErrorActionPreference = "Stop"

$GHRepo = "loops-so/cli"
$GHAssetsUrl = "https://github.com/$GHRepo/releases/download"
$ProjName = "loops_cli"
$BinName = "loops.exe"

$Arch = switch ($env:PROCESSOR_ARCHITECTURE) {
"AMD64" { "x86_64" }
"ARM64" { "arm64" }
"x86" { "i386" }
default { throw "Unsupported architecture: $env:PROCESSOR_ARCHITECTURE" }
}

$AuthHeader = @{}
if ($env:GITHUB_TOKEN) {
$AuthHeader["Authorization"] = "Bearer $env:GITHUB_TOKEN"
}

function Get-GithubRelease {
param([string]$Repo, [string]$Version)
$url = if ($Version -eq "latest") {
"https://api.github.com/repos/$Repo/releases/latest"
} else {
"https://api.github.com/repos/$Repo/releases/tags/$Version"
}
$response = Invoke-RestMethod -Uri $url -Headers $AuthHeader
return $response.tag_name
}

function Confirm-Checksum {
param([string]$FilePath, [string]$ChecksumsPath)
$filename = Split-Path $FilePath -Leaf
$line = Get-Content $ChecksumsPath | Where-Object { $_ -match [regex]::Escape($filename) }
if (-not $line) {
throw "Could not find checksum for $filename"
}
$want = ($line -split '\s+')[0].ToLower()
$got = (Get-FileHash -Algorithm SHA256 -Path $FilePath).Hash.ToLower()
if ($want -ne $got) {
throw "Checksum mismatch for $filename`: expected $want, got $got"
}
}

$release = Get-GithubRelease -Repo $GHRepo -Version $Tag
$versionNoV = $release -replace '^v', ''
$archiveName = "${ProjName}_windows_${Arch}.zip"
$checksumsName = "${ProjName}_${versionNoV}_checksums.txt"
$downloadUrl = "$GHAssetsUrl/$release/$archiveName"
$checksumsUrl = "$GHAssetsUrl/$release/$checksumsName"

Write-Host "Installing $ProjName $release for windows/$Arch..."

$tmpDir = Join-Path $env:TEMP ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Path $tmpDir | Out-Null

try {
Invoke-WebRequest -Uri $downloadUrl -OutFile "$tmpDir\$archiveName" -Headers $AuthHeader
Invoke-WebRequest -Uri $checksumsUrl -OutFile "$tmpDir\$checksumsName" -Headers $AuthHeader

Confirm-Checksum -FilePath "$tmpDir\$archiveName" -ChecksumsPath "$tmpDir\$checksumsName"

Expand-Archive -Path "$tmpDir\$archiveName" -DestinationPath $tmpDir -Force

if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir | Out-Null
}

Copy-Item "$tmpDir\$BinName" "$InstallDir\$BinName" -Force

$userPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$InstallDir*") {
[System.Environment]::SetEnvironmentVariable("Path", "$userPath;$InstallDir", "User")
$env:PATH = "$env:PATH;$InstallDir"
Write-Host "Added $InstallDir to your PATH"
}
} finally {
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
}

Write-Host "Done!"
Write-Host "Installed to $InstallDir\$BinName"