Skip to content

Commit d4800a8

Browse files
committed
feat: 双版本支持(EDITION=zh/en) + 兼容 edition 格式 latest.json
- install.cmd / install.sh 支持 EDITION 环境变量 (zh=汉化版, en=官方原版) - 解析新版 latest.json 的 editions.<EDITION>.version 格式 - 修正文件名前缀: 汉化版 openclaw-zh-*, 官方版 openclaw-* - 修正 R2 下载路径: /<EDITION>/<version>/ - GitHub fallback 正确获取 release tag (基于汉化版版本号)
1 parent 5ebee93 commit d4800a8

2 files changed

Lines changed: 71 additions & 14 deletions

File tree

install.cmd

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,30 @@ echo ║ OpenClaw 一键安装 by 晴辰云 ║
1212
echo ╚══════════════════════════════════════╝
1313
echo.
1414

15+
:: EDITION 环境变量: zh=汉化版(默认), en=官方原版
16+
if "%EDITION%"=="" set "EDITION=zh"
1517
set "INSTALL_DIR=%LOCALAPPDATA%\OpenClaw"
1618
set "R2_BASE=https://dl.qrj.ai/openclaw-standalone"
1719
set "PLATFORM=win-x64"
1820

21+
if "%EDITION%"=="en" (
22+
set "ARCHIVE_PREFIX=openclaw"
23+
echo [INFO] 版本: 官方原版 ^(en^)
24+
) else (
25+
set "EDITION=zh"
26+
set "ARCHIVE_PREFIX=openclaw-zh"
27+
echo [INFO] 版本: 汉化版 ^(zh^)
28+
)
29+
1930
:: --- Get latest version ---
2031
echo [INFO] 获取最新版本...
21-
for /f "delims=" %%v in ('powershell -NoProfile -Command "(Invoke-RestMethod -Uri '%R2_BASE%/latest.json' -TimeoutSec 5).version" 2^>nul') do set "VERSION=%%v"
32+
:: 新格式: editions.<EDITION>.version;旧格式兼容: .version
33+
for /f "delims=" %%v in ('powershell -NoProfile -Command "$m = Invoke-RestMethod -Uri '%R2_BASE%/latest.json' -TimeoutSec 5; $ed = $m.editions.'%EDITION%'; if ($ed.version) { $ed.version } elseif ($m.version) { $m.version }" 2^>nul') do set "VERSION=%%v"
2234

