windows系统安装Dapr时,使用给的命令:powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex",运行后报错。
发现来源是github,直接去看github上找源文件就好了。https://github.com/dapr/cli/blob/master/install/install.ps1
在本地创建一个txt文件,把网页内容复制到txt文件中并重命名成install.ps1。
记住这个路径,并将powershell中的路径进行替换powershell -Command "iwr -useb D:\EXE\install.ps1 | iex"。
将https换成本地路径。
安装完成后,在系统变量中加入文件所在的路径。
重新启动powershell,输入dapr,如图说明成功安装了。
文件内容贴在这里了。
param (
[string]$Version,
[string]$DaprRoot = "c:\dapr",
[string]$DaprReleaseJsonUrl = "",
[scriptblock]$CustomAssetFactory = $null
)
Write-Output ""
$ErrorActionPreference = 'stop'
$DaprRoot = $DaprRoot -replace ' ', '` '
$DaprCliFileName = "dapr.exe"
$DaprCliFilePath = "${DaprRoot}${DaprCliFileName}"
$GitHubOrg = "dapr"
$GitHubRepo = "cli"
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 = @{}
}
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'"
break
}
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
if (Test-Path $DaprCliFilePath -PathType Leaf) {
Write-Warning "Dapr is detected - $DaprCliFilePath"
Invoke-Expression "$DaprCliFilePath --version"
Write-Output "Reinstalling Dapr..."
}
else {
Write-Output "Installing Dapr..."
}
Write-Output "Creating $DaprRoot directory"
New-Item -ErrorAction Ignore -Path $DaprRoot -ItemType "directory"
if (!(Test-Path $DaprRoot -PathType Container)) {
Write-Warning "Please visit https://docs.dapr.io/getting-started/install-dapr-cli/ for instructions on how to install without admin rights."
throw "Cannot create $DaprRoot"
}
$releaseJsonUrl = $DaprReleaseJsonUrl
if (!$releaseJsonUrl) {
$releaseJsonUrl = "https://api.github.com/repos/${GitHubOrg}/${GitHubRepo}/releases"
}
$releases = Invoke-RestMethod -Headers $githubHeader -Uri $releaseJsonUrl -Method Get
if ($releases.Count -eq 0) {
throw "No releases from github.com/dapr/cli repo"
}
function GetVersionInfo {
param (
[string]$Version,
$Releases
)
# Filter windows binary and download archive
if (!$Version) {
$release = $Releases | Where-Object { $.tag_name -notlike "rc" } | Select-Object -First 1
}
else {
$release = $Releases | Where-Object { $.tag_name -eq "v$Version" } | Select-Object -First 1
}
return $release
}
function GetWindowsAsset {
param (
$Release
)
if ($CustomAssetFactory) {
Write-Output "CustomAssetFactory dectected, try to invoke it"
return $CustomAssetFactory.Invoke($Release)
}
else {
$windowsAsset = $Release | Select-Object -ExpandProperty assets | Where-Object { $_.name -Like "*windows_amd64.zip" }
if (!$windowsAsset) {
throw "Cannot find the windows Dapr CLI binary"
}
[hashtable]$return = @{}
$return.url = $windowsAsset.url
$return.name = $windowsAsset.name
return $return
}`
}
$release = GetVersionInfo -Version $Version -Releases $releases
if (!$release) {
throw "Cannot find the specified Dapr CLI binary version"
}
$asset = GetWindowsAsset -Release $release
$zipFileUrl = $asset.url
$assetName = $asset.name
$zipFilePath = $DaprRoot + "" + $assetName
Write-Output "Downloading $zipFileUrl ..."
$githubHeader.Accept = "application/octet-stream"
$oldProgressPreference = $progressPreference;
$progressPreference = 'SilentlyContinue';
Invoke-WebRequest -Headers $githubHeader -Uri $zipFileUrl -OutFile $zipFilePath
$progressPreference = $oldProgressPreference;
if (!(Test-Path $zipFilePath -PathType Leaf)) {
throw "Failed to download Dapr Cli binary - $zipFilePath"
}
Write-Output "Extracting $zipFilePath..."
Microsoft.Powershell.Archive\Expand-Archive -Force -Path $zipFilePath -DestinationPath $DaprRoot
if (!(Test-Path $DaprCliFilePath -PathType Leaf)) {
throw "Failed to download Dapr Cli archieve - $zipFilePath"
}
Invoke-Expression "$DaprCliFilePath --version"
Write-Output "Clean up $zipFilePath..."
Remove-Item $zipFilePath -Force
Write-Output "Try to add $DaprRoot to User Path Environment variable..."
$UserPathEnvironmentVar = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPathEnvironmentVar -like 'dapr') {
Write-Output "Skipping to add $DaprRoot to User Path - $UserPathEnvironmentVar"
}
else {
[System.Environment]::SetEnvironmentVariable("PATH", $UserPathEnvironmentVar + ";$DaprRoot", "User")
$UserPathEnvironmentVar = [Environment]::GetEnvironmentVariable("PATH", "User")
Write-Output "Added $DaprRoot to User Path - $UserPathEnvironmentVar"
}
Write-Output "r
nDapr CLI is installed successfully."
Write-Output "To get started with Dapr, please visit https://docs.dapr.io/getting-started/ ."
Write-Output "Ensure that Docker Desktop is set to Linux containers mode when you run Dapr in self hosted mode."