5
5
6
6
echo -e " \033]0;MCSManager安装\007"
7
7
8
+ log () {
9
+ current_time=$( date +' %H:%M:%S' )
10
+ case " $1 " in
11
+ " INFO" )
12
+ echo -e " ${blue_bg} [$current_time ]${reset} ${blue_fg_strong} [信息]${reset} $2 "
13
+ ;;
14
+ " WARN" )
15
+ echo -e " ${yellow_bg} [$current_time ]${reset} ${yellow_fg_strong} [警告]${reset} $2 "
16
+ ;;
17
+ " ERROR" )
18
+ echo -e " ${red_bg} [$current_time ]${reset} ${red_fg_strong} [错误]${reset} $2 "
19
+ ;;
20
+ * )
21
+ echo -e " ${blue_bg} [$current_time ]${reset} ${blue_fg_strong} [调试]${reset} $2 "
22
+ ;;
23
+ esac
24
+ }
25
+
26
+ # 错误处理函数
27
+ error_exit () {
28
+ log " ERROR" " $1 "
29
+ exit 1
30
+ }
31
+
32
+ # 检查命令是否存在
33
+ command_exists () {
34
+ command -v " $1 " > /dev/null 2>&1
35
+ }
36
+
37
+ function unsupported_arch() {
38
+ error_exit " 不支持的架构: $( getprop ro.product.cpu.abi) "
39
+ }
40
+
8
41
function ask() {
9
42
# http://djm.me/ask
10
43
while true ; do
@@ -37,4 +70,273 @@ function ask() {
37
70
N* |n* ) return 1 ;;
38
71
esac
39
72
done
40
- }
73
+ }
74
+
75
+ function get_arch() {
76
+ log " INFO" " 检查设备架构..."
77
+ case $( getprop ro.product.cpu.abi) in
78
+ arm64-v8a)
79
+ SYS_ARCH=arm64
80
+ log " INFO" " 检测到架构: ARM64"
81
+ ;;
82
+ armeabi|armeabi-v7a)
83
+ SYS_ARCH=armhf
84
+ log " INFO" " 检测到架构: ARMhf"
85
+ ;;
86
+ * )
87
+ unsupported_arch
88
+ ;;
89
+ esac
90
+ }
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+ # #!/bin/bash
99
+ # # This script file is specifically designed for the Chinese region, and servers in the Chinese region are used to accelerate file downloads.
100
+
101
+ # mcsmanager_install_path="/opt/mcsmanager"
102
+ # mcsmanager_download_addr="https://cdn.imlazy.ink:233/files/mcsmanager_linux_release.tar.gz"
103
+ # package_name="mcsmanager_linux_release.tar.gz"
104
+ # node="v20.12.2"
105
+ # arch=$(uname -m)
106
+
107
+ # if [ "$(id -u)" -ne 0 ]; then
108
+ # echo "This script must be run as root. Please use \"sudo bash\" instead."
109
+ # exit 1
110
+ # fi
111
+
112
+ # printf "\033c"
113
+
114
+ # echo_cyan() {
115
+ # printf '\033[1;36m%b\033[0m\n' "$@"
116
+ # }
117
+ # echo_red() {
118
+ # printf '\033[1;31m%b\033[0m\n' "$@"
119
+ # }
120
+ # echo_green() {
121
+ # printf '\033[1;32m%b\033[0m\n' "$@"
122
+ # }
123
+ # echo_cyan_n() {
124
+ # printf '\033[1;36m%b\033[0m' "$@"
125
+ # }
126
+ # echo_yellow() {
127
+ # printf '\033[1;33m%b\033[0m\n' "$@"
128
+ # }
129
+
130
+ # # script info
131
+ # echo_cyan "+----------------------------------------------------------------------
132
+ # | MCSManager 安装脚本 (MCSManager Installer)
133
+ # +----------------------------------------------------------------------
134
+ # "
135
+
136
+ # Red_Error() {
137
+ # echo '================================================='
138
+ # printf '\033[1;31;40m%b\033[0m\n' "$@"
139
+ # echo '================================================='
140
+ # exit 1
141
+ # }
142
+
143
+ # Install_Node() {
144
+ # if [[ -f "$node_install_path"/bin/node ]] && [[ "$("$node_install_path"/bin/node -v)" == "$node" ]]; then
145
+ # echo_green "Node.js version is up-to-date, skipping installation."
146
+ # return
147
+ # fi
148
+
149
+ # echo_cyan "[+] Install Node.JS environment..."
150
+
151
+ # rm -irf "$node_install_path"
152
+
153
+ # cd /opt || Red_Error "[x] Failed to enter /opt"
154
+
155
+ # rm -rf "node-$node-linux-$arch.tar.gz"
156
+
157
+ # # wget "https://nodejs.org/dist/$node/node-$node-linux-$arch.tar.gz" || Red_Error "[x] Failed to download node release"
158
+ # wget "https://registry.npmmirror.com/-/binary/node/$node/node-$node-linux-$arch.tar.gz" || Red_Error "[x] Failed to download node release"
159
+
160
+ # tar -zxf "node-$node-linux-$arch.tar.gz" || Red_Error "[x] Failed to untar node"
161
+
162
+ # rm -rf "node-$node-linux-$arch.tar.gz"
163
+
164
+ # if [[ -f "$node_install_path"/bin/node ]] && [[ "$("$node_install_path"/bin/node -v)" == "$node" ]]; then
165
+ # echo_green "Success"
166
+ # else
167
+ # Red_Error "[x] Node installation failed!"
168
+ # fi
169
+
170
+ # echo
171
+ # echo_yellow "=============== Node.JS Version ==============="
172
+ # echo_yellow " node: $("$node_install_path"/bin/node -v)"
173
+ # echo_yellow " npm: v$(env "$node_install_path"/bin/node "$node_install_path"/bin/npm -v)"
174
+ # echo_yellow "=============== Node.JS Version ==============="
175
+ # echo
176
+
177
+ # sleep 3
178
+ # }
179
+
180
+ # Install_MCSManager() {
181
+ # echo_cyan "[+] Install MCSManager..."
182
+
183
+ # # stop service
184
+ # systemctl disable --now mcsm-{web,daemon}
185
+
186
+ # # delete service
187
+ # rm -rf /etc/systemd/system/mcsm-{daemon,web}.service
188
+ # systemctl daemon-reload
189
+
190
+ # mkdir -p "${mcsmanager_install_path}" || Red_Error "[x] Failed to create ${mcsmanager_install_path}"
191
+
192
+ # # cd /opt/mcsmanager
193
+ # cd "${mcsmanager_install_path}" || Red_Error "[x] Failed to enter ${mcsmanager_install_path}"
194
+
195
+ # # download MCSManager release
196
+ # wget "${mcsmanager_download_addr}" -O "${package_name}" || Red_Error "[x] Failed to download MCSManager"
197
+ # tar -zxf ${package_name} -o || Red_Error "[x] Failed to untar ${package_name}"
198
+ # rm -rf "${mcsmanager_install_path}/${package_name}"
199
+
200
+ # # compatible with tar.gz packages of different formats
201
+ # if [ -d "/opt/mcsmanager/mcsmanager" ]; then
202
+ # cp -rf /opt/mcsmanager/mcsmanager/* /opt/mcsmanager/
203
+ # rm -rf /opt/mcsmanager/mcsmanager
204
+ # fi
205
+
206
+ # # echo "[→] cd daemon"
207
+ # cd "${mcsmanager_install_path}/daemon" || Red_Error "[x] Failed to enter ${mcsmanager_install_path}/daemon"
208
+
209
+ # echo_cyan "[+] Install MCSManager-Daemon dependencies..."
210
+ # env "$node_install_path"/bin/node "$node_install_path"/bin/npm install --registry=https://registry.npmmirror.com --production --no-fund --no-audit &>/dev/null || Red_Error "[x] Failed to npm install in ${mcsmanager_install_path}/daemon"
211
+
212
+ # # echo "[←] cd .."
213
+ # cd "${mcsmanager_install_path}/web" || Red_Error "[x] Failed to enter ${mcsmanager_install_path}/web"
214
+
215
+ # echo_cyan "[+] Install MCSManager-Web dependencies..."
216
+ # env "$node_install_path"/bin/node "$node_install_path"/bin/npm install --registry=https://registry.npmmirror.com --production --no-fund --no-audit &>/dev/null || Red_Error "[x] Failed to npm install in ${mcsmanager_install_path}/web"
217
+
218
+ # echo
219
+ # echo_yellow "=============== MCSManager ==============="
220
+ # echo_green "Daemon: ${mcsmanager_install_path}/daemon"
221
+ # echo_green "Web: ${mcsmanager_install_path}/web"
222
+ # echo_yellow "=============== MCSManager ==============="
223
+ # echo
224
+ # echo_green "[+] MCSManager installation success!"
225
+
226
+ # chmod -R 755 "$mcsmanager_install_path"
227
+
228
+ # sleep 3
229
+ # }
230
+
231
+ # Create_Service() {
232
+ # echo_cyan "[+] Create MCSManager service..."
233
+
234
+ # echo "[Unit]
235
+ # Description=MCSManager-Daemon
236
+
237
+ # [Service]
238
+ # WorkingDirectory=${mcsmanager_install_path}/daemon
239
+ # ExecStart=${node_install_path}/bin/node app.js
240
+ # ExecReload=/bin/kill -s QUIT \$MAINPID
241
+ # ExecStop=/bin/kill -s QUIT \$MAINPID
242
+ # Environment=\"PATH=${PATH}\"
243
+
244
+ # [Install]
245
+ # WantedBy=multi-user.target
246
+ # " >/etc/systemd/system/mcsm-daemon.service
247
+
248
+ # echo "[Unit]
249
+ # Description=MCSManager-Web
250
+
251
+ # [Service]
252
+ # WorkingDirectory=${mcsmanager_install_path}/web
253
+ # ExecStart=${node_install_path}/bin/node app.js
254
+ # ExecReload=/bin/kill -s QUIT \$MAINPID
255
+ # ExecStop=/bin/kill -s QUIT \$MAINPID
256
+ # Environment=\"PATH=${PATH}\"
257
+
258
+ # [Install]
259
+ # WantedBy=multi-user.target
260
+ # " >/etc/systemd/system/mcsm-web.service
261
+
262
+ # systemctl daemon-reload
263
+ # systemctl enable --now mcsm-{daemon,web}.service
264
+ # echo_green "Registered!"
265
+
266
+ # sleep 2
267
+
268
+ # printf "\n\n\n\n"
269
+
270
+ # echo_yellow "=================================================================="
271
+ # echo_green "安装完成,欢迎使用 MCSManager !"
272
+ # echo_yellow " "
273
+ # echo_cyan_n "主控网页访问地址: "
274
+ # echo_yellow "http://<Your IP>:23333 (Browser)"
275
+ # echo_cyan_n "被控守护进程地址: "
276
+ # echo_yellow "ws://<Your IP>:24444 (Cluster)"
277
+ # echo_red "默认情况下,你必须开放 23333 和 24444 端口才能确保面板工作正常!"
278
+ # echo_yellow " "
279
+ # echo_cyan "面板开关指令:"
280
+ # echo_cyan "systemctl start mcsm-{daemon,web}.service"
281
+ # echo_cyan "systemctl stop mcsm-{daemon,web}.service"
282
+ # echo_cyan "systemctl restart mcsm-{daemon,web}.service"
283
+ # echo_yellow " "
284
+ # echo_green "官方文档: https://docs.mcsmanager.com/"
285
+ # echo_yellow "=================================================================="
286
+ # }
287
+
288
+ # # Environmental inspection
289
+ # if [[ "$arch" == x86_64 ]]; then
290
+ # arch=x64
291
+ # #echo "[-] x64 architecture detected"
292
+ # elif [[ $arch == aarch64 ]]; then
293
+ # arch=arm64
294
+ # #echo "[-] 64-bit ARM architecture detected"
295
+ # elif [[ $arch == arm ]]; then
296
+ # arch=armv7l
297
+ # #echo "[-] 32-bit ARM architecture detected"
298
+ # elif [[ $arch == ppc64le ]]; then
299
+ # arch=ppc64le
300
+ # #echo "[-] IBM POWER architecture detected"
301
+ # elif [[ $arch == s390x ]]; then
302
+ # arch=s390x
303
+ # #echo "[-] IBM LinuxONE architecture detected"
304
+ # else
305
+ # Red_Error "[x] Sorry, this architecture is not supported yet!\n[x]Please try to install manually: https://github.com/MCSManager/MCSManager#linux"
306
+ # fi
307
+
308
+ # # Define the variable Node installation directory
309
+ # node_install_path="/opt/node-$node-linux-$arch"
310
+
311
+ # # Check network connection
312
+ # echo_cyan "[-] Architecture: $arch"
313
+
314
+ # # Install related software
315
+ # echo_cyan_n "[+] Installing dependent software (git, tar, wget)... "
316
+ # if [[ -x "$(command -v yum)" ]]; then
317
+ # yum install -y git tar wget
318
+ # elif [[ -x "$(command -v apt-get)" ]]; then
319
+ # apt-get install -y git tar wget
320
+ # elif [[ -x "$(command -v pacman)" ]]; then
321
+ # pacman -S --noconfirm --needed git tar wget
322
+ # elif [[ -x "$(command -v zypper)" ]]; then
323
+ # zypper --non-interactive install git tar wget
324
+ # else
325
+ # echo_red "[!] Cannot find your package manager! You may need to install git, tar and wget manually!"
326
+ # fi
327
+
328
+ # # Determine whether the relevant software is installed successfully
329
+ # if [[ -x "$(command -v git)" && -x "$(command -v tar)" && -x "$(command -v wget)" ]]; then
330
+ # echo_green "Success"
331
+ # else
332
+ # Red_Error "[x] Failed to find git, tar and wget, please install them manually!"
333
+ # fi
334
+
335
+ # # Install the Node environment
336
+ # Install_Node
337
+
338
+ # # Install MCSManager
339
+ # Install_MCSManager
340
+
341
+ # # Create MCSManager background service
342
+ # Create_Service
0 commit comments