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