# Lermy CLI installer and updater for Windows (PowerShell) # Usage: irm https://lermy.com/install.ps1 | iex # # Checks your installed `lermy` version and updates only when a newer release # is available (set $env:LERMY_FORCE_INSTALL = "1" to reinstall unconditionally). # Also checks a local Lermy project SKILL.md (via $env:LERMY_SKILL_PATH or # .\SKILL.md / .\.claude\skills\lermy-evidence\SKILL.md) and updates it when # a newer skill version is available on your Lermy server. $ErrorActionPreference = "Stop" $Version = if ($env:LERMY_CLI_VERSION) { $env:LERMY_CLI_VERSION } else { "latest" } $InstallDir = if ($env:LERMY_INSTALL_DIR) { $env:LERMY_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "lermy\bin" } $ForceInstall = $env:LERMY_FORCE_INSTALL -eq "1" $SkillPath = $env:LERMY_SKILL_PATH function Get-LermyTarget { $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant() switch ($arch) { "x64" { return "x86_64-pc-windows-msvc" } "amd64" { return "x86_64-pc-windows-msvc" } "arm64" { return "aarch64-pc-windows-msvc" } default { throw "Unsupported Windows CPU architecture '$arch'. Supported: x64 (AMD64) and ARM64." } } } function Get-BaseUrl { if ($env:LERMY_INSTALL_BASE_URL) { return $env:LERMY_INSTALL_BASE_URL.TrimEnd("/") } if ($Version -eq "latest") { return "https://lermy.com/downloads/cli/latest" } $tag = $Version if (-not $tag.StartsWith("cli-v")) { $tag = "cli-v" + $tag.TrimStart("v") } return "https://lermy.com/downloads/cli/$tag" } function Get-InstalledVersion($BinPath) { if (Test-Path $BinPath) { try { $out = & $BinPath --version 2>$null if ($out -match "lermy\s+(\S+)") { return $Matches[1].Trim() } } catch { return $null } } return $null } function Get-TargetVersion($BaseUrl) { if ($Version -ne "latest") { return ($Version -replace "^cli-v", "") -replace "^v", "" } try { $raw = (Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/VERSION").Content return ($raw -split "`n")[0].Trim().TrimStart("v") } catch { return $null } } function Update-LocalSkill($BinPath) { $candidates = @() if ($SkillPath) { $candidates += $SkillPath } else { foreach ($p in @( ".\.claude\skills\lermy-evidence\SKILL.md", ".\.codex\skills\lermy-evidence\SKILL.md", ".\.agents\skills\lermy-evidence\SKILL.md", ".\SKILL.md" )) { if ((Test-Path $p) -and ((Get-Content -Raw $p) -match "(?m)^name:\s*lermy-evidence")) { $candidates += $p } } } foreach ($candidate in $candidates) { if (-not (Test-Path $candidate)) { continue } if (-not ((Get-Content -Raw $candidate) -match "(?m)^name:\s*lermy-evidence")) { continue } $checkOutput = & $BinPath skill check $candidate 2>&1 | Out-String if ($LASTEXITCODE -eq 0) { Write-Host $checkOutput.Trim() continue } if ($checkOutput -match "(?i)outdated") { Write-Host $checkOutput.Trim() $updateOutput = & $BinPath skill update $candidate 2>&1 | Out-String if ($LASTEXITCODE -eq 0) { Write-Host $updateOutput.Trim() } else { Write-Host "Could not auto-update skill at $candidate ($($updateOutput.Trim()))." Write-Host "Sign in with 'lermy login' and run: lermy skill update --all" } } } } $Target = Get-LermyTarget $BaseUrl = Get-BaseUrl $Archive = "lermy-$Target.zip" $BinDest = Join-Path $InstallDir "lermy.exe" $CurrentVersion = Get-InstalledVersion $BinDest $TargetVersion = Get-TargetVersion $BaseUrl $NeedInstall = $true if (-not $ForceInstall -and $CurrentVersion -and $TargetVersion -and ($CurrentVersion -eq $TargetVersion)) { Write-Host "lermy $CurrentVersion is already up to date ($BinDest)." $NeedInstall = $false } if ($NeedInstall) { if ($CurrentVersion -and $TargetVersion) { Write-Host "Updating lermy from $CurrentVersion to $TargetVersion..." } else { Write-Host "Downloading $Archive from $BaseUrl..." } $TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ("lermy-install-" + [System.Guid]::NewGuid().ToString("N")) New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null try { $ArchivePath = Join-Path $TmpDir $Archive $SumsPath = Join-Path $TmpDir "SHA256SUMS" Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/$Archive" -OutFile $ArchivePath Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/SHA256SUMS" -OutFile $SumsPath $ExpectedSha = $null foreach ($line in Get-Content $SumsPath) { if ($line -match "^\s*([0-9a-fA-F]{64})\s+\*?\.?/?(.+?)\s*$") { if ($Matches[2] -eq $Archive) { $ExpectedSha = $Matches[1].ToLowerInvariant() break } } } if (-not $ExpectedSha) { throw "Checksum entry for $Archive not found in SHA256SUMS." } $ActualSha = (Get-FileHash -Algorithm SHA256 -Path $ArchivePath).Hash.ToLowerInvariant() if ($ActualSha -ne $ExpectedSha) { throw "SHA-256 verification failed for $Archive. Expected $ExpectedSha, got $ActualSha." } Write-Host "Verified SHA-256 checksum." Expand-Archive -Path $ArchivePath -DestinationPath $TmpDir -Force $ExtractedBin = Join-Path $TmpDir "lermy.exe" if (-not (Test-Path $ExtractedBin)) { throw "Archive $Archive did not contain expected 'lermy.exe' binary." } New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null Copy-Item -Path $ExtractedBin -Destination $BinDest -Force Write-Host "Installed lermy to $BinDest" } finally { Remove-Item -Path $TmpDir -Recurse -Force -ErrorAction SilentlyContinue } } $UserPath = [Environment]::GetEnvironmentVariable("Path", "User") $PathEntries = if ($UserPath) { $UserPath -split ";" } else { @() } if (-not ($PathEntries -contains $InstallDir)) { $NewUserPath = if ($UserPath) { "$UserPath;$InstallDir" } else { $InstallDir } [Environment]::SetEnvironmentVariable("Path", $NewUserPath, "User") $env:Path = "$InstallDir;$env:Path" Write-Host "Added $InstallDir to your user PATH. Restart your terminal if 'lermy' is not immediately found." } & $BinDest --version Update-LocalSkill $BinDest if ($env:LERMY_HANDOFF) { Write-Host "" if ($env:LERMY_URL) { & $BinDest --url $env:LERMY_URL handoff } else { & $BinDest handoff } exit $LASTEXITCODE } Write-Host "" Write-Host "Next steps: run 'lermy doctor' to check your environment, or 'lermy login' to sign in."