# dten-speed installer for Windows: https://dten.com.br/cli # # irm https://dten.com.br/cli/install.ps1 | iex # # It downloads the dten-speed binary from the signed release at # https://github.com/Dten-Org/dten-speed/releases, checks it against the checksum written in this # script (taken from the signed SHA256SUMS of that release), puts it in # %LOCALAPPDATA%\Programs\dten-speed and adds that folder to the user's PATH, without administrator # rights. Set DTEN_SPEED_INSTALL_DIR to install somewhere else. # # SM-CLI-07 & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $Version = '1.0.0' $Expected = '05404c08f176be818b3e1ba27429b1abe69d9e195ae3e55380c47d3fb8a6d00c' $Url = "https://github.com/Dten-Org/dten-speed/releases/download/v$Version/dten-speed-windows-x64.exe" if (-not [Environment]::Is64BitOperatingSystem) { Write-Error 'dten-speed needs 64-bit Windows. Measure in the browser: https://dten.com.br' return } $Dir = if ($env:DTEN_SPEED_INSTALL_DIR) { $env:DTEN_SPEED_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\dten-speed' } $Tmp = Join-Path ([IO.Path]::GetTempPath()) ("dten-speed-" + [guid]::NewGuid().ToString() + '.exe') [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 Write-Host "Downloading dten-speed $Version for windows-x64..." try { Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Tmp $Actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $Tmp).Hash.ToLowerInvariant() if ($Actual -ne $Expected) { Write-Error "The download does not match the signed checksum (expected $Expected, got $Actual). Nothing was installed." return } $Runs = & $Tmp --version 2>$null if ($LASTEXITCODE -ne 0) { Write-Error 'dten-speed was downloaded but does not run on this system. Nothing was installed.' return } New-Item -ItemType Directory -Force -Path $Dir | Out-Null $Exe = Join-Path $Dir 'dten-speed.exe' Move-Item -Force -LiteralPath $Tmp -Destination $Exe } finally { if (Test-Path -LiteralPath $Tmp) { Remove-Item -Force -LiteralPath $Tmp } } # The user's PATH is read and written raw, as an expandable string: entries such as # %USERPROFILE%\AppData\Local\Microsoft\WindowsApps keep their variables. $Key = 'HKCU:\Environment' $Raw = (Get-Item -LiteralPath $Key).GetValue('Path', '', 'DoNotExpandEnvironmentNames') $Parts = @($Raw -split ';' | Where-Object { $_ }) if ($Parts -notcontains $Dir) { Set-ItemProperty -LiteralPath $Key -Name 'Path' -Value (($Parts + $Dir) -join ';') -Type ExpandString # Setting and clearing a variable through .NET announces the change to the open programs. [Environment]::SetEnvironmentVariable('DTEN_SPEED_INSTALLING', '1', 'User') [Environment]::SetEnvironmentVariable('DTEN_SPEED_INSTALLING', $null, 'User') $env:Path = "$env:Path;$Dir" Write-Host "Added $Dir to your PATH. Open a new terminal to use it everywhere." } Write-Host "Installed $Exe ($Runs)." Write-Host 'Run: dten-speed' }