Skip to content

Commit 90b6712

Browse files
authored
Refactor: EMQX + Update-Function + Improved NodeJS Crawling (#5907)
1 parent 3140438 commit 90b6712

File tree

4 files changed

+75
-22
lines changed

4 files changed

+75
-22
lines changed

ct/emqx.sh

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,39 @@ color
2020
catch_errors
2121

2222
function update_script() {
23-
header_info
24-
check_container_storage
25-
check_container_resources
26-
if [[ ! -d /var ]]; then
27-
msg_error "No ${APP} Installation Found!"
28-
exit
29-
fi
30-
msg_info "Updating $APP LXC"
31-
$STD apt-get update
32-
$STD apt-get -y upgrade
33-
msg_ok "Updated $APP LXC"
34-
exit
23+
header_info
24+
check_container_storage
25+
check_container_resources
26+
27+
RELEASE=$(curl -fsSL https://www.emqx.com/en/downloads/enterprise | grep -oP '/en/downloads/enterprise/v\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1)
28+
if [[ "$RELEASE" != "$(cat ~/.emqx 2>/dev/null)" ]] || [[ ! -f ~/.emqx ]]; then
29+
msg_info "Stopping EMQX"
30+
systemctl stop emqx
31+
msg_ok "Stopped EMQX"
32+
33+
msg_info "Downloading EMQX v${RELEASE}"
34+
DEB_FILE="/tmp/emqx-enterprise-${RELEASE}-debian12-amd64.deb"
35+
curl -fsSL -o "$DEB_FILE" "https://www.emqx.com/en/downloads/enterprise/v${RELEASE}/emqx-enterprise-${RELEASE}-debian12-amd64.deb"
36+
msg_ok "Downloaded EMQX"
37+
38+
msg_info "Installing EMQX"
39+
$STD apt-get install -y "$DEB_FILE"
40+
msg_ok "Installed EMQX v${RELEASE}"
41+
42+
msg_info "Starting EMQX"
43+
systemctl start emqx
44+
echo "$RELEASE" >~/.emqx
45+
msg_ok "Started EMQX"
46+
47+
msg_info "Cleaning Up"
48+
rm -f "$DEB_FILE"
49+
msg_ok "Cleanup Completed"
50+
msg_ok "Update Successful"
51+
else
52+
msg_ok "No update required. EMQX is already at v${RELEASE}"
53+
fi
54+
55+
exit
3556
}
3657

3758
start
@@ -41,4 +62,4 @@ description
4162
msg_ok "Completed Successfully!\n"
4263
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
4364
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
44-
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:18083${CL}"
65+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:18083${CL}"

frontend/public/json/emqx.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/emqx-install.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,38 @@ network_check
1414
update_os
1515

1616
msg_info "Installing dependencies"
17-
$STD apt-get install -y \
18-
apt-transport-https \
19-
ca-certificates \
20-
lsb-release
17+
$STD apt-get install -y ca-certificates
2118
msg_ok "Installed dependencies"
2219

20+
msg_info "Fetching latest EMQX Enterprise version"
21+
LATEST_VERSION=$(curl -fsSL https://www.emqx.com/en/downloads/enterprise | grep -oP '/en/downloads/enterprise/v\K[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n1)
22+
if [[ -z "$LATEST_VERSION" ]]; then
23+
msg_error "Failed to determine latest EMQX version"
24+
exit 1
25+
fi
26+
msg_ok "Latest version: v$LATEST_VERSION"
27+
28+
DOWNLOAD_URL="https://www.emqx.com/en/downloads/enterprise/v$LATEST_VERSION/emqx-enterprise-${LATEST_VERSION}-debian12-amd64.deb"
29+
DEB_FILE="/tmp/emqx-enterprise-${LATEST_VERSION}-debian12-amd64.deb"
30+
31+
msg_info "Downloading EMQX v$LATEST_VERSION"
32+
$STD curl -fsSL -o "$DEB_FILE" "$DOWNLOAD_URL"
33+
msg_ok "Downloaded EMQX"
34+
2335
msg_info "Installing EMQX"
24-
curl -fsSL https://packagecloud.io/emqx/emqx/gpgkey | gpg --dearmor -o /usr/share/keyrings/emqx-archive-keyring.gpg
25-
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/emqx-archive-keyring.gpg] https://packagecloud.io/emqx/emqx/debian/ bookworm main" >/etc/apt/sources.list.d/emqx.list
26-
$STD apt-get install -y emqx
36+
$STD apt-get install -y "$DEB_FILE"
37+
echo "$LATEST_VERSION" >~/.emqx
2738
msg_ok "Installed EMQX"
2839

40+
msg_info "Starting EMQX service"
41+
$STD systemctl enable -q --now emqx
42+
msg_ok "Enabled EMQX service"
43+
2944
motd_ssh
3045
customize
3146

3247
msg_info "Cleaning up"
48+
rm -f "$DEB_FILE"
3349
$STD apt-get autoremove
3450
$STD apt-get autoclean
3551
msg_ok "Cleaned"

misc/tools.func

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,24 @@ function setup_nodejs() {
5454
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" \
5555
>/etc/apt/sources.list.d/nodesource.list
5656

57+
sleep 2
5758
if ! apt-get update >/dev/null 2>&1; then
58-
msg_error "Failed to update APT repositories after adding NodeSource"
59+
msg_warn "APT update failed – retrying in 5s"
60+
sleep 5
61+
if ! apt-get update >/dev/null 2>&1; then
62+
msg_error "Failed to update APT repositories after adding NodeSource"
63+
exit 1
64+
fi
65+
fi
66+
67+
if ! apt-cache policy nodejs | grep -q 'Candidate:'; then
68+
msg_error "Node.js package not found – repository might be broken or too fresh"
69+
apt-cache policy nodejs >&2
70+
exit 1
71+
fi
72+
73+
if ! apt-get install -y nodejs >/dev/null 2>&1; then
74+
msg_error "Failed to install Node.js ${NODE_VERSION} from NodeSource"
5975
exit 1
6076
fi
6177

0 commit comments

Comments
 (0)