-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
150 lines (137 loc) · 4.53 KB
/
main.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
#!/bin/sh
# The URL of the script project is:
# https://github.com/wy580477/replit-trojan
# https://github.com/XTLS/Xray-install
FILES_PATH=${FILES_PATH:-./}
# Gobal verbals
green(){ echo -e "\033[32m\033[01m$1\033[0m";}
yellow(){ echo -e "\033[33m\033[01m$1\033[0m";}
# Xray current version
CURRENT_VERSION=''
# Xray latest release version
RELEASE_LATEST=''
get_current_version() {
# Get the CURRENT_VERSION
if [[ -f "${FILES_PATH}/web" ]]; then
CURRENT_VERSION="$(${FILES_PATH}/web -version | awk 'NR==1 {print $2}')"
CURRENT_VERSION="v${CURRENT_VERSION#v}"
else
CURRENT_VERSION=""
fi
}
get_latest_version() {
# Get latest release version number
RELEASE_LATEST="$(curl -IkLs -o ${TMP_DIRECTORY}/NUL -w %{url_effective} https://github.com/XTLS/Xray-core/releases/latest | grep -o "[^/]*$")"
RELEASE_LATEST="v${RELEASE_LATEST#v}"
if [[ -z "$RELEASE_LATEST" ]]; then
echo "error: Failed to get the latest release version, please check your network."
exit 1
fi
}
download_xray() {
DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/download/$RELEASE_LATEST/Xray-linux-64.zip"
if ! wget -qO "$ZIP_FILE" "$DOWNLOAD_LINK"; then
echo 'error: Download failed! Please check your network or try again.'
return 1
fi
return 0
if ! wget -qO "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst"; then
echo 'error: Download failed! Please check your network or try again.'
return 1
fi
if [[ "$(cat "$ZIP_FILE".dgst)" == 'Not Found' ]]; then
echo 'error: This version does not support verification. Please replace with another version.'
return 1
fi
# Verification of Xray archive
for LISTSUM in 'md5' 'sha1' 'sha256' 'sha512'; do
SUM="$(${LISTSUM}sum "$ZIP_FILE" | sed 's/ .*//')"
CHECKSUM="$(grep ${LISTSUM^^} "$ZIP_FILE".dgst | grep "$SUM" -o -a | uniq)"
if [[ "$SUM" != "$CHECKSUM" ]]; then
echo 'error: Check failed! Please check your network or try again.'
return 1
fi
done
}
decompression() {
busybox unzip -q "$1" -d "$TMP_DIRECTORY"
EXIT_CODE=$?
if [ ${EXIT_CODE} -ne 0 ]; then
"rm" -r "$TMP_DIRECTORY"
echo "removed: $TMP_DIRECTORY"
exit 1
fi
}
install_xray() {
install -m 755 ${TMP_DIRECTORY}/xray ${FILES_PATH}/web
}
run_xray() {
re_uuid=$(curl -s $REPLIT_DB_URL/re_uuid)
if [ "${re_uuid}" = "" ]; then
NEW_uuid="$(cat /proc/sys/kernel/random/uuid)"
curl -sXPOST $REPLIT_DB_URL/re_uuid="${NEW_uuid}"
fi
if [ "${uuid}" = "" ]; then
user_uuid=$(curl -s $REPLIT_DB_URL/re_uuid)
else
user_uuid=${uuid}
fi
cp -f ./config.yaml /tmp/config.yaml
sed -i "s|uuid|${user_uuid}|g" /tmp/config.yaml
./web -c /tmp/config.yaml 2>&1 >/dev/null &
echo
green "当前已安装的Xray正式版本:$RELEASE_LATEST"
echo
UA_Browser="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36"
v4=$(curl -s4m6 api64.ipify.org -k)
v4l=`curl -sm6 --user-agent "${UA_Browser}" http://ip-api.com/json/$v4?lang=zh-CN -k | cut -f2 -d"," | cut -f4 -d '"'`
echo
green "当前检测到的IP:$v4 地区:$v4l"
echo
yellow "vless+ws+tls配置明文如下,相关参数可复制到客户端"
echo "服务器地址:${REPL_SLUG}.${REPL_OWNER}.repl.co"
echo "端口:443"
echo "uuid:$user_uuid"
echo "传输协议:ws"
echo "host:${REPL_SLUG}.${REPL_OWNER}.repl.co"
echo "path路径:/$user_uuid"
echo "tls:开启"
echo
replit_xray_vless="vless://${user_uuid}@${REPL_SLUG}.${REPL_OWNER}.repl.co:443?encryption=none&security=tls&type=ws&host=${REPL_SLUG}.${REPL_OWNER}.repl.co&path=/$user_uuid#replit_xray_vless"
yellow "分享链接如下"
echo "${replit_xray_vless}"
echo
yellow "二维码如下"
qrencode -t ansiutf8 ${replit_xray_vless}
echo
green "安装完毕"
echo
echo "23.1.20更新:集成每10分钟自动唤醒功能"
echo
while true; do
curl https://${REPL_SLUG}.${REPL_OWNER}.repl.co;sleep 600
done
tail -f
}
# Two very important variables
TMP_DIRECTORY="$(mktemp -d)"
ZIP_FILE="${TMP_DIRECTORY}/web.zip"
get_current_version
get_latest_version
if [ "${RELEASE_LATEST}" = "${CURRENT_VERSION}" ]; then
"rm" -rf "$TMP_DIRECTORY"
run_xray
fi
download_xray
EXIT_CODE=$?
if [ ${EXIT_CODE} -eq 0 ]; then
:
else
"rm" -r "$TMP_DIRECTORY"
echo "removed: $TMP_DIRECTORY"
run_xray
fi
decompression "$ZIP_FILE"
install_xray
"rm" -rf "$TMP_DIRECTORY"
run_xray