Skip to content

feat: auto-repair missing dependencies on start#7

Open
Brajesh2022 wants to merge 2 commits into
wallentx:devfrom
Brajesh2022:fix-auto-repair
Open

feat: auto-repair missing dependencies on start#7
Brajesh2022 wants to merge 2 commits into
wallentx:devfrom
Brajesh2022:fix-auto-repair

Conversation

@Brajesh2022
Copy link
Copy Markdown

@Brajesh2022 Brajesh2022 commented May 28, 2026

Context & Motivation

Many users have been reporting execution failures during the final stage of the installation. Upon investigation, I discovered these failures were consistently caused by broken or missing Termux dependencies (such as glibc, proot, or ca-certificates).

In some cases, the dependencies were simply missing. In more stubborn cases, the installer (or Termux package manager) detected the dependency as "already installed" and skipped reinstalling it, even though the underlying libraries were corrupted. To solve this permanently, I added a multi-layered auto-repair system.

Changes Included

  1. Initial Auto-Repair: If the standalone binary fails to execute, the script automatically triggers a pkg reinstall for the required packages (proot, glibc, ca-certificates). This forces Termux to repair corrupted libraries even if it thinks they are already installed.
  2. Deep Update Fallback: If the first repair fails (which can happen if the local package cache is severely desynced), a secondary fallback is triggered. It performs a completely headless pkg upgrade (using --force-confdef --force-confold to avoid blocking user prompts) followed by another repair pass.
  3. Legacy Conflict Resolution: The repair block actively removes old/conflicting binaries from ~/.local/bin and clears the shell cache (hash -r) so the system reliably executes the new installation in $PREFIX/bin.

Testing & Verification

I deliberately corrupted my own Termux environment to ensure the auto-repair functions precisely as intended.

  • Missing Dependency Test: I verified that pkg reinstall correctly acts as an installation command if the package is entirely missing.
  • Corrupted Dependency Test: I manually corrupted the crucial libc.so.6 library. The script successfully detected the resulting binary execution failure, initiated the repair sequence, and fully restored the corrupted library.
  • Stubborn Failure Simulation: I created a wrapper around the pkg command to deliberately intercept and block the initial pkg reinstall, verifying that the script successfully detects the persisting failure, moves to the deep pkg upgrade fallback, and successfully repairs the binary on the second pass.

To test this fix locally, you can run:

curl -fsSL https://raw.githubusercontent.com/Brajesh2022/antigravity-cli-termux/fix-auto-repair/install.sh | bash

Copilot AI review requested due to automatic review settings May 28, 2026 06:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a dependency repair fallback when the installed agy binary fails to execute, attempting to reinstall key packages and retrying the version check before failing.

Changes:

  • Adds an automatic pkg reinstall step for proot, glibc, and ca-certificates when binary execution fails.
  • Removes installed binaries and the ~/.local/agy directory before retrying.
  • Re-runs the --version check and only dies if the retry also fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install.sh
Comment on lines +320 to +321
rm -f ~/.local/bin/agy ~/.local/bin/agy.va39
rm -rf ~/.local/agy
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Copilot missed the context here. If you look at line 8 of this script, "$INSTALL_BIN_DIR" is explicitly defined as "$PREFIX/bin" (which resolves to "/data/data/com.termux/files/usr/bin"). The "rm -f ~/.local/bin/agy" command targets an entirely different path and exists solely to remove legacy installations that could shadow the new binary through "$PATH" precedence. It does not remove the binary that was just installed.

Comment thread install.sh
rm -f "$INSTALL_BIN_DIR/agy" "$INSTALL_BIN_DIR/agy.va39"
die "Binaries failed to execute locally. Check dependencies."
info "Binary failed. Attempting dependency repair..."
pkg reinstall -y proot glibc ca-certificates >/dev/null 2>&1 || true
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This suggestion is invalid because the script already performs an environment validation at startup (lines 237-241), including both "[[ -d /data/data/com.termux ]]" and "command -v pkg || die". Reaching this repair block without "pkg" being available is therefore impossible.

Comment thread install.sh
die "Binaries failed to execute locally. Check dependencies."
info "Binary failed. Attempting dependency repair..."
pkg reinstall -y proot glibc ca-certificates >/dev/null 2>&1 || true
rm -f ~/.local/bin/agy ~/.local/bin/agy.va39
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This suggestion is incorrect because it fails to distinguish between the cleanup target and the installation target. "~/.local/bin" is intentionally hardcoded because the script is specifically removing obsolete legacy installations from that exact location. Replacing it with "$INSTALL_BIN_DIR" would cause the script to delete the freshly installed binary immediately before validation, introducing a fatal bug.

@Brajesh2022
Copy link
Copy Markdown
Author

Brajesh2022 commented May 28, 2026

@wallentx A quick heads up regarding the Copilot AI review on PR: please don't rely on it! Copilot hallucinates
I'd highly recommend using Google Gemini Code Assist GitHub Review instead! I've been using it and it's significantly better. It actually finds real bugs and understands full file context rather than producing hallucinations like this one.

Copilot AI review requested due to automatic review settings May 28, 2026 07:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@Brajesh2022
Copy link
Copy Markdown
Author

@wallentx Can you please review this PR and merge it if everything looks good? Thanks 🙂

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants