Files
nas/scripts/setup-frp-remote.sh

38 lines
1.9 KiB
Bash
Executable File
Raw Permalink 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.
#!/usr/bin/env bash
# 在 Mac 上执行的一键部署入口:
# rbw 取 token → 送到 NAS → 上传并执行 setup-frp-on-nas.shsudo 会提示输 DSM 密码)
# 用法:
# bash scripts/setup-frp-remote.sh # 默认走 Tailscale IP(人在外)
# bash scripts/setup-frp-remote.sh wangjia@192.168.3.200 # 在家走局域网
# 前提:Mac 已连 Tailscalepangolin 先断开);rbw 已 unlock。
set -euo pipefail
NAS_HOST="${1:-wangjia@100.95.151.13}"
cd "${0%/*}" # scripts/ 目录
echo "==> 从 Bitwarden 取 frp token"
TMPTOKEN=/tmp/frp-token.$$
rbw get "frp home-tunnel" > "$TMPTOKEN"
[ -s "$TMPTOKEN" ] || { echo "!! rbw 取 token 失败(先 rbw unlock"; rm -f "$TMPTOKEN"; exit 1; }
chmod 600 "$TMPTOKEN"
echo "==> 准备 frpc 二进制(linux_amd64NAS 出国通道不通,由 Mac 代下载)"
FRP_VER=0.70.0
FRP_TAR="/tmp/frp_${FRP_VER}_linux_amd64.tar.gz"
if [ ! -x "/tmp/frp_${FRP_VER}_linux_amd64/frpc" ]; then
curl -sL -o "$FRP_TAR" "https://github.com/fatedier/frp/releases/download/v${FRP_VER}/frp_${FRP_VER}_linux_amd64.tar.gz"
tar xzf "$FRP_TAR" -C /tmp
fi
[ -x "/tmp/frp_${FRP_VER}_linux_amd64/frpc" ] || { echo "!! frpc 下载/解包失败"; exit 1; }
echo "==> 上传 token / 脚本 / 二进制到 $NAS_HOST:/tmp/frp-setup/"
# 用 ssh cat 管道而非 scpDSM 默认没开 SFTP 子系统,新版 scp(走SFTP协议)会 Connection closed
ssh "$NAS_HOST" 'mkdir -p /tmp/frp-setup && chmod 700 /tmp/frp-setup'
ssh "$NAS_HOST" 'cat > /tmp/frp-setup/token && chmod 600 /tmp/frp-setup/token' < "$TMPTOKEN"
ssh "$NAS_HOST" 'cat > /tmp/frp-setup/setup-frp-on-nas.sh' < setup-frp-on-nas.sh
ssh "$NAS_HOST" 'cat > /tmp/frp-setup/frpc' < "/tmp/frp_${FRP_VER}_linux_amd64/frpc"
rm -f "$TMPTOKEN"
echo "==> 在 NAS 上执行(sudo 步骤会提示输入 DSM 密码)"
ssh -t "$NAS_HOST" 'bash /tmp/frp-setup/setup-frp-on-nas.sh'