修复代理
This commit is contained in:
34
install.sh
34
install.sh
@@ -441,13 +441,13 @@ install_go_from_official() {
|
||||
echo '' | sudo tee -a /etc/profile > /dev/null
|
||||
echo '# Go 代理配置(使用国内镜像加速)' | sudo tee -a /etc/profile > /dev/null
|
||||
echo 'export GOPROXY=https://goproxy.cn,direct' | sudo tee -a /etc/profile > /dev/null
|
||||
echo 'export GOSUMDB=sum.golang.google.cn' | sudo tee -a /etc/profile > /dev/null
|
||||
echo 'export GOSUMDB=off' | sudo tee -a /etc/profile > /dev/null
|
||||
fi
|
||||
|
||||
# 设置当前会话的 PATH 和 GOPROXY
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
export GOPROXY=https://goproxy.cn,direct
|
||||
export GOSUMDB=sum.golang.google.cn
|
||||
export GOSUMDB=off
|
||||
|
||||
# 验证安装
|
||||
if command -v go > /dev/null 2>&1; then
|
||||
@@ -513,12 +513,12 @@ install_go() {
|
||||
echo '' | sudo tee -a /etc/profile > /dev/null
|
||||
echo '# Go 代理配置(使用国内镜像加速)' | sudo tee -a /etc/profile > /dev/null
|
||||
echo 'export GOPROXY=https://goproxy.cn,direct' | sudo tee -a /etc/profile > /dev/null
|
||||
echo 'export GOSUMDB=sum.golang.google.cn' | sudo tee -a /etc/profile > /dev/null
|
||||
echo 'export GOSUMDB=off' | sudo tee -a /etc/profile > /dev/null
|
||||
fi
|
||||
|
||||
# 设置当前会话的 GOPROXY
|
||||
export GOPROXY=https://goproxy.cn,direct
|
||||
export GOSUMDB=sum.golang.google.cn
|
||||
export GOSUMDB=off
|
||||
|
||||
return 0
|
||||
fi
|
||||
@@ -683,11 +683,11 @@ build_from_source() {
|
||||
# 配置 Go 代理(使用国内镜像)
|
||||
echo -e "${BLUE}配置 Go 代理(使用国内镜像加速)...${NC}"
|
||||
# Go 代理镜像列表(按优先级排序,使用多个镜像以提高成功率)
|
||||
# 注意:不包含 proxy.golang.org,因为在中国大陆无法访问
|
||||
GO_PROXY_MIRRORS=(
|
||||
"https://goproxy.cn,https://goproxy.io,https://mirrors.aliyun.com/go-proxy/,direct"
|
||||
"https://goproxy.io,https://goproxy.cn,https://mirrors.aliyun.com/go-proxy/,direct"
|
||||
"https://mirrors.aliyun.com/go-proxy/,https://goproxy.cn,https://goproxy.io,direct"
|
||||
"https://proxy.golang.org,direct"
|
||||
)
|
||||
|
||||
# 测试并选择最快的 Go 代理(使用多个镜像作为备选)
|
||||
@@ -705,13 +705,15 @@ build_from_source() {
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果所有镜像都不可用,使用默认配置
|
||||
# 如果所有镜像都不可用,使用 direct 模式(直接从源码仓库下载)
|
||||
if [ -z "$GO_PROXY" ]; then
|
||||
GO_PROXY="https://proxy.golang.org,direct"
|
||||
echo -e "${YELLOW}⚠ 所有国内镜像不可用,使用默认代理${NC}"
|
||||
GO_PROXY="direct"
|
||||
echo -e "${YELLOW}⚠ 所有国内镜像不可用,使用 direct 模式(直接从 GitHub/GitLab 等下载)${NC}"
|
||||
echo -e "${YELLOW}⚠ 注意: direct 模式可能较慢,建议检查网络连接${NC}"
|
||||
else
|
||||
echo -e "${GREEN}✓ 使用 Go 代理链: ${GO_PROXY}${NC}"
|
||||
echo -e "${BLUE}说明: Go 会按顺序尝试代理列表中的镜像,提高下载成功率${NC}"
|
||||
echo -e "${BLUE}说明: Go 会按顺序尝试代理列表中的镜像,最后使用 direct 模式${NC}"
|
||||
echo -e "${BLUE}注意: 已禁用 GOSUMDB,避免连接 proxy.golang.org${NC}"
|
||||
fi
|
||||
|
||||
# 下载依赖(使用 sudo 以 root 用户执行,确保 PATH 包含 Go,并设置 GOPROXY)
|
||||
@@ -723,10 +725,15 @@ build_from_source() {
|
||||
if [ -d "/usr/local/go/bin" ]; then
|
||||
GO_PATH_ENV="PATH=/usr/local/go/bin:\$PATH"
|
||||
fi
|
||||
GO_ENV="$GO_PATH_ENV GOPROXY=${GO_PROXY} GOSUMDB=sum.golang.google.cn GOTIMEOUT=300"
|
||||
|
||||
# 禁用 GOSUMDB 以避免连接 proxy.golang.org(在中国大陆通常无法访问)
|
||||
# 如果必须启用校验和,可以使用 GOSUMDB=sum.golang.google.cn,但可能仍有问题
|
||||
GO_ENV="$GO_PATH_ENV GOPROXY=${GO_PROXY} GOSUMDB=off GOTIMEOUT=300"
|
||||
|
||||
# 显示当前 Go 环境信息
|
||||
echo -e "${BLUE}Go 环境信息:${NC}"
|
||||
echo -e "${BLUE} GOPROXY=${GO_PROXY}${NC}"
|
||||
echo -e "${BLUE} GOSUMDB=off (已禁用,避免连接 proxy.golang.org)${NC}"
|
||||
sudo bash -c "cd '$SOURCE_DIR' && $GO_ENV && go env GOPROXY GOSUMDB" || true
|
||||
echo ""
|
||||
|
||||
@@ -769,9 +776,10 @@ build_from_source() {
|
||||
echo -e "${YELLOW}最后30行日志:${NC}"
|
||||
tail -30 "$DOWNLOAD_LOG" 2>/dev/null || true
|
||||
echo ""
|
||||
echo -e "${YELLOW}尝试使用官方源...${NC}"
|
||||
# 如果失败,尝试使用官方源
|
||||
GO_ENV="$GO_PATH_ENV GOPROXY=https://proxy.golang.org,direct GOSUMDB=sum.golang.google.cn GOTIMEOUT=300"
|
||||
echo -e "${YELLOW}尝试使用 direct 模式(直接从 GitHub/GitLab 等下载)...${NC}"
|
||||
# 如果失败,尝试使用 direct 模式,直接从源码仓库下载
|
||||
# 注意:不使用 proxy.golang.org,因为在中国大陆无法访问
|
||||
GO_ENV="$GO_PATH_ENV GOPROXY=direct GOSUMDB=off GOTIMEOUT=300"
|
||||
DOWNLOAD_START_TIME=$(date +%s)
|
||||
if sudo bash -c "cd '$SOURCE_DIR' && $GO_ENV && timeout 600 go mod download -x" > "$DOWNLOAD_LOG" 2>&1; then
|
||||
DOWNLOAD_END_TIME=$(date +%s)
|
||||
|
||||
Reference in New Issue
Block a user