-
Notifications
You must be signed in to change notification settings - Fork 33
/
install.sh
280 lines (260 loc) · 7.8 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
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
#!/bin/bash
VERSION=""
APP_PATH="/usr/local/bin/"
CONFIG_PATH="/usr/local/etc/au/"
create_folders() {
if [[ ! -e "${APP_PATH}" ]]; then
mkdir "${APP_PATH}"
fi
if [[ ! -e "${CONFIG_PATH}" ]]; then
mkdir "${CONFIG_PATH}"
fi
}
panelConfig() {
echo "Air-Universe $VERSION + Xray"
echo "########Air-Universe config#######"
read -r -p "Enter panel domain(Include https:// or http://): " pUrl
read -r -p "Enter panel token: " nKey
read -r -p "Enter node_ids, (eg 1,2,3): " nIds
echo && echo -e "Choose panel type:
1. SSPanel
2. V2board
3. Django-sspanel"
read -r -p "Choose panel type: " panelnum
if [ "$panelnum" == "1" ]; then
panelType="sspanel"
fi
if [ "$panelnum" == "2" ]; then
panelType="v2board"
fi
if [ "$panelnum" == "3" ]; then
panelType="django-sspanel"
fi
IFS=', ' read -r -a id_arr <<< "$nIds"
if [ "$panelnum" == "2" ] || [ "$panelnum" == "3" ]; then
echo
echo "Please select node type[0-2]:"
echo "0. VMess"
echo "1. ShadowSocks"
echo "2. Trojan "
echo
for id in "${id_arr[@]}"
do
while ((1)); do
read -r -p "Please select node type for id ${id} : " inputNodeType
if [ "$inputNodeType" == "0" ]; then
nType=$nType"\"vmess\","
break
elif [ "$inputNodeType" == "1" ]; then
nType=$nType"\"ss\","
break
elif [ "$inputNodeType" == "2" ]; then
nType=$nType"\"trojan\","
break
else
echo "Input error [0-2]"
fi
done
done
nType=${nType%?}
fi
}
check_root() {
[[ $EUID != 0 ]] && echo -e "${Error} 当前非ROOT账号(或没有ROOT权限),无法继续操作,请更换ROOT账号或使用 ${Green_background_prefix}sudo su${Font_color_suffix} 命令获取临时ROOT权限(执行后可能会提示输入当前账号的密码)。" && exit 1
}
check_sys() {
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
bit=$(uname -m)
}
Installation_dependency() {
if [[ ${release} == "centos" ]]; then
yum update -y
yum install -y gzip ca-certificates curl wget unzip socat
else
apt-get update -y
apt-get install -y ca-certificates curl wget unzip socat
fi
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
mkdir /var/log/au
chown -R nobody /var/log/au
}
download() {
mkdir /usr/local/etc/au/
airuniverse_url="https://github.com/crossfw/Air-Universe/releases/download/${VERSION}/Air-Universe-linux-${MACHINE}.zip"
xray_json_url="https://raw.githubusercontent.com/crossfw/Air-Universe-install/master/xray_config.json"
mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.bak
wget -N ${xray_json_url} -O /usr/local/etc/xray/config.json
wget -N ${airuniverse_url} -O ./au.zip
unzip ./au.zip -d /usr/local/bin/
rm ./au.zip
mv /usr/local/bin/Air-Universe /usr/local/bin/au
chmod +x /usr/local/bin/au
}
identify_the_operating_system_and_architecture() {
if [[ "$(uname)" == 'Linux' ]]; then
case "$(uname -m)" 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
if [[ ! -f '/etc/os-release' ]]; then
echo "error: Don't use outdated Linux distributions."
exit 1
fi
# Do not combine this judgment condition with the following judgment condition.
## Be aware of Linux distribution like Gentoo, which kernel supports switch between Systemd and OpenRC.
if [[ -f /.dockerenv ]] || grep -q 'docker\|lxc' /proc/1/cgroup && [[ "$(type -P systemctl)" ]]; then
true
elif [[ -d /run/systemd/system ]] || grep -q systemd <(ls -l /sbin/init); then
true
else
echo "error: Only Linux distributions using systemd are supported."
exit 1
fi
if [[ "$(type -P apt)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='apt -y --no-install-recommends install'
PACKAGE_MANAGEMENT_REMOVE='apt purge'
package_provide_tput='ncurses-bin'
elif [[ "$(type -P dnf)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='dnf -y install'
PACKAGE_MANAGEMENT_REMOVE='dnf remove'
package_provide_tput='ncurses'
elif [[ "$(type -P yum)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='yum -y install'
PACKAGE_MANAGEMENT_REMOVE='yum remove'
package_provide_tput='ncurses'
elif [[ "$(type -P zypper)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='zypper install -y --no-recommends'
PACKAGE_MANAGEMENT_REMOVE='zypper remove'
package_provide_tput='ncurses-utils'
elif [[ "$(type -P pacman)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='pacman -Syu --noconfirm'
PACKAGE_MANAGEMENT_REMOVE='pacman -Rsn'
package_provide_tput='ncurses'
else
echo "error: The script does not support the package manager in this operating system."
exit 1
fi
else
echo "error: This operating system is not supported."
exit 1
fi
}
get_latest_version() {
# Get Xray latest release version number
local tmp_file
tmp_file="$(mktemp)"
if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$tmp_file" 'https://api.github.com/repos/crossfw/Air-Universe/releases/latest'; then
"rm" "$tmp_file"
echo 'error: Failed to get release list, please check your network.'
exit 1
fi
RELEASE_LATEST="$(sed 'y/,/\n/' "$tmp_file" | grep 'tag_name' | awk -F '"' '{print $4}')"
if [[ -z "$RELEASE_LATEST" ]]; then
if grep -q "API rate limit exceeded" "$tmp_file"; then
echo "error: github API rate limit exceeded"
else
echo "error: Failed to get the latest release version."
echo "Welcome bug report:https://github.com/crossfw/Air-Universe/issues"
fi
"rm" "$tmp_file"
exit 1
fi
"rm" "$tmp_file"
VERSION="v${RELEASE_LATEST#v}"
}
makeConfig() {
mkdir -p /usr/lib/systemd/system/
cat >/usr/local/etc/au/au.json <<EOF
{
"panel": {
"type": "${panelType}",
"url": "${pUrl}",
"key": "${nKey}",
"node_ids": [${nIds}],
"nodes_type": [${nType}]
},
"proxy": {
"type":"xray"
}
}
EOF
chmod 644 /usr/local/etc/au/au.json
}
createService() {
service_file="https://raw.githubusercontent.com/crossfw/Air-Universe-install/master/au.service"
wget -N -O /etc/systemd/system/au.service ${service_file}
chmod 644 /etc/systemd/system/au.service
systemctl daemon-reload
}
check_root
check_sys
Installation_dependency
get_latest_version
identify_the_operating_system_and_architecture
panelConfig
download
makeConfig
createService
systemctl enable au
systemctl restart xray
systemctl start au