- sing-box 单进程 bind 数据网卡 - mixed HTTP+SOCKS + 中文静态面板 - install.sh 支持 curl | sudo bash - 512MB 友好 MemoryMax 默认 96MB
97 lines
3.5 KiB
Bash
Executable File
97 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
# shellcheck source=lib.sh
|
|
source "$ROOT_DIR/scripts/lib.sh"
|
|
|
|
if [[ ! -f "$ROOT_DIR/config/settings.conf" ]]; then
|
|
cp "$ROOT_DIR/config/settings.conf.example" "$ROOT_DIR/config/settings.conf"
|
|
warn "已创建 config/settings.conf,请至少修改:"
|
|
warn " CELLULAR_IFACE / PANEL_SECRET /(建议)PROXY_USER+PROXY_PASS"
|
|
warn "然后重新执行: sudo $ROOT_DIR/scripts/install.sh"
|
|
warn "可先: $ROOT_DIR/scripts/detect.sh"
|
|
exit 1
|
|
fi
|
|
|
|
load_config
|
|
need_root
|
|
|
|
info "1/5 探测数据网卡"
|
|
"$ROOT_DIR/scripts/detect.sh" || true
|
|
|
|
info "2/5 下载/安装 sing-box + UI"
|
|
"$ROOT_DIR/scripts/fetch-binaries.sh"
|
|
|
|
info "3/5 生成配置(代理出口 = 数据网卡)"
|
|
"$ROOT_DIR/scripts/generate.sh" "$ROOT_DIR/generated"
|
|
ensure_dirs
|
|
mkdir -p /var/lib/cellular-proxy
|
|
install -m 0644 "$ROOT_DIR/generated/config.json" "$INSTALL_DIR/etc/config.json"
|
|
install -m 0644 "$ROOT_DIR/generated/runtime.env" "$INSTALL_DIR/etc/runtime.env"
|
|
install -m 0644 "$ROOT_DIR/config/settings.conf" "$INSTALL_DIR/etc/settings.conf"
|
|
cp -a "$ROOT_DIR/scripts" "$INSTALL_DIR/"
|
|
cp -a "$ROOT_DIR/ui" "$INSTALL_DIR/" 2>/dev/null || true
|
|
if ! "$INSTALL_DIR/bin/sing-box" check -c "$INSTALL_DIR/etc/config.json"; then
|
|
die "sing-box 配置校验失败"
|
|
fi
|
|
|
|
install -m 0755 /dev/stdin "$INSTALL_DIR/bin/cpxy" <<'EOF'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
BASE="$(cd "$(dirname "$0")/.." && pwd)"
|
|
export CONFIG_FILE="${CONFIG_FILE:-$BASE/etc/settings.conf}"
|
|
cmd="${1:-help}"
|
|
shift || true
|
|
case "$cmd" in
|
|
detect) exec "$BASE/scripts/detect.sh" "$@" ;;
|
|
generate)
|
|
"$BASE/scripts/generate.sh" "$BASE/generated"
|
|
install -m 0644 "$BASE/generated/config.json" "$BASE/etc/config.json"
|
|
install -m 0644 "$BASE/generated/runtime.env" "$BASE/etc/runtime.env"
|
|
install -m 0644 "$CONFIG_FILE" "$BASE/etc/settings.conf" 2>/dev/null || true
|
|
"$BASE/bin/sing-box" check -c "$BASE/etc/config.json"
|
|
systemctl restart cellular-proxy 2>/dev/null || true
|
|
;;
|
|
start) systemctl start cellular-proxy ;;
|
|
stop) systemctl stop cellular-proxy ;;
|
|
restart) systemctl restart cellular-proxy ;;
|
|
status) systemctl status cellular-proxy --no-pager || true ;;
|
|
verify) exec "$BASE/scripts/verify.sh" "$@" ;;
|
|
logs) journalctl -u cellular-proxy -n "${1:-80}" -f ;;
|
|
help|*)
|
|
cat <<H
|
|
cpxy — cellular-proxy
|
|
语义: 走代理的连接一律从数据网卡出口
|
|
cpxy detect | generate | start | stop | restart | status
|
|
cpxy verify | logs [N]
|
|
H
|
|
;;
|
|
esac
|
|
EOF
|
|
ln -sfn "$INSTALL_DIR/bin/cpxy" /usr/local/bin/cpxy
|
|
|
|
info "4/5 安装 systemd"
|
|
MEM="${MEMORY_MAX_MB:-96}"
|
|
install -m 0644 "$ROOT_DIR/systemd/cellular-proxy.service" /etc/systemd/system/cellular-proxy.service
|
|
sed -i "s|@INSTALL_DIR@|$INSTALL_DIR|g" /etc/systemd/system/cellular-proxy.service
|
|
sed -i "s|@LOG_DIR@|$LOG_DIR|g" /etc/systemd/system/cellular-proxy.service
|
|
if [[ "$MEM" != "0" && -n "$MEM" ]]; then
|
|
sed -i "s|@MEMORY_MAX@|${MEM}M|g" /etc/systemd/system/cellular-proxy.service
|
|
else
|
|
sed -i '/MemoryMax=@MEMORY_MAX@/d' /etc/systemd/system/cellular-proxy.service
|
|
fi
|
|
systemctl daemon-reload
|
|
|
|
info "5/5 启动"
|
|
systemctl enable cellular-proxy.service
|
|
systemctl restart cellular-proxy.service
|
|
sleep 1
|
|
systemctl --no-pager --full status cellular-proxy.service || true
|
|
|
|
echo
|
|
info "安装完成"
|
|
echo " 语义: 不走代理 → 系统默认(WiFi);走代理 → 数据流量"
|
|
echo " 代理: HTTP/SOCKS ${PROXY_LISTEN_HOST}:${PROXY_MIXED_PORT}"
|
|
echo " 面板: http://<LAN-IP>:${PANEL_PORT}/ 密钥: PANEL_SECRET"
|
|
echo " 验证: cpxy verify"
|