forked from hrostami/tuic-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
142 lines (121 loc) · 3.62 KB
/
setup.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
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
#!/bin/bash
# Install jq if not already installed
if ! command -v jq &>/dev/null; then
echo "Installing jq..."
if ! sudo apt-get install jq -y; then
echo "Error: Failed to install jq."
exit 1
fi
echo "jq installed successfully."
fi
# Determine the appropriate TUIC_FOLDER based on the user
if [ "$EUID" -eq 0 ]; then
TUIC_FOLDER="/root/tuic"
else
TUIC_FOLDER="$HOME/tuic"
fi
CONFIG_FILE="$TUIC_FOLDER/config.json"
# Update packages
apt update
apt install nano net-tools uuid-runtime wget openssl -y
# Create TUIC directory and navigate to it
mkdir ~/tuic
cd ~/tuic
# Download TUIC server binary
wget -O tuic-server https://github.com/EAimTY/tuic/releases/download/tuic-server-1.0.0/tuic-server-1.0.0-x86_64-unknown-linux-gnu
chmod 755 tuic-server
# Generate certificate
openssl ecparam -genkey -name prime256v1 -out ca.key
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=bing.com"
# Generate random UUID
UUID=$(uuidgen)
# Prompt for port
read -p "Enter port number: " PORT
# Prompt for password
read -p "Enter a password for the server: " PASSWORD
# Prompt for congestion control
OPTIONS=("cubic" "new_reno" "bbr")
PS3='Select congestion control: '
select OPT in "${OPTIONS[@]}"
do
CONGESTION_CONTROL=$OPT
break
done
# Create config file
cat <<EOF >config.json
{
"server": "[::]:$PORT",
"users": {
"${UUID}": "$PASSWORD"
},
"certificate": "/root/tuic/ca.crt",
"private_key": "/root/tuic/ca.key",
"congestion_control": "$CONGESTION_CONTROL",
"alpn": ["h3", "spdy/3.1"],
"udp_relay_ipv6": true,
"zero_rtt_handshake": false,
"dual_stack": true,
"auth_timeout": "3s",
"task_negotiation_timeout": "3s",
"max_idle_time": "10s",
"max_external_packet_size": 1500,
"send_window": 16777216,
"receive_window": 8388608,
"gc_interval": "3s",
"gc_lifetime": "15s",
"log_level": "warn"
}
EOF
cat <<EOF > /etc/systemd/system/tuic.service
[Unit]
Description=tuic service
Documentation=by iSegaro
After=network.target nss-lookup.target
[Service]
User=root
WorkingDirectory=/root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW
ExecStart=/root/tuic/tuic-server -c /root/tuic/config.json
Restart=on-failure
RestartSec=10
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
EOF
# Reload and start service
systemctl daemon-reload
systemctl enable tuic
systemctl start tuic
# Get public IPs
IPV4=$(curl -s https://v4.ident.me)
if [ $? -ne 0 ]; then
echo "Error: Failed to get IPv4 address"
return
fi
IPV6=$(curl -s https://v6.ident.me)
if [ $? -ne 0 ]; then
echo "Error: Failed to get IPv6 address"
return
fi
# Generate and print URLs
IPV4_URL="tuic://$UUID:$PASSWORD@$IPV4:$PORT/?congestion_control=$CONGESTION_CONTROL&udp_relay_mode=native&alpn=h3%2Cspdy%2F3.1&allow_insecure=1"
IPV6_URL="tuic://$UUID:$PASSWORD@[$IPV6]:$PORT/?congestion_control=$CONGESTION_CONTROL&udp_relay_mode=native&alpn=h3%2Cspdy%2F3.1&allow_insecure=1"
echo "----------------config info-----------------"
echo -e "\e[1;33mUUID: $UUID\e[0m"
echo -e "\e[1;33mPassword: $PASSWORD\e[0m"
echo "--------------------------------------------"
echo
echo "----------------IP and Port-----------------"
echo -e "\e[1;33mPort: $PORT\e[0m"
echo -e "\e[1;33mIPv4: $IPV4\e[0m"
echo -e "\e[1;33mIPv6: $IPV6\e[0m"
echo "--------------------------------------------"
echo
echo "----------------Config IPv4-----------------"
echo -e "\e[1;33m$IPV4_URL\e[0m"
echo "--------------------------------------------"
echo
echo "-----------------Config IPv6----------------"
echo -e "\e[1;33m$IPV6_URL\e[0m"
echo "--------------------------------------------"