Skip to content

Bug: telemt 3.5.16 source fallback fails with /bin/sh: Bad substitution #162

Closed

Description

@Krezi-777

Summary

With MTProxyMax v1.4.2-LTS, updating the pinned telemt engine from 3.5.14 to 3.5.16-84e5b82 fails when the pre-built image is unavailable and the script falls back to building from source.

The failure is deterministic and occurs before Rust compilation. The Dockerfile uses Bash-only substring expansion under Docker's default /bin/sh shell.

Steps to reproduce

  1. Run the MTProxyMax engine update (or Proxy Management → Start proxy) when the exact ghcr.io/samnet-dev/mtproxymax-telemt:3.5.16-84e5b82 image cannot be pulled.
  2. The script prints Pre-built image not available, compiling from source....
  3. The generated Dockerfile fails at the commit verification step.

Actual output

[i] Pulling pre-built telemt v3.5.16-84e5b82...
[!] Pre-built image not available, compiling from source...
[i] Compiling from source (first build takes a few minutes)...
=> ERROR [builder 5/6] RUN git checkout --detach "${TELEMT_COMMIT}" && test "$(git rev-parse HEAD | cut -c1-7)" = "${TELEMT_COMMIT:0:7}"
HEAD is now at 84e5b82 Merge pull request #964 from telemt/flow/3.5.16
/bin/sh: 1: Bad substitution
ERROR: failed to build: ... exit code: 2
[✗] Source build failed — ensure Docker has enough memory (2GB+)
[✗] Failed to build telemt image

Root cause

In build_telemt_image(), the generated Dockerfile contains:

RUN git checkout --detach "${TELEMT_COMMIT}" && test "$(git rev-parse HEAD | cut -c1-7)" = "${TELEMT_COMMIT:0:7}"

${TELEMT_COMMIT:0:7} is Bash-specific; RUN executes via /bin/sh -c by default (Debian's dash), which reports Bad substitution.

Suggested fix

Use POSIX-compatible syntax, for example:

RUN git checkout --detach "${TELEMT_COMMIT}" && \
    test "$(git rev-parse HEAD | cut -c1-7)" = "$(printf '%.7s' "$TELEMT_COMMIT")"

The error message about insufficient RAM is misleading for this failure mode; compilation never starts.

Impact

On the affected server, following the attempted update, the mtproxymax container was absent, the telemt listening port was unavailable, and the HAProxy backend reported no available server. Service was restored manually using the previously saved telemt 3.5.14 image and existing configuration.

It would also be helpful for the update/start workflow to retain or restore the previous working container/image if image retrieval/build fails, instead of leaving the service unavailable.

Expected: source fallback builds the pinned commit successfully, or safely aborts without disrupting the currently working proxy.

Activity

  1. mozgu13 commented on Nov 3, 2026

    @mozgu13

    I also had a problem with updating using AI. I restored functionality. Before compiling, you need to disable autoreset in the bot and on the server itself.

  2. Wyatt-Dian commented on Nov 5, 2026

    @Wyatt-Dian

    is there a way to fix it for people who are not an expert ?

    I am facing the same issue with several servers. I am installing it for the first time.

    Should we wait for the owner to fix the code?

  3. SamNet-dev commented on Nov 8, 2026

    @SamNet-dev
    Owner

    Hello @Krezi-777, @mozgu13, @Wyatt-Dian,

    Thank you for the detailed report and root-cause analysis!

    What Happened

    1. POSIX Dash Incompatibility in Dockerfile:
      During source-build fallback, the generated Dockerfile executed RUN ... test ... = "${TELEMT_COMMIT:0:7}". Because Docker executes RUN steps using Debian's /bin/sh (dash), the Bash-only parameter expansion ${var:0:7} failed immediately with /bin/sh: Bad substitution before Rust compilation could begin.
    2. Premature Proxy Teardown During Update:
      When build_telemt_image failed during an update, self_update() did not guard the subsequent container restart, causing restart_proxy_container to stop and remove the existing working proxy container before verifying that the new engine image was ready.

    Fixes Applied (Commit 981bb80):

    1. POSIX Truncation in Dockerfiles:
      Replaced ${TELEMT_COMMIT:0:7} with the POSIX-compliant builtin $(printf '%.7s' "${TELEMT_COMMIT}") in both mtproxymax.sh and .github/workflows/build-engine.yml. This works seamlessly across /bin/sh (dash), ash, bash, and busybox.
    2. Non-Destructive Update & Rebuild Safeguards:
      Added strict status checks in self_update(), rebuild, engine rebuild, and the TUI menu. If engine image acquisition or compilation fails, the update safely aborts with an error while leaving your current running proxy container and port listeners untouched.
    3. Diagnostic Error Messages:
      Replaced the speculative memory-limit error message with guidance directing operators to the actual docker build logs and prerequisites.
    4. Automated Pre-Built Engine Image:
      Dispatched GitHub Actions workflow run to compile and publish ghcr.io/samnet-dev/mtproxymax-telemt:3.5.16-84e5b82 and latest. Once published, mtproxymax update will pull the pre-built multi-arch binary in seconds without needing local compilation.

    Closing this issue as resolved. To update your installation:

    mtproxymax update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions