Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Prefer to inspect first:
# irm https://open-codereview.ai/install.ps1 -OutFile install.ps1
# notepad install.ps1 # review, then: .\install.ps1
# Env: OCR_INSTALL_DIR (default $env:LOCALAPPDATA\Programs\ocr), OCR_VERSION (default latest).
# Env: OCR_INSTALL_DIR (default $env:LOCALAPPDATA\Programs\ocr), OCR_VERSION (default latest),
# OCR_GITHUB_MIRROR (default unset; download the binary through a mirror domain).
# Requires PowerShell 5.1+ or PowerShell 7+.

$ErrorActionPreference = 'Stop'
Expand Down Expand Up @@ -103,7 +104,20 @@ $arch = Get-OcrArch
$os = 'windows'
$Version = Resolve-OcrVersion $Repo
$asset = "$AssetPrefix-$os-$arch.exe"
$base = "https://github.com/$Repo/releases/download/$Version"
$Mirror = if (-not [string]::IsNullOrWhiteSpace($env:OCR_GITHUB_MIRROR)) {
$env:OCR_GITHUB_MIRROR.Trim() -replace '^https?://' -replace '/$'
} else {
$null
}
if ($Mirror -and $Mirror -match '\s') {
Err "OCR_GITHUB_MIRROR contains spaces: '$Mirror'"
}
if ($Mirror) {
[Console]::Error.WriteLine("warning: downloading from unofficial GitHub mirror `"$Mirror`" (checksum integrity is not guaranteed)")
$base = "https://$Mirror/github.com/$Repo/releases/download/$Version"
} else {
$base = "https://github.com/$Repo/releases/download/$Version"
}

$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("ocr-install-" + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Force -Path $tmp | Out-Null
Expand All @@ -118,8 +132,9 @@ try {
} catch {
Err "download failed: $base/$asset"
}

try {
Invoke-WebRequest -Uri "$base/sha256sum.txt" -OutFile $sumPath -UseBasicParsing
Invoke-WebRequest -Uri "$base/sha256sum.txt" -OutFile $sumPath -UseBasicParsing -TimeoutSec 15
} catch {
Err 'sha256sum.txt download failed'
}
Expand Down
19 changes: 16 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# Prefer to inspect first:
# curl -fsSL https://open-codereview.ai/install.sh -o install.sh
# less install.sh && sh install.sh
# Env: OCR_INSTALL_DIR (default /usr/local/bin), OCR_VERSION (default latest).
# Env: OCR_INSTALL_DIR (default /usr/local/bin), OCR_VERSION (default latest),
# OCR_GITHUB_MIRROR (default unset; download the binary through a mirror domain).
set -eu

main() {
Expand Down Expand Up @@ -42,13 +43,25 @@ main() {
fi

asset="${ASSET_PREFIX}-${os}-${arch}"
base="https://github.com/$REPO/releases/download/$VERSION"
prefix="$(printf '%s' "${OCR_GITHUB_MIRROR:-}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
prefix="${prefix#https://}"
prefix="${prefix#http://}"
prefix="${prefix%/}"
case "$prefix" in *[[:space:]]*) err "OCR_GITHUB_MIRROR contains spaces: '$prefix'" ;; esac
if [ -n "$prefix" ]; then
printf 'warning: downloading from unofficial GitHub mirror "%s" (checksum integrity is not guaranteed)\n' "$prefix" >&2
base="https://${prefix}/github.com/$REPO/releases/download/$VERSION"
else
base="https://github.com/$REPO/releases/download/$VERSION"
fi
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' INT TERM EXIT

printf 'downloading %s %s (%s/%s)...\n' "$BIN" "$VERSION" "$os" "$arch"
curl -fsSL -o "$tmp/$asset" "$base/$asset" || err "download failed: $base/$asset"
curl -fsSL -o "$tmp/sha256sum.txt" "$base/sha256sum.txt" || err "sha256sum.txt download failed"

curl -fsSL --connect-timeout 5 --max-time 15 -o "$tmp/sha256sum.txt" "$base/sha256sum.txt" ||
err "sha256sum.txt download failed"

want="$(awk -v a="$asset" '$2 == a {print tolower($1)}' "$tmp/sha256sum.txt")"
[ -n "$want" ] || err "no checksum entry for $asset in sha256sum.txt"
Expand Down
43 changes: 39 additions & 4 deletions pages/src/content/docs/en/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,59 @@ machines:
curl -fsSL https://open-codereview.ai/install.sh | sh
```

It honours two environment variables:
It honours three environment variables:

| Variable | Default | Purpose |
|---|---|---|
| `OCR_INSTALL_DIR` | `/usr/local/bin` | Where to place the `ocr` binary. |
| `OCR_VERSION` | latest release | Pin a specific release tag (e.g. `v1.2.3`). |
| `OCR_GITHUB_MIRROR` | *(unset)* | Download the release binary and its checksum through a GitHub mirror domain (e.g. `gh-proxy.com`). |

The script supports `darwin` and `linux` on `amd64` / `arm64`.

#### Using a GitHub mirror

In regions where network access to GitHub is slow, set `OCR_GITHUB_MIRROR`
to a mirror domain to download the release binary and its checksum through it:

```bash
export OCR_GITHUB_MIRROR='YOUR_MIRROR_DOMAIN'
```

The value must be a bare domain name — no `https://` scheme and no trailing
slash (`gh-proxy.com`, not `https://gh-proxy.com/`). It is used as a *path
prefix* mirror: the binary is fetched from
`https://<mirror>/github.com/alibaba/open-code-review/releases/download/<version>/…`.
Domain-substitution mirrors (e.g. one that rewrites `github.com` to
`hub.example.org`) won't match this shape — use a path-prefix mirror instead.

The mirror covers both the release binary and its `sha256sum.txt` checksum.
Version resolution (when `OCR_VERSION` is unset) still calls the GitHub API
directly, not the mirror. To skip version resolution entirely, pin a version:

```bash
export OCR_VERSION='v1.2.3'
```

> **Security note:** The mirror is a third-party service, so when
> `OCR_GITHUB_MIRROR` is set both the binary and its `sha256sum.txt` are
> downloaded from it. A malicious mirror can therefore serve a tampered
> binary together with a matching checksum; the integrity guarantee does not
> apply in mirror mode. Verify the downloaded file against the upstream
> `sha256sum.txt` on the
> [releases page](https://github.com/alibaba/open-code-review/releases)
> if you cannot trust the mirror.

On Windows (PowerShell 5.1+), use the PowerShell installer instead:

```powershell
irm https://open-codereview.ai/install.ps1 | iex
```

It honours the same `OCR_INSTALL_DIR` and `OCR_VERSION` variables (set via
`$env:OCR_INSTALL_DIR` / `$env:OCR_VERSION`). The default install location is
`%LOCALAPPDATA%\Programs\ocr`.
It honours the same `OCR_INSTALL_DIR`, `OCR_VERSION`, and
`OCR_GITHUB_MIRROR` variables (set via `$env:OCR_INSTALL_DIR` /
`$env:OCR_VERSION` / `$env:OCR_GITHUB_MIRROR`). The default
install location is `%LOCALAPPDATA%\Programs\ocr`.

## GitHub Release binary

Expand Down
28 changes: 25 additions & 3 deletions pages/src/content/docs/ja/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,45 @@ GitHub Release バイナリのダウンロード(検証付き)をラップ
curl -fsSL https://open-codereview.ai/install.sh | sh
```

2 つの環境変数を認識します。
3 つの環境変数を認識します。

| 変数 | デフォルト値 | 用途 |
|---|---|---|
| `OCR_INSTALL_DIR` | `/usr/local/bin` | `ocr` バイナリを配置する場所。 |
| `OCR_VERSION` | 最新 release | 特定の release tag に固定します(例:`v1.2.3`)。 |
| `OCR_GITHUB_MIRROR` | (未設定) | GitHub ミラードメイン経由でリリースバイナリとそのチェックサムをダウンロードします(例:`gh-proxy.com`)。 |

このスクリプトは `darwin` と `linux` の `amd64` / `arm64` をサポートします。

#### GitHub ミラーを使用する

一部の地域では GitHub へのネットワークアクセスが遅いため、`OCR_GITHUB_MIRROR` にミラードメインを設定すると、リリースバイナリとそのチェックサムをミラー経由でダウンロードできます:

```bash
export OCR_GITHUB_MIRROR='YOUR_MIRROR_DOMAIN'
```

値はスキームや末尾スラッシュを含まないベアドメインである必要があります(`https://gh-proxy.com/` ではなく `gh-proxy.com`)。これは*パスプレフィックス*ミラーとして使用されます。バイナリは
`https://<ミラー>/github.com/alibaba/open-code-review/releases/download/<バージョン>/…`
から取得されます。ドメイン置換型ミラー(例:`github.com` を `hub.example.org` に書き換えるもの)はこの形式に一致しません——パスプレフィックス型のミラーを使用してください。

ミラーはリリースバイナリとその `sha256sum.txt` チェックサムの両方をカバーします。バージョン解決(`OCR_VERSION` が未設定の場合)は引き続きミラーではなく GitHub API を直接呼び出します。バージョン解決を完全にスキップするには、バージョンを固定してください:

```bash
export OCR_VERSION='v1.2.3'
```

> **セキュリティ上の注意:** ミラーは第三者のサービスであるため、`OCR_GITHUB_MIRROR` を設定するとバイナリとその `sha256sum.txt` の両方がミラーからダウンロードされます。つまり、悪意のあるミラーは改ざんされたバイナリと一致するチェックサムを同時に配布できます。そのため、ミラーモードでは完全性の保証はありません。ミラーを信頼できない場合は、[releases ページ](https://github.com/alibaba/open-code-review/releases) のアップストリームの `sha256sum.txt` と照合して検証してください。

Windows(PowerShell 5.1+)では、代わりに PowerShell インストーラーを使用してください:

```powershell
irm https://open-codereview.ai/install.ps1 | iex
```

同じ `OCR_INSTALL_DIR` と `OCR_VERSION` を認識します(`$env:OCR_INSTALL_DIR` /
`$env:OCR_VERSION` で設定)。デフォルトのインストール先は
同じ `OCR_INSTALL_DIR`、`OCR_VERSION`、`OCR_GITHUB_MIRROR` を認識します
(`$env:OCR_INSTALL_DIR` / `$env:OCR_VERSION` /
`$env:OCR_GITHUB_MIRROR` で設定)。デフォルトのインストール先は
`%LOCALAPPDATA%\Programs\ocr` です。

## GitHub Release バイナリ
Expand Down
30 changes: 26 additions & 4 deletions pages/src/content/docs/ru/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,46 @@ sudo port upgrade open-code-review
curl -fsSL https://open-codereview.ai/install.sh | sh
```

Скрипт учитывает две переменные окружения:
Скрипт учитывает три переменные окружения:

| Переменная | По умолчанию | Назначение |
|---|---|---|
| `OCR_INSTALL_DIR` | `/usr/local/bin` | Куда положить бинарник `ocr`. |
| `OCR_VERSION` | последний релиз | Закрепить конкретный тег релиза (например `v1.2.3`). |
| `OCR_GITHUB_MIRROR` | не задана | Скачивать бинарник релиза и его контрольную сумму через зеркало GitHub (например `gh-proxy.com`). |

Скрипт поддерживает `darwin` и `linux` на `amd64` / `arm64`.

#### Использование зеркала GitHub

В некоторых регионах доступ к GitHub может быть медленным. Задайте `OCR_GITHUB_MIRROR` как домен зеркала, чтобы загружать бинарник релиза и его контрольную сумму через него:

```bash
export OCR_GITHUB_MIRROR='YOUR_MIRROR_DOMAIN'
```

Значение должно быть «голым» доменом — без схемы `https://` и без завершающего слэша (`gh-proxy.com`, а не `https://gh-proxy.com/`). Оно используется как зеркало с *префиксом пути*: бинарник загружается с
`https://<зеркало>/github.com/alibaba/open-code-review/releases/download/<версия>/…`.
Зеркала с подменой домена (например, переписывающие `github.com` на `hub.example.org`) не подходят под эту форму — используйте зеркало с префиксом пути.

Зеркало покрывает и бинарник релиза, и его контрольную сумму `sha256sum.txt`. Разрешение версии (когда `OCR_VERSION` не задана) по-прежнему обращается к GitHub API напрямую, а не к зеркалу. Чтобы полностью пропустить разрешение версии, закрепите версию:

```bash
export OCR_VERSION='v1.2.3'
```

> **Примечание по безопасности:** Зеркало — это сторонний сервис, поэтому при заданной `OCR_GITHUB_MIRROR` и бинарник, и его `sha256sum.txt` загружаются с зеркала. Это значит, что вредоносное зеркало может отдать подменённый бинарник вместе с подходящей контрольной суммой; в режиме зеркала гарантия целостности не действует. Если зеркало не заслуживает доверия, сверьте загруженный файл с оригинальным `sha256sum.txt` на [странице релизов](https://github.com/alibaba/open-code-review/releases).

В Windows с PowerShell 5.1 или новее запустите PowerShell-установщик:

```powershell
irm https://open-codereview.ai/install.ps1 | iex
```

Установщик учитывает те же переменные `OCR_INSTALL_DIR` и `OCR_VERSION` (через
`$env:OCR_INSTALL_DIR` / `$env:OCR_VERSION`). По умолчанию файлы устанавливаются
в `%LOCALAPPDATA%\Programs\ocr`.
Установщик учитывает те же переменные `OCR_INSTALL_DIR`, `OCR_VERSION` и
`OCR_GITHUB_MIRROR` (через `$env:OCR_INSTALL_DIR` /
`$env:OCR_VERSION` / `$env:OCR_GITHUB_MIRROR`). По умолчанию файлы
устанавливаются в `%LOCALAPPDATA%\Programs\ocr`.

## Бинарник из GitHub Release

Expand Down
28 changes: 25 additions & 3 deletions pages/src/content/docs/zh/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,45 @@ sudo port upgrade open-code-review
curl -fsSL https://open-codereview.ai/install.sh | sh
```

它识别两个环境变量
它识别三个环境变量

| 变量 | 默认值 | 用途 |
|---|---|---|
| `OCR_INSTALL_DIR` | `/usr/local/bin` | 放置 `ocr` 二进制的位置。 |
| `OCR_VERSION` | 最新 release | 固定到某个 release tag(如 `v1.2.3`)。 |
| `OCR_GITHUB_MIRROR` | (未设置) | 通过 GitHub 镜像域名下载 release 二进制及其校验和(如 `gh-proxy.com`)。 |

该脚本支持 `darwin` 与 `linux` 的 `amd64` / `arm64`。

#### 使用 GitHub 镜像

在部分网络访问 GitHub 较慢的地区,可设置 `OCR_GITHUB_MIRROR` 为某个镜像域名,通过它下载 release 二进制及其校验和:

```bash
export OCR_GITHUB_MIRROR='YOUR_MIRROR_DOMAIN'
```

该值必须是裸域名——不带 `https://` 前缀,也不带结尾斜杠(如 `gh-proxy.com`,而不是 `https://gh-proxy.com/`)。它作为*路径前缀*镜像使用:二进制从
`https://<镜像>/github.com/alibaba/open-code-review/releases/download/<版本>/…`
下载。域名替换型镜像(例如把 `github.com` 重写为 `hub.example.org`)不匹配这种形式——请改用路径前缀型镜像。

镜像同时覆盖 release 二进制及其 `sha256sum.txt` 校验和。版本解析(当未设置 `OCR_VERSION` 时)仍会直接调用 GitHub API,而非镜像。要完全跳过版本解析,请固定版本:

```bash
export OCR_VERSION='v1.2.3'
```

> **安全提示:** 镜像是第三方服务,设置 `OCR_GITHUB_MIRROR` 后,二进制及其 `sha256sum.txt` 都会从该镜像下载。这意味着恶意镜像可以同时提供被篡改的二进制和与之匹配的校验和,因此镜像模式下完整性保证不再成立。如果无法信任该镜像,请对照 [releases 页面](https://github.com/alibaba/open-code-review/releases) 上的上游 `sha256sum.txt` 验证下载文件。

在 Windows(PowerShell 5.1+)上,请改用 PowerShell 安装脚本:

```powershell
irm https://open-codereview.ai/install.ps1 | iex
```

它同样识别 `OCR_INSTALL_DIR` 与 `OCR_VERSION`(通过 `$env:OCR_INSTALL_DIR` /
`$env:OCR_VERSION` 设置)。默认安装位置为 `%LOCALAPPDATA%\Programs\ocr`。
它同样识别 `OCR_INSTALL_DIR`、`OCR_VERSION` 与 `OCR_GITHUB_MIRROR`
(通过 `$env:OCR_INSTALL_DIR` / `$env:OCR_VERSION` /
`$env:OCR_GITHUB_MIRROR` 设置)。默认安装位置为 `%LOCALAPPDATA%\Programs\ocr`。

## GitHub Release 二进制

Expand Down
Loading