# EnvKit installer for Windows 10/11 (x64). # # irm https://envkit.net/install.ps1 | iex # # Downloads the latest EnvKit-Setup-.exe from GitHub Releases and runs # it silently (per-machine install, so Windows shows one UAC prompt). Re-running # upgrades an existing install; your sites, databases and settings are kept. # # The installer is told it came from this script (/SOURCE=script-ps1) so EnvKit # can count installs per channel. An optional website campaign code rides along # from $env:ENVKIT_CAMPAIGN (lowercase letters, digits, - and _; max 64): # # $env:ENVKIT_CAMPAIGN = 'hn'; irm https://envkit.net/install.ps1 | iex # # macOS: curl -fsSL https://envkit.net/install.sh | sh $ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Repo = 'Env-Kit/envkit-releases' $Api = "https://api.github.com/repos/$Repo/releases/latest" $Releases = "https://github.com/$Repo/releases" # Anything that is not a plain code is ignored rather than passed on. $InstallerArgs = '/S /SOURCE=script-ps1' if ($env:ENVKIT_CAMPAIGN -and $env:ENVKIT_CAMPAIGN -cmatch '^[a-z0-9][a-z0-9_-]{0,63}$') { $InstallerArgs += " /CAMPAIGN=$($env:ENVKIT_CAMPAIGN)" } function Fail($msg) { Write-Host "envkit: $msg" -ForegroundColor Red exit 1 } if (-not [Environment]::Is64BitOperatingSystem) { Fail "EnvKit needs 64-bit Windows 10/11. See $Releases" } Write-Host 'Looking up the latest EnvKit release...' try { $release = Invoke-RestMethod -Uri $Api -Headers @{ Accept = 'application/vnd.github+json'; 'User-Agent' = 'envkit-install' } } catch { Fail "Could not reach the GitHub API. See $Releases" } $asset = $release.assets | Where-Object { $_.name -like '*.exe' } | Select-Object -First 1 if (-not $asset) { Fail "No Windows installer found in the latest release. See $Releases" } $version = $release.tag_name $tmp = Join-Path ([IO.Path]::GetTempPath()) "envkit-install-$([Guid]::NewGuid().ToString('N').Substring(0, 8))" New-Item -ItemType Directory -Path $tmp -Force | Out-Null $exe = Join-Path $tmp $asset.name try { Write-Host "Downloading EnvKit $version..." $prev = $ProgressPreference $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $exe -UseBasicParsing $ProgressPreference = $prev # Close a running copy so the installer can replace its files. Get-Process -Name 'EnvKit' -ErrorAction SilentlyContinue | ForEach-Object { Write-Host 'Closing the running EnvKit...' $_.CloseMainWindow() | Out-Null if (-not $_.WaitForExit(5000)) { $_ | Stop-Process -Force } } Write-Host 'Running the installer (Windows will ask for permission)...' # NSIS silent install; per-machine install needs elevation. $proc = Start-Process -FilePath $exe -ArgumentList $InstallerArgs -Verb RunAs -Wait -PassThru if ($proc.ExitCode -ne 0) { Fail "Installer exited with code $($proc.ExitCode)." } } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } $installed = @( (Join-Path $env:ProgramFiles 'EnvKit\EnvKit.exe'), (Join-Path $env:LOCALAPPDATA 'Programs\EnvKit\EnvKit.exe') ) | Where-Object { Test-Path $_ } | Select-Object -First 1 Write-Host "EnvKit $version installed." -ForegroundColor Green if ($installed) { Write-Host 'Launching...' Start-Process -FilePath $installed } else { Write-Host 'Open EnvKit from the Start menu to get started.' }