-
Notifications
You must be signed in to change notification settings - Fork 0
/
443docker.sh
359 lines (332 loc) · 10.5 KB
/
443docker.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#!/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=(Install Update UpdateConfig logs restart delete)
# Make sure only root can run our script
[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] Vui lòng chạy với quyền 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}] Bắt đầu cài đặt các gói ${depend}"
${command} >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Cài đặt gói không thành công ${red}${depend}${plain}"
exit 1
fi
}
# Pre-installation settings
pre_install_docker_compose() {
read -p "Nhập Link Web (VD: https://example.com): " domain
echo -e "Link Web : ${domain}"
read -p "Nhập Api Key(Khoá giao tiếp của web): " APIKEY
echo -e "API KEY : ${APIKEY}"
read -p "Nhập Node ID port 443 : " node_443
echo -e "Node 443 : ${node_443}"
read -p "Nhập Subdomain hoặc IP VPS (Khác Subdomain Port 80): " CertDomain443
echo -e "CertDomain Port 443 = ${CertDomain443}"
read -p "Nhập Mail Cloudfalre: " mailcf
echo -e "Mail Cloudflare : ${mailcf}"
read -p "Nhập API TOKEN Cloudflare: " token
echo -e "API TOKEN Cloudflare : ${token}"
}
# Config docker
config_docker() {
cd ${cur_dir} || exit
echo "Bắt đầu cài đặt các gói"
install_dependencies
echo "Tải tệp cấu hình DOCKER"
cat >docker-compose.yml <<EOF
version: '3'
services:
xrayr:
image: ghcr.io/xrayr-project/xrayr:latest
volumes:
- ./config.yml:/etc/XrayR/config.yml # Thư mục cài file Config
- ./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: none # Log level: none, error, warning, info, debug
AccessPath: # ./access.Log
ErrorPath: # ./error.log
DnsConfigPath: # ./dns.json Path to dns config
ConnectionConfig:
Handshake: 4
ConnIdle: 30
UplinkOnly: 2
DownlinkOnly: 4
BufferSize: 64
Nodes:
-
PanelType: "V2board" # Panel type: SSpanel, V2board, PMpanel
ApiConfig:
ApiHost: "$domain"
ApiKey: "$APIKEY"
NodeID: $node_443
NodeType: Trojan # Node type: V2ray, Shadowsocks, Trojan
Timeout: 30 # Timeout for the api request
EnableVless: false # Enable Vless for V2ray Type
EnableXTLS: false # Enable XTLS for V2ray and Trojan
SpeedLimit: 0 # Mbps, Local settings will replace remote settings, 0 means disable
DeviceLimit: 0 # Local settings will replace remote settings, 0 means disable
RuleListPath: # ./rulelist # Path to local arulelist file
ControllerConfig:
ListenIP: 0.0.0.0 # IP address you want to listen
SendIP: 0.0.0.0 # IP address you want to send pacakage
UpdatePeriodic: 60 # Time to update the nodeinfo, how many sec.
EnableDNS: false # Use custom DNS config, Please ensure that you set the dns.json well
DNSType: AsIs # AsIs, UseIP, UseIPv4, UseIPv6, DNS strategy
DisableUploadTraffic: false # Disable Upload Traffic to the panel
DisableGetRule: false # Disable Get Rule from the panel
DisableIVCheck: false # Disable the anti-reply protection for Shadowsocks
DisableSniffing: true # Disable domain sniffing
EnableProxyProtocol: false # Only works for WebSocket and TCP
EnableFallback: false # Only support for Trojan and Vless
FallBackConfigs: # Support multiple fallbacks
-
SNI: # TLS SNI(Server Name Indication), Empty for any
Path: # HTTP PATH, Empty for any
Dest: 80
ProxyProtocolVer: 0 # Send PROXY protocol version, 0 for dsable
CertConfig:
CertMode: dns # Option about how to get certificate: none, file, http, dns. Choose "none" will forcedly disable the tls config.
CertDomain: "$CertDomain443" # Domain to cert
CertFile: ./cert/node1.test.com.cert # Provided if the CertMode is file
KeyFile: ./cert/node1.test.com.key
Provider: cloudflare # DNS cert provider, Get the full support list here: https://go-acme.github.io/lego/dns/
Email: lole7176@gmail.com
DNSEnv: # DNS ENV option used by DNS provider
CLOUDFLARE_EMAIL: $mailcf
CLOUDFLARE_API_KEY: $token
EOF
}
# Install docker and docker compose
install_docker() {
echo -e "bắt đầu cài đặt DOCKER "
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker
echo -e "bắt đầu cài đặt Docker Compose "
curl -fsSL https://get.docker.com | bash -s docker
curl -L "https://github.com/docker/compose/releases/download/1.26.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
echo "khởi động Docker "
service docker start
echo "khởi động Docker-Compose "
docker-compose up -d
echo
echo -e "Đã hoàn tất cài đặt phụ trợ !"
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 "Cài đặt tự khởi chạy đã hoàn tất! Hệ thống sẽ Update sau [${green}24H${plain}] Từ lúc bạn cài đặt"
}
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}] Kiểm tra kho 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}] Không cài đặt được kho EPEL, vui lòng kiểm tra." && 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}] Đang kiểm tra kho lưu trữ 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}] Đặt múi giờ thành phố Hà Nội GTM+7"
ln -sf /usr/share/zoneinfo/Asia/Hanoi /etc/localtime
date -s "$(curl -sI g.cn | grep Date | cut -d' ' -f3-6)Z"
}
#update_image
Update_xrayr() {
cd ${cur_dir}
echo "Tải Plugin DOCKER"
docker-compose pull
echo "Bắt đầu chạy dịch vụ DOCKER"
docker-compose up -d
}
#show last 100 line log
logs_xrayr() {
echo "Nhật ký chạy sẽ được hiển thị"
docker-compose logs --tail 100
}
# Update config
UpdateConfig_xrayr() {
cd ${cur_dir}
echo "Đóng dịch vụ hiện tại"
docker-compose down
pre_install_docker_compose
config_docker
echo "Bắt đầu chạy dịch vụ DOKCER"
docker-compose up -d
}
restart_xrayr() {
cd ${cur_dir}
docker-compose down
docker-compose up -d
echo "Khởi động lại thành công!"
}
delete_xrayr() {
cd ${cur_dir}
docker-compose down
cd ~
rm -Rf ${cur_dir}
echo "Đã xóa thành công!"
}
# Install xrayr
Install_xrayr() {
pre_install_docker_compose
config_docker
install_docker
}
# Initialization step
clear
while true; do
echo "Phiên bản này đã được tối ưu hóa từ XrayR Project"
echo "Đã được fix lỗi Zalo và một số lỗi vặt khác"
echo "Vui lòng nhập một số để Thực Hiện Câu Lệnh:"
for ((i = 1; i <= ${#operation[@]}; i++)); do
hint="${operation[$i - 1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Vui lòng chọn một số và nhấn Enter (Enter theo mặc định ${operation[0]}):" selected
[ -z "${selected}" ] && selected="1"
case "${selected}" in
1 | 2 | 3 | 4 | 5 | 6 | 7)
echo
echo "Bắt Đầu : ${operation[${selected} - 1]}"
echo
${operation[${selected} - 1]}_xrayr
break
;;
*)
echo -e "[${red}Error${plain}] Vui lòng nhập số chính xác [1-6]"
;;
esac
done