Skip to content

Commit

Permalink
pkg: Ensure curl can be executed before checking mirrors as otherwi…
Browse files Browse the repository at this point in the history
…se all mirror checks will fail with `bad`

Curl can fail to execute due to linker issues:
`CANNOT LINK EXECUTABLE "curl": cannot locate symbol "SSL_set_value_uint" referenced by "/data/data/com.termux/files/usr/lib/libcurl.so"...`

Related issue termux/termux-app#4179
  • Loading branch information
agnostic-apollo committed Oct 16, 2024
1 parent 0ed48d4 commit a4461a0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/pkg.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ check_mirror() {
"$mirror/dists/stable/Release" >/dev/null 2>&1
}

check_command() {
local command="$1"

local errors
if ! errors="$("$@" 2>&1 1>/dev/null)"; then
echo "$errors" 1>&2
echo "Failed to run the '$command' command." 1>&2
if [[ "$errors" == *"CANNOT LINK EXECUTABLE"* ]]; then
echo -n "To fix the '$command' command, manually upgrade all packages by running: " 1>&2
case "$TERMUX_APP_PACKAGE_MANAGER" in
apt) echo "\`apt update && apt full-upgrade\`" 1>&2;;
pacman) echo "\`pacman -Syu\`" 1>&2;;
esac
fi
exit 1
fi
}

hostname() {
echo "$1" | awk -F'[/:]' '{print $4}'
}
Expand Down Expand Up @@ -185,6 +203,9 @@ select_mirror() {
mirrors+=($(find ${MIRROR_BASE_DIR}/{asia,chinese_mainland,europe,north_america,oceania,russia}/ -type f ! -name "*\.dpkg-old" ! -name "*\.dpkg-new" ! -name "*~"))
fi

# Ensure `curl` can execute, otherwise all mirror checks will fail with `bad`.
check_command curl --version

# Mirrors are rotated if 6 hours timeout has been passed or mirror is no longer accessible.
local pkgcache="@TERMUX_CACHE_DIR@/apt/pkgcache.bin"
if [ -e "$pkgcache" ] && (( $(last_modified "$pkgcache") <= 6 * 3600 )) && [ "$force_check_mirror" = "false" ]; then
Expand Down

0 comments on commit a4461a0

Please sign in to comment.