Skip to content

Commit 8abce88

Browse files
authored
Merge pull request #255 from KiraCore/release/v0.3.42
2 parents 0b6b92b + bad21f9 commit 8abce88

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Features:
22

3-
* auto-update cosign version
3+
* added timeout and retry to safeWget

bash-utils/bash-utils.sh

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function bashUtilsVersion() {
2626
# this is default installation script for utils
2727
# ./bash-utils.sh bashUtilsSetup "/var/kiraglob"
2828
function bashUtilsSetup() {
29-
local BASH_UTILS_VERSION="v0.3.41"
29+
local BASH_UTILS_VERSION="v0.3.42"
3030
local COSIGN_VERSION="v2.0.0"
3131
if [ "$1" == "version" ] ; then
3232
echo "$BASH_UTILS_VERSION"
@@ -652,12 +652,14 @@ function ipfsGet() {
652652
local file=""
653653
local url=""
654654
local timeout=""
655+
local tries=""
655656

656-
getArgs --gargs_throw=false --gargs_verbose=false "$1" "$2" "$3" "$4"
657+
getArgs --gargs_throw=false --gargs_verbose=false "$1" "$2" "$3" "$4" "$5"
657658

658659
[ -z "$file" ] && file="$1"
659-
[ -z "$cid" ] && cid="$2"
660-
[ -z $timeout ] && timeout="30"
660+
(! $(isCID "$cid")) && cid="$2"
661+
(! $(isNaturalNumber "$timeout")) && timeout=30
662+
(! $(isNaturalNumber "$tries")) && tries=2
661663

662664
local PUB_URL=""
663665
local DOWNLOAD_SUCCESS="false"
@@ -668,33 +670,39 @@ function ipfsGet() {
668670
if [ ! -z "$url" ] ; then
669671
PUB_URL="${url}/${cid}"
670672
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] && [[ $(urlContentLength "$PUB_URL" $timeout) -gt 1 ]] ) ; then
671-
wget --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ${url} :("
673+
wget --tries="$tries" --waitretry=1 --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && \
674+
DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ${url} :("
672675
fi
673676
fi
674677

675678
PUB_URL="https://gateway.ipfs.io/ipfs/${cid}"
676679
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] && [[ $(urlContentLength "$PUB_URL" $timeout) -gt 1 ]] ) ; then
677-
wget --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from gateway.ipfs.io :("
680+
wget --tries="$tries" --waitretry=1 --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && \
681+
DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from gateway.ipfs.io :("
678682
fi
679683

680684
PUB_URL="https://dweb.link/ipfs/${cid}"
681685
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] && [[ $(urlContentLength "$PUB_URL" $timeout) -gt 1 ]] ) ; then
682-
wget --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from dweb.link :("
686+
wget --tries="$tries" --waitretry=1 --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && \
687+
DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from dweb.link :("
683688
fi
684689

685690
PUB_URL="https://ipfs.joaoleitao.org/ipfs/${cid}"
686691
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] && [[ $(urlContentLength "$PUB_URL" $timeout) -gt 1 ]] ) ; then
687-
wget --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ipfs.joaoleitao.org :("
692+
wget --tries="$tries" --waitretry=1 --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && \
693+
DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ipfs.joaoleitao.org :("
688694
fi
689695

690696
PUB_URL="https://ipfs.kira.network/ipfs/${cid}"
691697
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] && [[ $(urlContentLength "$PUB_URL" $timeout) -gt 1 ]] ) ; then
692-
wget --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ipfs.kira.network :("
698+
wget --tries="$tries" --waitretry=1 --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && \
699+
DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ipfs.kira.network :("
693700
fi
694701

695702
PUB_URL="https://ipfs.snggle.com/ipfs/${cid}"
696703
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] && [[ $(urlContentLength "$PUB_URL" $timeout) -gt 1 ]] ) ; then
697-
wget --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ipfs.snggle.com :("
704+
wget --tries="$tries" --waitretry=1 --timeout="$timeout" --user-agent="$UBUNTU_AGENT" "$PUB_URL" -O "$file" && \
705+
DOWNLOAD_SUCCESS="true" || echoWarn "WARNING: Faild download from ipfs.snggle.com :("
698706
fi
699707

700708
if ( [ "$DOWNLOAD_SUCCESS" != "true" ] || [ ! -f "$file" ] ) ; then
@@ -716,9 +724,19 @@ function ipfsGet() {
716724
# safeWget <file> <url> <hash>,<hash>,<hash>...
717725
# safeWget <file> <url> <CID>
718726
function safeWget() {
719-
local OUT_PATH=$1
720-
local FILE_URL=$2
721-
local EXPECTED_HASH=$3
727+
local OUT_PATH="$1"
728+
local FILE_URL="$2"
729+
local EXPECTED_HASH="$3"
730+
local timeout=""
731+
local sig_timeout=""
732+
local waitretry=""
733+
local tries=""
734+
getArgs --gargs_throw=false --gargs_verbose=false "$1" "$2" "$3" "$4" "$5" "$6" "$7"
735+
736+
(! $(isNaturalNumber "$timeout")) && timeout=900
737+
(! $(isNaturalNumber "$sig_timeout")) && sig_timeout=30
738+
(! $(isNaturalNumber "$waitretry")) && waitretry=1
739+
(! $(isNaturalNumber "$tries")) && tries=2
722740

723741
# we need to use MD5 for TMP files to ensure that we download the file again if URL changes
724742
local OUT_NAME=$(echo "$OUT_PATH" | md5)
@@ -749,7 +767,7 @@ function safeWget() {
749767
if ($(isCID "$EXPECTED_HASH_FIRST")) ; then
750768
echoInfo "INFO: Detected IPFS CID, searching available gatewys..."
751769
COSIGN_PUB_KEY="$TMP_PATH_PUB"
752-
ipfsGet --file="$COSIGN_PUB_KEY" --cid="$EXPECTED_HASH_FIRST" --timeout="30"
770+
ipfsGet --file="$COSIGN_PUB_KEY" --cid="$EXPECTED_HASH_FIRST" --timeout="$sig_timeout"
753771

754772
if ($(isFileEmpty $COSIGN_PUB_KEY)); then
755773
echoErr "ERROR: Failed to locate or download public key file '$EXPECTED_HASH_FIRST' from any public IPFS gateway :("
@@ -762,7 +780,7 @@ function safeWget() {
762780

763781
if (! $(isFileEmpty $COSIGN_PUB_KEY)) || ($(urlExists "$COSIGN_PUB_KEY")) ; then
764782
echoWarn "WARNING: Attempting to fetch signature file..."
765-
wget --user-agent="$UBUNTU_AGENT" "$SIG_URL" -O $TMP_PATH_SIG
783+
wget --timeout="$sig_timeout" --tries="$tries" --waitretry=1 --user-agent="$UBUNTU_AGENT" "$SIG_URL" -O $TMP_PATH_SIG
766784
else
767785
echoErr "ERROR: Public key was not found in '$COSIGN_PUB_KEY'"
768786
return 1
@@ -801,7 +819,7 @@ function safeWget() {
801819

802820
if [ "$HASH_MATCH" == "false" ] ; then
803821
rm -fv $OUT_PATH
804-
wget --user-agent="$UBUNTU_AGENT" "$FILE_URL" -O $TMP_PATH
822+
wget --timeout="$timeout" --tries="$tries" --waitretry=1 --user-agent="$UBUNTU_AGENT" "$FILE_URL" -O $TMP_PATH
805823
[ "$TMP_PATH" != "$OUT_PATH" ] && cp -fv $TMP_PATH $OUT_PATH
806824
FILE_HASH=$(sha256 $OUT_PATH)
807825
fi
@@ -2241,7 +2259,7 @@ fileFollow() {
22412259
if (! $(isFileEmpty "$file")) ; then
22422260
trap fileFollowInt INT
22432261
trap fileFollowErr ERR
2244-
tail -n 1000 -f "$file" &
2262+
tail -n 2147483646 -f "$file" &
22452263
pid=$!
22462264

22472265
pressToContinue "q"

scripts/version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
echo "v0.3.41"
3+
echo "v0.3.42"

0 commit comments

Comments
 (0)