Keep installer wget timeouts portable

This commit is contained in:
ushan0v
2026-07-12 16:05:06 +03:00
parent 5af3aaddaf
commit bcb9794cb9
2 changed files with 41 additions and 6 deletions
+24 -2
View File
@@ -119,10 +119,32 @@ detect_fetcher() {
fail "wget or curl is required to download Forkop"
}
run_with_deadline() {
forkop_deadline_seconds="$1"
shift
"$@" &
forkop_deadline_command_pid=$!
(
trap 'kill "$forkop_deadline_sleep_pid" 2>/dev/null || true; exit 0' TERM INT
sleep "$forkop_deadline_seconds" &
forkop_deadline_sleep_pid=$!
wait "$forkop_deadline_sleep_pid"
kill "$forkop_deadline_command_pid" 2>/dev/null || true
) &
forkop_deadline_watchdog_pid=$!
wait "$forkop_deadline_command_pid"
forkop_deadline_status=$?
kill "$forkop_deadline_watchdog_pid" 2>/dev/null || true
wait "$forkop_deadline_watchdog_pid" 2>/dev/null || true
return "$forkop_deadline_status"
}
http_get() {
case "$FETCHER" in
wget)
wget -T "$METADATA_TIMEOUT_SECONDS" -t 1 -qO- "$1"
run_with_deadline "$METADATA_TIMEOUT_SECONDS" wget -T "$CONNECT_TIMEOUT_SECONDS" -qO- "$1"
;;
curl)
curl --connect-timeout "$CONNECT_TIMEOUT_SECONDS" --max-time "$METADATA_TIMEOUT_SECONDS" -fsSL "$1"
@@ -2497,7 +2519,7 @@ install_json_ucode() {
download_file_once() {
case "$FETCHER" in
wget)
wget -T "$DOWNLOAD_TIMEOUT_SECONDS" -t 1 -q -O "$2" "$1"
run_with_deadline "$DOWNLOAD_TIMEOUT_SECONDS" wget -T "$CONNECT_TIMEOUT_SECONDS" -q -O "$2" "$1"
;;
curl)
curl --connect-timeout "$CONNECT_TIMEOUT_SECONDS" --max-time "$DOWNLOAD_TIMEOUT_SECONDS" -fsSL "$1" -o "$2"
+17 -4
View File
@@ -20,10 +20,23 @@ fail() {
[ -r "$INSTALLER" ] || fail "install.sh is missing"
grep -Fq 'wget -T "$METADATA_TIMEOUT_SECONDS" -t 1 -qO-' "$INSTALLER" ||
fail "installer wget metadata requests must have a timeout and no hidden retries"
grep -Fq 'wget -T "$DOWNLOAD_TIMEOUT_SECONDS" -t 1 -q -O' "$INSTALLER" ||
fail "installer wget downloads must have a timeout and no hidden retries"
grep -Fq 'run_with_deadline "$METADATA_TIMEOUT_SECONDS" wget -T "$CONNECT_TIMEOUT_SECONDS" -qO-' "$INSTALLER" ||
fail "installer wget metadata requests must have portable connect and total timeouts"
grep -Fq 'run_with_deadline "$DOWNLOAD_TIMEOUT_SECONDS" wget -T "$CONNECT_TIMEOUT_SECONDS" -q -O' "$INSTALLER" ||
fail "installer wget downloads must have portable connect and total timeouts"
if grep -n -E 'wget.*[[:space:]]-t([[:space:]]|$)' "$INSTALLER" >/dev/null; then
fail "installer wget commands must not use the unsupported OpenWrt -t option"
fi
eval "$(sed -n '/^run_with_deadline()/,/^}/p' "$INSTALLER")"
deadline_started="$(date +%s)"
if run_with_deadline 1 sh -c 'sleep 5'; then
fail "installer deadline watchdog must fail a command that exceeds its deadline"
fi
deadline_elapsed="$(($(date +%s) - deadline_started))"
[ "$deadline_elapsed" -lt 4 ] ||
fail "installer deadline watchdog did not stop the command promptly"
run_with_deadline 3 sh -c 'exit 0' ||
fail "installer deadline watchdog must preserve successful command status"
grep -Fq 'curl --connect-timeout "$CONNECT_TIMEOUT_SECONDS" --max-time "$METADATA_TIMEOUT_SECONDS"' "$INSTALLER" ||
fail "installer curl metadata requests must have connect and total timeouts"
grep -Fq 'curl --connect-timeout "$CONNECT_TIMEOUT_SECONDS" --max-time "$DOWNLOAD_TIMEOUT_SECONDS"' "$INSTALLER" ||