2020-01-25 17:16:14 +03:00
|
|
|
#!/bin/bash
|
|
|
|
# Usage: curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s <HUB_VERSION>
|
|
|
|
#
|
|
|
|
# Downloads the hub binary into `bin/hub` within the current directory.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
latest-version() {
|
2020-03-09 04:19:16 +03:00
|
|
|
curl -fsi https://github.com/github/hub/releases/latest | awk -F/ 'tolower($1) ~ /^location:/ {print $(NF)}'
|
2020-01-25 17:16:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HUB_VERSION="${1#v}"
|
|
|
|
if [ -z "$HUB_VERSION" ]; then
|
|
|
|
latest=$(latest-version) || true
|
|
|
|
[ -n "$latest" ] || latest="v2.14.1"
|
|
|
|
cat <<MSG >&2
|
|
|
|
Error: You must specify a version of hub via the first argument. Example:
|
|
|
|
curl -L <script> | bash -s ${latest#v}
|
|
|
|
MSG
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ARCH="amd64"
|
|
|
|
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
2020-01-29 16:31:30 +03:00
|
|
|
case "$OS" in
|
|
|
|
mingw* | msys* ) OS=windows ;;
|
|
|
|
esac
|
2020-01-25 17:16:14 +03:00
|
|
|
|
|
|
|
download() {
|
2020-01-29 16:20:36 +03:00
|
|
|
case "$OS" in
|
2020-01-29 16:31:30 +03:00
|
|
|
windows )
|
2020-01-25 17:16:14 +03:00
|
|
|
zip="${1%.tgz}.zip"
|
|
|
|
curl -fsSLO "$zip"
|
|
|
|
unzip "$(basename "$zip")" bin/hub.exe
|
2020-01-29 16:36:56 +03:00
|
|
|
rm -f "$(basename "$zip")"
|
2020-01-29 16:20:36 +03:00
|
|
|
;;
|
|
|
|
darwin )
|
2020-01-25 17:16:14 +03:00
|
|
|
curl -fsSL "$1" | tar xz --strip-components=1 '*/bin/hub'
|
2020-01-29 16:20:36 +03:00
|
|
|
;;
|
|
|
|
* )
|
2020-01-25 17:16:14 +03:00
|
|
|
curl -fsSL "$1" | tar xz --strip-components=1 --wildcards '*/bin/hub'
|
2020-01-29 16:20:36 +03:00
|
|
|
;;
|
|
|
|
esac
|
2020-01-25 17:16:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
download "https://github.com/github/hub/releases/download/v$HUB_VERSION/hub-$OS-$ARCH-$HUB_VERSION.tgz"
|
|
|
|
|
|
|
|
bin/hub version
|
|
|
|
if [ -z "$GITHUB_TOKEN" ]; then
|
|
|
|
cat <<MSG >&2
|
|
|
|
Warning: We recommend supplying the GITHUB_TOKEN environment variable to avoid
|
|
|
|
being prompted for authentication.
|
|
|
|
MSG
|
|
|
|
fi
|