# 安装脚本参考

脚本位于 **`scripts/`**（与本目录 Markdown 同级）。

## 总览

| 脚本 | 平台 | 作用 |
|------|------|------|
| **install** / **install.sh** | Linux, macOS | 普通组合包首装 |
| **install.ps1** / **install.cmd** | Windows | 普通组合包首装 → `sa_upgrader.exe` |
| **install-tar.sh** / **install-tar.ps1** | Unix / Windows | 指定 tar 文件或 URL |
| **install-docker.sh** / **docker-install** | Linux, macOS | Docker 栈首装（`--udp-mode`） |
| **install-docker.ps1** / **docker-install.ps1** / **docker-install.cmd** | Windows | Docker Desktop 栈首装（默认 UDP relay） |
| **sa2-udp-relay.sh** / **udp_broadcast_relay.py** | Unix / Windows | Desktop 宿主机 UDP 广播 → 容器转发 |
| **upgrade.sh** / **upgrade.ps1** | Unix / Windows | 统一升级入口（自动分发原生/Docker） |
| **upgrade-docker.sh** / **upgrade-docker.ps1** | Unix / Windows | Docker 栈升级 |
| **setup_docker_cron.sh** | Linux | Docker 定时自动升级 |
| **lib/common.sh** / **lib/common.ps1** | bash / PowerShell | 共享下载与 manifest 逻辑 |
| **lib/docker-conf.sh** / **lib/docker-upgrade.sh** | bash | Docker conf 契约与升级辅助 |

## install.sh / install.ps1 选项

`--edition` · `--version` · `--offline` · `--user` · `--home` · `-y`  
PowerShell：`-Edition` · `-Version` · `-Home` · `-Offline` · `-ArchiveFile` · `-Yes`

环境变量：`SA2_PACKAGE_LAN`, `SA2_PACKAGE_INTERNET`, `SA2_EDITION`, `SA_AUTH_TOKEN`

## install-docker 选项

`--edition device|server|wind` · `--version` · `--compose-only` · `--udp-mode auto|publish|relay|none` · `--migrate-conf` · `--auto-upgrade`  
PowerShell：`-Edition` · `-Version` · `-ComposeOnly` · `-MigrateConf` · `-AutoUpgrade`（UDP 默认 `relay`，可用环境变量 `SA2_UDP_MODE`）

| `udp-mode` | 说明 |
|------------|------|
| `auto`（默认） | macOS/Windows → `relay`；Linux → `publish` |
| `publish` | `compose.udp-publish.yml`（`8190:8190/udp`） |
| `relay` | `compose.udp-relay.yml` + `sa2-udp-relay.sh`（Desktop 收 LAN 广播） |
| `none` | 不接 UDP |

详见 [docker-install.md](docker-install.md)「UDP 接入模式」。

## 制品源自动探测

`lib/common.sh` / `lib/common.ps1` / 自包含 `install.ps1` 在首次下载前探测内网、外网 `latest/index.json`；详见 [cli-install.md](cli-install.md)、[windows.md](windows.md)。

## 本目录内执行示例

```bash
# Linux / macOS（install/ 根目录）
sudo bash scripts/install.sh -y --edition device
bash scripts/install-docker.sh --edition device
bash scripts/upgrade.sh --auto-upgrade
```

```powershell
# Windows
powershell -ExecutionPolicy Bypass -File .\scripts\install.ps1 -Edition device
powershell -ExecutionPolicy Bypass -File .\scripts\install-docker.ps1 -Edition device
powershell -File .\scripts\upgrade.ps1 -AutoUpgrade
```

## 制品库入口文件名

发布到 Package `latest/` / 文档镜像的典型文件：

`install`, `install.sh`, `install.ps1`, `install.cmd`, `docker-install`, `docker-install.sh`, `docker-install.ps1`, `docker-install.cmd`, `upgrade`, `upgrade.sh`, `upgrade.ps1`, `upgrade-docker.ps1`, `install-tar.sh`

**仅拷贝 install/ 目录时**：直接使用 `scripts/` 下同名文件即可。

## 文档索引

| 主题 | 文档 |
|------|------|
| CLI | [cli-install.md](cli-install.md) |
| Windows | [windows.md](windows.md) |
| tar | [tar-install.md](tar-install.md) |
| Docker | [docker-install.md](docker-install.md) |
| 升级 | [upgrade.md](upgrade.md) |
