sync: add mirror/switch on version fetch fail, asset platform guard, install fallback to fork (Linux)
This commit is contained in:
+188
-24
@@ -462,8 +462,11 @@ for asset in assets:
|
||||
if any(k in name for k in exclude_kw):
|
||||
continue
|
||||
score = 0
|
||||
has_platform = False
|
||||
for kw in platform_kw:
|
||||
if kw in name: score += 10; break
|
||||
if kw in name: score += 10; has_platform = True; break
|
||||
if not has_platform:
|
||||
continue
|
||||
for kw in arch_kw:
|
||||
if kw in name: score += 10; break
|
||||
if not any(name.endswith(ext) for ext in ['.tar.gz', '.tgz', '.zip', '.7z']):
|
||||
@@ -1156,23 +1159,76 @@ main_menu() {
|
||||
select_source
|
||||
info "安装来源: $SELECTED_SOURCE"
|
||||
|
||||
if ! get_remote_version "$SELECTED_SOURCE"; then
|
||||
err "无法获取远程版本"
|
||||
read -rp "按 Enter 继续..."
|
||||
return
|
||||
fi
|
||||
while ! get_remote_version "$SELECTED_SOURCE"; do
|
||||
warn "无法从 $SELECTED_SOURCE 获取远程版本"
|
||||
echo ""
|
||||
echo -e "${YELLOW}请选择操作:${NC}"
|
||||
echo " 1) 配置镜像重试 ($SELECTED_SOURCE)"
|
||||
echo " 2) 切换其他来源"
|
||||
echo " 0) 退出"
|
||||
echo ""
|
||||
read -rp "请输入选项 [0-2]: " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
if [[ "$SELECTED_SOURCE" == "npm" ]]; then
|
||||
read -rp "请输入 npm registry URL (Enter 使用默认 https://registry.npmmirror.com): " reg
|
||||
NPM_REGISTRY="${reg:-https://registry.npmmirror.com}"
|
||||
ok "npm registry 已设置为: $NPM_REGISTRY"
|
||||
else
|
||||
read -rp "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com): " mirror
|
||||
GITHUB_MIRROR="${mirror:-https://ghproxy.com}"
|
||||
ok "GitHub 镜像已设置为: $GITHUB_MIRROR"
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
local found=false
|
||||
for fs in npm github-official github-fork; do
|
||||
[[ "$fs" == "$SELECTED_SOURCE" ]] && continue
|
||||
info "尝试从 $fs 获取..."
|
||||
if get_remote_version "$fs"; then
|
||||
SELECTED_SOURCE="$fs"
|
||||
ok "从 $fs 获取版本成功: v$REMOTE_VERSION"
|
||||
found=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "$found" != true ]]; then
|
||||
warn "所有来源均无法获取版本"
|
||||
fi
|
||||
;;
|
||||
0) exit 1 ;;
|
||||
*) warn "无效选项,请重新输入" ;;
|
||||
esac
|
||||
echo ""
|
||||
done
|
||||
STATUS_REMOTE_VERSION="$REMOTE_VERSION"
|
||||
|
||||
if [[ "$SELECTED_SOURCE" == "npm" ]]; then
|
||||
install_nodejs
|
||||
fi
|
||||
|
||||
local ok=false
|
||||
case "$SELECTED_SOURCE" in
|
||||
npm) install_from_npm ;;
|
||||
github-official) install_from_github "$GITHUB_OFFICIAL_REPO" ;;
|
||||
github-fork) install_from_github "$GITHUB_FORK_REPO" ;;
|
||||
npm)
|
||||
install_from_npm && ok=true || ok=false
|
||||
;;
|
||||
github-official)
|
||||
if install_from_github "$GITHUB_OFFICIAL_REPO"; then
|
||||
ok=true
|
||||
else
|
||||
warn "官方仓库无匹配 asset,尝试本仓库..."
|
||||
install_from_github "$GITHUB_FORK_REPO" && ok=true || ok=false
|
||||
fi
|
||||
;;
|
||||
github-fork)
|
||||
install_from_github "$GITHUB_FORK_REPO" && ok=true || ok=false
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$ok" != true ]]; then
|
||||
err "HAPI CLI 安装失败"
|
||||
fi
|
||||
|
||||
collect_status
|
||||
read -rp "按 Enter 继续..."
|
||||
;;
|
||||
@@ -1186,11 +1242,48 @@ main_menu() {
|
||||
[[ "$upgrade_source" == "arkylin/Hapi-Docker" ]] && SELECTED_SOURCE="github-fork"
|
||||
[[ -z "$SELECTED_SOURCE" ]] && SELECTED_SOURCE="npm"
|
||||
|
||||
if ! get_remote_version "$SELECTED_SOURCE"; then
|
||||
err "无法获取远程版本"
|
||||
read -rp "按 Enter 继续..."
|
||||
return
|
||||
fi
|
||||
while ! get_remote_version "$SELECTED_SOURCE"; do
|
||||
warn "无法从 $SELECTED_SOURCE 获取远程版本"
|
||||
echo ""
|
||||
echo -e "${YELLOW}请选择操作:${NC}"
|
||||
echo " 1) 配置镜像重试 ($SELECTED_SOURCE)"
|
||||
echo " 2) 切换其他来源"
|
||||
echo " 0) 退出"
|
||||
echo ""
|
||||
read -rp "请输入选项 [0-2]: " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
if [[ "$SELECTED_SOURCE" == "npm" ]]; then
|
||||
read -rp "请输入 npm registry URL (Enter 使用默认 https://registry.npmmirror.com): " reg
|
||||
NPM_REGISTRY="${reg:-https://registry.npmmirror.com}"
|
||||
ok "npm registry 已设置为: $NPM_REGISTRY"
|
||||
else
|
||||
read -rp "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com): " mirror
|
||||
GITHUB_MIRROR="${mirror:-https://ghproxy.com}"
|
||||
ok "GitHub 镜像已设置为: $GITHUB_MIRROR"
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
local found=false
|
||||
for fs in npm github-official github-fork; do
|
||||
[[ "$fs" == "$SELECTED_SOURCE" ]] && continue
|
||||
info "尝试从 $fs 获取..."
|
||||
if get_remote_version "$fs"; then
|
||||
SELECTED_SOURCE="$fs"
|
||||
ok "从 $fs 获取版本成功: v$REMOTE_VERSION"
|
||||
found=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "$found" != true ]]; then
|
||||
warn "所有来源均无法获取版本"
|
||||
fi
|
||||
;;
|
||||
0) exit 1 ;;
|
||||
*) warn "无效选项,请重新输入" ;;
|
||||
esac
|
||||
echo ""
|
||||
done
|
||||
STATUS_REMOTE_VERSION="$REMOTE_VERSION"
|
||||
fi
|
||||
|
||||
@@ -1208,12 +1301,28 @@ main_menu() {
|
||||
install_nodejs
|
||||
fi
|
||||
|
||||
local ok=false
|
||||
case "$SELECTED_SOURCE" in
|
||||
npm) install_from_npm ;;
|
||||
github-official) install_from_github "$GITHUB_OFFICIAL_REPO" ;;
|
||||
github-fork) install_from_github "$GITHUB_FORK_REPO" ;;
|
||||
npm)
|
||||
install_from_npm && ok=true || ok=false
|
||||
;;
|
||||
github-official)
|
||||
if install_from_github "$GITHUB_OFFICIAL_REPO"; then
|
||||
ok=true
|
||||
else
|
||||
warn "官方仓库无匹配 asset,尝试本仓库..."
|
||||
install_from_github "$GITHUB_FORK_REPO" && ok=true || ok=false
|
||||
fi
|
||||
;;
|
||||
github-fork)
|
||||
install_from_github "$GITHUB_FORK_REPO" && ok=true || ok=false
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$ok" != true ]]; then
|
||||
err "HAPI CLI 升级失败"
|
||||
fi
|
||||
|
||||
collect_status
|
||||
read -rp "按 Enter 继续..."
|
||||
;;
|
||||
@@ -1294,10 +1403,48 @@ run_quick_mode() {
|
||||
fi
|
||||
[[ -z "$SELECTED_SOURCE" ]] && SELECTED_SOURCE="npm"
|
||||
|
||||
if ! get_remote_version "$SELECTED_SOURCE"; then
|
||||
err "无法获取远程版本"
|
||||
exit 1
|
||||
fi
|
||||
while ! get_remote_version "$SELECTED_SOURCE"; do
|
||||
warn "无法从 $SELECTED_SOURCE 获取远程版本"
|
||||
echo ""
|
||||
echo -e "${YELLOW}请选择操作:${NC}"
|
||||
echo " 1) 配置镜像重试 ($SELECTED_SOURCE)"
|
||||
echo " 2) 切换其他来源"
|
||||
echo " 0) 退出"
|
||||
echo ""
|
||||
read -rp "请输入选项 [0-2]: " choice
|
||||
case "$choice" in
|
||||
1)
|
||||
if [[ "$SELECTED_SOURCE" == "npm" ]]; then
|
||||
read -rp "请输入 npm registry URL (Enter 使用默认 https://registry.npmmirror.com): " reg
|
||||
NPM_REGISTRY="${reg:-https://registry.npmmirror.com}"
|
||||
ok "npm registry 已设置为: $NPM_REGISTRY"
|
||||
else
|
||||
read -rp "请输入 GitHub 镜像 URL (Enter 使用默认 https://ghproxy.com): " mirror
|
||||
GITHUB_MIRROR="${mirror:-https://ghproxy.com}"
|
||||
ok "GitHub 镜像已设置为: $GITHUB_MIRROR"
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
local found=false
|
||||
for fs in npm github-official github-fork; do
|
||||
[[ "$fs" == "$SELECTED_SOURCE" ]] && continue
|
||||
info "尝试从 $fs 获取..."
|
||||
if get_remote_version "$fs"; then
|
||||
SELECTED_SOURCE="$fs"
|
||||
ok "从 $fs 获取版本成功: v$REMOTE_VERSION"
|
||||
found=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ "$found" != true ]]; then
|
||||
warn "所有来源均无法获取版本"
|
||||
fi
|
||||
;;
|
||||
0) exit 1 ;;
|
||||
*) warn "无效选项,请重新输入" ;;
|
||||
esac
|
||||
echo ""
|
||||
done
|
||||
|
||||
detect_installed
|
||||
|
||||
@@ -1351,12 +1498,29 @@ run_quick_mode() {
|
||||
install_nodejs || true
|
||||
fi
|
||||
|
||||
local ok=false
|
||||
case "$SELECTED_SOURCE" in
|
||||
npm) install_from_npm ;;
|
||||
github-official) install_from_github "$GITHUB_OFFICIAL_REPO" ;;
|
||||
github-fork) install_from_github "$GITHUB_FORK_REPO" ;;
|
||||
npm)
|
||||
install_from_npm && ok=true || ok=false
|
||||
;;
|
||||
github-official)
|
||||
if install_from_github "$GITHUB_OFFICIAL_REPO"; then
|
||||
ok=true
|
||||
else
|
||||
warn "官方仓库无匹配 asset,尝试本仓库..."
|
||||
install_from_github "$GITHUB_FORK_REPO" && ok=true || ok=false
|
||||
fi
|
||||
;;
|
||||
github-fork)
|
||||
install_from_github "$GITHUB_FORK_REPO" && ok=true || ok=false
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ "$ok" != true ]]; then
|
||||
err "HAPI CLI 安装失败"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$SKIP_HUB" != true ]]; then
|
||||
setup_hub
|
||||
if [[ "$IS_ROOT" == true ]]; then
|
||||
|
||||
Reference in New Issue
Block a user