my/frpc.sh
2025-02-13 05:44:42 +00:00

95 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 定义变量
FRPC_VERSION="0.61.1"
INSTALL_DIR="/usr/local/bin"
SERVICE_NAME="frpc"
CONFIG_DIR="/etc/frp"
CONFIG_FILE="$CONFIG_DIR/frpc.toml"
# 检测系统架构
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCH="amd64"
;;
aarch64)
ARCH="arm64"
;;
armv7l)
ARCH="arm"
;;
*)
echo "不支持的架构: $ARCH"
exit 1
;;
esac
# 下载 frpc
echo "正在下载 frpc v$FRPC_VERSION ..."
DOWNLOAD_URL="https://ghub.z1.mk/https://github.com/fatedier/frp/releases/download/v${FRPC_VERSION}/frp_${FRPC_VERSION}_linux_${ARCH}.tar.gz"
wget -q --show-progress -O /tmp/frp.tar.gz $DOWNLOAD_URL
# 解压并安装
echo "正在安装 frpc ..."
tar -xzf /tmp/frp.tar.gz -C /tmp
sudo mv /tmp/frp_${FRPC_VERSION}_linux_${ARCH}/frpc $INSTALL_DIR/
sudo chmod +x $INSTALL_DIR/frpc
# 创建配置文件目录
echo "正在创建配置文件目录 ..."
sudo mkdir -p $CONFIG_DIR
# 用户输入 frps 服务器地址和端口号
echo "请输入 frps 服务器地址例如frps.example.com"
read FRPS_SERVER
echo "请输入 frps 服务器端口号例如7000"
read FRPS_PORT
# 写入 TOML 配置文件
echo "正在写入 TOML 配置文件 ..."
sudo bash -c "cat > $CONFIG_FILE" <<EOF
[common]
server_addr = "$FRPS_SERVER"
server_port = $FRPS_PORT
# 添加您的隧道规则,例如:
# [[proxies]]
# name = "web"
# type = "http"
# localPort = 80
# customDomains = ["example.com"]
EOF
# 创建 Systemd 服务
echo "正在创建 Systemd 服务 ..."
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
sudo bash -c "cat > $SERVICE_FILE" <<EOF
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
ExecStart=$INSTALL_DIR/frpc -c $CONFIG_FILE
Restart=on-failure
User=nobody
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
# 重载 Systemd 并启动服务
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE_NAME
sudo systemctl start $SERVICE_NAME
# 检查服务状态
echo "frpc 安装完成!"
echo "服务状态:"
sudo systemctl status $SERVICE_NAME
# 清理临时文件
rm -rf /tmp/frp_${FRPC_VERSION}_linux_${ARCH} /tmp/frp.tar.gz