-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathinstall.sh
More file actions
375 lines (344 loc) · 14.3 KB
/
install.sh
File metadata and controls
375 lines (344 loc) · 14.3 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
#!/bin/bash
curl -sS -H "Accept: application/vnd.github.v3+json" -o "/tmp/tmp_file" 'https://api.github.com/repos/qist/xray-ui/releases/latest'
releases_version=($(sed 'y/,/\n/' "/tmp/tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}'))
rm /tmp/tmp_file -f
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
bblue='\033[0;34m'
plain='\033[0m'
red() { echo -e "\033[31m\033[01m$1\033[0m"; }
green() { echo -e "\033[32m\033[01m$1\033[0m"; }
yellow() { echo -e "\033[33m\033[01m$1\033[0m"; }
blue() { echo -e "\033[36m\033[01m$1\033[0m"; }
white() { echo -e "\033[37m\033[01m$1\033[0m"; }
readp() { read -p "$(yellow "$1")" $2; }
remoteV=${releases_version}
clear
white "Github项目 :github.com/qist/xray-ui"
yellow "感谢xray-ui代码贡献者们(vaxilu)"
green "当前安装版本: $remoteV"
yellow "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
sleep 2
cur_dir=$(pwd)
# check root
[[ $EUID -ne 0 ]] && echo -e "${red}错误:${plain} 必须使用root用户运行此脚本!\n" && exit 1
# check os
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
release="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -Eqi "debian"; then
release="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
release="centos"
elif cat /etc/system-release-cpe | grep -Eqi "amazon_linux"; then
release="amazon_linux"
else
echo -e "${red}未检测到系统版本,请联系脚本作者!${plain}\n" && exit 1
fi
arch() {
case "$(uname -m)" in
x86_64 | x64 | amd64) echo 'amd64' ;;
i*86 | x86) echo '386' ;;
armv8* | armv8 | arm64 | aarch64) echo 'arm64' ;;
armv7* | armv7 | arm) echo 'armv7' ;;
armv6* | armv6) echo 'armv6' ;;
armv5* | armv5) echo 'armv5' ;;
s390x) echo 's390x' ;;
*) echo -e "${green}Unsupported CPU architecture! ${plain}" && rm -f install.sh && exit 1 ;;
esac
}
echo "arch: $(arch)"
sys() {
[ -f /etc/os-release ] && grep -i pretty_name /etc/os-release | cut -d \" -f2 && return
[ -f /etc/lsb-release ] && grep -i description /etc/lsb-release | cut -d \" -f2 && return
[ -f /etc/redhat-release ] && awk '{print $0}' /etc/redhat-release && return
}
op=$(sys)
version=$(uname -r | awk -F "-" '{print $1}')
vi=$(systemd-detect-virt)
white "VPS操作系统: $(blue "$op") \c" && white " 内核版本: $(blue "$version") \c" && white " CPU架构 : $(blue "$arch") \c" && white " 虚拟化类型: $(blue "$vi")"
sleep 2
if [ $(getconf WORD_BIT) != '32' ] && [ $(getconf LONG_BIT) != '64' ]; then
echo "本软件不支持 32 位系统(x86),请使用 64 位系统(x86_64),如果检测有误,请联系作者"
exit -1
fi
os_version=""
# os version
if [[ -f /etc/os-release ]]; then
os_version=$(awk -F'[= ."]' '/VERSION_ID/{print $3}' /etc/os-release)
fi
if [[ -z "$os_version" && -f /etc/lsb-release ]]; then
os_version=$(awk -F'[= ."]+' '/DISTRIB_RELEASE/{print $2}' /etc/lsb-release)
fi
if [[ x"${release}" == x"centos" ]]; then
if [[ ${os_version} -le 6 ]]; then
echo -e "${red}请使用 CentOS 7 或更高版本的系统!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"ubuntu" ]]; then
if [[ ${os_version} -lt 16 ]]; then
echo -e "${red}请使用 Ubuntu 16 或更高版本的系统!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"debian" ]]; then
if [[ ${os_version} -lt 8 ]]; then
echo -e "${red}请使用 Debian 8 或更高版本的系统!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"amazon_linux" ]]; then
if [[ ${os_version} -lt 2 ]]; then
echo -e "${red}请使用 Amazon Linux 2 或更高版本的系统!${plain}\n" && exit 1
fi
fi
ports=$(/usr/local/xray-ui/xray-ui 2>&1 | grep tcp | awk '{print $5}' | sed "s/://g")
if [[ -n $ports ]]; then
green "经检测,xray-ui已安装"
echo
acp=$(/usr/local/xray-ui/xray-ui setting -show 2>/dev/null)
green "$acp"
echo
readp "是否直接重装xray-ui,请输入Y/y键并回车。如不重装,输入N/n键回车退出脚本):" ins
if [[ $ins = [Yy] ]]; then
systemctl stop xray-ui
systemctl disable xray-ui
rm /etc/systemd/system/xray-ui.service -f
systemctl daemon-reload
systemctl reset-failed
rm /etc/xray-ui/ -rf
rm /usr/local/xray-ui/ -rf
rm -rf /root/rayuil.sh /root/acme.sh
sed -i '/xrayuil.sh/d' /etc/crontab
sed -i '/xray-ui restart/d' /etc/crontab
else
exit 1
fi
fi
install_base() {
if [[ x"${release}" == x"centos" ]]; then
if [[ ${os_version} =~ 8 ]]; then
yum clean all && yum makecache
fi
yum install epel-release -y && yum install wget curl tar gzip lsof -y
setenforce 0 >/dev/null 2>&1
else
apt update && apt install wget curl tar lsof gzip -y
fi
}
generate_random_string() {
local n=$1
# 定义数字、大写字母和小写字母的集合
local characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
# 生成随机字符并限制在指定字符集中
# 从 /dev/urandom 生成随机字节,使用 tr 进行过滤
local random_string=$(cat /dev/urandom | tr -dc "$characters" | fold -w "$n" | head -n 1)
echo "$random_string"
}
install_xray-ui() {
systemctl stop xray-ui
cd /usr/local/
if [ $# == 0 ]; then
wget --no-check-certificate -O /usr/local/xray-ui-linux-$(arch).tar.gz https://github.com/qist/xray-ui/releases/download/${releases_version}/xray-ui-linux-$(arch).tar.gz
if [[ $? -ne 0 ]]; then
echo -e "${red}下载 xray-ui 失败,请确保你的服务器能够下载 Github 的文件${plain}"
rm -f install.sh
exit 1
fi
else
last_version=$1
url="https://github.com/qist/xray-ui/releases/download/${releases_version}/xray-ui-linux-$(arch).tar.gz"
echo -e "开始安装 xray-ui v$1"
wget --no-check-certificate -O /usr/local/xray-ui-linux-$(arch).tar.gz ${url}
if [[ $? -ne 0 ]]; then
echo -e "${red}下载 xray-ui v$1 失败,请确保此版本存在${plain}"
rm -f install.sh
exit 1
fi
fi
if [[ -e /usr/local/xray-ui/ ]]; then
rm /usr/local/xray-ui/ -rf
fi
tar -zxvf xray-ui-linux-$(arch).tar.gz
rm xray-ui-linux-$(arch).tar.gz -f
cd xray-ui
# Check the system's architecture and rename the file accordingly
if [[ $(arch) == "armv5" || $(arch) == "armv6" || $(arch) == "armv7" ]]; then
mv bin/xray-linux-$(arch) bin/xray-linux-arm
chmod +x bin/xray-linux-arm
fi
chmod +x xray-ui bin/xray-linux-$(arch)
cp -f xray-ui.service /etc/systemd/system/
wget --no-check-certificate -O /usr/bin/xray-ui https://raw.githubusercontent.com/qist/xray-ui/main/xray-ui.sh
chmod +x /usr/bin/xray-ui
systemctl daemon-reload
systemctl enable xray-ui
systemctl start xray-ui
sleep 2
cat >/root/xrayuil.sh <<-\EOF
#!/bin/bash
xui=`ps -aux |grep "xray-ui" |grep -v "grep" |wc -l`
xray=`ps -aux |grep "xray-linux" |grep -v "grep" |wc -l`
sleep 1
if [ $xui = 0 ];then
xray-ui restart
fi
if [ $xray = 0 ];then
xray-ui restart
fi
EOF
chmod +x /root/xrayuil.sh
sed -i '/xrayuil.sh/d' /etc/crontab
echo "*/1 * * * * root bash /root/xrayuil.sh >/dev/null 2>&1" >>/etc/crontab
sed -i '/xray-ui restart/d' /etc/crontab
echo "0 1 1 * * root xray-ui restart >/dev/null 2>&1" >>/etc/crontab
sleep 1
echo -e ""
blue "以下设置内容建议自定义,以防止账号密码路径及端口泄露"
echo -e ""
readp "设置xray-ui登录用户名(回车跳过为随机6位字符):" username
if [[ -z ${username} ]]; then
uauto=$(date +%s%N | md5sum | cut -c 1-6)
username=$uauto
fi
sleep 1
green "xray-ui登录用户名:${username}"
echo -e ""
readp "设置xray-ui登录密码(回车跳过为随机6位字符):" password
if [[ -z ${password} ]]; then
pauto=$(date +%s%N | md5sum | cut -c 1-6)
password=$pauto
fi
green "xray-ui登录密码:${password}"
/usr/local/xray-ui/xray-ui setting -username ${username} -password ${password} >/dev/null 2>&1
sleep 1
echo -e ""
readp "设置xray-ui登录端口[1-65535](回车跳过为2000-65535之间的随机端口):" port
if [[ -z $port ]]; then
port=$(shuf -i 2000-65535 -n 1)
until [[ -z $(ss -ntlp | awk '{print $4}' | grep -w "$port") ]]; do
[[ -n $(ss -ntlp | awk '{print $4}' | grep -w "$port") ]] && yellow "\n端口被占用,请重新输入端口" && readp "自定义xray-ui端口:" port
done
else
until [[ -z $(ss -ntlp | awk '{print $4}' | grep -w "$port") ]]; do
[[ -n $(ss -ntlp | awk '{print $4}' | grep -w "$port") ]] && yellow "\n端口被占用,请重新输入端口" && readp "自定义xray-ui端口:" port
done
fi
/usr/local/xray-ui/xray-ui setting -port $port >/dev/null 2>&1
green "xray-ui登录端口:${port}"
sleep 1
echo -e ""
readp "设置xray-ui web 路径 (回车跳过为随机10位字符):" path
if [[ -z ${path} ]]; then
path=$(generate_random_string 10)
fi
/usr/local/xray-ui/xray-ui setting -webBasePath $path >/dev/null 2>&1
green "xray-ui web 路径:${path}"
sleep 1
xray-ui restart
}
xuilogin() {
v4=$(curl -s4m8 http://ip.sb -k)
v6=$(curl -s6m8 http://ip.sb -k)
if [[ -z $v4 ]]; then
int="${green}请在浏览器地址栏复制${plain} ${bblue}[$v6]:$ports/$path${plain} ${green}进入xray-ui登录界面\n当前xray-ui登录用户名:${plain}${bblue}${username}${plain}${green} \n当前xray-ui登录密码:${plain}${bblue}${password}${plain}"
elif [[ -n $v4 && -n $v6 ]]; then
int="${green}请在浏览器地址栏复制${plain} ${bblue}$v4:$ports/$path${plain} ${yellow}或者${plain} ${bblue}[$v6]:$ports/$path${plain} ${green}进入xray-ui登录界面\n当前xray-ui登录用户名:${plain}${bblue}${username}${plain}${green} \n当前xray-ui登录密码:${plain}${bblue}${password}${plain}"
else
int="${green}请在浏览器地址栏复制${plain} ${bblue}$v4:$ports/$path${plain} ${green}进入xray-ui登录界面\n当前xray-ui登录用户名:${plain}${bblue}${username}${plain}${green} \n当前xray-ui登录密码:${plain}${bblue}${password}${plain}"
fi
}
ssh_forwarding() {
# ========== 获取公网 IP ==========
local v4=""
local v6=""
local Ip=""
local ip_type=""
v4=$(curl -s4m8 http://ip.sb -k)
v6=$(curl -s6m8 http://ip.sb -k)
if [[ -n "${v4}" ]]; then
Ip="${v4}"
ip_type="ipv4"
elif [[ -n "${v6}" ]]; then
Ip="${v6}"
ip_type="ipv6"
else
Ip="127.0.0.1"
ip_type="local"
yellow "无法获取公网 IP,将使用本地回环地址: ${Ip}"
fi
# 询问是否申请 SSL 证书
read -p "$(yellow "是否申请 SSL 证书?输入1申请,输入0跳过(HTTP回环地址访问): ")" ssl_choice
if [[ "$ssl_choice" == "1" ]]; then
# ========== 调用 xray-ui ip_ssl_main ==========
if ! command -v xray-ui &>/dev/null; then
red "未检测到 xray-ui,请先安装面板"
return 1
fi
yellow "正在为 IP 申请 SSL 证书..."
xray-ui ip_ssl_main
if [[ $? -ne 0 ]]; then
red "IP SSL 证书申请失败"
return 1
fi
protocol="https"
else
yellow "跳过 SSL 证书申请,使用 HTTP 协议访问(本地回环地址)"
protocol="http"
Ip="127.0.0.1"
fi
ports=$(/usr/local/xray-ui/xray-ui 2>&1 | grep "tcp" | awk '{print $5}' | cut -d':' -f2)
if [[ -n $ports ]]; then
# ========== 输出访问地址 ==========
echo -e ""
yellow "xray-ui $remoteV 安装成功,请稍等3秒,输出面板登录信息……"
# xuilogin
green "面板已配置完成,可通过以下地址访问 xray-ui:"
echo -e "${bblue}${protocol}://${Ip}:${ports}/${path}${plain}"
echo -e ""
green "当前 xray-ui 登录信息:"
echo -e "用户名:${bblue}${username}${plain}"
echo -e "密码:${bblue}${password}${plain}"
if [[ "$ssl_choice" == "0" ]]; then
yellow "使用 HTTP,请自行通过 Nginx 或防火墙做端口转发,将 ${Ip}:${ports} 暴露给外网"
fi
else
red "xray-ui安装失败,请查看日志,运行 xray-ui log"
fi
sleep 1
echo -e ""
echo -e "$int"
echo -e ""
green "xray-ui 管理脚本使用方法:"
echo -e "----------------------------------------------"
echo -e "xray-ui - 显示管理菜单"
echo -e "xray-ui start - 启动 xray-ui 面板"
echo -e "xray-ui stop - 停止 xray-ui 面板"
echo -e "xray-ui restart - 重启 xray-ui 面板"
echo -e "xray-ui status - 查看 xray-ui 状态"
echo -e "xray-ui enable - 设置 xray-ui 开机自启"
echo -e "xray-ui disable - 取消 xray-ui 开机自启"
echo -e "xray-ui log - 查看 xray-ui 日志"
echo -e "xray-ui v2-ui - 迁移本机器的 v2-ui 账号数据至 xray-ui"
echo -e "xray-ui update - 更新 xray-ui 面板"
echo -e "xray-ui geoip - 更新 geoip ip库"
echo -e "xray-ui update_shell - 更新 xray-ui 脚本"
echo -e "xray-ui install - 安装 xray-ui 面板"
echo -e "xray-ui x25519 - REALITY key 生成"
echo -e "xray-ui ssl_main - SSL 证书管理"
echo -e "xray-ui ip_ssl_main - IP SSL 证书安装"
echo -e "xray-ui ssl_CF - Cloudflare SSL 证书"
echo -e "xray-ui crontab - 添加 geoip 到任务计划每天凌晨1:30执行"
echo -e "xray-ui uninstall - 卸载 xray-ui 面板"
echo -e "----------------------------------------------"
rm -f install.sh
}
echo -e "${green}开始安装xray-ui必要依赖${plain}"
install_base
echo -e "${green}开始安装xray-ui核心组件${plain}"
install_xray-ui $1
echo -e "${green}ip 证书申请 等下信息查询${plain}"
ssh_forwarding