From e2fb8484be22ff555204af2297f2032ea5c514d9 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Mon, 13 Jan 2025 22:39:38 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=B8=8B=E8=BD=BD=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E9=97=B4=E9=9A=94=205=20=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit link #234 --- trans.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/trans.sh b/trans.sh index 8ac2d35..c78a15a 100644 --- a/trans.sh +++ b/trans.sh @@ -99,10 +99,21 @@ is_have_cmd_on_disk() { return 1 } +is_num() { + echo "$1" | grep -Exq '[0-9]*\.?[0-9]*' +} + retry() { - max_try=$1 + local max_try=$1 shift + if is_num "$1"; then + local interval=$1 + shift + else + local interval=5 + fi + for i in $(seq $max_try); do if "$@"; then return @@ -111,7 +122,7 @@ retry() { if [ $i -ge $max_try ]; then return $ret fi - sleep 1 + sleep $interval fi done } @@ -166,7 +177,7 @@ download() { # --user-agent=Wget/1.21.1 \ echo "$url" - retry 5 stdbuf -oL -eL aria2c -x4 \ + retry 5 5 stdbuf -oL -eL aria2c -x4 \ --allow-overwrite=true \ --summary-interval=0 \ --max-tries 1 \