termux-tools: pkg: when checking mirrors, force terminate curl command after 6 seconds timeout

Before this, we had only '--connect-timeout 5' option specified but unfortunately
it doesn't work in cases when remote host is behind some proxy (e.g. CloudFlare)
but is not connected to Internet.

To prevent curl from hanging for unspecified amount of time, we need to introduce
external timeout here.
This commit is contained in:
Leonid Pliushch 2020-11-12 20:02:17 +02:00
parent d3e4aee6e2
commit d98a741ac6
2 changed files with 3 additions and 3 deletions

View File

@ -1,7 +1,7 @@
TERMUX_PKG_HOMEPAGE=https://termux.com/
TERMUX_PKG_DESCRIPTION="Basic system tools for Termux"
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_VERSION=0.96
TERMUX_PKG_VERSION=0.97
TERMUX_PKG_SKIP_SRC_EXTRACT=true
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_ESSENTIAL=true

View File

@ -63,7 +63,7 @@ select_mirror() {
if [ -n "$(find @TERMUX_CACHE_DIR@/apt/pkgcache.bin -mmin -360 2>/dev/null)" ]; then
if [ -n "${current_mirror}" ]; then
echo -n "Checking availability of current mirror: "
if curl --connect-timeout 5 --user-agent 'Termux-PKG/1.0 mirror-checker' --head --fail --location "${current_mirror%/}/dists/stable/Release" >/dev/null 2>&1; then
if timeout 6 curl --connect-timeout 5 --user-agent 'Termux-PKG/1.0 mirror-checker' --head --fail --location "${current_mirror%/}/dists/stable/Release" >/dev/null 2>&1; then
echo "ok"
return
else
@ -77,7 +77,7 @@ select_mirror() {
local w total_mirror_weight=0
for w in "${!mirrors[@]}"; do
echo -n "[*] ${mirrors[$w]}: "
if curl --connect-timeout 5 --user-agent 'Termux-PKG/1.0 mirror-checker' --head --fail --location "${mirrors[$w]%/}/dists/stable/Release" >/dev/null 2>&1; then
if timeout 6 curl --connect-timeout 5 --user-agent 'Termux-PKG/1.0 mirror-checker' --head --fail --location "${mirrors[$w]%/}/dists/stable/Release" >/dev/null 2>&1; then
echo "ok"
total_mirror_weight=$((total_mirror_weight + w))
else