forked from vts163/XrayR_onekey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxrayr.sh
345 lines (326 loc) · 9.47 KB
/
xrayr.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
345
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Current folder
cur_dir=$(pwd)
# Color
red='\033[0;31m'
green='\033[0;32m'
#yellow='\033[0;33m'
plain='\033[0m'
operation=(全新安装 更新配置 更新镜像 查看日志 重启后端 删除后端)
# Make sure only root can run our script
[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] 你没权没势 请先获取ROOT权限!" && exit 1
#Check system
check_sys() {
local checkType=$1
local value=$2
local release=''
local systemPackage=''
if [[ -f /etc/redhat-release ]]; then
release="centos"
systemPackage="yum"
elif grep -Eqi "debian|raspbian" /etc/issue; then
release="debian"
systemPackage="apt"
elif grep -Eqi "ubuntu" /etc/issue; then
release="ubuntu"
systemPackage="apt"
elif grep -Eqi "centos|red hat|redhat" /etc/issue; then
release="centos"
systemPackage="yum"
elif grep -Eqi "debian|raspbian" /proc/version; then
release="debian"
systemPackage="apt"
elif grep -Eqi "ubuntu" /proc/version; then
release="ubuntu"
systemPackage="apt"
elif grep -Eqi "centos|red hat|redhat" /proc/version; then
release="centos"
systemPackage="yum"
fi
if [[ "${checkType}" == "sysRelease" ]]; then
if [ "${value}" == "${release}" ]; then
return 0
else
return 1
fi
elif [[ "${checkType}" == "packageManager" ]]; then
if [ "${value}" == "${systemPackage}" ]; then
return 0
else
return 1
fi
fi
}
# Get version
getversion() {
if [[ -s /etc/redhat-release ]]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}
# CentOS version
centosversion() {
if check_sys sysRelease centos; then
local code=$1
local version="$(getversion)"
local main_ver=${version%%.*}
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
get_char() {
SAVEDSTTY=$(stty -g)
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2>/dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
error_detect_depends() {
local command=$1
local depend=$(echo "${command}" | awk '{print $4}')
echo -e "[${green}Info${plain}] 开始安装软件包 ${depend}"
${command} >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] 软件包安装失败 ${red}${depend}${plain}"
exit 1
fi
}
# Pre-installation settings
pre_install_docker_compose() {
read -p "前端节点信息里面的节点ID:" node_id
[ -z "${node_id}" ] && node_id=0
read -p "前端面板域名(包括https://):" api_host
[ -z "${api_host}" ] && api_host="http://8.8.8.8"
read -p "前端面板的apikey:" api_key
[ -z "${api_key}" ] && api_key="123"
echo -e "[1] SSpanel"
echo -e "[2] V2board"
read -p "前端面板类型:" panel_num
if [ "$panel_num" == "1" ]; then
panel_type="SSpanel"
elif [ "$panel_num" == "2" ]; then
panel_type="V2board"
else
echo "type error, please try again"
exit
fi
echo -e "[1] V2ray"
echo -e "[2] Shadowsocks"
echo -e "[2] Trojan"
read -p "节点类型:" node_num
if [ "$node_num" == "1" ]; then
node_type="V2ray"
elif [ "$node_num" == "2" ]; then
node_type="Shadowsocks"
elif [ "$node_num" == "3" ]; then
node_type="Trojan"
else
echo "type error, please try again"
exit
fi
}
# Config docker
config_docker() {
cd ${cur_dir} || exit
echo "开始安装软件包"
install_dependencies
echo "加载DOCKER配置文件"
cat>docker-compose.yml<<EOF
version: '3'
services:
xrayr:
image: crackair/xrayr:latest
volumes:
- ./config.yml:/etc/XrayR/config.yml # 映射配置文件夹
- ./dns.json:/etc/XrayR/dns.json
restart: always
network_mode: host
EOF
cat>dns.json<<EOF
{
"servers": [
"1.1.1.1",
"8.8.8.8",
"localhost"
],
"tag": "dns_inbound"
}
EOF
cat>config.yml<<EOF
Log:
Level: debug # Log level: none, error, warning, info, debug
AccessPath: # ./access.Log
ErrorPath: # ./error.log
DnsConfigPath: # ./dns.json Path to dns config
Nodes:
-
PanelType: "SSpanel" # Panel type: SSpanel
ApiConfig:
ApiHost: "http://8.8.8.8"
ApiKey: "123"
NodeID: 41
NodeType: V2ray # Node type: V2ray, Shadowsocks, Trojan
Timeout: 30 # Timeout for the api request, Default is 5 sec
EnableVless: false # Enable Vless for V2ray Type, Prefer remote configuration
EnableXTLS: false # Enable XTLS for V2ray and Trojan, Prefer remote configuration
ControllerConfig:
ListenIP: 0.0.0.0 # IP address you want to listen
UpdatePeriodic: 60 # Time to update the nodeinfo, how many sec.
EnableDNS: false # Enable custom DNS config, Please ensure that you set the dns.json well
CertConfig:
CertMode: dns # Option about how to get certificate: none, file, http, dns. Choose "none" will forcedly disable the tls config.
CertDomain: "node1.test.com" # Domain to cert
CertFile: ./cert/node1.test.com.cert # Provided if the CertMode is file
KeyFile: ./cert/node1.test.com.key
Provider: alidns # DNS cert provider, Get the full support list here: https://go-acme.github.io/lego/dns/
Email: [email protected]
DNSEnv: # DNS ENV option used by DNS provider
ALICLOUD_ACCESS_KEY: aaa
ALICLOUD_SECRET_KEY: bbb
EOF
sed -i "s|NodeID:.*|NodeID: ${node_id}|" ./config.yml
sed -i "s|ApiHost:.*|ApiHost: \"${api_host}\"|" ./config.yml
sed -i "s|ApiKey:.*|ApiKey: \"${api_key}\"|" ./config.yml
sed -i "s|PanelType:.*|PanelType: \"${panel_type}\"|" ./config.yml
sed -i "s|NodeType:.*|NodeType: ${node_type}|" ./config.yml
}
# Install docker and docker compose
install_docker() {
echo -e "开始安装 DOCKER "
docker version >/dev/null || curl -fsSL get.docker.com | bash
service docker restart
systemctl enable docker
service postfix stop
systemctl disable postfix
echo -e "开始安装 Docker Compose "
curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-$(uname -s)-$(uname -m) >/usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
curl -L https://raw.githubusercontent.com/docker/compose/1.8.0/contrib/completion/bash/docker-compose >/etc/bash_completion.d/docker-compose
clear
echo "启动 Docker "
service docker start
echo "启动 Docker-Compose "
docker-compose up -d
echo
echo -e "后端安装完成!"
echo -e "0 0 */3 * * cd /root/${cur_dir} && /usr/local/bin/docker-compose pull && /usr/local/bin/docker-compose up -d" >>/etc/crontab
echo -e "后端定时更新设置完成!(3天一次)"
}
install_check() {
if check_sys packageManager yum || check_sys packageManager apt; then
if centosversion 5; then
return 1
fi
return 0
else
return 1
fi
}
install_dependencies() {
if check_sys packageManager yum; then
echo -e "[${green}Info${plain}] 检查EPEL存储库..."
if [ ! -f /etc/yum.repos.d/epel.repo ]; then
yum install -y epel-release >/dev/null 2>&1
fi
[ ! -f /etc/yum.repos.d/epel.repo ] && echo -e "[${red}Error${plain}] 安装EPEL储存库失败,请检查一下." && exit 1
[ ! "$(command -v yum-config-manager)" ] && yum install -y yum-utils >/dev/null 2>&1
[ x"$(yum-config-manager epel | grep -w enabled | awk '{print $3}')" != x"True" ] && yum-config-manager --enable epel >/dev/null 2>&1
echo -e "[${green}Info${plain}] 检查EPEL储存库是否完整..."
yum_depends=(
curl
)
for depend in ${yum_depends[@]}; do
error_detect_depends "yum -y install ${depend}"
done
elif check_sys packageManager apt; then
apt_depends=(
curl
)
apt-get -y update
for depend in ${apt_depends[@]}; do
error_detect_depends "apt-get -y install ${depend}"
done
fi
echo -e "[${green}Info${plain}] 将时区设置为上海"
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date -s "$(curl -sI g.cn | grep Date | cut -d' ' -f3-6)Z"
}
#update_image
更新镜像_xrayr() {
cd ${cur_dir}
echo "关闭当前服务"
docker-compose down
echo "加载DOCKER镜像"
docker-compose pull
echo "开始运行DOKCER服务"
docker-compose up -d
}
#show last 100 line log
查看日志_xrayr() {
echo "将要显示100行的运行日志"
docker-compose logs --tail 100
}
# Update config
更新配置_xrayr() {
cd ${cur_dir}
echo "关闭当前服务"
docker-compose down
pre_install_docker_compose
config_docker
echo "开始运行DOKCER服务"
docker-compose up -d
}
重启后端_xrayr() {
cd ${cur_dir}
docker-compose down
docker-compose up -d
echo "重启成功!"
}
删除后端_xrayr() {
cd ${cur_dir}
docker-compose down
cd ~
rm -Rf ${cur_dir}
echo "删除成功!"
}
# Install xrayr
全新安装_xrayr() {
pre_install_docker_compose
config_docker
install_docker
}
# Initialization step
clear
while true; do
echo "-----XrayR onekey-----"
echo "项目地址及帮助文档: https://github.com/KANIKIG/XrayR_onekey"
echo "请输入数字选择你要进行的操作:"
for ((i = 1; i <= ${#operation[@]}; i++)); do
hint="${operation[$i - 1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "请选择数字后回车 (回车默认 ${operation[0]}):" selected
[ -z "${selected}" ] && selected="1"
case "${selected}" in
1 | 2 | 3 | 4 | 5 | 6 | 7 )
echo
echo "你的想法 = ${operation[${selected} - 1]}"
echo
${operation[${selected} - 1]}_xrayr
break
;;
*)
echo -e "[${red}Error${plain}] 请输入正确数字 [1-4]"
;;
esac
done