35+
:: GitHub API fallback(tag 基于汉化版版本号)
2336
if "%VERSION%"=="" (
2437
echo [WARN] R2 获取失败,尝试 GitHub...
25-
for /f "delims=" %%v in ('powershell -NoProfile -Command "(Invoke-RestMethod -Uri 'https://api.github.com/repos/qingchencloud/openclaw-standalone/releases/latest' -TimeoutSec 10).tag_name -replace 'v',''" 2^>nul') do set "VERSION=%%v"
38+
for /f "delims=" %%v in ('powershell -NoProfile -Command "$tag = (Invoke-RestMethod -Uri 'https://api.github.com/repos/qingchencloud/openclaw-standalone/releases/latest' -TimeoutSec 10).tag_name -replace 'v',''; if ('%EDITION%' -eq 'en') { $tag -replace '-zh\.\d+$','' } else { $tag }" 2^>nul') do set "VERSION=%%v"
2639
)
2740

2841
if "%VERSION%"=="" (
@@ -35,16 +48,19 @@ if "%VERSION%"=="" (
3548
echo [INFO] 最新版本: %VERSION%
3649

3750
:: --- Download ---
38-
set "ARCHIVE=openclaw-%VERSION%-win-x64.zip"
39-
set "DOWNLOAD_URL=%R2_BASE%/%VERSION%/%ARCHIVE%"
51+
set "ARCHIVE=%ARCHIVE_PREFIX%-%VERSION%-win-x64.zip"
52+
set "DOWNLOAD_URL=%R2_BASE%/%EDITION%/%VERSION%/%ARCHIVE%"
4053
set "TMP_FILE=%TEMP%\%ARCHIVE%"
4154

4255
echo [INFO] 下载安装包...
4356
powershell -NoProfile -Command "try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '%DOWNLOAD_URL%' -OutFile '%TMP_FILE%' -UseBasicParsing } catch { exit 1 }"
4457

4558
if errorlevel 1 (
4659
echo [WARN] R2 下载失败,尝试 GitHub...
47-
set "DOWNLOAD_URL=https://github.com/qingchencloud/openclaw-standalone/releases/download/v%VERSION%/%ARCHIVE%"
60+
:: GitHub release tag 统一用汉化版版本号,先获取 tag
61+
for /f "delims=" %%t in ('powershell -NoProfile -Command "(Invoke-RestMethod -Uri 'https://api.github.com/repos/qingchencloud/openclaw-standalone/releases/latest' -TimeoutSec 10).tag_name" 2^>nul') do set "GH_TAG=%%t"
62+
if "!GH_TAG!"=="" set "GH_TAG=v%VERSION%"
63+
set "DOWNLOAD_URL=https://github.com/qingchencloud/openclaw-standalone/releases/download/!GH_TAG!/%ARCHIVE%"
4864
powershell -NoProfile -Command "try { $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '!DOWNLOAD_URL!' -OutFile '%TMP_FILE%' -UseBasicParsing } catch { exit 1 }"
4965
)
5066

install.sh

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66
set -euo pipefail
77

88
# --- Configuration ---
9+
EDITION="${EDITION:-zh}" # zh=汉化版, en=官方原版
910
INSTALL_DIR="${OPENCLAW_HOME:-$HOME/.openclaw-bin}"
1011
R2_BASE="https://dl.qrj.ai/openclaw-standalone"
1112
GITHUB_BASE="https://github.com/qingchencloud/openclaw-standalone/releases/download"
1213

14+
if [ "$EDITION" = "en" ]; then
15+
ARCHIVE_PREFIX="openclaw"
16+
EDITION_LABEL="官方原版"
17+
else
18+
EDITION="zh"
19+
ARCHIVE_PREFIX="openclaw-zh"
20+
EDITION_LABEL="汉化版"
21+
fi
22+
1323
# --- Colors ---
1424
RED='\033[0;31m'
1525
GREEN='\033[0;32m'
@@ -46,19 +56,39 @@ detect_platform() {
4656

4757
# --- Get latest version ---
4858
get_latest_version() {
49-
local version=""
59+
local version="" json=""
5060
# Try R2 first
61+
# 新格式: editions.<EDITION>.version;旧格式兼容: .version
5162
if command -v curl &>/dev/null; then
52-
version=$(curl -fsSL --connect-timeout 5 "$R2_BASE/latest.json" 2>/dev/null | \
53-
grep -o '"version"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | \
54-
grep -o '"[^"]*"$' | tr -d '"') || true
63+
json=$(curl -fsSL --connect-timeout 5 "$R2_BASE/latest.json" 2>/dev/null) || true
64+
if [ -n "$json" ]; then
65+
# 先尝试新格式 editions.<EDITION>.version
66+
version=$(echo "$json" | grep -o "\"$EDITION\"[^}]*\"version\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" | \
67+
grep -o '"version"[[:space:]]*:[[:space:]]*"[^"]*"' | \
68+
grep -o '"[^"]*"$' | tr -d '"') || true
69+
# 回退旧格式 .version(取第一个 version 字段)
70+
if [ -z "$version" ]; then
71+
version=$(echo "$json" | \
72+
grep -o '"version"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | \
73+
grep -o '"[^"]*"$' | tr -d '"') || true
74+
fi
75+
fi
5576
fi
56-
# Fallback: GitHub API
77+
# Fallback: GitHub API(tag 基于汉化版版本号,两个版本文件都在同一个 release 下)
5778
if [ -z "$version" ]; then
58-
version=$(curl -fsSL --connect-timeout 5 \
79+
local tag_ver
80+
tag_ver=$(curl -fsSL --connect-timeout 5 \
5981
"https://api.github.com/repos/qingchencloud/openclaw-standalone/releases/latest" 2>/dev/null | \
6082
grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | \
6183
grep -o '"[^"]*"$' | tr -d '"v') || true
84+
if [ -n "$tag_ver" ]; then
85+
if [ "$EDITION" = "en" ]; then
86+
# 官方版版本号 = 去掉 -zh.N 后缀
87+
version=$(echo "$tag_ver" | sed 's/-zh\.[0-9]*$//')
88+
else
89+
version="$tag_ver"
90+
fi
91+
fi
6292
fi
6393
if [ -z "$version" ]; then
6494
error "无法获取最新版本号。请检查网络连接或手动下载安装。"
@@ -92,13 +122,24 @@ main() {
92122

93123
PLATFORM=$(detect_platform)
94124
info "检测到平台: $PLATFORM"
125+
info "版本: $EDITION_LABEL ($EDITION)"
95126

96127
VERSION=$(get_latest_version)
97128
info "最新版本: $VERSION"
98129

99-
ARCHIVE="openclaw-${VERSION}-${PLATFORM}.tar.gz"
100-
DOWNLOAD_URL="${R2_BASE}/${VERSION}/${ARCHIVE}"
101-
GITHUB_URL="${GITHUB_BASE}/v${VERSION}/${ARCHIVE}"
130+
ARCHIVE="${ARCHIVE_PREFIX}-${VERSION}-${PLATFORM}.tar.gz"
131+
DOWNLOAD_URL="${R2_BASE}/${EDITION}/${VERSION}/${ARCHIVE}"
132+
# GitHub release tag 统一用汉化版版本号,两个版本的文件都在同一个 release 下
133+
if [ "$EDITION" = "en" ]; then
134+
# 需要从 R2 或 GitHub API 获取汉化版版本号作为 tag
135+
GH_TAG_VER=$(curl -fsSL --connect-timeout 5 \
136+
"https://api.github.com/repos/qingchencloud/openclaw-standalone/releases/latest" 2>/dev/null | \
137+
grep -o '"tag_name"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | \
138+
grep -o '"[^"]*"$' | tr -d '"') || true
139+
GITHUB_URL="${GITHUB_BASE}/${GH_TAG_VER:-v${VERSION}}/${ARCHIVE}"
140+
else
141+
GITHUB_URL="${GITHUB_BASE}/v${VERSION}/${ARCHIVE}"
142+
fi
102143
TMP_DIR=$(mktemp -d)
103144
TMP_FILE="${TMP_DIR}/${ARCHIVE}"
104145

0 commit comments

Comments
 (0)