diff --git a/install.sh b/install.sh index d3b12cf..cbedd23 100755 --- a/install.sh +++ b/install.sh @@ -90,6 +90,7 @@ parse_args() { esac } + # this function wraps all the destructive operations # if a curl|bash cuts off the end of the script due to # network, either nothing will happen or will syntax error @@ -112,6 +113,7 @@ execute() { done rm -rf "${tmpdir}" } + get_binaries() { case "$PLATFORM" in darwin/amd64) BINARIES="$BINARY" ;; @@ -125,6 +127,7 @@ get_binaries() { ;; esac } + tag_to_version() { if [ -z "${TAG}" ]; then log_info "checking GitHub for latest tag" @@ -140,6 +143,7 @@ tag_to_version() { TAG="$REALTAG" VERSION=${TAG#v} } + adjust_format() { # change format (tar.gz or zip) based on OS case ${OS} in @@ -147,6 +151,7 @@ adjust_format() { esac true } + adjust_os() { # adjust archive name based on OS case ${OS} in @@ -156,6 +161,7 @@ adjust_os() { esac true } + adjust_arch() { # adjust archive name based on ARCH case ${ARCH} in @@ -166,6 +172,16 @@ adjust_arch() { true } +adjust_libmusl() { + # adjust archive name based on LIBMUSL + if [ -n "$LIBMUSL" ] && [ -n "$FLAVOR" ]; then + LIBMUSL="_libmusl" + else + LIBMUSL="" + fi + true +} + cat /dev/null </dev/null } + echoerr() { echo "$@" 1>&2 } + +# shellcheck disable=SC2329 log_prefix() { - # shellcheck disable=SC2317 echo "$0" } + _logp=6 log_set_priority() { _logp="$1" } + log_priority() { if test -z "$1"; then echo "$_logp" @@ -195,6 +216,7 @@ log_priority() { fi [ "$1" -le "$_logp" ] } + log_tag() { case $1 in 0) echo "emerg" ;; @@ -208,22 +230,27 @@ log_tag() { *) echo "$1" ;; esac } + log_debug() { log_priority 7 || return 0 echoerr "$(log_prefix)" "$(log_tag 7)" "$@" } + log_info() { log_priority 6 || true echoerr "$(log_prefix)" "$(log_tag 6)" "$@" } + log_err() { log_priority 3 || true echoerr "$(log_prefix)" "$(log_tag 3)" "$@" } + log_crit() { log_priority 2 || true echoerr "$(log_prefix)" "$(log_tag 2)" "$@" } + uname_os() { os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in @@ -233,6 +260,7 @@ uname_os() { esac echo "$os" } + uname_arch() { arch=$(uname -m) case $arch in @@ -247,6 +275,7 @@ uname_arch() { esac echo "${arch}" } + uname_os_check() { os=$(uname_os) case "$os" in @@ -265,6 +294,7 @@ uname_os_check() { 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" return 1 } + uname_arch_check() { arch=$(uname_arch) case "$arch" in @@ -286,6 +316,15 @@ uname_arch_check() { 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" return 1 } + +libmusl_check() { + if [ "$OS" = "linux" ] && command -v ldd >/dev/null 2>&1; then + ldd --version 2>&1 | grep -qi musl + else + return 1 + fi +} + untar() { tarball=$1 case "${tarball}" in @@ -298,6 +337,7 @@ untar() { ;; esac } + http_download_curl() { local_file=$1 source_url=$2 @@ -313,6 +353,7 @@ http_download_curl() { fi return 0 } + http_download_wget() { local_file=$1 source_url=$2 @@ -323,6 +364,7 @@ http_download_wget() { wget -q --header "$header" -O "$local_file" "$source_url" fi } + http_download() { log_debug "http_download $2" if is_command curl; then @@ -335,6 +377,7 @@ http_download() { log_crit "http_download unable to find wget or curl" return 1 } + http_copy() { tmp=$(mktemp) http_download "${tmp}" "$1" "$2" || return 1 @@ -342,6 +385,7 @@ http_copy() { rm -f "${tmp}" echo "$body" } + github_release() { owner_repo=$1 version=$2 @@ -353,6 +397,7 @@ github_release() { test -z "$version" && return 1 echo "$version" } + hash_sha256() { TARGET=${1:-/dev/stdin} if is_command gsha256sum; then @@ -372,6 +417,7 @@ hash_sha256() { return 1 fi } + hash_sha256_verify() { TARGET=$1 checksums=$2 @@ -391,6 +437,7 @@ hash_sha256_verify() { return 1 fi } + cat /dev/null <