diff --git a/singbox.sh b/singbox.sh index f8e3066..db00ef5 100644 --- a/singbox.sh +++ b/singbox.sh @@ -1,78 +1,93 @@ #!/usr/bin/env bash # install_singbox.sh -# 一键安装 Sing-box,并配置 VLESS Reality,自动生成字段、写入配置、创建 Systemd 服务并输出链接 +# 一键安装 Sing-box,并配置 VLESS Reality,支持菜单操作:安装、状态、显示链接、卸载、重装 set -euo pipefail -### 0. 输入名称 ### -read -rp "请输入用户名称 (name 字段,例如 AK-JP-100G): " NAME -if [[ -z "$NAME" ]]; then - echo "名称不能为空,退出。" >&2 - exit 1 -fi -echo "使用名称:$NAME" -### 1. 安装 Sing-box 内核 ### -if command -v apt-get &>/dev/null; then - echo "检测到 Debian/Ubuntu,使用官方 deb 安装脚本..." - bash <(curl -fsSL https://sing-box.app/deb-install.sh) -elif command -v dnf &>/dev/null || command -v yum &>/dev/null; then - echo "检测到 RHEL/CentOS,使用官方 rpm 安装脚本..." - bash <(curl -fsSL https://sing-box.app/rpm-install.sh) -elif command -v pacman &>/dev/null; then - echo "检测到 Arch Linux,使用官方 arch 安装脚本..." - bash <(curl -fsSL https://sing-box.app/arch-install.sh) -else - echo "无法识别发行版,请手动安装 Sing-box 内核" >&2 - exit 1 -fi -# 确定 sing-box 可执行文件 -BIN_PATH=$(command -v sing-box || true) -if [[ -z "$BIN_PATH" ]]; then - echo "未找到 sing-box,可执行文件路径异常,请检查安装" >&2 - exit 1 -fi -echo "Sing-box 内核版本:$("$BIN_PATH" version | head -n1)" -### 2. 生成 UUID / Reality 密钥 / ShortID / uTLS ### -UUID=$("$BIN_PATH" generate uuid) -KEY_OUTPUT=$("$BIN_PATH" generate reality-keypair) -PRIVATE_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PrivateKey/ {print $2}') -PUB_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PublicKey/ {print $2}') -SHORT_ID=$(openssl rand -hex 8) -FP="chrome" -### 3. 写入配置文件 ### + CONFIG_DIR=/etc/singbox -mkdir -p "$CONFIG_DIR" -cat > "$CONFIG_DIR/config.json" <&2 + exit 1 + } + read -rp "请输入 SNI 域名 (默认: s0.awsstatic.com): " SNI + SNI=${SNI:-s0.awsstatic.com} + + # 1. 安装 Sing-box + if command -v apt-get &>/dev/null; then + echo "检测到 Debian/Ubuntu,使用官方 deb 安装脚本..." + bash <(curl -fsSL https://sing-box.app/deb-install.sh) + elif command -v dnf &>/dev/null || command -v yum &>/dev/null; then + echo "检测到 RHEL/CentOS,使用官方 rpm 安装脚本..." + bash <(curl -fsSL https://sing-box.app/rpm-install.sh) + elif command -v pacman &>/dev/null; then + echo "检测到 Arch Linux,使用官方 arch 安装脚本..." + bash <(curl -fsSL https://sing-box.app/arch-install.sh) + else + echo "无法识别发行版,请手动安装 Sing-box 内核" >&2 + exit 1 + fi + BIN_PATH=$(command -v $BIN_NAME) + [[ -z "$BIN_PATH" ]] && { + echo "未找到 $BIN_NAME,可执行文件路径异常,请检查安装" >&2 + exit 1 + } + echo "已安装 $BIN_NAME 版本:$($BIN_PATH version | head -n1)" + + # 2. 生成 UUID / Reality 密钥 / ShortID / uTLS + UUID=$($BIN_PATH generate uuid) + KEY_OUTPUT=$($BIN_PATH generate reality-keypair) + PRIVATE_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PrivateKey/ {print $2}') + PUB_KEY=$(echo "$KEY_OUTPUT" | awk -F': ' '/PublicKey/ {print $2}') + SHORT_ID=$(openssl rand -hex 8) + FP="chrome" + SERVER_IP=$(curl -s https://ifconfig.me) + PORT=443 + SPX="/" + + # 写入配置和状态 + mkdir -p "$CONFIG_DIR" + cat >"$CONFIG_DIR/config.json" < "$SERVICE_FILE" <"$STATE_FILE" <"$SERVICE_FILE" <