# Installs the pixel command line for the person who runs it, with no administrator rights: # # irm | iex # # It puts the command line under your local app data folder, with a private Node runtime from # nodejs.org when this computer has no Node 22 or later, and checks the SHA-256 of every download # before anything is put in place. Run the same line again to update; a run that stops leaves the # previous install as it was. Windows PowerShell 5.1 or PowerShell 7. # # Overrides (environment variables): # PIXEL_INSTALL_DIR= where the files go (default %LOCALAPPDATA%\pixel) # PIXEL_BIN_DIR= where the launchers go (default %LOCALAPPDATA%\pixel\bin): pixel.cmd # for cmd and PowerShell, and pixel, a shell script for Git Bash # PIXEL_NO_MODIFY_PATH=1 leave your user PATH alone, even when the launchers are not on it # PIXEL_PRIVATE_NODE=1 download Node even when this computer has Node 22 or later # PIXEL_NODE_MIRROR= where Node is downloaded from (default https://nodejs.org/dist) # PIXEL_INSTALL_ORIGIN= where pixel.cjs is downloaded from (default: where this script came from) # PIXEL_USER_ENV_KEY= for tests: a scratch registry key the user PATH is read from and written # to instead of HKCU:\Environment. Only a key HKCU:\Software\__pixel_install_test* # is taken; any other value stops the install before it changes anything. # # To remove it, delete the install folder and take the bin folder out of your user PATH (Settings, # System, About, Advanced system settings, Environment Variables). function Install-CommandLine { # Set here, not at the top: under `iex` the top of this script is the caller's own session. $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Windows PowerShell 5.1 on an older .NET may not offer TLS 1.2 by default. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $portalUrl = 'https://pxsignage.com' $origin = 'https://cli.pxsignage.com' $release = '2026.10.64' $bundleSha256 = '1f3bab4fadc2c45a0a4b6603ac9310333faaefa316d10ec3c0412a31b41ce11f' $nodeVersion = '24.22.3' $nodeSha256 = @{ 'win-x64' = 'e612af99f626ab415ea225af6bce5c971feb448cb5cae250bb1c3fa50c5f7d9f'; 'win-arm64' = 'b3cc74a295b39d4f273271e96f58c06dd2b35757ca12abec64c7d0598b434f14' } # A throw, never `exit`: under `iex`, exit would close the window the person typed the line in. function Stop-Install([string] $message) { throw "Install stopped: $message" } function Test-Address([string] $value) { $value -cmatch '\Ahttps?://[A-Za-z0-9.:/_~-]+\z' } # Plain http to another computer, as pixel login judges it: anyone on the way can change what comes back. function Test-UnencryptedRemote([string] $value) { $value -cmatch '\Ahttp://' -and $value -notmatch '\Ahttp://(localhost|127\.0\.0\.1|\[::1\])(:[0-9]+)?(/|\z)' } # .NET's SHA-256, not Get-FileHash: Windows PowerShell started from a PowerShell 7 terminal inherits # a module path under which Get-FileHash does not load. function Confirm-Sha256([string] $path, [string] $expected, [string] $what) { $sha = [Security.Cryptography.SHA256]::Create() $stream = [IO.File]::OpenRead($path) try { $actual = -join ($sha.ComputeHash($stream) | ForEach-Object { $_.ToString('x2') }) } finally { $stream.Dispose(); $sha.Dispose() } if ($actual -cne $expected) { Stop-Install "$what does not match its SHA-256 (expected $expected, got $actual), so nothing was changed." } } function Save-Url([string] $url, [string] $path) { try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $path } catch { Stop-Install "Could not download ${url}: $($_.Exception.Message)" } } function Get-NodeMajor([string] $node) { $printed = & $node --version if ($printed -match '\Av(\d+)\.') { [int] $Matches[1] } else { 0 } } function Test-Ascii([string] $value) { $value -cmatch '\A[\x20-\x7e]*\z' } # The path from folder $from to file $to, with .. where needed; null when they are on different drives. function Get-RelativePath([string] $from, [string] $to) { $from = [IO.Path]::GetFullPath($from) $to = [IO.Path]::GetFullPath($to) $root = [IO.Path]::GetPathRoot($to) if ($root -ine [IO.Path]::GetPathRoot($from)) { return $null } $fromParts = @($from.Substring($root.Length).Split('\') | Where-Object { $_ }) $toParts = @($to.Substring($root.Length).Split('\') | Where-Object { $_ }) $same = 0 while ($same -lt $fromParts.Count -and $same -lt $toParts.Count - 1 -and $fromParts[$same] -ieq $toParts[$same]) { $same++ } (@(@('..') * ($fromParts.Count - $same)) + @($toParts[$same..($toParts.Count - 1)])) -join '\' } # A file as pixel.cmd names it (cmd expands % even inside quotes), or null when only non-ASCII would name it. function Get-CmdPath([string] $launcherDir, [string] $file) { $relative = Get-RelativePath $launcherDir $file if ($null -ne $relative -and (Test-Ascii $relative)) { return '"%~dp0' + ($relative -replace '%', '%%') + '"' } if (Test-Ascii $file) { return '"' + ($file -replace '%', '%%') + '"' } $null } # A path in single quotes for sh, with forward slashes, which Git Bash's sh reads as Windows paths. function Get-ShQuoted([string] $path) { "'" + (($path -replace '\\', '/') -replace "'", "'\''") + "'" } function Get-ShPath([string] $launcherDir, [string] $file) { $relative = Get-RelativePath $launcherDir $file if ($null -ne $relative) { '"$here"/' + (Get-ShQuoted $relative) } else { Get-ShQuoted $file } } $installDir = if ($env:PIXEL_INSTALL_DIR) { $env:PIXEL_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'pixel' } $binDir = if ($env:PIXEL_BIN_DIR) { $env:PIXEL_BIN_DIR } else { Join-Path $env:LOCALAPPDATA 'pixel\bin' } $mirror = if ($env:PIXEL_NODE_MIRROR) { $env:PIXEL_NODE_MIRROR.TrimEnd('/') } else { 'https://nodejs.org/dist' } if ($env:PIXEL_INSTALL_ORIGIN) { $origin = $env:PIXEL_INSTALL_ORIGIN.TrimEnd('/') } if (-not [IO.Path]::IsPathRooted($installDir)) { Stop-Install 'PIXEL_INSTALL_DIR must be an absolute path.' } if (-not [IO.Path]::IsPathRooted($binDir)) { Stop-Install 'PIXEL_BIN_DIR must be an absolute path.' } if (-not (Test-Address $origin)) { Stop-Install 'PIXEL_INSTALL_ORIGIN must be an http or https address of plain letters, digits and . : / _ ~ -.' } if (-not (Test-Address $mirror)) { Stop-Install 'PIXEL_NODE_MIRROR must be an http or https address of plain letters, digits and . : / _ ~ -.' } # A warning, not a refusal: such installs exist, and someone who can change the download can delete a refusal too. if (Test-UnencryptedRemote $origin) { Write-Host -ForegroundColor Yellow "Warning: $origin is plain http, so the connection is not encrypted: what this installer downloads can be changed on the way, and its checks cannot catch that. Use it on a network you trust, or serve the portal over https." } $envKeyPath = 'HKCU:\Environment' if ($env:PIXEL_USER_ENV_KEY) { if ($env:PIXEL_USER_ENV_KEY -notmatch '\AHKCU:\\Software\\__pixel_install_test\w*\z') { Stop-Install "PIXEL_USER_ENV_KEY is for tests and must name a key HKCU:\Software\__pixel_install_test..., not $env:PIXEL_USER_ENV_KEY, so nothing was changed." } $envKeyPath = $env:PIXEL_USER_ENV_KEY } $envKey = Get-Item -LiteralPath $envKeyPath -ErrorAction SilentlyContinue if ($envKey -isnot [Microsoft.Win32.RegistryKey]) { Stop-Install "$envKeyPath is not a registry key, so your user PATH cannot be read; nothing was changed." } $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } $target = switch ($arch) { 'AMD64' { 'win-x64' } 'ARM64' { 'win-arm64' } default { $null } } $nodeExe = $null if ($env:PIXEL_PRIVATE_NODE -ne '1') { $found = Get-Command node -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if ($found -and (Get-NodeMajor $found.Source) -ge 22) { $nodeExe = $found.Source $nodeSaid = "Node $(& $nodeExe --version) at $nodeExe" } } $privateNode = Join-Path $installDir 'node\node.exe' $newNode = $false if (-not $nodeExe) { if (-not $target) { Stop-Install "nodejs.org has no Node build for Windows on $arch. Install Node 22 or later, then run this again." } $nodeExe = $privateNode $nodeSaid = "a private Node $nodeVersion" $newNode = -not ((Test-Path -LiteralPath $privateNode) -and ((& $privateNode --version) -eq "v$nodeVersion")) } # cmd reads a batch file in the console's code page, which differs between computers and can be # changed in a session, so a profile folder with characters outside it breaks a full path written # there. pixel.cmd therefore holds only ASCII: each file by its path from the launcher's own folder # (%~dp0, which cmd expands itself), else by its full path when that is ASCII, else (a system Node # only) as node, from the PATH the installer found it on. $bundlePath = Join-Path $installDir 'pixel.cjs' $cmdBundle = Get-CmdPath $binDir $bundlePath $cmdNode = if ($nodeExe -eq $privateNode) { Get-CmdPath $binDir $privateNode } elseif (Test-Ascii $nodeExe) { '"' + ($nodeExe -replace '%', '%%') + '"' } else { 'node' } foreach ($cmdPath in @($cmdBundle, $cmdNode)) { if (-not $cmdPath) { Stop-Install "cmd could not read the path from $binDir to $installDir in every code page, so pixel.cmd could not find its files; nothing was changed. Put PIXEL_BIN_DIR inside PIXEL_INSTALL_DIR, or use folders with ASCII names." } } # Git Bash reads its launcher as UTF-8, so any path works there; relative to the script, as pixel.cmd is. $shBundle = Get-ShPath $binDir $bundlePath $shNode = if ($nodeExe -eq $privateNode) { Get-ShPath $binDir $privateNode } else { Get-ShQuoted $nodeExe } New-Item -ItemType Directory -Force -Path $installDir, $binDir | Out-Null Get-ChildItem -LiteralPath $installDir -Directory -Force -Filter '.old-node.*' | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $staging = Join-Path $installDir ('.update.' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $staging | Out-Null try { Write-Host "Downloading pixel $release from $origin" $bundle = Join-Path $staging 'pixel.cjs' Save-Url "$origin/pixel.cjs" $bundle Confirm-Sha256 $bundle $bundleSha256 'The downloaded pixel.cjs' $runner = $nodeExe $unpacked = Join-Path $staging 'node' if ($newNode) { $archive = "node-v$nodeVersion-$target" $zip = Join-Path $staging 'node.zip' Write-Host "Downloading Node $nodeVersion for $target from $mirror" Save-Url "$mirror/v$nodeVersion/$archive.zip" $zip Confirm-Sha256 $zip $nodeSha256[$target] 'The downloaded Node archive' # Only node.exe and its licence: unpacking the whole archive (npm included) takes minutes on 5.1. New-Item -ItemType Directory -Path $unpacked | Out-Null Add-Type -AssemblyName System.IO.Compression.FileSystem $zipFile = [IO.Compression.ZipFile]::OpenRead($zip) try { foreach ($name in 'node.exe', 'LICENSE') { $entry = $zipFile.GetEntry("$archive/$name") if (-not $entry) { Stop-Install "The Node archive has no $archive/$name." } [IO.Compression.ZipFileExtensions]::ExtractToFile($entry, (Join-Path $unpacked $name)) } } finally { $zipFile.Dispose() } $runner = Join-Path $unpacked 'node.exe' } $json = "{`n `"url`": `"$portalUrl`",`n `"origin`": `"$origin`",`n `"release`": `"$release`"`n}`n" [IO.File]::WriteAllText((Join-Path $staging 'install.json'), $json) $printed = (& $runner $bundle version | Out-String).Trim() if ($LASTEXITCODE -ne 0) { Stop-Install "The downloaded command line did not run on this computer: $printed" } if (-not $printed.StartsWith("pixel $release ")) { Stop-Install "The downloaded command line says it is `"$printed`", not release $release." } $nodeDir = Join-Path $installDir 'node' if ($newNode) { if (Test-Path -LiteralPath $nodeDir) { try { Rename-Item -LiteralPath $nodeDir -NewName ('.old-node.' + [guid]::NewGuid().ToString('N')) } catch { Stop-Install "$nodeDir is in use. Close any pixel command that is running, then run this again." } } Move-Item -LiteralPath $unpacked -Destination $nodeDir Get-ChildItem -LiteralPath $installDir -Directory -Force -Filter '.old-node.*' | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue } elseif ($nodeExe -ne $privateNode -and (Test-Path -LiteralPath $privateNode)) { Remove-Item -LiteralPath $nodeDir -Recurse -Force -ErrorAction SilentlyContinue } Move-Item -LiteralPath $bundle -Destination (Join-Path $installDir 'pixel.cjs') -Force Move-Item -LiteralPath (Join-Path $staging 'install.json') -Destination (Join-Path $installDir 'install.json') -Force $launcher = Join-Path $staging 'pixel.cmd' Set-Content -LiteralPath $launcher -Encoding Ascii -Value @('@echo off', "$cmdNode $cmdBundle %*", 'exit /b %ERRORLEVEL%') Move-Item -LiteralPath $launcher -Destination (Join-Path $binDir 'pixel.cmd') -Force # Git Bash finds a command by its exact name, so it needs a shell script: LF endings and no # byte-order mark. $shLauncher = Join-Path $staging 'pixel' $shText = @('#!/bin/sh', 'case $0 in */*) here=${0%/*} ;; *) here=. ;; esac', "exec $shNode $shBundle `"`$@`"", '') -join "`n" [IO.File]::WriteAllText($shLauncher, $shText, (New-Object Text.UTF8Encoding $false)) Move-Item -LiteralPath $shLauncher -Destination (Join-Path $binDir 'pixel') -Force } finally { Remove-Item -LiteralPath $staging -Recurse -Force -ErrorAction SilentlyContinue } $pathSaid = $null # The raw value: %USERPROFILE% and the like must stay unexpanded when it is written back. $userPath = [string] $envKey.GetValue('Path', '', 'DoNotExpandEnvironmentNames') $wanted = $binDir.TrimEnd('\') $onPath = @(($userPath -split ';') + ($env:Path -split ';') | Where-Object { $_ -and [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') -ieq $wanted }).Count -gt 0 if (-not $onPath) { if ($env:PIXEL_NO_MODIFY_PATH -eq '1') { $pathSaid = "$binDir is not on your PATH, and PIXEL_NO_MODIFY_PATH=1 left your user PATH alone: add it to PATH, or run $binDir\pixel.cmd." } else { # Appended to the value as it is, so every other entry comes back byte for byte. $newPath = if ($userPath -eq '' -or $userPath.EndsWith(';')) { "$userPath$binDir" } else { "$userPath;$binDir" } New-ItemProperty -LiteralPath $envKeyPath -Name 'Path' -PropertyType ExpandString -Value $newPath -Force | Out-Null if ($envKeyPath -eq 'HKCU:\Environment') { # Setting any user variable through .NET tells open programs that the environment changed, so a # terminal started from Explorer sees the new PATH without signing out. [Environment]::SetEnvironmentVariable('PIXEL_INSTALL_PATH_CHANGED', '1', 'User') [Environment]::SetEnvironmentVariable('PIXEL_INSTALL_PATH_CHANGED', $null, 'User') } $pathSaid = "Added $binDir to your user PATH. Open a new terminal to use pixel." } } Write-Host "Installed pixel $release in $installDir, run by $nodeSaid." Write-Host "The launchers are $binDir\pixel.cmd, and $binDir\pixel for Git Bash." if ($pathSaid) { Write-Host $pathSaid } if (Test-UnencryptedRemote $portalUrl) { Write-Host "Next, sign in: pixel login --allow-http (the portal's address is plain http, so pixel login needs --allow-http to send your key there)" } else { Write-Host 'Next, sign in: pixel login' } } Install-CommandLine