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