Debian Codegraph @

make/golangci-install.sh

raw symbols SCIP
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 golangci/golangci-lint
10
11 Usage: $this [-b] bindir [-d] [tag]
12 -b sets bindir or installation directory, Defaults to ./bin
13 -d turns on debug logging
14 [tag] is a tag from
15 https://github.com/golangci/golangci-lint/releases
16 If tag is missing, then the latest will be used.
17
18 Generated by godownloader
19 https://github.com/goreleaser/godownloader
20
21 EOF
22 exit 2
23 }
24
25 parse_args() {
26 #BINDIR is ./bin unless set be ENV
27 # over-ridden by flag below
28
29 BINDIR=${BINDIR:-./bin}
30 while getopts "b:dh?x" arg; do
31 case "$arg" in
32 b) BINDIR="$OPTARG" ;;
33 d) log_set_priority 10 ;;
34 h | \?) usage "$0" ;;
35 x) set -x ;;
36 esac
37 done
38 shift $((OPTIND - 1))
39 TAG=$1
40 }
41 # this function wraps all the destructive operations
42 # if a curl|bash cuts off the end of the script due to
43 # network, either nothing will happen or will syntax error
44 # out preventing half-done work
45 execute() {
46 tmpdir=$(mktemp -d)
47 log_debug "downloading files into ${tmpdir}"
48 http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
49 http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
50 hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
51 srcdir="${tmpdir}/${NAME}"
52 rm -rf "${srcdir}"
53 (cd "${tmpdir}" && untar "${TARBALL}")
54 test ! -d "${BINDIR}" && install -d "${BINDIR}"
55 for binexe in $BINARIES; do
56 if [ "$OS" = "windows" ]; then
57 binexe="${binexe}.exe"
58 fi
59 install "${srcdir}/${binexe}" "${BINDIR}/"
60 log_info "installed ${BINDIR}/${binexe}"
61 done
62 rm -rf "${tmpdir}"
63 }
64 get_binaries() {
65 case "$PLATFORM" in
66 darwin/amd64) BINARIES="golangci-lint" ;;
67 darwin/arm64) BINARIES="golangci-lint" ;;
68 darwin/armv6) BINARIES="golangci-lint" ;;
69 darwin/armv7) BINARIES="golangci-lint" ;;
70 darwin/mips64) BINARIES="golangci-lint" ;;
71 darwin/mips64le) BINARIES="golangci-lint" ;;
72 darwin/ppc64le) BINARIES="golangci-lint" ;;
73 darwin/s390x) BINARIES="golangci-lint" ;;
74 freebsd/386) BINARIES="golangci-lint" ;;
75 freebsd/amd64) BINARIES="golangci-lint" ;;
76 freebsd/armv6) BINARIES="golangci-lint" ;;
77 freebsd/armv7) BINARIES="golangci-lint" ;;
78 freebsd/mips64) BINARIES="golangci-lint" ;;
79 freebsd/mips64le) BINARIES="golangci-lint" ;;
80 freebsd/ppc64le) BINARIES="golangci-lint" ;;
81 freebsd/s390x) BINARIES="golangci-lint" ;;
82 linux/386) BINARIES="golangci-lint" ;;
83 linux/amd64) BINARIES="golangci-lint" ;;
84 linux/arm64) BINARIES="golangci-lint" ;;
85 linux/armv6) BINARIES="golangci-lint" ;;
86 linux/armv7) BINARIES="golangci-lint" ;;
87 linux/mips64) BINARIES="golangci-lint" ;;
88 linux/mips64le) BINARIES="golangci-lint" ;;
89 linux/ppc64le) BINARIES="golangci-lint" ;;
90 linux/s390x) BINARIES="golangci-lint" ;;
91 windows/386) BINARIES="golangci-lint" ;;
92 windows/amd64) BINARIES="golangci-lint" ;;
93 windows/arm64) BINARIES="golangci-lint" ;;
94 windows/armv6) BINARIES="golangci-lint" ;;
95 windows/armv7) BINARIES="golangci-lint" ;;
96 windows/mips64) BINARIES="golangci-lint" ;;
97 windows/mips64le) BINARIES="golangci-lint" ;;
98 windows/ppc64le) BINARIES="golangci-lint" ;;
99 windows/s390x) BINARIES="golangci-lint" ;;
100 *)
101 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"
102 exit 1
103 ;;
104 esac
105 }
106 tag_to_version() {
107 if [ -z "${TAG}" ]; then
108 log_info "checking GitHub for latest tag"
109 else
110 log_info "checking GitHub for tag '${TAG}'"
111 fi
112 REALTAG=$(github_release "$OWNER/$REPO" "${TAG}") && true
113 if test -z "$REALTAG"; then
114 log_crit "unable to find '${TAG}' - use 'latest' or see https://github.com/${PREFIX}/releases for details"
115 exit 1
116 fi
117 # if version starts with 'v', remove it
118 TAG="$REALTAG"
119 VERSION=${TAG#v}
120 }
121 adjust_format() {
122 # change format (tar.gz or zip) based on OS
123 case ${OS} in
124 windows) FORMAT=zip ;;
125 esac
126 true
127 }
128 adjust_os() {
129 # adjust archive name based on OS
130 true
131 }
132 adjust_arch() {
133 # adjust archive name based on ARCH
134 true
135 }
136
137 cat /dev/null <<EOF
138 ------------------------------------------------------------------------
139 https://github.com/client9/shlib - portable posix shell functions
140 Public domain - http://unlicense.org
141 https://github.com/client9/shlib/blob/master/LICENSE.md
142 but credit (and pull requests) appreciated.
143 ------------------------------------------------------------------------
144 EOF
145 is_command() {
146 command -v "$1" >/dev/null
147 }
148 echoerr() {
149 echo "$@" 1>&2
150 }
151 log_prefix() {
152 echo "$0"
153 }
154 _logp=6
155 log_set_priority() {
156 _logp="$1"
157 }
158 log_priority() {
159 if test -z "$1"; then
160 echo "$_logp"
161 return
162 fi
163 [ "$1" -le "$_logp" ]
164 }
165 log_tag() {
166 case $1 in
167 0) echo "emerg" ;;
168 1) echo "alert" ;;
169 2) echo "crit" ;;
170 3) echo "err" ;;
171 4) echo "warning" ;;
172 5) echo "notice" ;;
173 6) echo "info" ;;
174 7) echo "debug" ;;
175 *) echo "$1" ;;
176 esac
177 }
178 log_debug() {
179 log_priority 7 || return 0
180 echoerr "$(log_prefix)" "$(log_tag 7)" "$@"
181 }
182 log_info() {
183 log_priority 6 || return 0
184 echoerr "$(log_prefix)" "$(log_tag 6)" "$@"
185 }
186 log_err() {
187 log_priority 3 || return 0
188 echoerr "$(log_prefix)" "$(log_tag 3)" "$@"
189 }
190 log_crit() {
191 log_priority 2 || return 0
192 echoerr "$(log_prefix)" "$(log_tag 2)" "$@"
193 }
194 uname_os() {
195 os=$(uname -s | tr '[:upper:]' '[:lower:]')
196 case "$os" in
197 cygwin_nt*) os="windows" ;;
198 mingw*) os="windows" ;;
199 msys_nt*) os="windows" ;;
200 esac
201 echo "$os"
202 }
203 uname_arch() {
204 arch=$(uname -m)
205 case $arch in
206 x86_64) arch="amd64" ;;
207 x86) arch="386" ;;
208 i686) arch="386" ;;
209 i386) arch="386" ;;
210 aarch64) arch="arm64" ;;
211 armv5*) arch="armv5" ;;
212 armv6*) arch="armv6" ;;
213 armv7*) arch="armv7" ;;
214 esac
215 echo ${arch}
216 }
217 uname_os_check() {
218 os=$(uname_os)
219 case "$os" in
220 darwin) return 0 ;;
221 dragonfly) return 0 ;;
222 freebsd) return 0 ;;
223 linux) return 0 ;;
224 android) return 0 ;;
225 nacl) return 0 ;;
226 netbsd) return 0 ;;
227 openbsd) return 0 ;;
228 plan9) return 0 ;;
229 solaris) return 0 ;;
230 windows) return 0 ;;
231 esac
232 log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib"
233 return 1
234 }
235 uname_arch_check() {
236 arch=$(uname_arch)
237 case "$arch" in
238 386) return 0 ;;
239 amd64) return 0 ;;
240 arm64) return 0 ;;
241 armv5) return 0 ;;
242 armv6) return 0 ;;
243 armv7) return 0 ;;
244 ppc64) return 0 ;;
245 ppc64le) return 0 ;;
246 mips) return 0 ;;
247 mipsle) return 0 ;;
248 mips64) return 0 ;;
249 mips64le) return 0 ;;
250 s390x) return 0 ;;
251 amd64p32) return 0 ;;
252 esac
253 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/client9/shlib"
254 return 1
255 }
256 untar() {
257 tarball=$1
258 case "${tarball}" in
259 *.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;;
260 *.tar) tar --no-same-owner -xf "${tarball}" ;;
261 *.zip) unzip "${tarball}" ;;
262 *)
263 log_err "untar unknown archive format for ${tarball}"
264 return 1
265 ;;
266 esac
267 }
268 http_download_curl() {
269 local_file=$1
270 source_url=$2
271 header=$3
272 if [ -z "$header" ]; then
273 code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url")
274 else
275 code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url")
276 fi
277 if [ "$code" != "200" ]; then
278 log_debug "http_download_curl received HTTP status $code"
279 return 1
280 fi
281 return 0
282 }
283 http_download_wget() {
284 local_file=$1
285 source_url=$2
286 header=$3
287 if [ -z "$header" ]; then
288 wget -q -O "$local_file" "$source_url"
289 else
290 wget -q --header "$header" -O "$local_file" "$source_url"
291 fi
292 }
293 http_download() {
294 log_debug "http_download $2"
295 if is_command curl; then
296 http_download_curl "$@"
297 return
298 elif is_command wget; then
299 http_download_wget "$@"
300 return
301 fi
302 log_crit "http_download unable to find wget or curl"
303 return 1
304 }
305 http_copy() {
306 tmp=$(mktemp)
307 http_download "${tmp}" "$1" "$2" || return 1
308 body=$(cat "$tmp")
309 rm -f "${tmp}"
310 echo "$body"
311 }
312 github_release() {
313 owner_repo=$1
314 version=$2
315 test -z "$version" && version="latest"
316 giturl="https://github.com/${owner_repo}/releases/${version}"
317 json=$(http_copy "$giturl" "Accept:application/json")
318 test -z "$json" && return 1
319 version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//')
320 test -z "$version" && return 1
321 echo "$version"
322 }
323 hash_sha256() {
324 TARGET=${1:-/dev/stdin}
325 if is_command gsha256sum; then
326 hash=$(gsha256sum "$TARGET") || return 1
327 echo "$hash" | cut -d ' ' -f 1
328 elif is_command sha256sum; then
329 hash=$(sha256sum "$TARGET") || return 1
330 echo "$hash" | cut -d ' ' -f 1
331 elif is_command shasum; then
332 hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
333 echo "$hash" | cut -d ' ' -f 1
334 elif is_command openssl; then
335 hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
336 echo "$hash" | cut -d ' ' -f a
337 else
338 log_crit "hash_sha256 unable to find command to compute sha-256 hash"
339 return 1
340 fi
341 }
342 hash_sha256_verify() {
343 TARGET=$1
344 checksums=$2
345 if [ -z "$checksums" ]; then
346 log_err "hash_sha256_verify checksum file not specified in arg2"
347 return 1
348 fi
349 BASENAME=${TARGET##*/}
350 want=$(grep "${BASENAME}" "${checksums}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1)
351 if [ -z "$want" ]; then
352 log_err "hash_sha256_verify unable to find checksum for '${TARGET}' in '${checksums}'"
353 return 1
354 fi
355 got=$(hash_sha256 "$TARGET")
356 if [ "$want" != "$got" ]; then
357 log_err "hash_sha256_verify checksum for '$TARGET' did not verify ${want} vs $got"
358 return 1
359 fi
360 }
361 cat /dev/null <<EOF
362 ------------------------------------------------------------------------
363 End of functions from https://github.com/client9/shlib
364 ------------------------------------------------------------------------
365 EOF
366
367 PROJECT_NAME="golangci-lint"
368 OWNER=golangci
369 REPO="golangci-lint"
370 BINARY=golangci-lint
371 FORMAT=tar.gz
372 OS=$(uname_os)
373 ARCH=$(uname_arch)
374 PREFIX="$OWNER/$REPO"
375
376 # use in logging routines
377 log_prefix() {
378 echo "$PREFIX"
379 }
380 PLATFORM="${OS}/${ARCH}"
381 GITHUB_DOWNLOAD=https://github.com/${OWNER}/${REPO}/releases/download
382
383 uname_os_check "$OS"
384 uname_arch_check "$ARCH"
385
386 parse_args "$@"
387
388 get_binaries
389
390 tag_to_version
391
392 adjust_format
393
394 adjust_os
395
396 adjust_arch
397
398 log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}"
399
400 NAME=${BINARY}-${VERSION}-${OS}-${ARCH}
401 TARBALL=${NAME}.${FORMAT}
402 TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
403 CHECKSUM=${PROJECT_NAME}-${VERSION}-checksums.txt
404 CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}
405
406
407 execute