From 3c0ec02a168a406f68c7dac98f104f67b88d49a0 Mon Sep 17 00:00:00 2001 From: Van Tian Date: Sat, 14 Nov 2020 02:00:01 +0800 Subject: [PATCH] Support path that contains spaces (#514) Executing Install.ps1 will fail when DaprRoot contains spaces --- install/install.ps1 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/install/install.ps1 b/install/install.ps1 index ec285ada..093f7911 100755 --- a/install/install.ps1 +++ b/install/install.ps1 @@ -8,23 +8,27 @@ param ( $ErrorActionPreference = 'stop' +#Escape space of DapRoot path +$DaprRoot = $DaprRoot -replace ' ', '` ' + # Constants $DaprCliFileName = "dapr.exe" $DaprCliFilePath = "${DaprRoot}\${DaprCliFileName}" # GitHub Org and repo hosting Dapr CLI -$GitHubOrg="dapr" -$GitHubRepo="cli" +$GitHubOrg = "dapr" +$GitHubRepo = "cli" # Set Github request authentication for basic authentication. if ($Env:GITHUB_USER) { $basicAuth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Env:GITHUB_USER + ":" + $Env:GITHUB_TOKEN)); - $githubHeader = @{"Authorization"="Basic $basicAuth"} -} else { + $githubHeader = @{"Authorization" = "Basic $basicAuth" } +} +else { $githubHeader = @{} } -if((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') { +if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') { Write-Output "PowerShell requires an execution policy of 'RemoteSigned'." Write-Output "To make this change please run:" Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" @@ -39,7 +43,8 @@ if (Test-Path $DaprCliFilePath -PathType Leaf) { Write-Warning "Dapr is detected - $DaprCliFilePath" Invoke-Expression "$DaprCliFilePath --version" Write-Output "Reinstalling Dapr..." -} else { +} +else { Write-Output "Installing Dapr..." } @@ -57,7 +62,7 @@ if ($releases.Count -eq 0) { } # Filter windows binary and download archive -$windowsAsset = $releases | Where-Object { $_.tag_name -notlike "*rc*"} | Select-Object -First 1 | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows_amd64.zip" } +$windowsAsset = $releases | Where-Object { $_.tag_name -notlike "*rc*" } | Select-Object -First 1 | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows_amd64.zip" } if (!$windowsAsset) { throw "Cannot find the windows Dapr CLI binary" } @@ -88,9 +93,10 @@ Remove-Item $zipFilePath -Force # Add DaprRoot directory to User Path environment variable Write-Output "Try to add $DaprRoot to User Path Environment variable..." $UserPathEnvionmentVar = [Environment]::GetEnvironmentVariable("PATH", "User") -if($UserPathEnvionmentVar -like '*dapr*') { +if ($UserPathEnvionmentVar -like '*dapr*') { Write-Output "Skipping to add $DaprRoot to User Path - $UserPathEnvionmentVar" -} else { +} +else { [System.Environment]::SetEnvironmentVariable("PATH", $UserPathEnvionmentVar + ";$DaprRoot", "User") $UserPathEnvionmentVar = [Environment]::GetEnvironmentVariable("PATH", "User") Write-Output "Added $DaprRoot to User Path - $UserPathEnvionmentVar"