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