-
Notifications
You must be signed in to change notification settings - Fork 158
termux-info: Add Termux APK update status check (Requires curl and jq) #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
scripts/termux-info.in
Outdated
| fi | ||
|
|
||
| # Check if TERMUX_VERSION and TERMUX_APK_RELEASE are available | ||
| if [ -z "${TERMUX_VERSION:-}" ] || [ -z "${TERMUX_APK_RELEASE:-}" ]; then |
There was a problem hiding this comment.
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:
TomJo2000
left a comment
There was a problem hiding this 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
scripts/termux-info.in
Outdated
| 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 |
There was a problem hiding this comment.
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?
scripts/termux-info.in
Outdated
| # 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 |
There was a problem hiding this comment.
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.
scripts/termux-info.in
Outdated
| 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 |
There was a problem hiding this comment.
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.
scripts/termux-info.in
Outdated
| 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 |
There was a problem hiding this comment.
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
# [...]
fiThis has the same effect and can't be broken by interjecting another command in between the assignment and the error code check.
scripts/termux-info.in
Outdated
| " | ||
| fi | ||
| # ADDED APK UPDATE CHECK HERE |
There was a problem hiding this comment.
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.
scripts/termux-info.in
Outdated
| # --- VERSION COMPARISON LOGIC --- | ||
|
|
||
| # Check if version extraction failed or returned null/empty | ||
| if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" == "null" ]; then |
There was a problem hiding this comment.
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" ]]; thenWe 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.
scripts/termux-info.in
Outdated
| fi | ||
|
|
||
| # Extract version tag using jq. | ||
| LATEST_VERSION=$(echo "$RELEASE_DATA" | jq -r '.tag_name' | sed 's/^v//') |
There was a problem hiding this comment.
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.
| 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.
|
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:
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. |
"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."