-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
56 lines (47 loc) · 2.22 KB
/
Copy pathinstall.ps1
File metadata and controls
56 lines (47 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# phpvm Windows Installer Script
# Usage: irm https://raw.githubusercontent.com/Vikrez22/phpvm/main/install.ps1 | iex
$ErrorActionPreference = 'Stop'
$Repo = "Vikrez22/phpvm"
$InstallDir = "$env:APPDATA\phpvm\bin"
$ExePath = Join-Path $InstallDir "phpvm.exe"
Write-Host "Installing phpvm (PHP Version Manager for Windows)..." -ForegroundColor Cyan
# Ensure installation directory exists
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
# Resolve latest release download URL
try {
$ReleaseUrl = "https://api.github.com/repos/$Repo/releases/latest"
$ReleaseInfo = Invoke-RestMethod -Uri $ReleaseUrl -Headers @{ "User-Agent" = "phpvm-installer" } -ErrorAction SilentlyContinue
$Asset = $ReleaseInfo.assets | Where-Object { $_.name -like "*windows*.exe" -or $_.name -eq "phpvm.exe" } | Select-Object -First 1
if ($Asset) {
$DownloadUrl = $Asset.browser_download_url
} else {
# Fallback to direct main tag binary URL if release asset isn't published yet
$DownloadUrl = "https://github.com/$Repo/releases/latest/download/phpvm.exe"
}
} catch {
# Fallback to direct URL on API failure
$DownloadUrl = "https://github.com/$Repo/releases/latest/download/phpvm.exe"
}
Write-Host "Downloading phpvm executable..." -ForegroundColor Yellow
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ExePath -UseBasicParsing
} catch {
Write-Error "Failed to download phpvm executable from $DownloadUrl. Error: $_"
exit 1
}
# Update User PATH if needed
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
Write-Host "Adding $InstallDir to User PATH..." -ForegroundColor Yellow
$NewPath = "$UserPath;$InstallDir"
[Environment]::SetEnvironmentVariable("Path", $NewPath, "User")
$env:Path = "$env:Path;$InstallDir"
}
Write-Host "`nphpvm successfully installed!" -ForegroundColor Green
Write-Host "Location: $ExePath"
Write-Host "`nTo verify installation in a new terminal, run:" -ForegroundColor Cyan
Write-Host " phpvm --version" -ForegroundColor White
Write-Host " phpvm doctor`n" -ForegroundColor White