这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Nov 8, 2025

  • ​"This change adds a function to termux-info to check if the Termux APK installed is the latest version available from the official source (GITHUB or F_DROID)."

  • ​"This is helpful for debugging and troubleshooting, ensuring users report issues using the latest version of the application."

  • "Dependencies curl and jq are handled gracefully; the check is skipped if they are missing."

fi

# Check if TERMUX_VERSION and TERMUX_APK_RELEASE are available
if [ -z "${TERMUX_VERSION:-}" ] || [ -z "${TERMUX_APK_RELEASE:-}" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

After this commit, TERMUX_APK_RELEASE does not exist anymore:

termux/termux-app@afc06cf

Copy link
Member

@TomJo2000 TomJo2000 left a comment

Choose a reason for hiding this comment

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

This could use some refactoring but the general concept is good.

I should also ask this now rather than later...
If you have used AI in order to write all or part of this PR that should be disclosed so we can properly evaluate your contribution.
I am not trying to accuse you of anything, or dismiss your work, parts of it just come off as vaguely AI generated.
https://en.wikipedia.org/wiki/Wikipedia:Signs_of_AI_writing

Comment on lines 26 to 29
if ! command -v curl &> /dev/null || ! command -v jq &> /dev/null; then
echo "Warning: 'curl' or 'jq' not found. Install with 'pkg install curl jq' to enable this feature."
return
fi
Copy link
Member

Choose a reason for hiding this comment

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

This can be more specific than just "either or is missing".
It should say jq is missing, or curl is missing.
Or both.
Why are we lumping these together?

Comment on lines 31 to 35
# Check if TERMUX_VERSION and TERMUX_APK_RELEASE are available
if [ -z "${TERMUX_VERSION:-}" ] || [ -z "${TERMUX_APK_RELEASE:-}" ]; then
echo "Info: TERMUX_VERSION or TERMUX_APK_RELEASE not set. APK check skipped."
return
fi
Copy link
Member

Choose a reason for hiding this comment

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

Again, this is very non-specific about what the error is actually caused by.
And why it is an error in the first place.

Comment on lines 46 to 83
if [[ "$TERMUX_APK_RELEASE" == "GITHUB" ]]; then
URL_API="https://api.github.com/repos/termux/termux-app/releases/latest"
DOWNLOAD_URL="https://github.com/termux/termux-app/releases/latest"

# Fetch latest release data from GitHub API.
RELEASE_DATA=$(curl --fail -s "$URL_API")

# Check curl success status
if [ $? -ne 0 ]; then
echo "# API URL Source: $URL_API"
echo "[!] Failed to connect to the internet or fetch $SOURCE_NAME release data."
return
fi

# Extract version tag using jq.
LATEST_VERSION=$(echo "$RELEASE_DATA" | jq -r '.tag_name' | sed 's/^v//')

elif [[ "$TERMUX_APK_RELEASE" == "F_DROID" ]]; then
URL_API="https://f-droid.org/api/v1/packages/com.termux"
DOWNLOAD_URL="https://f-droid.org/en/packages/com.termux"

# Fetch latest release data from F-Droid API
RELEASE_DATA=$(curl --fail -s "$URL_API")

# Check curl success status
if [ $? -ne 0 ]; then
echo "# API URL Source: $URL_API"
echo "[!] Failed to connect to the internet or fetch $SOURCE_NAME release data."
return
fi

# Find versionName matching suggestedVersionCode
LATEST_VERSION=$(echo "$RELEASE_DATA" | \
jq -r '. as $data | $data.packages[] | select(.versionCode == $data.suggestedVersionCode) | .versionName')
else
echo "Info: Termux APK Source ('$TERMUX_APK_RELEASE') is unknown. Check skipped."
return
fi
Copy link
Member

Choose a reason for hiding this comment

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

Consider using a case statement for this and deduplicating the code to avoid issues from appearing in one codepath or the other.

Comment on lines 68 to 75
RELEASE_DATA=$(curl --fail -s "$URL_API")

# Check curl success status
if [ $? -ne 0 ]; then
echo "# API URL Source: $URL_API"
echo "[!] Failed to connect to the internet or fetch $SOURCE_NAME release data."
return
fi
Copy link
Member

Choose a reason for hiding this comment

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

Instead of relying on $? you can just put the assignment in place of the condition.

if ! RELEASE_DATA=$(curl --fail -s "$URL_API"); then
    # [...]
fi

This has the same effect and can't be broken by interjecting another command in between the assignment and the error code check.

"
fi
# ADDED APK UPDATE CHECK HERE
Copy link
Member

Choose a reason for hiding this comment

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

This is not a comment, it is reproduced as part of the string.

# --- VERSION COMPARISON LOGIC ---

# Check if version extraction failed or returned null/empty
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" == "null" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

Please consider using [[ ]] bash test instead of [ ] old test.
It is more clearly defined, and supports || as an internal operator.
e.g.

  if [[ -z "$LATEST_VERSION" || "$LATEST_VERSION" == "null" ]]; then

We haven't been rigorous about that in this script in the past, but it's nice to use as the preferred test syntax going forward.

fi

# Extract version tag using jq.
LATEST_VERSION=$(echo "$RELEASE_DATA" | jq -r '.tag_name' | sed 's/^v//')
Copy link
Member

Choose a reason for hiding this comment

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

<<< (herestrings) may be used as a substitute for echo here.

Suggested change
LATEST_VERSION=$(echo "$RELEASE_DATA" | jq -r '.tag_name' | sed 's/^v//')
LATEST_VERSION=$(jq -r '.tag_name' <<< "$RELEASE_DATA" | sed 's/^v//')

Create a new local variable:
local TERMUX_SOURCE="${TERMUX_APP__APK_RELEASE:-$TERMUX_APK_RELEASE}"
If the new name `TERMUX_APP__APK_RELEASE` variable exists, use it.
Otherwise, use the old name `TERMUX_APK_RELEASE` variable as a fallback.

- Separated curl and jq checking to make error messages more specific.
- Using case statements to condense and de-duplicate API data retrieval code, avoiding repeating if/elif blocks.
- Use the recommended syntax: if ! RELEASE_DATA=$(curl ...); then ... for more reliable error handling.
- Replace echo "..." | jq ... with the more modern herestring (<<<): jq ... <<< "$RELEASE_DATA".
- Consider using the bash [[...]] test instead of the old [...] test. Its definition is clearer, and it supports the internal || operator.
@ghost
Copy link
Author

ghost commented Nov 8, 2025

Hi @TomJo2000 and @robertkirkman , thank you very much for your detailed reviews and valuable suggestions and feedback! I have implemented all the requested changes.

Create a new local variable:
local TERMUX_SOURCE="${TERMUX_APP__APK_RELEASE:-$TERMUX_APK_RELEASE}"
If the new name TERMUX_APP__APK_RELEASE variable exists, use it. Otherwise, use the old name TERMUX_APK_RELEASE variable as a fallback.

  • Separated curl and jq checking to make error messages more specific.
  • Using case statements to condense and de-duplicate API data retrieval code, avoiding repeating if/elif blocks.
  • Use the recommended syntax: if ! RELEASE_DATA=$(curl ...); then ... for more reliable error handling.
  • Replace echo "..." | jq ... with the more modern herestring (<<<): jq ... <<< "$RELEASE_DATA".
  • Consider using the bash [[...]] test instead of the old [...] test. Its definition is clearer, and it supports the internal || operator.

Regarding the disclosure of the use of AI, I was in too much of a hurry to mention it. I really appreciate it; it's been my responsibility to be transparent from the start.

The answer is Yes, I used a large AI language model assistant to partially structure the initial function and explanatory text, but the core logic, Termux variable handling, and all subsequent refactorings, based on your specifics (such as case statements, [[...]], and TERMUX_APP__APK_RELEASE fixes), I have tried to understand and learn as much as I can to the best of my ability, then implemented them manually.
Let me know if there are any other issues!

@ghost ghost requested a review from TomJo2000 November 9, 2025 05:11
@ghost ghost closed this by deleting the head repository Nov 10, 2025
This pull request was closed.
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