问题现象
Linux正常通过dotnet-install.sh
安装dotnet(本篇以安装dotnet-runtime为例)时,会显示以下信息:
dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.
dotnet-install: Attempting to download using aka.ms link https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.13/dotnet-runtime-6.0.13-linux-x64.tar.gz
如果显示:
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
dotnet-install: Download attempt #1 has failed: 200 Unable to download https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.13/dotnet-runtime-6.0.13-linux-x64.tar.gz.
说明服务器下载指定文件失败,毕竟是国外源,再加上伟大的长城,也就见怪不怪了。
尝试在本机挂魔法下载,如果可以下载,说明只是服务器单方面无法连接
解决办法
给服务器挂代理肯定是可行的,但是操作比较繁琐,故不推荐
既然dotnet-install.sh
可以看到源码,那么直接在源码里指定下载链接岂不美哉?
- 在脚本中搜索语句
Attempting to download using
,跳转到1434
行(可能会不太一样,但原理相同),显示如下:
say "Attempting to download using $link_type link $download_link"
这是控制台输出固定的语句,简单分析这句话,包含了$link_type
和$download_link
两个变量,其中:
$link_type
:使用的下载源,不必关注$download_link
:使用的下载链接,原来就是这个链接导致下载失败啊
既然找到了存储下载链接的变量,那么就替换为能正常访问的链接。
从该行开始向上找,找离得最近的变量$download_link
赋值语句,就在不远的1429
行,显示如下:
download_link="${download_links[$link_index]}"
看起来很复杂,等号后的内容又嵌套了其他变量。
其实只用把引号内替换为能正常访问的下载链接就行了。
我为了方便,就把原本链接下载得到的文件(dotnet-runtime-6.0.13-linux-x64.tar.gz)上传到了蓝奏云,从蓝奏云解析到的下载链接为https://i41.lanzoug.com/0119150098126364bb/2023/01/19/758b5c9030a455df9d69df84075f1b01.gz?st=ZrY_80DQAuRaT-pnxI8kTQ&e=1674117127&b=BTMMYwl9B2xVZVNxUSxTJQkpWmgDdlE_bBjgBaQIoV2MAfFpqVHoFMVQyVC8EOFQ5U2hddAR9Bi0CKQ02UmEDLwUjDG0JewcsVWdTfw_c_c&fi=98126364&pid=223-90-112-230&up=2&mp=0&co=1
替换后原语句就变成了:
download_link="https://i41.lanzoug.com/0119150098126364bb/2023/01/19/758b5c9030a455df9d69df84075f1b01.gz?st=ZrY_80DQAuRaT-pnxI8kTQ&e=1674117127&b=BTMMYwl9B2xVZVNxUSxTJQkpWmgDdlE_bBjgBaQIoV2MAfFpqVHoFMVQyVC8EOFQ5U2hddAR9Bi0CKQ02UmEDLwUjDG0JewcsVWdTfw_c_c&fi=98126364&pid=223-90-112-230&up=2&mp=0&co=1"
保存后退出,然后重新运行脚本,如果显示(和上述链接一致):
dotnet-install: Attempting to download using aka.ms link https://i41.lanzoug.com/0119150098126364bb/2023/01/19/758b5c9030a455df9d69df84075f1b01.gz?st=ZrY_80DQAuRaT-pnxI8kTQ&e=1674117127&b=BTMMYwl9B2xVZVNxUSxTJQkpWmgDdlE_bBjgBaQIoV2MAfFpqVHoFMVQyVC8EOFQ5U2hddAR9Bi0CKQ02UmEDLwUjDG0JewcsVWdTfw_c_c&fi=98126364&pid=223-90-112-230&up=2&mp=0&co=1
说明脚本成功的用指定的链接下载了,后续安装也可以正常进行了。
标签:download,sh,link,install,dotnet,链接,下载 From: https://www.cnblogs.com/night-ray/p/17061921.html