-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinstall.sh
190 lines (167 loc) · 6.94 KB
/
install.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
#!/bin/bash
rm -rf $0
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
cur_dir=$(pwd)
# check root
[[ $EUID -ne 0 ]] && echo -e "${red}Lỗi:${plain} Tập lệnh này phải được chạy với tư cách người dùng 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"
else
echo -e "${red}Phiên bản hệ thống không được phát hiện, vui lòng liên hệ với tác giả kịch bản!${plain}\n" && exit 1
fi
arch=$(arch)
if [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then
arch="64"
elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then
arch="arm64-v8a"
else
arch="64"
echo -e "${red}Không phát hiện được giản đồ, hãy sử dụng lược đồ mặc định: ${arch}${plain}"
fi
echo "Ngành kiến trúc: ${arch}"
if [ "$(getconf WORD_BIT)" != '32' ] && [ "$(getconf LONG_BIT)" != '64' ] ; then
echo "Phần mềm này không hỗ trợ hệ thống 32-bit (x86), vui lòng sử dụng hệ thống 64-bit (x86_64), nếu phát hiện sai, vui lòng liên hệ với tác giả"
exit 2
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}Vui lòng sử dụng CentOS 7 trở lên!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"ubuntu" ]]; then
if [[ ${os_version} -lt 16 ]]; then
echo -e "${red}Vui lòng sử dụng Ubuntu 16 hoặc cao hơn!${plain}\n" && exit 1
fi
elif [[ x"${release}" == x"debian" ]]; then
if [[ ${os_version} -lt 8 ]]; then
echo -e "${red}Vui lòng sử dụng Debian 8 trở lên!${plain}\n" && exit 1
fi
fi
install_base() {
if [[ x"${release}" == x"centos" ]]; then
yum install epel-release -y
yum install wget curl unzip tar crontabs socat -y
else
apt update -y
apt install wget curl unzip tar cron socat -y
fi
}
# 0: running, 1: not running, 2: not installed
check_status() {
if [[ ! -f /etc/systemd/system/XrayR.service ]]; then
return 2
fi
temp=$(systemctl status XrayR | grep Active | awk '{print $3}' | cut -d "(" -f2 | cut -d ")" -f1)
if [[ x"${temp}" == x"running" ]]; then
return 0
else
return 1
fi
}
install_acme() {
curl https://get.acme.sh | sh
}
install_XrayR() {
if [[ -e /usr/local/XrayR/ ]]; then
rm /usr/local/XrayR/ -rf
fi
mkdir /usr/local/XrayR/ -p
cd /usr/local/XrayR/
if [ $# == 0 ] ;then
last_version=$(curl -Ls "https://api.github.com/repos/AikoXrayR-Project/XrayR/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ ! -n "$last_version" ]]; then
echo -e "${red}Phát hiện phiên bản XrayR không thành công, có thể vượt quá giới hạn GIthub API, vui lòng thử lại sau hoặc chỉ định cài đặt phiên bản XrayR theo cách thủ công${plain}"
exit 1
fi
echo -e "Phiên bản mới nhất của XrayR đã được phát hiện:${last_version},Bắt đầu cài đặt"
wget -N --no-check-certificate -O /usr/local/XrayR/XrayR-linux.zip https://github.com/AikoXrayR-Project/XrayR/releases/download/latest/XrayR-linux-${arch}.zip
if [[ $? -ne 0 ]]; then
echo -e "${red}Tải xuống XrayR thất bại, hãy chắc chắn rằng máy chủ của bạn có thể tải về các tập tin Github${plain}"
exit 1
fi
else
last_version=$1
url="https://github.com/AikoXrayR-Project/XrayR/releases/download/latest/XrayR-linux-${arch}.zip"
echo -e "Bắt đầu cài đặt XrayR v$1"
wget -N --no-check-certificate -O /usr/local/XrayR/XrayR-linux.zip ${url}
if [[ $? -ne 0 ]]; then
echo -e "${red}Tải xuống XrayR v$1 Thất bại, hãy chắc chắn rằng phiên bản này tồn tại${plain}"
exit 1
fi
fi
unzip XrayR-linux.zip
rm XrayR-linux.zip -f
chmod +x XrayR
mkdir /etc/XrayR/ -p
rm /etc/systemd/system/XrayR.service -f
file="https://raw.githubusercontent.com/AikoXrayR-Project/AikoXrayR-install/main/XrayR.service"
wget -N --no-check-certificate -O /etc/systemd/system/XrayR.service ${file}
#cp -f XrayR.service /etc/systemd/system/
systemctl daemon-reload
systemctl stop XrayR
systemctl enable XrayR
echo -e "${green}XrayR ${last_version}${plain} Quá trình cài đặt hoàn tất, nó đã được thiết lập để bắt đầu tự động"
cp geoip.dat /etc/XrayR/
cp geosite.dat /etc/XrayR/
if [[ ! -f /etc/XrayR/config.yml ]]; then
cp config.yml /etc/XrayR/
echo -e ""
echo -e "Cài đặt mới, vui lòng tham khảo hướng dẫn trước:https://github.com/AikoCute/XrayR,Định cấu hình nội dung cần thiết"
else
systemctl start XrayR
sleep 2
check_status
echo -e ""
if [[ $? == 0 ]]; then
echo -e "${green}XrayR khởi động lại thành công${plain}"
else
echo -e "${red}XrayR Có thể không khởi động được, vui lòng sử dụng sau XrayR log Kiểm tra thông tin nhật ký, nếu không khởi động được, định dạng cấu hình có thể đã bị thay đổi, vui lòng vào wiki để kiểm tra:https://github.com/herotbty/Aiko-XrayR/wiki${plain}"
fi
fi
if [[ ! -f /etc/XrayR/dns.json ]]; then
cp dns.json /etc/XrayR/
fi
if [[ ! -f /etc/XrayR/route.json ]]; then
cp route.json /etc/XrayR/
fi
if [[ ! -f /etc/XrayR/custom_outbound.json ]]; then
cp custom_outbound.json /etc/XrayR/
fi
curl -o /usr/bin/XrayR -Ls https://raw.githubusercontent.com/AikoCute/AikoXrayR-install/master/XrayR.sh
chmod +x /usr/bin/XrayR
ln -s /usr/bin/XrayR /usr/bin/xrayr # chữ thường tương thích
chmod +x /usr/bin/xrayr
echo -e ""
echo " Cách sử dụng tập lệnh quản lý XrayR "
echo "------------------------------------------"
echo " XrayR - Show admin menu "
echo " AikoXrayR - XrayR by AikoCute "
echo "------------------------------------------"
}
echo -e "${green}bắt đầu cài đặt${plain}"
install_base
install_acme
install_XrayR $1