8
8
9
9
# ignore runtime environment variables
10
10
# shellcheck disable=SC2153
11
- version=0.25
11
+ version=0.26
12
12
13
13
set -o pipefail
14
14
@@ -35,6 +35,7 @@ source=https://storage.googleapis.com/golang
35
35
destination=/usr/local
36
36
release=1.19 ; # just the default. the script detects the latest available release.
37
37
arch_probe=" uname -m"
38
+ connect_timeout=5
38
39
39
40
os=$( uname -s | tr " [:upper:]" " [:lower:]" )
40
41
@@ -82,7 +83,8 @@ scan_versions() {
82
83
debug scan_versions: from " $release_list "
83
84
if has_cmd jq; then
84
85
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 "
86
88
$fetch " $rl " | jq -r ' .[].files[].version' | sort | uniq | exclude_beta | sed -e ' s/go//' | sort -V
87
89
else
88
90
$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() {
94
96
hash " $1 " 2> /dev/null
95
97
}
96
98
99
+ has_wget () {
100
+ [ -z " $SKIP_WGET " ] && has_cmd wget
101
+ }
102
+
103
+ has_curl () {
104
+ has_cmd curl
105
+ }
106
+
97
107
tmp=' ' ; # will be set
98
108
save_dir=$PWD
99
109
previous_install=' ' ; # will be set
@@ -112,22 +122,32 @@ die() {
112
122
exit 3
113
123
}
114
124
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
+
115
133
find_latest () {
116
134
debug find_latest: built-in version: " $release "
117
135
debug find_latest: from " $release_list "
118
136
local last=
119
137
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"
124
142
else
125
143
die " find_latest: missing both 'wget' and 'curl'"
126
144
fi
127
145
last=$( scan_versions " $fetch " | tail -1)
128
146
if echo " $last " | grep -q -E ' [0-9]\.[0-9]+(\.[0-9]+)?' ; then
129
147
msg find_latest: found last release: " $last "
130
148
release=$last
149
+ else
150
+ msg find_latest: FAILED
131
151
fi
132
152
}
133
153
147
167
cache=$destination
148
168
[ -n " $CACHE " ] && cache=$CACHE
149
169
[ -n " $PROFILED " ] && profiled=$PROFILED
170
+ [ -n " $CONNECT_TIMEOUT " ] && connect_timeout=$CONNECT_TIMEOUT
150
171
151
172
show_vars () {
152
173
echo user: " $( id) "
153
174
154
175
cat << EOF
176
+
155
177
RELEASE_LIST=$release_list
156
178
SOURCE=$source
157
179
DESTINATION=$destination
@@ -163,6 +185,9 @@ PROFILED=$profiled
163
185
CACHE=$cache
164
186
GOPATH=$GOPATH
165
187
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
166
191
167
192
EOF
168
193
}
@@ -202,11 +227,13 @@ download() {
202
227
if [ -f " $abs_filepath " ]; then
203
228
msg no need to download - file cached: " $abs_filepath "
204
229
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 "
207
233
[ -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 "
210
237
[ -f " $abs_filepath " ] || die missing file downloaded with curl: " $abs_filepath "
211
238
else
212
239
die " download: missing both 'wget' and 'curl'"
0 commit comments