-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathxray_grpc.sh
344 lines (270 loc) · 7.42 KB
/
xray_grpc.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
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
Acme_Get(){
apt install socat -y
curl -sL https://get.acme.sh | sh -s [email protected]
source ~/.bashrc
~/.acme.sh/acme.sh --upgrade --auto-upgrade
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
~/.acme.sh/acme.sh --issue -d $Domain --keylength ec-256 --force --standalone --listen-v6
}
Get_Key_Path(){
echo -e "如果~/.acme.sh下有正确的域名cer/key,不需要80端口"
echo -e "如果~/.acme.sh下没有正确的域名cer/key"
echo -e "请确保80端口没有被占用,脚本自动获取域名cer/key \n"
read -p "请输入域名: " Domain
if [[ -f $cer_path ]] && [[ -f $key_path ]] ; then
cer_path=/root/.acme.sh/${Domain}_ecc/${Domain}.cer
key_path=/root/.acme.sh/${Domain}_ecc/${Domain}.key
echo $cer_path
echo $key_path
else
Acme_Get
cer_path=/root/.acme.sh/${Domain}_ecc/${Domain}.cer
key_path=/root/.acme.sh/${Domain}_ecc/${Domain}.key
echo $cer_path
echo $key_path
fi
}
RED="\033[31m" # Error message
GREEN="\033[32m" # Success message
YELLOW="\033[33m" # Warning message
BLUE="\033[36m" # Info message
PLAIN='\033[0m'
function echoColor() {
case $1 in
# 红色
"red")
echo -e "\033[31m${printN}$2 \033[0m"
;;
# 天蓝色
"skyBlue")
echo -e "\033[1;36m${printN}$2 \033[0m"
;;
# 绿色
"green")
echo -e "\033[32m${printN}$2 \033[0m"
;;
# 白色
"white")
echo -e "\033[37m${printN}$2 \033[0m"
;;
"magenta")
echo -e "\033[31m${printN}$2 \033[0m"
;;
# 黄色
"yellow")
echo -e "\033[33m${printN}$2 \033[0m"
;;
# 紫色
"purple")
echo -e "\033[1;;35m${printN}$2 \033[0m"
;;
#
"yellowBlack")
# 黑底黄字
echo -e "\033[1;33;40m${printN}$2 \033[0m"
;;
"greenWhite")
# 绿底白字
echo -e "\033[42;37m${printN}$2 \033[0m"
;;
esac
}
Xray_Grpc() {
mkdir -p /etc/xrayG/
read -p "port default: 80: " Port
if [[ -z "$Port" ]]; then
Port=80
fi
read -p "input grpc serviceName default: @hijkclub: " ServiceName
if [[ -z "$ServiceName" ]]; then
ServiceName="@hijkclub"
fi
Get_Key_Path
#while true
# do
# read -p "Domain :" Domain
# if [[ -z "${Domain}" ]]; then
# echo "Domain 请重新输入!"
# else
# break
# fi
# done
#
#while true
# do
# read -p " 请输入cer path:" cer_path
# if [ ! -f "${cer_path}" ]; then
# echoColor red " certificate path wrong,请重新输入!"
# echoColor green "请输入证书cert文件路径:"
# else
# break
# fi
# done
#
#while true
# do
# read -p " 请输入key path:" key_path
# if [ ! -f "${key_path}" ]; then
# echoColor red " key path wrong,请重新输入!"
# echoColor green "请输入证书key文件路径:"
# else
# break
# fi
# done
#
read -p "uuid空就随机:" uuid
if [[ -z "$uuid" ]]; then
uuid="$(cat '/proc/sys/kernel/random/uuid')"
fi
cat <<EOF > /etc/xrayG/config.json
{
"log": {
"loglevel": "debug"
},
"inbounds": [
{
"port": $Port,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$uuid"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "grpc",
"security": "tls",
"tlsSettings": {
"serverName": "$Domain",
"alpn": [
"h2"
],
"certificates": [{
"certificateFile": "$cer_path",
"keyFile": "$key_path"
}]
},
"grpcSettings": {
"serviceName": "$ServiceName"
}
}
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom",
"settings": {}
},
{
"tag": "blocked",
"protocol": "blackhole",
"settings": {}
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"ip": [
"geoip:private"
],
"outboundTag": "blocked"
}
]
}
}
EOF
}
function DownloadxrayGCore(){
version=`wget -qO- -t1 -T2 --no-check-certificate "https://api.github.com/repos/XTLS/xray-core/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'`
wget -qO- -t1 -T2 --no-check-certificate "https://api.github.com/repos/XTLS/xray-core/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'
echo -e "The Latest xrayG version:"`echoColor red "${version}"`"\nDownload..."
get_arch=`arch`
#https://github.com/XTLS/xray-core/releases/download/v1.6.1/xray-linux-64.zip
temp_f=$(mktemp)
temp_d=$(mktemp -d)
if [ $get_arch = "x86_64" ];then
wget -q -O $temp_f --no-check-certificate https://github.com/XTLS/xray-core/releases/download/${version}/xray-linux-64.zip
#echo https://github.com/XTLS/xray-core/releases/download/${version}/xray-linux-64.zip
unzip $temp_f -d $temp_d/
mv -fv $temp_d/xray /usr/bin/xrayG
mv -fv $temp_d/* /usr/bin/
elif [ $get_arch = "aarch64" ];then
wget -q -O $temp_f --no-check-certificate https://github.com/XTLS/xray-core/releases/download/${version}/xray-linux-64.zip
unzip $temp_f -d $temp_d/
mv -fv $temp_d/xray /usr/bin/xrayG
mv -fv $temp_d/* /usr/bin/
else
echoColor yellowBlack "Error[OS Message]:${get_arch}\nPlease open a issue to https://github.com/XTLS/xray-core/releases/"
exit
fi
if [ -f "/usr/bin/xrayG" ]; then
chmod 755 /usr/bin/xrayG
echoColor purple "\nDownload completed."
else
echoColor red "Network Error: Can't connect to Github!"
fi
cat <<EOF > /etc/systemd/system/xrayG.service
[Unit]
Description=xrayG Service
Documentation=https://github.com/XTLS/xrayG-core/
After=network.target nss-lookup.target
[Service]
User=root
#User=nobody
#CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/bin/xrayG -c /etc/xrayG/config.json
Restart=on-failure
RestartPreventExitStatus=23
[Install]
WantedBy=multi-user.target
EOF
#apt update -y
#apt upgrade -y
#apt install -y nginx
#sed -i 's/include \/etc\/nginx\/sites-enabled.*/#include \/etc\/nginx\/sites-enabled\/\*;/g' /etc/nginx/nginx.conf
#
#systemctl stop nginx
#systemctl enable nginx
}
start(){
netstat -lptnu |grep $Port
echo "/etc/xrayG/config.json"
cat "/etc/xrayG/config.json"
systemctl daemon-reload
systemctl enable xrayG
systemctl start xrayG
systemctl restart xrayG
systemctl status xrayG
}
echo -e " ${GREEN}1.${PLAIN} 安装 ${BLUE}xrayGrpc${PLAIN}"
echo -e " ${GREEN}2.${PLAIN} 查看 ${BLUE}config${PLAIN}"
echo -e " ${GREEN}3.${PLAIN} restart ${BLUE}config${PLAIN}"
echo -e " ${GREEN}00.${PLAIN} ${BLUE}exit${PLAIN}"
read -p " 选择:" answer
case $answer in
1)
Xray_Grpc
DownloadxrayGCore
start
;;
2)
echo "/etc/xrayG/config.json"
cat "/etc/xrayG/config.json"
systemctl status xrayG
;;
3)
systemctl restart xrayG
systemctl status xrayG
;;
00)
exit
;;
esac