diff --git a/install.ps1 b/install.ps1 old mode 100644 new mode 100755 index dc94f14d6..fc2cfcb4a --- a/install.ps1 +++ b/install.ps1 @@ -1,19 +1,46 @@ +#!/usr/bin/env pwsh + $version = '0.1.145' $name = 'languageclient' $url = "https://github.com/autozimu/LanguageClient-neovim/releases/download/$version/$name-$version-" -if ($ENV:PROCESSOR_ARCHITECTURE -eq 'AMD64') { - $url += 'x86_64' -} else { - $url += 'i686' -} +$path = "$PSScriptRoot\bin\$name" -$url += '-pc-windows-gnu.exe' +switch ($true) { + $IsMacOS { + # MacOS is always x86_64 + $url += 'x86_64-apple-darwin' + } + $IsLinux { + # Detecting architecture is more involved on Linux + $arch = uname -sm + $url += switch ($arch) { + 'Linux x86_64' { 'x86_64' } + 'Linux i686' { 'i686' } + 'Linux aarch64' { 'aarch64' } + Default { throw 'architecture not supported' } + } + $url += '-unknown-linux-musl' + } + Default { + # Windows + $url += if ([Environment]::Is64BitOperatingSystem) { 'x86_64' } else { 'i686' } + $url += '-pc-windows-gnu.exe' + + # We need to tack on the .exe to the end of the download path + $path += '.exe' + } +} -$path = "$PSScriptRoot\bin\$name.exe" -if (Test-Path $path) { - Remove-Item -Force $path +if (Test-Path -LiteralPath $path) { + Remove-Item -Force -LiteralPath $path } + echo "Downloading $url ..." -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +if (!$IsCoreCLR) { + # We only need to do this for Windows PowerShell + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +} + Invoke-WebRequest -Uri $url -OutFile $path