github.com/be-b10g/golangci-lint@v1.17.2/install.sh (about)

     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?" 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 "golangci-lint" ; 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/386) found=0 ;;
    68      windows/amd64) found=0 ;;
    69      windows/386) found=0 ;;
    70      linux/amd64) found=0 ;;
    71      linux/386) found=0 ;;
    72    esac
    73    return $found
    74  }
    75  check_platform() {
    76    if is_supported_platform "$PLATFORM"; then
    77      # optional logging goes here
    78      true
    79    else
    80      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"
    81      exit 1
    82    fi
    83  }
    84  tag_to_version() {
    85    if [ -z "${TAG}" ]; then
    86      log_info "checking GitHub for latest tag"
    87    else
    88      log_info "checking GitHub for tag '${TAG}'"
    89    fi
    90    REALTAG=$(github_release "$OWNER/$REPO" "${TAG}") && true
    91    if test -z "$REALTAG"; then
    92      log_crit "unable to find '${TAG}' - use 'latest' or see https://github.com/${PREFIX}/releases for details"
    93      exit 1
    94    fi
    95    # if version starts with 'v', remove it
    96    TAG="$REALTAG"
    97    VERSION=${TAG#v}
    98  }
    99  adjust_format() {
   100    # change format (tar.gz or zip) based on ARCH
   101    case ${ARCH} in
   102      windows) FORMAT=zip ;;
   103    esac
   104    true
   105  }
   106  adjust_os() {
   107    # adjust archive name based on OS
   108    true
   109  }
   110  adjust_arch() {
   111    # adjust archive name based on ARCH
   112    true
   113  }
   114  
   115  cat /dev/null <<EOF
   116  ------------------------------------------------------------------------
   117  https://github.com/client9/shlib - portable posix shell functions
   118  Public domain - http://unlicense.org
   119  https://github.com/client9/shlib/blob/master/LICENSE.md
   120  but credit (and pull requests) appreciated.
   121  ------------------------------------------------------------------------
   122  EOF
   123  is_command() {
   124    command -v "$1" >/dev/null
   125  }
   126  echoerr() {
   127    echo "$@" 1>&2
   128  }
   129  log_prefix() {
   130    echo "$0"
   131  }
   132  _logp=6
   133  log_set_priority() {
   134    _logp="$1"
   135  }
   136  log_priority() {
   137    if test -z "$1"; then
   138      echo "$_logp"
   139      return
   140    fi
   141    [ "$1" -le "$_logp" ]
   142  }
   143  log_tag() {
   144    case $1 in
   145      0) echo "emerg" ;;
   146      1) echo "alert" ;;
   147      2) echo "crit" ;;
   148      3) echo "err" ;;
   149      4) echo "warning" ;;
   150      5) echo "notice" ;;
   151      6) echo "info" ;;
   152      7) echo "debug" ;;
   153      *) echo "$1" ;;
   154    esac
   155  }
   156  log_debug() {
   157    log_priority 7 || return 0
   158    echoerr "$(log_prefix)" "$(log_tag 7)" "$@"
   159  }
   160  log_info() {
   161    log_priority 6 || return 0
   162    echoerr "$(log_prefix)" "$(log_tag 6)" "$@"
   163  }
   164  log_err() {
   165    log_priority 3 || return 0
   166    echoerr "$(log_prefix)" "$(log_tag 3)" "$@"
   167  }
   168  log_crit() {
   169    log_priority 2 || return 0
   170    echoerr "$(log_prefix)" "$(log_tag 2)" "$@"
   171  }
   172  uname_os() {
   173    os=$(uname -s | tr '[:upper:]' '[:lower:]')
   174    case "$os" in
   175      msys_nt*) os="windows" ;;
   176      mingw*) os="windows" ;;
   177    esac
   178    echo "$os"
   179  }
   180  uname_arch() {
   181    arch=$(uname -m)
   182    case $arch in
   183      x86_64) arch="amd64" ;;
   184      x86) arch="386" ;;
   185      i686) arch="386" ;;
   186      i386) arch="386" ;;
   187      aarch64) arch="arm64" ;;
   188      armv5*) arch="armv5" ;;
   189      armv6*) arch="armv6" ;;
   190      armv7*) arch="armv7" ;;
   191    esac
   192    echo ${arch}
   193  }
   194  uname_os_check() {
   195    os=$(uname_os)
   196    case "$os" in
   197      darwin) return 0 ;;
   198      dragonfly) return 0 ;;
   199      freebsd) return 0 ;;
   200      linux) return 0 ;;
   201      android) return 0 ;;
   202      nacl) return 0 ;;
   203      netbsd) return 0 ;;
   204      openbsd) return 0 ;;
   205      plan9) return 0 ;;
   206      solaris) return 0 ;;
   207      windows) return 0 ;;
   208    esac
   209    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"
   210    return 1
   211  }
   212  uname_arch_check() {
   213    arch=$(uname_arch)
   214    case "$arch" in
   215      386) return 0 ;;
   216      amd64) return 0 ;;
   217      arm64) return 0 ;;
   218      armv5) return 0 ;;
   219      armv6) return 0 ;;
   220      armv7) return 0 ;;
   221      ppc64) return 0 ;;
   222      ppc64le) return 0 ;;
   223      mips) return 0 ;;
   224      mipsle) return 0 ;;
   225      mips64) return 0 ;;
   226      mips64le) return 0 ;;
   227      s390x) return 0 ;;
   228      amd64p32) return 0 ;;
   229    esac
   230    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"
   231    return 1
   232  }
   233  untar() {
   234    tarball=$1
   235    case "${tarball}" in
   236      *.tar.gz | *.tgz) tar -xzf "${tarball}" ;;
   237      *.tar) tar -xf "${tarball}" ;;
   238      *.zip) unzip "${tarball}" ;;
   239      *)
   240        log_err "untar unknown archive format for ${tarball}"
   241        return 1
   242        ;;
   243    esac
   244  }
   245  mktmpdir() {
   246    test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
   247    mkdir -p "${TMPDIR}"
   248    echo "${TMPDIR}"
   249  }
   250  http_download_curl() {
   251    local_file=$1
   252    source_url=$2
   253    header=$3
   254    if [ -z "$header" ]; then
   255      code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url")
   256    else
   257      code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url")
   258    fi
   259    if [ "$code" != "200" ]; then
   260      log_debug "http_download_curl received HTTP status $code"
   261      return 1
   262    fi
   263    return 0
   264  }
   265  http_download_wget() {
   266    local_file=$1
   267    source_url=$2
   268    header=$3
   269    if [ -z "$header" ]; then
   270      wget -q -O "$local_file" "$source_url"
   271    else
   272      wget -q --header "$header" -O "$local_file" "$source_url"
   273    fi
   274  }
   275  http_download() {
   276    log_debug "http_download $2"
   277    if is_command curl; then
   278      http_download_curl "$@"
   279      return
   280    elif is_command wget; then
   281      http_download_wget "$@"
   282      return
   283    fi
   284    log_crit "http_download unable to find wget or curl"
   285    return 1
   286  }
   287  http_copy() {
   288    tmp=$(mktemp)
   289    http_download "${tmp}" "$1" "$2" || return 1
   290    body=$(cat "$tmp")
   291    rm -f "${tmp}"
   292    echo "$body"
   293  }
   294  github_release() {
   295    owner_repo=$1
   296    version=$2
   297    test -z "$version" && version="latest"
   298    giturl="https://github.com/${owner_repo}/releases/${version}"
   299    json=$(http_copy "$giturl" "Accept:application/json")
   300    test -z "$json" && return 1
   301    version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name":"//' | sed 's/".*//')
   302    test -z "$version" && return 1
   303    echo "$version"
   304  }
   305  hash_sha256() {
   306    TARGET=${1:-/dev/stdin}
   307    if is_command gsha256sum; then
   308      hash=$(gsha256sum "$TARGET") || return 1
   309      echo "$hash" | cut -d ' ' -f 1
   310    elif is_command sha256sum; then
   311      hash=$(sha256sum "$TARGET") || return 1
   312      echo "$hash" | cut -d ' ' -f 1
   313    elif is_command shasum; then
   314      hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
   315      echo "$hash" | cut -d ' ' -f 1
   316    elif is_command openssl; then
   317      hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
   318      echo "$hash" | cut -d ' ' -f a
   319    else
   320      log_crit "hash_sha256 unable to find command to compute sha-256 hash"
   321      return 1
   322    fi
   323  }
   324  hash_sha256_verify() {
   325    TARGET=$1
   326    checksums=$2
   327    if [ -z "$checksums" ]; then
   328      log_err "hash_sha256_verify checksum file not specified in arg2"
   329      return 1
   330    fi
   331    BASENAME=${TARGET##*/}
   332    want=$(grep "${BASENAME}" "${checksums}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1)
   333    if [ -z "$want" ]; then
   334      log_err "hash_sha256_verify unable to find checksum for '${TARGET}' in '${checksums}'"
   335      return 1
   336    fi
   337    got=$(hash_sha256 "$TARGET")
   338    if [ "$want" != "$got" ]; then
   339      log_err "hash_sha256_verify checksum for '$TARGET' did not verify ${want} vs $got"
   340      return 1
   341    fi
   342  }
   343  cat /dev/null <<EOF
   344  ------------------------------------------------------------------------
   345  End of functions from https://github.com/client9/shlib
   346  ------------------------------------------------------------------------
   347  EOF
   348  
   349  PROJECT_NAME="golangci-lint"
   350  OWNER=golangci
   351  REPO="golangci-lint"
   352  BINARY=golangci-lint
   353  FORMAT=tar.gz
   354  OS=$(uname_os)
   355  ARCH=$(uname_arch)
   356  PREFIX="$OWNER/$REPO"
   357  
   358  # use in logging routines
   359  log_prefix() {
   360  	echo "$PREFIX"
   361  }
   362  PLATFORM="${OS}/${ARCH}"
   363  GITHUB_DOWNLOAD=https://github.com/${OWNER}/${REPO}/releases/download
   364  
   365  uname_os_check "$OS"
   366  uname_arch_check "$ARCH"
   367  
   368  parse_args "$@"
   369  
   370  check_platform
   371  
   372  tag_to_version
   373  
   374  adjust_format
   375  
   376  adjust_os
   377  
   378  adjust_arch
   379  
   380  log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}"
   381  
   382  NAME=${BINARY}-${VERSION}-${OS}-${ARCH}
   383  TARBALL=${NAME}.${FORMAT}
   384  TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
   385  CHECKSUM=${PROJECT_NAME}-${VERSION}-checksums.txt
   386  CHECKSUM_URL=${GITHUB_DOWNLOAD}/${TAG}/${CHECKSUM}
   387  
   388  
   389  execute