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