1
+ #! /bin/sh
2
+ set -e
3
+ # Code generated by godownloader. DO NOT EDIT.
4
+ #
5
+
6
+ usage () {
7
+ this=$1
8
+ cat << EOF
9
+ $this : download go binaries for saucelabs/saucectl
10
+
11
+ Usage: $this [-b] bindir [tag]
12
+ -b sets bindir or installation directory, Defaults to ./bin
13
+ [tag] is a tag from
14
+ https://github.com/saucelabs/saucectl/releases
15
+ If tag is missing, then an attempt to find the latest will be found.
16
+
17
+ Consider setting GITHUB_TOKEN to avoid triggering GitHub rate limits.
18
+ See the following for more details:
19
+ https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
20
+
21
+ Generated by godownloader
22
+ https://github.com/goreleaser/godownloader
23
+
24
+ EOF
25
+ exit 2
26
+ }
27
+
28
+ parse_args () {
29
+ # BINDIR is ./bin unless set be ENV
30
+ # over-ridden by flag below
31
+
32
+ BINDIR=${BINDIR:- ./ bin}
33
+ while getopts " b:h?" arg; do
34
+ case " $arg " in
35
+ b) BINDIR=" $OPTARG " ;;
36
+ h | \? ) usage " $0 " ;;
37
+ esac
38
+ done
39
+ shift $(( OPTIND - 1 ))
40
+ TAG=$1
41
+ }
42
+ # this function wraps all the destructive operations
43
+ # if a curl|bash cuts off the end of the script due to
44
+ # network, either nothing will happen or will syntax error
45
+ # out preventing half-done work
46
+ execute () {
47
+ TMPDIR=$( mktmpdir)
48
+ log_debug " downloading tarball ${TARBALL_URL} "
49
+ http_download " ${TMPDIR} /${TARBALL} " " ${TARBALL_URL} "
50
+ log_debug " downloading checksum ${CHECKSUM_URL} "
51
+ http_download " ${TMPDIR} /${CHECKSUM} " " ${CHECKSUM_URL} "
52
+ hash_sha256_verify " ${TMPDIR} /${TARBALL} " " ${TMPDIR} /${CHECKSUM} "
53
+
54
+ (cd " ${TMPDIR} " && untar " ${TARBALL} " )
55
+ install -d " ${BINDIR} "
56
+ install " ${TMPDIR} /${BINARY} " " ${BINDIR} /"
57
+ log_info " installed as ${BINDIR} /${BINARY} "
58
+ }
59
+ is_supported_platform () {
60
+ platform=$1
61
+ found=1
62
+ case " $platform " in
63
+ darwin/amd64) found=0 ;;
64
+ linux/amd64) found=0 ;;
65
+ windows/amd64) found=0 ;;
66
+ esac
67
+ case " $platform " in
68
+ darwin/386) found=1 ;;
69
+ windows/386) found=1 ;;
70
+ esac
71
+ return $found
72
+ }
73
+ check_platform () {
74
+ if is_supported_platform " $PLATFORM " ; then
75
+ # optional logging goes here
76
+ true
77
+ else
78
+ log_crit " platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX} /issues/new"
79
+ exit 1
80
+ fi
81
+ }
82
+ tag_to_version () {
83
+ if [ -z " ${TAG} " ]; then
84
+ log_info " checking GitHub for latest tag"
85
+ TAG=$( github_last_release " $OWNER /$REPO " )
86
+ fi
87
+ # if version starts with 'v', remove it
88
+ VERSION=${TAG# v}
89
+ }
90
+ adjust_format () {
91
+ # change format (tar.gz or zip) based on ARCH
92
+ true
93
+ }
94
+ adjust_os () {
95
+ # adjust archive name based on OS
96
+ case ${OS} in
97
+ 386) OS=32bit ;;
98
+ amd64) OS=64bit ;;
99
+ darwin) OS=mac ;;
100
+ esac
101
+ true
102
+ }
103
+ adjust_arch () {
104
+ # adjust archive name based on ARCH
105
+ case ${ARCH} in
106
+ 386) ARCH=32bit ;;
107
+ amd64) ARCH=64bit ;;
108
+ darwin) ARCH=mac ;;
109
+ esac
110
+ true
111
+ }
112
+
113
+ cat /dev/null << EOF
114
+ ------------------------------------------------------------------------
115
+ https://github.com/saucelabs/saucectl - portable posix shell functions
116
+ Public domain - http://unlicense.org
117
+ https://github.com/saucelabs/saucectl/blob/master/LICENSE
118
+ but credit (and pull requests) appreciated.
119
+ ------------------------------------------------------------------------
120
+ EOF
121
+ is_command () {
122
+ command -v " $1 " > /dev/null
123
+ }
124
+ echoerr () {
125
+ echo " $@ " 1>&2
126
+ }
127
+ log_prefix () {
128
+ echo " $0 "
129
+ }
130
+ _logp=6
131
+ log_set_priority () {
132
+ _logp=" $1 "
133
+ }
134
+ log_priority () {
135
+ if test -z " $1 " ; then
136
+ echo " $_logp "
137
+ return
138
+ fi
139
+ [ " $1 " -ge " $_logp " ]
140
+ }
141
+ log_debug () {
142
+ log_priority 7 && echoerr " $( log_prefix) " " DEBUG" " $@ "
143
+ }
144
+ log_info () {
145
+ log_priority 6 && echoerr " $( log_prefix) " " INFO" " $@ "
146
+ }
147
+ log_err () {
148
+ log_priority 3 && echoerr " $( log_prefix) " " ERR" " $@ "
149
+ }
150
+ log_crit () {
151
+ log_priority 2 && echoerr " $( log_prefix) " " CRIT" " $@ "
152
+ }
153
+ uname_os () {
154
+ os=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
155
+ case " $os " in
156
+ msys_nt) os=" windows" ;;
157
+ esac
158
+ echo " $os "
159
+ }
160
+ uname_arch () {
161
+ arch=$( uname -m)
162
+ case $arch in
163
+ x86_64) arch=" amd64" ;;
164
+ x86) arch=" 386" ;;
165
+ i686) arch=" 386" ;;
166
+ i386) arch=" 386" ;;
167
+ aarch64) arch=" arm64" ;;
168
+ armv5* ) arch=" arm5" ;;
169
+ armv6* ) arch=" arm6" ;;
170
+ armv7* ) arch=" arm7" ;;
171
+ esac
172
+ echo ${arch}
173
+ }
174
+ uname_os_check () {
175
+ os=$( uname_os)
176
+ case " $os " in
177
+ darwin) return 0 ;;
178
+ dragonfly) return 0 ;;
179
+ freebsd) return 0 ;;
180
+ linux) return 0 ;;
181
+ android) return 0 ;;
182
+ nacl) return 0 ;;
183
+ netbsd) return 0 ;;
184
+ openbsd) return 0 ;;
185
+ plan9) return 0 ;;
186
+ solaris) return 0 ;;
187
+ windows) return 0 ;;
188
+ esac
189
+ log_crit " uname_os_check '$( uname -s) ' got converted to '$os ' which is not a GOOS value. Please file bug at https://github.com/saucelabs/saucectl"
190
+ return 1
191
+ }
192
+ uname_arch_check () {
193
+ arch=$( uname_arch)
194
+ case " $arch " in
195
+ 386) return 0 ;;
196
+ amd64) return 0 ;;
197
+ arm64) return 0 ;;
198
+ armv5) return 0 ;;
199
+ armv6) return 0 ;;
200
+ armv7) return 0 ;;
201
+ ppc64) return 0 ;;
202
+ ppc64le) return 0 ;;
203
+ mips) return 0 ;;
204
+ mipsle) return 0 ;;
205
+ mips64) return 0 ;;
206
+ mips64le) return 0 ;;
207
+ s390x) return 0 ;;
208
+ amd64p32) return 0 ;;
209
+ esac
210
+ log_crit " uname_arch_check '$( uname -m) ' got converted to '$arch ' which is not a GOARCH value. Please file bug report at https://github.com/saucelabs/saucectl"
211
+ return 1
212
+ }
213
+ untar () {
214
+ tarball=$1
215
+ case " ${tarball} " in
216
+ * .tar.gz | * .tgz) tar -xzf " ${tarball} " ;;
217
+ * .tar) tar -xf " ${tarball} " ;;
218
+ * .zip) unzip " ${tarball} " ;;
219
+ * )
220
+ log_err " untar unknown archive format for ${tarball} "
221
+ return 1
222
+ ;;
223
+ esac
224
+ }
225
+ mktmpdir () {
226
+ test -z " $TMPDIR " && TMPDIR=" $( mktemp -d) "
227
+ mkdir -p " ${TMPDIR} "
228
+ echo " ${TMPDIR} "
229
+ }
230
+ http_download () {
231
+ local_file=$1
232
+ source_url=$2
233
+ header=$3
234
+ headerflag=' '
235
+ destflag=' '
236
+ if is_command curl; then
237
+ cmd=' curl --fail -sSL'
238
+ destflag=' -o'
239
+ headerflag=' -H'
240
+ elif is_command wget; then
241
+ cmd=' wget -q'
242
+ destflag=' -O'
243
+ headerflag=' --header'
244
+ else
245
+ log_crit " http_download unable to find wget or curl"
246
+ return 1
247
+ fi
248
+ if [ -z " $header " ]; then
249
+ $cmd $destflag " $local_file " " $source_url "
250
+ else
251
+ if [ -z " $GITHUB_TOKEN " ]; then
252
+ $cmd $headerflag " $header " $destflag " $local_file " " $source_url "
253
+ fi
254
+ $cmd $headerflag " $header " $headerflag " Authorization:token $GITHUB_TOKEN " $destflag " $local_file " " $source_url "
255
+ fi
256
+ }
257
+ github_api () {
258
+ local_file=$1
259
+ source_url=$2
260
+ header=" "
261
+ case " $source_url " in
262
+ https://api.github.com* )
263
+ test -z " $GITHUB_TOKEN " || header=" Authorization: token $GITHUB_TOKEN "
264
+ ;;
265
+ esac
266
+ http_download " $local_file " " $source_url " " $header "
267
+ }
268
+ github_last_release () {
269
+ owner_repo=$1
270
+ version=$2
271
+ test -z " $version " && version=" latest"
272
+ giturl=" https://api.github.com/repos/${owner_repo} /releases/${version} "
273
+ json=$( http_download " -" " $giturl " " Accept: application/json" )
274
+ version=$( echo " $json " | tr -s ' \n' ' ' | sed ' s/.*"tag_name": "//' | sed ' s/".*//' )
275
+ test -z " $version " && return 1
276
+ echo " $version "
277
+ }
278
+ hash_sha256 () {
279
+ TARGET=${1:-/ dev/ stdin}
280
+ if is_command gsha256sum; then
281
+ hash=$( gsha256sum " $TARGET " ) || return 1
282
+ echo " $hash " | cut -d ' ' -f 1
283
+ elif is_command sha256sum; then
284
+ hash=$( sha256sum " $TARGET " ) || return 1
285
+ echo " $hash " | cut -d ' ' -f 1
286
+ elif is_command shasum; then
287
+ hash=$( shasum -a 256 " $TARGET " 2> /dev/null) || return 1
288
+ echo " $hash " | cut -d ' ' -f 1
289
+ elif is_command openssl; then
290
+ hash=$( openssl -dst openssl dgst -sha256 " $TARGET " ) || return 1
291
+ echo " $hash " | cut -d ' ' -f a
292
+ else
293
+ log_crit " hash_sha256 unable to find command to compute sha-256 hash"
294
+ return 1
295
+ fi
296
+ }
297
+ hash_sha256_verify () {
298
+ TARGET=$1
299
+ checksums=$2
300
+ if [ -z " $checksums " ]; then
301
+ log_err " hash_sha256_verify checksum file not specified in arg2"
302
+ return 1
303
+ fi
304
+ BASENAME=${TARGET##*/ }
305
+ want=$( grep " ${BASENAME} " " ${checksums} " 2> /dev/null | tr ' \t' ' ' | cut -d ' ' -f 1)
306
+ if [ -z " $want " ]; then
307
+ log_err " hash_sha256_verify unable to find checksum for '${TARGET} ' in '${checksums} '"
308
+ return 1
309
+ fi
310
+ got=$( hash_sha256 " $TARGET " )
311
+ if [ " $want " != " $got " ]; then
312
+ log_err " hash_sha256_verify checksum for '$TARGET ' did not verify ${want} vs $got "
313
+ return 1
314
+ fi
315
+ }
316
+ cat /dev/null << EOF
317
+ ------------------------------------------------------------------------
318
+ End of functions from https://github.com/saucelabs/saucectl
319
+ ------------------------------------------------------------------------
320
+ EOF
321
+
322
+ OWNER=saucelabs
323
+ REPO=" saucectl"
324
+ BINARY=saucectl
325
+ FORMAT=tar.gz
326
+ OS=$( uname_os)
327
+ ARCH=$( uname_arch)
328
+ PREFIX=" $OWNER /$REPO "
329
+
330
+ # use in logging routines
331
+ log_prefix () {
332
+ echo " $PREFIX "
333
+ }
334
+ PLATFORM=" ${OS} /${ARCH} "
335
+ GITHUB_DOWNLOAD=https://github.com/${OWNER} /${REPO} /releases/download
336
+
337
+ uname_os_check " $OS "
338
+ uname_arch_check " $ARCH "
339
+
340
+ parse_args " $@ "
341
+
342
+ check_platform
343
+
344
+ tag_to_version
345
+
346
+ adjust_format
347
+
348
+ adjust_os
349
+
350
+ adjust_arch
351
+
352
+ log_info " found version: ${VERSION} for ${TAG} /${OS} /${ARCH} "
353
+
354
+ NAME=${BINARY} _${VERSION} _${OS} _${ARCH}
355
+ TARBALL=${NAME} .${FORMAT}
356
+ TARBALL_URL=${GITHUB_DOWNLOAD} /${TAG} /${TARBALL}
357
+ CHECKSUM=${BINARY} _${VERSION} _checksums.txt
358
+ CHECKSUM_URL=${GITHUB_DOWNLOAD} /${TAG} /${CHECKSUM}
359
+
360
+ # Adjust binary name if windows
361
+ if [ " $OS " = " windows" ]; then
362
+ BINARY=" ${BINARY} .exe"
363
+ fi
364
+
365
+ execute
0 commit comments