feat: auto-repair missing dependencies on start#7
Conversation
There was a problem hiding this comment.
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 reinstallstep forproot,glibc, andca-certificateswhen binary execution fails. - Removes installed binaries and the
~/.local/agydirectory before retrying. - Re-runs the
--versioncheck and only dies if the retry also fails.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| rm -f ~/.local/bin/agy ~/.local/bin/agy.va39 | ||
| rm -rf ~/.local/agy |
There was a problem hiding this comment.
@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.
| 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 |
There was a problem hiding this comment.
@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.
| 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 |
There was a problem hiding this comment.
@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.
|
@wallentx A quick heads up regarding the Copilot AI review on PR: please don't rely on it! Copilot hallucinates |
|
@wallentx Can you please review this PR and merge it if everything looks good? Thanks 🙂 |
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, orca-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
pkg reinstallfor the required packages (proot,glibc,ca-certificates). This forces Termux to repair corrupted libraries even if it thinks they are already installed.pkg upgrade(using--force-confdef --force-confoldto avoid blocking user prompts) followed by another repair pass.~/.local/binand 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.
pkg reinstallcorrectly acts as an installation command if the package is entirely missing.libc.so.6library. The script successfully detected the resulting binary execution failure, initiated the repair sequence, and fully restored the corrupted library.pkgcommand to deliberately intercept and block the initialpkg reinstall, verifying that the script successfully detects the persisting failure, moves to the deeppkg upgradefallback, 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