# pdep installer for Windows: irm https://pdep.dev/install.ps1 | iex # # Downloads the latest pdep (or the version in $env:PDEP_VERSION) from https://pdep.dev, checks it against the # release's SHA256SUMS, and puts it in %USERPROFILE%\.pdep\bin, which it adds to your user PATH. # No administrator rights needed. To remove pdep, delete %USERPROFILE%\.pdep. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $site = 'https://pdep.dev' $file = 'pdep-win-x64.exe' if (-not [Environment]::Is64BitOperatingSystem) { throw 'pdep needs 64-bit Windows.' } $version = $env:PDEP_VERSION if (-not $version) { $version = ([string](Invoke-RestMethod "$site/download/latest")).Trim() } if ($version -notmatch '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9a-z.-]+)?$') { throw "Not a pdep version: '$version'." } $dir = Join-Path $HOME '.pdep\bin' New-Item -ItemType Directory -Force -Path $dir | Out-Null $download = Join-Path $dir 'pdep.exe.download' Write-Host "Downloading pdep $version ..." Invoke-WebRequest "$site/download/$version/$file" -OutFile $download -UseBasicParsing $sums = [string](Invoke-RestMethod "$site/download/$version/SHA256SUMS") $expected = $sums -split "`n" | Where-Object { $_ -match "^([0-9a-fA-F]{64})\s+\*?$([regex]::Escape($file))\s*$" } | ForEach-Object { $Matches[1].ToUpperInvariant() } | Select-Object -First 1 $actual = (Get-FileHash -Path $download -Algorithm SHA256).Hash if (-not $expected -or $actual -ne $expected) { Remove-Item -Force $download throw "The download does not match its SHA-256 checksum; nothing was installed. Try again." } # Replace pdep.exe even while it runs (an agent's pdep mcp keeps it open): Windows refuses to overwrite or delete a # running program but lets it be renamed. Copies left by earlier updates go once nothing runs them any more. $exe = Join-Path $dir 'pdep.exe' $old = $null # never a same-named variable from the caller's session Get-ChildItem -Path $dir -Filter 'pdep.exe.old-*' -ErrorAction SilentlyContinue | ForEach-Object { Remove-Item -Force $_.FullName -ErrorAction SilentlyContinue } if (Test-Path $exe) { $old = Join-Path $dir ("pdep.exe.old-" + [Guid]::NewGuid().ToString('N')) Rename-Item -Path $exe -NewName (Split-Path $old -Leaf) } Move-Item -Path $download -Destination $exe if ($old) { Remove-Item -Force $old -ErrorAction SilentlyContinue } # still running: removed by the next update $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not (($userPath -split ';') -contains $dir)) { [Environment]::SetEnvironmentVariable('Path', ((@($userPath, $dir) | Where-Object { $_ }) -join ';'), 'User') } # This terminal too, also on a re-run: a terminal started before the first install (in VS Code, every terminal until # VS Code restarts) does not see the user PATH change. if (-not (($env:Path -split ';') -contains $dir)) { $env:Path = "$env:Path;$dir" } Write-Host '' Write-Host "pdep $version is installed: $dir\pdep.exe" -ForegroundColor Green Write-Host 'Next, inside a Git repository: pdep init' Write-Host 'If another terminal does not find pdep, open a new one (in VS Code: restart VS Code).' }