-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathrtxvpn_v2.sh
More file actions
426 lines (373 loc) · 15.2 KB
/
rtxvpn_v2.sh
File metadata and controls
426 lines (373 loc) · 15.2 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/bin/bash
#MmD
GREEN=$(tput setaf 2)
RED=$(tput setaf 1)
BLUE=$(tput setaf 4)
GOLD=$(tput setaf 3)
CYAN=$(tput setaf 6)
NC=$(tput sgr0)
UUID=""
root_check() {
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as ${RED}root!${NC}"
exit 1
fi
}
install_check() {
if [ -d "/opt/rtxvpn_v2/tunnel" ] || [ -d "/opt/rtxvpn_v2/edge" ]; then
echo "RTX-VPN v2 is already ${GREEN}installed!${NC}"
exit 1
fi
}
uninstall() {
if [ -d "/opt/rtxvpn_v2/tunnel" ]; then
while true; do
read -p "This will remove ${CYAN}RTX-VPN v2 (Tunnel)${NC} and its associated files. Are you sure? (y/n): " confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
echo "Uninstalling RTX-VPN v2 (Tunnel)..."
rm -rf "/opt/rtxvpn_v2/tunnel"
systemctl stop dnsmasq
systemctl disable dnsmasq
apt remove dnsmasq -y
sed -i '/200 rtx_table/d' /etc/iproute2/rt_tables
ip link set dev rtx down
ip tuntap del mode tun dev rtx
ip link set dev tap_softether down
ip addr del 198.19.0.1/24 dev tap_softether
ip route del 198.19.0.0/24 dev rtx table rtx_table
ip route del default dev rtx table rtx_table
ip rule del from 198.19.0.0/24 table rtx_table priority 10
ip rule del to 8.8.8.8 table main priority 11
ip rule del to 8.8.4.4 table main priority 12
iptables -D FORWARD -i tap_softether -o rtx -j ACCEPT
iptables -D FORWARD -i rtx -o tap_softether -m state --state ESTABLISHED,RELATED -j ACCEPT
netfilter-persistent save
if [ -f "/etc/systemd/system/rtxvpn.service" ]; then
systemctl stop rtxvpn.service
systemctl disable rtxvpn.service
rm -f /etc/systemd/system/rtxvpn.service
echo "RTX-VPN service ${GREEN}removed${NC}"
else
echo "RTX-VPN service ${RED}not found!${NC}"
fi
if [ -f "/etc/systemd/system/softether.service" ]; then
systemctl stop softether.service
systemctl disable softether.service
rm -f /etc/systemd/system/softether.service
echo "SoftEther service ${GREEN}removed${NC}"
else
echo "SoftEther service ${RED}not found!${NC}"
fi
echo "RTX-VPN v2 (Tunnel) has been ${GREEN}removed${NC}"
break
elif [ "$confirm" = "n" ] || [ "$confirm" = "N" ]; then
echo "Uninstallation of RTX-VPN v2 (Tunnel) ${RED}canceled${NC}"
break
else
echo "Invalid input. Please enter 'y' for yes or 'n' for no."
fi
done
fi
# Check and remove the edge directory
if [ -d "/opt/rtxvpn_v2/edge" ]; then
while true; do
read -p "This will remove ${CYAN}RTX-VPN v2 (Edge)${NC} and its associated files. Are you sure? (y/n): " confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
echo "Uninstalling RTX-VPN v2 (Edge)..."
rm -rf "/opt/rtxvpn_v2/edge"
# Remove RTX-VPN service
if [ -f "/etc/systemd/system/rtxvpn.service" ]; then
systemctl stop rtxvpn.service
systemctl disable rtxvpn.service
rm -f /etc/systemd/system/rtxvpn.service
echo "RTX-VPN service ${GREEN}removed${NC}"
else
echo "RTX-VPN service ${RED}not found!${NC}"
fi
echo "RTX-VPN v2 (Edge) has been ${GREEN}removed${NC}"
break
elif [ "$confirm" = "n" ] || [ "$confirm" = "N" ]; then
echo "Uninstallation of RTX-VPN v2 (Edge) ${RED}canceled${NC}"
break
else
echo "Invalid input. Please enter 'y' for yes or 'n' for no."
fi
done
else
echo "RTX-VPN v2 is ${RED}not installed!${NC}"
fi
}
download_edge_files(){
apt update && apt install tar sudo wget unzip python3 -y
if [ ! -d "/opt/rtxvpn_v2/edge" ]; then
mkdir -p /opt/rtxvpn_v2/edge || { echo -e "${RED}Failed to create /opt/rtxvpn_v2/edge directory!${NC}"; exit 1; }
fi
CPU_ARCH=$(uname -m)
case $CPU_ARCH in
"x86_64")
wget -P /opt/rtxvpn_v2/edge https://github.com/rapiz1/rathole/releases/download/v0.5.0/rathole-x86_64-unknown-linux-gnu.zip
wget -P /opt/rtxvpn_v2/edge https://github.com/XTLS/Xray-core/releases/download/v25.2.21/Xray-linux-64.zip
#Extract
unzip /opt/rtxvpn_v2/edge/rathole-x86_64-unknown-linux-gnu.zip -d /opt/rtxvpn_v2/edge
unzip /opt/rtxvpn_v2/edge/Xray-linux-64.zip -d /opt/rtxvpn_v2/edge
#Configs
wget -P /opt/rtxvpn_v2/edge/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/edge.json
wget -P /opt/rtxvpn_v2/edge/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/edge.toml
wget -P /opt/rtxvpn_v2/edge/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/edge.py
chmod -R +x /opt/rtxvpn_v2/edge/
;;
"aarch64")
wget -P /opt/rtxvpn_v2/edge/ https://github.com/rapiz1/rathole/releases/download/v0.5.0/rathole-aarch64-unknown-linux-musl.zip
wget -P /opt/rtxvpn_v2/edge/ https://github.com/XTLS/Xray-core/releases/download/v25.2.21/Xray-linux-arm64-v8a.zip
#Extract
unzip /opt/rtxvpn_v2/edge/rathole-aarch64-unknown-linux-musl.zip -d /opt/rtxvpn_v2/edge/
unzip /opt/rtxvpn_v2/edge/Xray-linux-arm64-v8a.zip -d /opt/rtxvpn_v2/edge/
#Configs
wget -P /opt/rtxvpn_v2/edge/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/edge.json
wget -P /opt/rtxvpn_v2/edge/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/edge.toml
wget -P /opt/rtxvpn_v2/edge/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/edge.py
chmod -R +x /opt/rtxvpn_v2/edge/
;;
*)
echo "${RED}Unsupported CPU architecture: $CPU_ARCH${NC}"
exit 1
;;
esac
}
download_tunnel_files() {
apt update && apt install tar sudo wget unzip dnsmasq iptables build-essential python3 -y
if [ ! -d "/opt/rtxvpn_v2/tunnel/" ]; then
mkdir -p /opt/rtxvpn_v2/tunnel/ || { echo -e "${RED}Failed to create /opt/rtxvpn_v2/tunnel/ directory!${NC}"; exit 1; }
fi
CPU_ARCH=$(uname -m)
case $CPU_ARCH in
"x86_64")
wget -P /opt/rtxvpn_v2/tunnel/ https://github.com/rapiz1/rathole/releases/download/v0.5.0/rathole-x86_64-unknown-linux-gnu.zip
wget -P /opt/rtxvpn_v2/tunnel/ https://github.com/xjasonlyu/tun2socks/releases/download/v2.5.2/tun2socks-linux-amd64.zip
wget -P /opt/rtxvpn_v2/tunnel/ https://github.com/XTLS/Xray-core/releases/download/v25.2.21/Xray-linux-64.zip
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/assets/softether-vpnserver-v4.43-9799-beta-2023.08.31-linux-x64-64bit.tar.gz
#Extract
unzip /opt/rtxvpn_v2/tunnel/rathole-x86_64-unknown-linux-gnu.zip -d /opt/rtxvpn_v2/tunnel/
unzip /opt/rtxvpn_v2/tunnel/tun2socks-linux-amd64.zip -d /opt/rtxvpn_v2/tunnel/
unzip /opt/rtxvpn_v2/tunnel/Xray-linux-64.zip -d /opt/rtxvpn_v2/tunnel/
tar xf /opt/rtxvpn_v2/tunnel/softether-vpnserver-v4.43-9799-beta-2023.08.31-linux-x64-64bit.tar.gz -C /opt/rtxvpn_v2/tunnel/
#Configs
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/tunnel.json
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/tunnel.toml
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/tunnel.py
mv /opt/rtxvpn_v2/tunnel/tun2socks-linux-amd64 /opt/rtxvpn_v2/tunnel/tun2socks
chmod -R +x /opt/rtxvpn_v2/tunnel/
;;
"aarch64")
wget -P /opt/rtxvpn_v2/tunnel/ https://github.com/rapiz1/rathole/releases/download/v0.5.0/rathole-aarch64-unknown-linux-musl.zip
wget -P /opt/rtxvpn_v2/tunnel/ https://github.com/xjasonlyu/tun2socks/releases/download/v2.5.2/tun2socks-linux-arm64.zip
wget -P /opt/rtxvpn_v2/tunnel/ https://github.com/XTLS/Xray-core/releases/download/v25.2.21/Xray-linux-arm64-v8a.zip
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/assets/softether-vpnserver-v4.43-9799-beta-2023.08.31-linux-arm64-64bit.tar.gz
#Extract
unzip /opt/rtxvpn_v2/tunnel/rathole-aarch64-unknown-linux-musl.zip -d /opt/rtxvpn_v2/tunnel/
unzip /opt/rtxvpn_v2/tunnel/tun2socks-linux-arm64.zip -d /opt/rtxvpn_v2/tunnel/
unzip /opt/rtxvpn_v2/tunnel/Xray-linux-arm64-v8a.zip -d /opt/rtxvpn_v2/tunnel/
tar xf /opt/rtxvpn_v2/tunnel/softether-vpnserver-v4.43-9799-beta-2023.08.31-linux-arm64-64bit.tar.gz -C /opt/rtxvpn_v2/tunnel/
#Configs
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/tunnel.json
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/tunnel.toml
wget -P /opt/rtxvpn_v2/tunnel/ https://raw.githubusercontent.com/Sir-MmD/RTX-VPN/v2/configs/tunnel.py
mv /opt/rtxvpn_v2/tunnel/tun2socks-linux-arm64 /opt/rtxvpn_v2/tunnel/tun2socks
chmod -R +x /opt/rtxvpn_v2/tunnel/
;;
*)
echo "${RED}Unsupported CPU architecture: $CPU_ARCH${NC}"
exit 1
;;
esac
}
softether_setup() {
if [ ! -d "/opt/rtxvpn_v2/tunnel/vpnserver" ]; then
echo "${RED}SoftEther not found!${NC}"
exit 1
else
make -C /opt/rtxvpn_v2/tunnel/vpnserver
cat <<EOF > /etc/systemd/system/softether.service
[Unit]
Description=SoftEther VPN Server
After=network.target
[Service]
Type=forking
ExecStart=/opt/rtxvpn_v2/tunnel/vpnserver/vpnserver start
ExecStop=/opt/rtxvpn_v2/tunnel/vpnserver/vpnserver stop
ExecReload=/opt/rtxvpn_v2/tunnel/vpnserver/vpnserver restart
WorkingDirectory=/opt/rtxvpn_v2/tunnel/vpnserver
Restart=always
RestartSec=3
User=root
Group=root
[Install]
WantedBy=multi-user.target
EOF
systemctl enable softether.service
systemctl start softether.service
fi
}
dnsmasq_setup(){
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
cat <<EOF > /etc/dnsmasq.conf
interface=tap_softether
dhcp-range=tap_softether,198.19.0.2,198.19.0.254,12h
dhcp-option=tap_softether,3,198.19.0.1
dhcp-option=tap_softether,6,8.8.8.8,8.8.4.4
EOF
systemctl enable dnsmasq
systemctl restart dnsmasq
}
tunnel_setup(){
echo "200 rtx_table" >> /etc/iproute2/rt_tables
cat <<EOF > /etc/systemd/system/rtxvpn.service
[Unit]
Description=RTX-VPN Tunnel Service
After=softether.service
Requires=softether.service
[Service]
Type=simple
ExecStart=/usr/bin/python3 /opt/rtxvpn_v2/tunnel/tunnel.py
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure
User=root
Group=root
Environment="PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
PIDFile=/var/run/vpn-service.pid
[Install]
WantedBy=multi-user.target
EOF
systemctl enable rtxvpn.service
systemctl start rtxvpn.service
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -i tap_softether -o rtx -j ACCEPT
iptables -A FORWARD -i rtx -o tap_softether -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
apt install iptables-persistent -y
}
edge_setup(){
cat <<EOF > /etc/systemd/system/rtxvpn.service
[Unit]
Description=RTX-VPN Edge Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /opt/rtxvpn_v2/edge/edge.py
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure
User=root
Group=root
Environment="PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
PIDFile=/var/run/vpn-service.pid
[Install]
WantedBy=multi-user.target
EOF
systemctl enable rtxvpn.service
systemctl start rtxvpn.service
}
uuid_tunnel() {
UUID=$( /opt/rtxvpn_v2/tunnel/xray uuid )
sed -i "s/\"uuid\"/\"$UUID\"/g" "/opt/rtxvpn_v2/tunnel/tunnel.json"
sed -i "s/\"uuid\"/\"$UUID\"/g" "/opt/rtxvpn_v2/tunnel/tunnel.toml"
}
uuid_edge() {
read -p "Enter UUID: " UUID
read -p "Enter Tunnel IP: " TUNNEL_IP
sed -i "s/\"uuid\"/\"$UUID\"/g" "/opt/rtxvpn_v2/edge/edge.json"
sed -i "s/\"uuid\"/\"$UUID\"/g" "/opt/rtxvpn_v2/edge/edge.toml"
sed -i "s/remote_addr = \".*:[0-9]\+\"/remote_addr = \"$TUNNEL_IP:7081\"/" "/opt/rtxvpn_v2/edge/edge.toml"
}
softether_tip(){
echo ""
echo ""
echo ""
echo "${RED}SoftEther Manual Setup:${NC} Please follow these steps then type ${CYAN}'verify'${NC} to continue:"
echo ""
echo "${GOLD}Link:${NC}${GREEN} https://github.com/Sir-MmD/RTX-VPN/blob/v2/softether_manual.md${NC}"
echo ""
echo ""
echo ""
}
root_check
clear
echo ""
echo "${GREEN} _____ _________ __ __ _______ _ _ "
echo " | __ \__ __\ \ / / \ \ / / __ \| \ | | ${NC}"
echo " | |__) | | | \ V /${GOLD}____${NC}\ \ / /| |__) | \| | "
echo " | _ / | | > <${GOLD}______${NC}\ \/ / | ___/| . | ${RED}"
echo " | | \ \ | | / . \ \ / | | | |\ | "
echo " |_| \_\ |_| /_/ \_\ ${GOLD}V2${RED} \/ |_| |_| \_| ${NC}"
echo " _ "
echo " _| |_ "
echo " |_ _| "
echo " |_| "
echo "${CYAN} _____ __ _ ______ _ _ "
echo " / ____| / _| | | ____| | | | "
echo " | (___ ___ | |_| |_| |__ | |_| |__ ___ _ __ "
echo " \___ \ / _ \| _| __| __| | __| '_ \ / _ \ '__|"
echo " ____) | (_) | | | |_| |____| |_| | | | __/ | "
echo " |_____/ \___/|_| \__|______|\__|_| |_|\___|_| ${NC}"
echo ""
echo ""
echo "Choose an option:"
echo ""
echo "1.Setup Tunnel"
echo "2.Setup Edge"
echo "3.Uninstall"
echo ""
while true; do
read -p "Enter your choice (1, 2 or 3): " choice
case $choice in
1)
install_check
download_tunnel_files
softether_setup
softether_tip
while true; do
read -p "Please follow instructions, then type ${CYAN}'verify'${NC} to continue: " confirm
if [ "$confirm" = "verify" ]; then
uuid_tunnel
tunnel_setup
dnsmasq_setup
echo ""
echo ""
echo "${GREEN}Tunnel installed!${NC} Please Setup the Edge server and enter this UUID: ${GOLD}$UUID${NC}"
echo ""
echo "You can use these commands to check RTX-VPN & SoftEther status:"
echo "${CYAN}systemctl status rtxvpn${NC}"
echo "${CYAN}systemctl status softether${NC}"
echo "${CYAN}systemctl status dnsmasq${NC}"
echo ""
echo ""
break
else
echo "Please follow instructions, then type ${CYAN}'verify'${NC} to continue: "
fi
done
break
;;
2)
install_check
download_edge_files
uuid_edge
edge_setup
echo ""
echo ""
echo "${GREEN}Edge installed!${NC} Enjoy your ${GOLD}FREEDOM${NC}"
echo ""
echo "You can use this command to check RTX-VPN status: ${CYAN}systemctl status rtxvpn${NC}"
echo ""
echo ""
break
;;
3)
uninstall
break
;;
*)
echo "Invalid option. Please enter 1, 2, or 3."
;;
esac
done