feat: 添加singbox.sh
这个提交包含在:
72
.gitignore
vendored
普通文件
72
.gitignore
vendored
普通文件
@@ -0,0 +1,72 @@
|
||||
# OS
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Editors / IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*.swn
|
||||
*~
|
||||
.*.sw[a-z]
|
||||
.history/
|
||||
*.code-workspace
|
||||
|
||||
# Claude / AI assistants
|
||||
.claude/
|
||||
.cursor/
|
||||
.aider*
|
||||
|
||||
# Logs & temp
|
||||
*.log
|
||||
*.tmp
|
||||
*.temp
|
||||
*.bak
|
||||
*.orig
|
||||
*.rej
|
||||
|
||||
# Archives & binaries (usually downloaded artifacts)
|
||||
*.tar
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
*.zip
|
||||
*.7z
|
||||
*.rar
|
||||
|
||||
# Secrets / local env
|
||||
.env
|
||||
.env.*
|
||||
*.key
|
||||
*.pem
|
||||
*.crt
|
||||
secrets/
|
||||
private/
|
||||
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.egg-info/
|
||||
.venv/
|
||||
venv/
|
||||
env/
|
||||
|
||||
# Node
|
||||
node_modules/
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Build / dist
|
||||
build/
|
||||
dist/
|
||||
out/
|
||||
|
||||
.claude
|
||||
23
CLAUDE.md
普通文件
23
CLAUDE.md
普通文件
@@ -0,0 +1,23 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Repository purpose
|
||||
|
||||
Personal collection of self-use shell scripts (个人收藏的自用脚本). Each top-level directory is an independent script project — there is no shared build system, package manager, test suite, or CI. Editing happens on Windows; the scripts themselves are deployed and executed on Linux VPS targets.
|
||||
|
||||
**Repo URL:** `https://git.suhang.me/suhang/scripts`. When writing docs/READMEs that contain `wget` / `curl` one-liners to fetch a script onto a server, point them at this repo's raw URL (e.g. `https://git.suhang.me/suhang/scripts/raw/branch/main/singbox/singbox.sh`) rather than upstream third-party URLs. This way users get the version actually maintained here.
|
||||
|
||||
## Layout
|
||||
|
||||
- `singbox/singbox.sh` — interactive Bash installer/manager for [sing-box](https://github.com/SagerNet/sing-box) proxy nodes. ~5400 lines, single file, no external sourced files. The `singbox/README.md` documents user-facing usage and runtime dependencies (`curl wget jq openssl tar cron` + systemd) — consult it before changing behavior described there.
|
||||
|
||||
When adding a new script, follow the same pattern: a top-level directory containing the script plus its own `README.md`.
|
||||
|
||||
## Working with `singbox/singbox.sh`
|
||||
|
||||
- **Entry points** live at the bottom of the file: `main_menu` (interactive, 21 options) and `run_option "$1"` (non-interactive — currently only `18` for cron-driven cert renewal). Option numbers in the menu map directly to `*_install` / management functions via the `case` block around line ~5287.
|
||||
- **State is on the target host, not in the repo.** The script writes to `/usr/local/bin/sing-box`, `/usr/local/etc/sing-box/`, `/etc/ssl/private/`, `/etc/systemd/system/sing-box.service`, and a weekly crontab entry. Any change that touches these paths needs to remain consistent with the uninstall path (`uninstall` function) and the `singbox/README.md` "路径与文件" table.
|
||||
- **No automated tests.** Validation means running the script on a disposable Linux VM and exercising the affected menu option end-to-end. There is no lint config; match the existing Bash style (top-level `function name() { ... }`, `${RED}/${CYAN}/${YELLOW}/${NC}` color vars, Chinese user-facing prompts, English log lines).
|
||||
- The script assumes root + systemd + one of ufw/iptables/firewalld. Don't add dependencies without updating the dependency table in `singbox/README.md`.
|
||||
- The "更新脚本" option (`Update_Script`) pulls from `https://raw.githubusercontent.com/TinrLin/script_installation/main/Install.sh` — this is the upstream, not this repo. Local edits will be overwritten if a user runs that option; mention this when relevant.
|
||||
155
singbox/README.md
普通文件
155
singbox/README.md
普通文件
@@ -0,0 +1,155 @@
|
||||
# singbox.sh
|
||||
|
||||
基于 [sing-box](https://github.com/SagerNet/sing-box) 的一键安装与管理脚本,提供交互式菜单来搭建、管理多种代理协议节点。
|
||||
|
||||
> 脚本作者:Mr. xiao([原项目地址](https://github.com/TinrLin))。本目录用于本地保存与备份,便于在不同 VPS 上快速部署。
|
||||
>
|
||||
> 本仓库地址:<https://git.suhang.me/suhang/scripts>,下方所有 `wget` / `curl` 命令均从该仓库直接拉取。
|
||||
|
||||
## 功能概览
|
||||
|
||||
支持的入站协议:
|
||||
|
||||
- SOCKS / HTTP / Direct
|
||||
- VMess / VLESS(含 Reality)/ Trojan
|
||||
- Hysteria / Hysteria2
|
||||
- TUIC / Juicity
|
||||
- ShadowTLS / NaiveProxy / Shadowsocks
|
||||
- WireGuard(出站,用于解锁流媒体等)
|
||||
|
||||
管理功能:
|
||||
|
||||
- 查看已搭建节点信息(含分享链接 / Clash 配置)
|
||||
- 更新内核(Latest / Beta / 编译安装完整功能版)
|
||||
- 更新脚本自身
|
||||
- 申请 / 续签 TLS 证书(基于 acme.sh,支持 Let's Encrypt、ZeroSSL,HTTP-01 与 Cloudflare DNS-01)
|
||||
- 重启 / 卸载服务
|
||||
- 节点管理(添加 / 删除单个用户或入站)
|
||||
- 自动配置防火墙(ufw / iptables / firewalld)
|
||||
- 自动开启 BBR
|
||||
|
||||
## 系统要求
|
||||
|
||||
- Linux x86_64 / ARMv7 / ARM64 / AMD64v3 / s390x
|
||||
- 使用 systemd 的发行版(Debian 10+ / Ubuntu 20.04+ / CentOS 8+ / Rocky / AlmaLinux 等)
|
||||
- 需要 root 权限
|
||||
- 公网 IPv4 或 IPv6(部分协议要求 80/443 端口可用于证书签发)
|
||||
|
||||
## 依赖安装
|
||||
|
||||
脚本运行时会调用以下命令,**请先确保已安装**(多数发行版默认包含 `bash` `tar` `systemctl` `iptables` 等):
|
||||
|
||||
| 依赖 | 用途 |
|
||||
| --- | --- |
|
||||
| `curl` / `wget` | 下载内核、调用 GitHub / Cloudflare API |
|
||||
| `jq` | 解析 GitHub Release / Cloudflare API 的 JSON |
|
||||
| `openssl` | 生成随机密钥、自签证书、TLS 探测 |
|
||||
| `tar` | 解压内核压缩包 |
|
||||
| `systemd` | 管理 sing-box / juicity 服务 |
|
||||
| `cron` (`cronie` / `crontabs`) | 自动续签证书的定时任务 |
|
||||
|
||||
### Debian / Ubuntu
|
||||
|
||||
```bash
|
||||
apt update
|
||||
apt install -y curl wget jq openssl tar cron
|
||||
```
|
||||
|
||||
### CentOS / RHEL / Rocky / Alma
|
||||
|
||||
```bash
|
||||
dnf install -y curl wget jq openssl tar cronie
|
||||
systemctl enable --now crond
|
||||
```
|
||||
|
||||
### Arch Linux
|
||||
|
||||
```bash
|
||||
pacman -Sy --noconfirm curl wget jq openssl tar cronie
|
||||
systemctl enable --now cronie
|
||||
```
|
||||
|
||||
> 选择「编译安装 sing-box(完整功能版本)」时,脚本会自动下载并安装 Go 编译器,无需额外安装。
|
||||
>
|
||||
> 申请证书时若系统未安装 acme.sh,脚本会自动通过 `curl https://get.acme.sh | sh` 安装。
|
||||
|
||||
## 使用方式
|
||||
|
||||
### 1. 下载脚本
|
||||
|
||||
从本仓库直接下载到服务器(推荐放到 `/root/`):
|
||||
|
||||
```bash
|
||||
# 方式一:直接下载脚本
|
||||
wget -O /root/singbox.sh https://git.suhang.me/suhang/scripts/raw/branch/main/singbox/singbox.sh
|
||||
chmod +x /root/singbox.sh
|
||||
|
||||
# 方式二:克隆整个仓库
|
||||
git clone https://git.suhang.me/suhang/scripts.git /root/scripts
|
||||
chmod +x /root/scripts/singbox/singbox.sh
|
||||
```
|
||||
|
||||
> 也可以使用 `curl`:
|
||||
> ```bash
|
||||
> curl -fsSL -o /root/singbox.sh https://git.suhang.me/suhang/scripts/raw/branch/main/singbox/singbox.sh && chmod +x /root/singbox.sh
|
||||
> ```
|
||||
|
||||
### 2. 运行交互式菜单
|
||||
|
||||
```bash
|
||||
bash /root/singbox.sh
|
||||
```
|
||||
|
||||
进入菜单后按编号选择操作:
|
||||
|
||||
```
|
||||
[1] SOCKS [2] Direct
|
||||
[3] HTTP [4] VMess
|
||||
[5] VLESS [6] TUIC
|
||||
[7] Juicity [8] Trojan
|
||||
[9] Hysteria [10] Hysteria2
|
||||
[11] ShadowTLS [12] NaiveProxy
|
||||
[13] Shadowsocks [14] WireGuard
|
||||
[15] 查看节点信息 [16] 更新内核
|
||||
[17] 更新脚本 [18] 更新证书
|
||||
[19] 重启服务 [20] 节点管理
|
||||
[21] 卸载 [0] 退出
|
||||
```
|
||||
|
||||
### 3. 命令行参数
|
||||
|
||||
目前脚本仅支持一个非交互参数,用于定时任务续签证书:
|
||||
|
||||
```bash
|
||||
bash /root/singbox.sh 18 # 等同于菜单 [18] 更新证书
|
||||
```
|
||||
|
||||
脚本会自动写入 crontab,每周一凌晨 2 点执行该命令续签:
|
||||
|
||||
```cron
|
||||
0 2 * * 1 /bin/bash /root/singbox.sh >> /usr/local/etc/certificate.log 2>&1
|
||||
```
|
||||
|
||||
## 路径与文件
|
||||
|
||||
| 路径 | 说明 |
|
||||
| --- | --- |
|
||||
| `/usr/local/bin/sing-box` | sing-box 主程序 |
|
||||
| `/usr/local/bin/juicity-server` | Juicity 主程序(仅 Juicity 模式) |
|
||||
| `/usr/local/etc/sing-box/config.json` | sing-box 配置文件 |
|
||||
| `/usr/local/etc/sing-box/clash.yaml` | 自动生成的 Clash 订阅 |
|
||||
| `/usr/local/etc/juicity/config.json` | Juicity 配置文件 |
|
||||
| `/etc/ssl/private/` | TLS 证书与私钥 |
|
||||
| `/etc/systemd/system/sing-box.service` | systemd 服务单元 |
|
||||
| `/usr/local/etc/certificate.log` | 续签日志 |
|
||||
|
||||
## 常见问题
|
||||
|
||||
- **菜单乱码**:终端使用 UTF-8(`export LANG=en_US.UTF-8` 或 `zh_CN.UTF-8`)。
|
||||
- **证书申请失败**:检查 80 端口是否被占用(HTTP-01),或使用 Cloudflare DNS API(需 API Token + Zone ID + Email)。
|
||||
- **节点不通**:脚本已自动放行所选端口,如使用云厂商安全组,请同步在面板放行 TCP/UDP。
|
||||
- **内核更新后无法启动**:`journalctl -u sing-box -n 100 --no-pager` 查看日志,多数为配置与新版内核字段不兼容,可重新搭建或回退版本。
|
||||
|
||||
## 卸载
|
||||
|
||||
菜单选择 `[21] 卸载`,会停止并移除 sing-box / juicity 的二进制、配置目录与 systemd 服务。
|
||||
5398
singbox/singbox.sh
普通文件
5398
singbox/singbox.sh
普通文件
文件差异内容过多而无法显示
加载差异
在新工单中引用
屏蔽一个用户