forked from stilleshan/frpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frpc_synology_install.sh
executable file
·108 lines (93 loc) · 3.92 KB
/
frpc_synology_install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
# fonts color
Green="\033[32m"
Red="\033[31m"
Yellow="\033[33m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"
# fonts color
# variable
WORK_PATH=$(dirname $(readlink -f $0))
FRP_NAME=frpc
FRP_VERSION=0.56.0
FRP_PATH=/usr/local/frp
PROXY_URL="https://mirror.ghproxy.com/"
# check frpc
if [ -f "/usr/local/frp/${FRP_NAME}" ] || [ -f "/usr/local/frp/${FRP_NAME}.toml" ] || [ -f "/lib/systemd/system/${FRP_NAME}.service" ];then
echo -e "${Green}=========================================================================${Font}"
echo -e "${RedBG}当前已退出脚本.${Font}"
echo -e "${Green}检查到服务器已安装${Font} ${Red}${FRP_NAME}${Font}"
echo -e "${Green}请手动确认和删除${Font} ${Red}/usr/local/frp/${Font} ${Green}目录下的${Font} ${Red}${FRP_NAME}${Font} ${Green}和${Font} ${Red}/${FRP_NAME}.toml${Font} ${Green}文件以及${Font} ${Red}/lib/systemd/system/${FRP_NAME}.service${Font} ${Green}文件,再次执行本脚本.${Font}"
echo -e "${Green}参考命令如下:${Font}"
echo -e "${Red}rm -rf /usr/local/frp/${FRP_NAME}${Font}"
echo -e "${Red}rm -rf /usr/local/frp/${FRP_NAME}.toml${Font}"
echo -e "${Red}rm -rf /lib/systemd/system/${FRP_NAME}.service${Font}"
echo -e "${Green}=========================================================================${Font}"
exit 0
fi
while ! test -z "$(ps -A | grep -w ${FRP_NAME})"; do
FRPCPID=$(ps -A | grep -w ${FRP_NAME} | awk 'NR==1 {print $1}')
kill -9 $FRPCPID
done
# check network
GOOGLE_HTTP_CODE=$(curl -o /dev/null --connect-timeout 5 --max-time 8 -s --head -w "%{http_code}" "https://www.google.com")
PROXY_HTTP_CODE=$(curl -o /dev/null --connect-timeout 5 --max-time 8 -s --head -w "%{http_code}" "${PROXY_URL}")
# check arch
if [ $(uname -m) = "x86_64" ]; then
PLATFORM=amd64
elif [ $(uname -m) = "aarch64" ]; then
PLATFORM=arm64
else
PLATFORM=arm
fi
FILE_NAME=frp_${FRP_VERSION}_linux_${PLATFORM}
# download
if [ $GOOGLE_HTTP_CODE == "200" ]; then
wget -P ${WORK_PATH} https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz
else
if [ $PROXY_HTTP_CODE == "200" ]; then
wget -P ${WORK_PATH} ${PROXY_URL}https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz
else
echo -e "${Red}检测 GitHub Proxy 代理失效 开始使用官方下载地址下载${Font}"
wget -P ${WORK_PATH} https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/${FILE_NAME}.tar.gz -O ${FILE_NAME}.tar.gz
fi
fi
tar -zxvf ${FILE_NAME}.tar.gz
mkdir -p ${FRP_PATH}
mv ${FILE_NAME}/${FRP_NAME} ${FRP_PATH}
# configure frpc.toml
RADOM_NAME=$(cat /dev/urandom | head -n 10 | md5sum | head -c 8)
cat >${FRP_PATH}/${FRP_NAME}.toml <<EOF
serverAddr = "frp.freefrp.net"
serverPort = 7000
auth.method = "token"
auth.token = "freefrp.net"
[[proxies]]
name = "web1_${RADOM_NAME}"
type = "http"
localIP = "192.168.1.2"
localPort = 5000
customDomains = ["nas.yourdomain.com"]
[[proxies]]
name = "web2_${RADOM_NAME}"
type = "https"
localIP = "192.168.1.2"
localPort = 5001
customDomains = ["nas.yourdomain.com"]
[[proxies]]
name = "tcp1_${RADOM_NAME}"
type = "tcp"
localIP = "192.168.1.3"
localPort = 22
remotePort = 22222
EOF
# clean
rm -rf ${WORK_PATH}/${FILE_NAME}.tar.gz ${WORK_PATH}/${FILE_NAME} ${FRP_NAME}_synology_install.sh
# 完成安装,手动修改frpc.toml并启动服务.
echo -e "${Green}=======================================================================${Font}"
echo -e "${Green}安装成功,请先修改 frpc.toml 文件,确保格式及配置正确无误!${Font}"
echo -e "${Red}vi /usr/local/frp/frpc.toml${Font}"
echo -e "${Green}修改完毕后执行以下命令启动服务并保持后台运行:${Font}"
echo -e "${Red}nohup /usr/local/frp/frpc -c /usr/local/frp/frpc.toml >/dev/null 2>&1 &${Font}"
echo -e "${Green}=======================================================================${Font}"