-
Notifications
You must be signed in to change notification settings - Fork 22
/
install-release.sh
199 lines (184 loc) · 5.46 KB
/
install-release.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
#!/usr/bin/env bash
set -euxo pipefail
# Identify architecture
case "$(arch -s)" in
'i386' | 'i686')
MACHINE='32'
;;
'amd64' | 'x86_64')
MACHINE='64'
;;
'armv5tel')
MACHINE='arm32-v5'
;;
'armv6l')
MACHINE='arm32-v6'
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
;;
'armv7' | 'armv7l')
MACHINE='arm32-v7a'
grep Features /proc/cpuinfo | grep -qw 'vfp' || MACHINE='arm32-v5'
;;
'armv8' | 'aarch64')
MACHINE='arm64-v8a'
;;
'mips')
MACHINE='mips32'
;;
'mipsle')
MACHINE='mips32le'
;;
'mips64')
MACHINE='mips64'
;;
'mips64le')
MACHINE='mips64le'
;;
'ppc64')
MACHINE='ppc64'
;;
'ppc64le')
MACHINE='ppc64le'
;;
'riscv64')
MACHINE='riscv64'
;;
's390x')
MACHINE='s390x'
;;
*)
echo "error: The architecture is not supported."
exit 1
;;
esac
TMP_DIRECTORY="$(mktemp -d)/"
ZIP_FILE="${TMP_DIRECTORY}Xray-linux-$MACHINE.zip"
DOWNLOAD_LINK="https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-$MACHINE.zip"
install_software() {
if [[ -n "$(command -v curl)" ]]; then
return
fi
if [[ -n "$(command -v unzip)" ]]; then
return
fi
if [ "$(command -v apk)" ]; then
apk add curl unzip
else
echo "error: The script does not support the package manager in this operating system."
exit 1
fi
}
download_xray() {
curl -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE" "$DOWNLOAD_LINK" -#
if [ "$?" -ne '0' ]; then
echo 'error: Download failed! Please check your network or try again.'
exit 1
fi
curl -L -H 'Cache-Control: no-cache' -o "$ZIP_FILE.dgst" "$DOWNLOAD_LINK.dgst" -#
if [ "$?" -ne '0' ]; then
echo 'error: Download failed! Please check your network or try again.'
exit 1
fi
}
verification_xray() {
CHECKSUM=$(cat "$ZIP_FILE".dgst | awk -F '= ' '/256=/ {print $2}')
LOCALSUM=$(sha256sum "$ZIP_FILE" | awk '{printf $1}')
if [[ "$CHECKSUM" != "$LOCALSUM" ]]; then
echo 'error: SHA256 check failed! Please check your network or try again.'
return 1
fi
}
decompression() {
unzip -q "$ZIP_FILE" -d "$TMP_DIRECTORY"
}
is_it_running() {
XRAY_RUNNING='0'
if [ -n "$(pgrep xray)" ]; then
rc-service xray stop
XRAY_RUNNING='1'
fi
}
install_xray() {
install -m 755 "${TMP_DIRECTORY}xray" "/usr/local/bin/xray"
install -d /usr/local/lib/xray/
install -m 755 "${TMP_DIRECTORY}geoip.dat" "/usr/local/lib/xray/geoip.dat"
install -m 755 "${TMP_DIRECTORY}geosite.dat" "/usr/local/lib/xray/geosite.dat"
}
install_confdir() {
CONFDIR='0'
if [ ! -d '/usr/local/etc/xray/' ]; then
install -d /usr/local/etc/xray/
for BASE in 00_log 01_api 02_dns 03_routing 04_policy 05_inbounds 06_outbounds 07_transport 08_stats 09_reverse; do
echo '{}' > "/usr/local/etc/xray/$BASE.json"
done
CONFDIR='1'
fi
}
install_log() {
LOG='0'
if [ ! -d '/var/log/xray/' ]; then
install -d -o nobody -g nobody /var/log/xray/
install -m 600 -o nobody -g nobody /dev/null /var/log/xray/access.log
install -m 600 -o nobody -g nobody /dev/null /var/log/xray/error.log
LOG='1'
fi
}
install_startup_service_file() {
OPENRC='0'
if [ ! -f '/etc/init.d/xray' ]; then
mkdir "${TMP_DIRECTORY}init.d/"
curl -o "${TMP_DIRECTORY}init.d/xray" https://raw.githubusercontent.com/XTLS/alpinelinux-install-xray/main/init.d/xray -s
if [ "$?" -ne '0' ]; then
echo 'error: Failed to start service file download! Please check your network or try again.'
exit 1
fi
install -m 755 "${TMP_DIRECTORY}init.d/xray" /etc/init.d/xray
OPENRC='1'
fi
}
information() {
echo 'installed: /usr/local/bin/xray'
echo 'installed: /usr/local/lib/xray/geoip.dat'
echo 'installed: /usr/local/lib/xray/geosite.dat'
if [ "$CONFDIR" -eq '1' ]; then
echo 'installed: /usr/local/etc/xray/00_log.json'
echo 'installed: /usr/local/etc/xray/01_api.json'
echo 'installed: /usr/local/etc/xray/02_dns.json'
echo 'installed: /usr/local/etc/xray/03_routing.json'
echo 'installed: /usr/local/etc/xray/04_policy.json'
echo 'installed: /usr/local/etc/xray/05_inbounds.json'
echo 'installed: /usr/local/etc/xray/06_outbounds.json'
echo 'installed: /usr/local/etc/xray/07_transport.json'
echo 'installed: /usr/local/etc/xray/08_stats.json'
echo 'installed: /usr/local/etc/xray/09_reverse.json'
fi
if [ "$LOG" -eq '1' ]; then
echo 'installed: /var/log/xray/'
fi
if [ "$OPENRC" -eq '1' ]; then
echo 'installed: /etc/init.d/xray'
fi
rm -r "$TMP_DIRECTORY"
echo "removed: $TMP_DIRECTORY"
echo "You may need to execute a command to remove dependent software: apk del curl unzip"
if [ "$XRAY_RUNNING" -eq '1' ]; then
rc-service xray start
else
echo 'Please execute the command: rc-update add xray; rc-service xray start'
fi
echo "info: Xray is installed."
}
main() {
install_software
install_software
download_xray
verification_xray
decompression
is_it_running
install_xray
install_confdir
install_log
install_startup_service_file
information
}
main