Skip to content

Commit 14505fc

Browse files
author
udhos
committed
Connect timeout.
1 parent 71c365b commit 14505fc

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

sha256-update.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ out=update-golang.sh.sha256
66
if hash $sum 2>/dev/null; then
77
$sum update-golang.sh > $out
88
else
9-
echo >&2 $0: missing $sum
9+
echo >&2 "$0: missing $sum"
1010
fi
1111

1212
echo $out

update-golang.sh

+37-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# ignore runtime environment variables
1010
# shellcheck disable=SC2153
11-
version=0.25
11+
version=0.26
1212

1313
set -o pipefail
1414

@@ -35,6 +35,7 @@ source=https://storage.googleapis.com/golang
3535
destination=/usr/local
3636
release=1.19 ;# just the default. the script detects the latest available release.
3737
arch_probe="uname -m"
38+
connect_timeout=5
3839

3940
os=$(uname -s | tr "[:upper:]" "[:lower:]")
4041

@@ -82,7 +83,8 @@ scan_versions() {
8283
debug scan_versions: from "$release_list"
8384
if has_cmd jq; then
8485
local rl="$release_list?mode=json"
85-
msg "parsing with jq from $rl"
86+
msg "scan_versions: fetch: $fetch $rl"
87+
msg "scan_versions: parsing with jq from $rl"
8688
$fetch "$rl" | jq -r '.[].files[].version' | sort | uniq | exclude_beta | sed -e 's/go//' | sort -V
8789
else
8890
$fetch "$release_list" | exclude_beta | grep -E -o 'go[0-9\.]+' | grep -E -o '[0-9]\.[0-9]+(\.[0-9]+)?' | sort -V | uniq
@@ -94,6 +96,14 @@ has_cmd() {
9496
hash "$1" 2>/dev/null
9597
}
9698

99+
has_wget() {
100+
[ -z "$SKIP_WGET" ] && has_cmd wget
101+
}
102+
103+
has_curl() {
104+
has_cmd curl
105+
}
106+
97107
tmp='' ;# will be set
98108
save_dir=$PWD
99109
previous_install='' ;# will be set
@@ -112,22 +122,32 @@ die() {
112122
exit 3
113123
}
114124

125+
wget_base() {
126+
echo wget --connect-timeout "$connect_timeout" "$FORCE_IPV4"
127+
}
128+
129+
curl_base() {
130+
echo curl --connect-timeout "$connect_timeout" "$FORCE_IPV4"
131+
}
132+
115133
find_latest() {
116134
debug find_latest: built-in version: "$release"
117135
debug find_latest: from "$release_list"
118136
local last=
119137
local fetch=
120-
if has_cmd wget; then
121-
fetch="wget -qO-"
122-
elif has_cmd curl; then
123-
fetch="curl --silent"
138+
if has_wget; then
139+
fetch="$(wget_base) -qO-"
140+
elif has_curl; then
141+
fetch="$(curl_base) --silent"
124142
else
125143
die "find_latest: missing both 'wget' and 'curl'"
126144
fi
127145
last=$(scan_versions "$fetch" | tail -1)
128146
if echo "$last" | grep -q -E '[0-9]\.[0-9]+(\.[0-9]+)?'; then
129147
msg find_latest: found last release: "$last"
130148
release=$last
149+
else
150+
msg find_latest: FAILED
131151
fi
132152
}
133153

@@ -147,11 +167,13 @@ fi
147167
cache=$destination
148168
[ -n "$CACHE" ] && cache=$CACHE
149169
[ -n "$PROFILED" ] && profiled=$PROFILED
170+
[ -n "$CONNECT_TIMEOUT" ] && connect_timeout=$CONNECT_TIMEOUT
150171

151172
show_vars() {
152173
echo user: "$(id)"
153174

154175
cat <<EOF
176+
155177
RELEASE_LIST=$release_list
156178
SOURCE=$source
157179
DESTINATION=$destination
@@ -163,6 +185,9 @@ PROFILED=$profiled
163185
CACHE=$cache
164186
GOPATH=$GOPATH
165187
DEBUG=$DEBUG
188+
FORCE_IPV4=$FORCE_IPV4 ;# set FORCE_IPV4=-4 to force IPv4
189+
CONNECT_TIMEOUT=$connect_timeout
190+
SKIP_WGET=$SKIP_WGET ;# set SKIP_WGET=1 to skip wget
166191
167192
EOF
168193
}
@@ -202,11 +227,13 @@ download() {
202227
if [ -f "$abs_filepath" ]; then
203228
msg no need to download - file cached: "$abs_filepath"
204229
else
205-
if has_cmd wget; then
206-
wget -O "$abs_filepath" "$url" || die could not download using wget from: "$url"
230+
if has_wget; then
231+
msg download: "$(wget_base)" -O "$abs_filepath" "$url"
232+
$(wget_base) -O "$abs_filepath" "$url" || die could not download using wget from: "$url"
207233
[ -f "$abs_filepath" ] || die missing file downloaded with wget: "$abs_filepath"
208-
elif has_cmd curl; then
209-
curl -o "$abs_filepath" "$url" || die could not download using curl from: "$url"
234+
elif has_curl; then
235+
msg download: "$(curl_base)" -o "$abs_filepath" "$url"
236+
$(curl_base) -o "$abs_filepath" "$url" || die could not download using curl from: "$url"
210237
[ -f "$abs_filepath" ] || die missing file downloaded with curl: "$abs_filepath"
211238
else
212239
die "download: missing both 'wget' and 'curl'"

update-golang.sh.sha256

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
285e1517e633618404b1a938e8122808348e41a720456a0376fc6b44bdb7f7a9 update-golang.sh
1+
907f142b15c6a12a48ae2d2fad361437da4d2b68aeff177b35e234ad68c2d30c update-golang.sh

0 commit comments

Comments
 (0)