#!/bin/bash ARCH=$(uname -m) if [[ "$ARCH" != "x86_64" ]]; then echo "❌ 不支持的架构: $ARCH,仅支持 x86_64。" exit 1 fi # 固定gost下载地址 DOWNLOAD_URL="https://raw.githubusercontent.com/bqlpfy/forward-panel/refs/heads/main/gost" while getopts "a:p:s:" opt; do case $opt in a) SERVER_ADDR="$OPTARG" ;; p) PORT="$OPTARG" ;; s) SECRET="$OPTARG" ;; *) echo "无效参数"; exit 1 ;; esac done if [[ -z "$SERVER_ADDR" || -z "$PORT" || -z "$SECRET" ]]; then echo "用法: $0 -a 服务器地址 -p 端口 -s 密钥" exit 1 fi INSTALL_DIR="/etc/gost" mkdir -p "$INSTALL_DIR" # 检查gost服务是否存在并运行 if systemctl list-units --full -all | grep -Fq "gost.service"; then echo "检测到已存在的gost服务" if systemctl is-active --quiet gost; then echo "停止运行中的gost服务..." systemctl stop gost fi if systemctl is-enabled --quiet gost; then echo "禁用gost服务自启动..." systemctl disable gost fi fi # 删除旧文件 for FILE in gost config.json gost.json; do if [[ -f "$INSTALL_DIR/$FILE" ]]; then echo "删除已有文件: $INSTALL_DIR/$FILE" rm -f "$INSTALL_DIR/$FILE" fi done # 下载gost可执行文件 curl -L "$DOWNLOAD_URL" -o "$INSTALL_DIR/gost" chmod +x "$INSTALL_DIR/gost" cat > "$INSTALL_DIR/config.json" < "$INSTALL_DIR/gost.json" < /etc/systemd/system/gost.service <