From de7c99ea8cfbeeb3fd2154e99fc9423477dfb96d Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Tue, 7 Apr 2026 10:03:30 +0200 Subject: [PATCH] refactor(mqttx): convert from LXC to addon MQTTX Web is a static browser-based MQTT client with no backend. Makes more sense as an addon installable into any existing container than as a dedicated LXC. Addon installs into /opt/mqttx, builds web/ with yarn, serves via Nginx on configurable port (default 8095). Supports install/update/uninstall. --- ct/mqttx.sh | 60 ----------------- install/mqttx-install.sh | 49 -------------- json/mqttx.json | 40 ------------ tools/addon/mqttx.sh | 136 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 149 deletions(-) delete mode 100644 ct/mqttx.sh delete mode 100644 install/mqttx-install.sh delete mode 100644 json/mqttx.json create mode 100644 tools/addon/mqttx.sh diff --git a/ct/mqttx.sh b/ct/mqttx.sh deleted file mode 100644 index 3ff60063..00000000 --- a/ct/mqttx.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func) - -# Copyright (c) 2021-2026 community-scripts ORG -# Author: MickLesk (CanbiZ) -# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE -# Source: https://github.com/emqx/MQTTX - -APP="MQTTX Web" -var_tags="${var_tags:-mqtt;iot;messaging}" -var_cpu="${var_cpu:-1}" -var_ram="${var_ram:-1024}" -var_disk="${var_disk:-4}" -var_os="${var_os:-debian}" -var_version="${var_version:-13}" -var_unprivileged="${var_unprivileged:-1}" - -header_info "$APP" -variables -color -catch_errors - -function update_script() { - header_info - check_container_storage - check_container_resources - - if [[ ! -d /opt/mqttx ]]; then - msg_error "No ${APP} Installation Found!" - exit - fi - - if check_for_gh_release "mqttx" "emqx/MQTTX"; then - msg_info "Stopping Nginx" - systemctl stop nginx - msg_ok "Stopped Nginx" - - msg_info "Updating MQTTX Web" - fetch_and_deploy_gh_release "mqttx" "emqx/MQTTX" "tarball" "latest" "/opt/mqttx" - cd /opt/mqttx/web - $STD yarn install --frozen-lockfile - $STD yarn build - msg_ok "Updated MQTTX Web" - - msg_info "Starting Nginx" - systemctl start nginx - msg_ok "Started Nginx" - msg_ok "Updated successfully!" - fi - exit -} - -start -build_container -description - -msg_ok "Completed Successfully!\n" -echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" -echo -e "${INFO}${YW} Access it using the following URL:${CL}" -echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:80${CL}" diff --git a/install/mqttx-install.sh b/install/mqttx-install.sh deleted file mode 100644 index 5d28843d..00000000 --- a/install/mqttx-install.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2021-2026 community-scripts ORG -# Author: MickLesk (CanbiZ) -# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE -# Source: https://github.com/emqx/MQTTX - -source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" -color -verb_ip6 -catch_errors -setting_up_container -network_check -update_os - -msg_info "Installing Dependencies" -$STD apt install -y \ - nginx -msg_ok "Installed Dependencies" - -NODE_VERSION="22" NODE_MODULE="yarn" setup_nodejs - -fetch_and_deploy_gh_release "mqttx" "emqx/MQTTX" "tarball" "latest" "/opt/mqttx" - -msg_info "Building MQTTX Web" -cd /opt/mqttx/web -$STD yarn install --frozen-lockfile -$STD yarn build -msg_ok "Built MQTTX Web" - -msg_info "Configuring Nginx" -cat <<'EOF' >/etc/nginx/sites-available/default -server { - listen 80; - - root /opt/mqttx/web/dist; - index index.html; - - location / { - try_files $uri $uri/ /index.html; - } -} -EOF -systemctl restart nginx -msg_ok "Configured Nginx" - -motd_ssh -customize -cleanup_lxc diff --git a/json/mqttx.json b/json/mqttx.json deleted file mode 100644 index 8a7b7833..00000000 --- a/json/mqttx.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "MQTTX Web", - "slug": "mqttx", - "categories": [ - 18 - ], - "date_created": "2026-04-07", - "type": "ct", - "updateable": true, - "privileged": false, - "interface_port": 80, - "documentation": "https://mqttx.app/docs/web", - "website": "https://mqttx.app/", - "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/mqttx.webp", - "config_path": "", - "description": "MQTTX Web is an open source MQTT 5.0 browser client tool. It uses WebSocket to connect to MQTT brokers directly from the browser, making it easy to test and debug MQTT services without local installation.", - "install_methods": [ - { - "type": "default", - "script": "ct/mqttx.sh", - "resources": { - "cpu": 1, - "ram": 1024, - "hdd": 4, - "os": "Debian", - "version": "13" - } - } - ], - "default_credentials": { - "username": null, - "password": null - }, - "notes": [ - { - "text": "MQTTX Web connects to MQTT brokers via WebSocket directly from the browser. No credentials are required for the web UI itself.", - "type": "info" - } - ] -} diff --git a/tools/addon/mqttx.sh b/tools/addon/mqttx.sh new file mode 100644 index 00000000..ff8d1cf0 --- /dev/null +++ b/tools/addon/mqttx.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash + +# community-scripts ORG | MQTTX Web Addon Installer +# Author: MickLesk +# License: MIT +# Source: https://github.com/emqx/MQTTX + +if command -v curl >/dev/null 2>&1; then + source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/core.func) + load_functions +elif command -v wget >/dev/null 2>&1; then + source <(wget -qO- https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/core.func) + load_functions +fi +source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/tools.func) + +color +catch_errors + +APP="MQTTX Web" +APP_TYPE="tools" +APP_DIR="/opt/mqttx" +SERVICE="mqttx-web" +REPO="emqx/MQTTX" +DEFAULT_PORT=8095 + +header_info "$APP" + +if ! grep -q -Ei 'debian|ubuntu' /etc/os-release; then + msg_error "Unsupported OS. This addon supports only Debian or Ubuntu." + exit 1 +fi + +IP=$(hostname -I | awk '{print $1}') + +function is_installed() { + [[ -d "$APP_DIR/web/dist" ]] && systemctl is-active --quiet "$SERVICE" +} + +function install_mqttx() { + local port="${1:-$DEFAULT_PORT}" + + NODE_VERSION="22" NODE_MODULE="yarn" setup_nodejs + + fetch_and_deploy_gh_release "mqttx" "$REPO" "tarball" "latest" "$APP_DIR" + + msg_info "Building ${APP}" + cd "$APP_DIR/web" + $STD yarn install --frozen-lockfile + $STD yarn build + msg_ok "Built ${APP}" + + if ! dpkg -l nginx &>/dev/null; then + msg_info "Installing Nginx" + $STD apt install -y nginx + msg_ok "Installed Nginx" + fi + + msg_info "Configuring ${APP}" + cat </etc/nginx/sites-available/mqttx-web +server { + listen ${port}; + + root ${APP_DIR}/web/dist; + index index.html; + + location / { + try_files \$uri \$uri/ /index.html; + } +} +EOF + ln -sf /etc/nginx/sites-available/mqttx-web /etc/nginx/sites-enabled/mqttx-web + $STD nginx -t + systemctl reload nginx + + cat </etc/systemd/system/${SERVICE}.service +[Unit] +Description=${APP} (Nginx on port ${port}) +After=network.target +BindsTo=nginx.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/true +ExecReload=/usr/sbin/nginx -s reload + +[Install] +WantedBy=multi-user.target +EOF + systemctl enable -q --now "$SERVICE" + msg_ok "${APP} installed at http://${IP}:${port}" +} + +function uninstall_mqttx() { + msg_info "Removing ${APP}" + systemctl disable -q --now "$SERVICE" 2>/dev/null || true + rm -f "/etc/systemd/system/${SERVICE}.service" + rm -f /etc/nginx/sites-enabled/mqttx-web + rm -f /etc/nginx/sites-available/mqttx-web + $STD nginx -t && systemctl reload nginx + rm -rf "$APP_DIR" + msg_ok "${APP} uninstalled" +} + +function update_mqttx() { + if check_for_gh_release "mqttx" "$REPO"; then + msg_info "Updating ${APP}" + CLEAN_INSTALL=1 fetch_and_deploy_gh_release "mqttx" "$REPO" "tarball" "latest" "$APP_DIR" + cd "$APP_DIR/web" + $STD yarn install --frozen-lockfile + $STD yarn build + systemctl reload nginx + msg_ok "${APP} updated" + else + msg_ok "${APP} is already up-to-date" + fi +} + +if is_installed; then + read -r -p "Update (1), Uninstall (2), Cancel (3)? [1/2/3]: " action + action="${action//[[:space:]]/}" + case "$action" in + 1) update_mqttx ;; + 2) uninstall_mqttx ;; + 3) msg_info "Cancelled" ;; + *) msg_error "Invalid input" ;; + esac +else + echo -e "${TAB}Enter port number (default: ${DEFAULT_PORT}): " + read -r PORT_INPUT + PORT="${PORT_INPUT:-$DEFAULT_PORT}" + read -r -p "Install ${APP}? (y/n): " answer + answer="${answer//[[:space:]]/}" + [[ "${answer,,}" =~ ^(y|yes)$ ]] && install_mqttx "$PORT" || msg_info "Installation skipped" +fi