Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -112,6 +113,7 @@ execute() {
done
rm -rf "${tmpdir}"
}

get_binaries() {
case "$PLATFORM" in
darwin/amd64) BINARIES="$BINARY" ;;
Expand All @@ -125,6 +127,7 @@ get_binaries() {
;;
esac
}

tag_to_version() {
if [ -z "${TAG}" ]; then
log_info "checking GitHub for latest tag"
Expand All @@ -140,13 +143,15 @@ tag_to_version() {
TAG="$REALTAG"
VERSION=${TAG#v}
}

adjust_format() {
# change format (tar.gz or zip) based on OS
case ${OS} in
windows) FORMAT=zip ;;
esac
true
}

adjust_os() {
# adjust archive name based on OS
case ${OS} in
Expand All @@ -156,6 +161,7 @@ adjust_os() {
esac
true
}

adjust_arch() {
# adjust archive name based on ARCH
case ${ARCH} in
Expand All @@ -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 <<EOF
------------------------------------------------------------------------
https://github.com/client9/shlib - portable posix shell functions
Expand All @@ -174,27 +190,33 @@ https://github.com/client9/shlib/blob/master/LICENSE.md
but credit (and pull requests) appreciated.
------------------------------------------------------------------------
EOF

is_command() {
command -v "$1" >/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"
return
fi
[ "$1" -le "$_logp" ]
}

log_tag() {
case $1 in
0) echo "emerg" ;;
Expand All @@ -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
Expand All @@ -233,6 +260,7 @@ uname_os() {
esac
echo "$os"
}

uname_arch() {
arch=$(uname -m)
case $arch in
Expand All @@ -247,6 +275,7 @@ uname_arch() {
esac
echo "${arch}"
}

uname_os_check() {
os=$(uname_os)
case "$os" in
Expand All @@ -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
Expand All @@ -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
Expand All @@ -298,6 +337,7 @@ untar() {
;;
esac
}

http_download_curl() {
local_file=$1
source_url=$2
Expand All @@ -313,6 +353,7 @@ http_download_curl() {
fi
return 0
}

http_download_wget() {
local_file=$1
source_url=$2
Expand All @@ -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
Expand All @@ -335,13 +377,15 @@ 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
body=$(cat "$tmp")
rm -f "${tmp}"
echo "$body"
}

github_release() {
owner_repo=$1
version=$2
Expand All @@ -353,6 +397,7 @@ github_release() {
test -z "$version" && return 1
echo "$version"
}

hash_sha256() {
TARGET=${1:-/dev/stdin}
if is_command gsha256sum; then
Expand All @@ -372,6 +417,7 @@ hash_sha256() {
return 1
fi
}

hash_sha256_verify() {
TARGET=$1
checksums=$2
Expand All @@ -391,6 +437,7 @@ hash_sha256_verify() {
return 1
fi
}

cat /dev/null <<EOF
------------------------------------------------------------------------
End of functions from https://github.com/client9/shlib
Expand All @@ -404,6 +451,12 @@ OS=$(uname_os)
ARCH=$(uname_arch)
PREFIX="$OWNER/$REPO"

if libmusl_check; then
LIBMUSL="/libmusl"
else
LIBMUSL=""
fi

# use in logging routines
log_prefix() {
echo "$PREFIX"
Expand All @@ -427,9 +480,11 @@ adjust_os

adjust_arch

log_info "found version: ${VERSION} for ${TAG}/${OS}/${ARCH}"
log_info "found version: ${VERSION} for ${TAG}/${OS}${LIBMUSL}/${ARCH}"

adjust_libmusl

NAME=${PROJECT_NAME}_${VERSION}-${OS}${FLAVOR}_${ARCH}
NAME=${PROJECT_NAME}_${VERSION}-${OS}${FLAVOR}${LIBMUSL}_${ARCH}
TARBALL=${NAME}.${FORMAT}
TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL}
CHECKSUM=checksums.txt
Expand Down
Loading