Skip to content

Commit 5fc4f82

Browse files
committed
feat: 添加更新以及純節點安裝腳本,將setup腳本中獲取版本改為自動獲取
1 parent e429a38 commit 5fc4f82

7 files changed

Lines changed: 1064 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ bin-release/
1919

2020
# Remove old cli sh
2121
cli_old.sh
22+
23+
.idea

daemon/setup.sh

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
#!/bin/bash
2+
# Official installation script.
3+
4+
mcsmanager_install_path="/opt/mcsmanager"
5+
mcsmanager_download_addr=$(curl -s https://api.github.com/repos/MCSManager/MCSManager/releases/latest | grep -o 'https://.*linux.*\.tar\.gz')
6+
package_name="mcsmanager_linux_release.tar.gz"
7+
node="v20.12.2"
8+
arch=$(uname -m)
9+
10+
if [ "$(id -u)" -ne 0 ]; then
11+
echo "This script must be run as root. Please use \"sudo bash\" instead."
12+
exit 1
13+
fi
14+
15+
printf "\033c"
16+
17+
echo_cyan() {
18+
printf '\033[1;36m%b\033[0m\n' "$@"
19+
}
20+
echo_red() {
21+
printf '\033[1;31m%b\033[0m\n' "$@"
22+
}
23+
echo_green() {
24+
printf '\033[1;32m%b\033[0m\n' "$@"
25+
}
26+
echo_cyan_n() {
27+
printf '\033[1;36m%b\033[0m' "$@"
28+
}
29+
echo_yellow() {
30+
printf '\033[1;33m%b\033[0m\n' "$@"
31+
}
32+
33+
# script info
34+
echo_cyan "+----------------------------------------------------------------------
35+
| MCSManager Installer
36+
+----------------------------------------------------------------------
37+
"
38+
39+
Red_Error() {
40+
echo '================================================='
41+
printf '\033[1;31;40m%b\033[0m\n' "$@"
42+
echo '================================================='
43+
exit 1
44+
}
45+
46+
Install_Node() {
47+
echo_cyan_n "[+] Install Node.JS environment...\n"
48+
49+
rm -irf "$node_install_path"
50+
51+
cd /opt || Red_Error "[x] Failed to enter /opt"
52+
53+
rm -rf "node-$node-linux-$arch.tar.gz"
54+
55+
wget "https://nodejs.org/dist/$node/node-$node-linux-$arch.tar.gz" || Red_Error "[x] Failed to download node release"
56+
57+
tar -zxf "node-$node-linux-$arch.tar.gz" || Red_Error "[x] Failed to untar node"
58+
59+
rm -rf "node-$node-linux-$arch.tar.gz"
60+
61+
if [[ -f "$node_install_path"/bin/node ]] && [[ "$("$node_install_path"/bin/node -v)" == "$node" ]]; then
62+
echo_green "Success"
63+
else
64+
Red_Error "[x] Node installation failed!"
65+
fi
66+
67+
echo
68+
echo_yellow "=============== Node.JS Version ==============="
69+
echo_yellow " node: $("$node_install_path"/bin/node -v)"
70+
echo_yellow " npm: v$(env "$node_install_path"/bin/node "$node_install_path"/bin/npm -v)"
71+
echo_yellow "=============== Node.JS Version ==============="
72+
echo
73+
74+
sleep 3
75+
}
76+
77+
Install_MCSManager() {
78+
echo_cyan "[+] Install MCSManager..."
79+
80+
# stop service
81+
systemctl disable --now mcsm-{web,daemon}
82+
83+
# delete service
84+
rm -rf /etc/systemd/system/mcsm-{daemon,web}.service
85+
systemctl daemon-reload
86+
87+
mkdir -p "${mcsmanager_install_path}" || Red_Error "[x] Failed to create ${mcsmanager_install_path}"
88+
89+
# cd /opt/mcsmanager
90+
cd "${mcsmanager_install_path}" || Red_Error "[x] Failed to enter ${mcsmanager_install_path}"
91+
92+
# download MCSManager release
93+
wget "${mcsmanager_download_addr}" -O "${package_name}" || Red_Error "[x] Failed to download MCSManager"
94+
tar -zxf ${package_name} -o || Red_Error "[x] Failed to untar ${package_name}"
95+
rm -rf "${mcsmanager_install_path}/${package_name}"
96+
97+
# compatible with tar.gz packages of different formats
98+
if [ -d "/opt/mcsmanager/mcsmanager" ]; then
99+
cp -rf /opt/mcsmanager/mcsmanager/* /opt/mcsmanager/
100+
rm -rf /opt/mcsmanager/mcsmanager
101+
fi
102+
103+
rm -rf "${mcsmanager_install_path}/web"
104+
105+
# echo "[→] cd daemon"
106+
cd "${mcsmanager_install_path}/daemon" || Red_Error "[x] Failed to enter ${mcsmanager_install_path}/daemon"
107+
108+
echo_cyan "[+] Install MCSManager-Daemon dependencies..."
109+
env "$node_install_path"/bin/node "$node_install_path"/bin/npm install --production --no-fund --no-audit &>/dev/null || Red_Error "[x] Failed to npm install in ${mcsmanager_install_path}/daemon"
110+
111+
echo
112+
echo_yellow "=============== MCSManager ==============="
113+
echo_green "Daemon: ${mcsmanager_install_path}/daemon"
114+
echo_yellow "=============== MCSManager ==============="
115+
echo
116+
echo_green "[+] MCSManager installation success!"
117+
118+
chmod -R 755 "$mcsmanager_install_path"
119+
120+
sleep 3
121+
}
122+
123+
Create_Service() {
124+
echo_cyan "[+] Create MCSManager service..."
125+
126+
echo "[Unit]
127+
Description=MCSManager-Daemon
128+
129+
[Service]
130+
WorkingDirectory=${mcsmanager_install_path}/daemon
131+
ExecStart=${node_install_path}/bin/node app.js
132+
ExecReload=/bin/kill -s QUIT \$MAINPID
133+
ExecStop=/bin/kill -s QUIT \$MAINPID
134+
Environment=\"PATH=${PATH}\"
135+
136+
[Install]
137+
WantedBy=multi-user.target
138+
" >/etc/systemd/system/mcsm-daemon.service
139+
140+
systemctl daemon-reload
141+
systemctl enable --now mcsm-daemon.service
142+
echo_green "Registered!"
143+
144+
sleep 2
145+
146+
printf "\n\n\n\n"
147+
148+
echo_yellow "=================================================================="
149+
echo_green "Installation is complete! Welcome to the MCSManager!!!"
150+
echo_yellow " "
151+
echo_cyan_n "Daemon Address: "
152+
echo_yellow "ws://<Your IP>:24444 (Cluster)"
153+
echo_red "You must expose ports "
154+
echo_yellow "24444"
155+
echo_red " to use the service properly on the Internet."
156+
echo_yellow " "
157+
echo_cyan "Usage:"
158+
echo_cyan "systemctl start mcsm-daemon.service"
159+
echo_cyan "systemctl stop mcsm-daemon.service"
160+
echo_cyan "systemctl restart mcsm-daemon.service"
161+
echo_yellow " "
162+
echo_green "Official Document: https://docs.mcsmanager.com/"
163+
echo_yellow "=================================================================="
164+
}
165+
166+
# Environmental inspection
167+
if [[ "$arch" == x86_64 ]]; then
168+
arch=x64
169+
#echo "[-] x64 architecture detected"
170+
elif [[ $arch == aarch64 ]]; then
171+
arch=arm64
172+
#echo "[-] 64-bit ARM architecture detected"
173+
elif [[ $arch == arm ]]; then
174+
arch=armv7l
175+
#echo "[-] 32-bit ARM architecture detected"
176+
elif [[ $arch == ppc64le ]]; then
177+
arch=ppc64le
178+
#echo "[-] IBM POWER architecture detected"
179+
elif [[ $arch == s390x ]]; then
180+
arch=s390x
181+
#echo "[-] IBM LinuxONE architecture detected"
182+
else
183+
Red_Error "[x] Sorry, this architecture is not supported yet!\n[x]Please try to install manually: https://github.com/MCSManager/MCSManager#linux"
184+
fi
185+
186+
# Define the variable Node installation directory
187+
node_install_path="/opt/node-$node-linux-$arch"
188+
189+
# Check network connection
190+
echo_cyan "[-] Architecture: $arch"
191+
192+
# Install related software
193+
echo_cyan_n "[+] Installing dependent software (git, tar, wget)... "
194+
if [[ -x "$(command -v yum)" ]]; then
195+
yum install -y git tar wget
196+
elif [[ -x "$(command -v apt-get)" ]]; then
197+
apt-get install -y git tar wget
198+
elif [[ -x "$(command -v pacman)" ]]; then
199+
pacman -S --noconfirm --needed git tar wget
200+
elif [[ -x "$(command -v zypper)" ]]; then
201+
zypper --non-interactive install git tar wget
202+
else
203+
echo_red "[!] Cannot find your package manager! You may need to install git, tar and wget manually!"
204+
fi
205+
206+
# Determine whether the relevant software is installed successfully
207+
if [[ -x "$(command -v git)" && -x "$(command -v tar)" && -x "$(command -v wget)" ]]; then
208+
echo_green "Success"
209+
else
210+
Red_Error "[x] Failed to find git, tar and wget, please install them manually!"
211+
fi
212+
213+
# Install the Node environment
214+
Install_Node
215+
216+
# Install MCSManager
217+
Install_MCSManager
218+
219+
# Create MCSManager background service
220+
Create_Service

0 commit comments

Comments
 (0)