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