Created
October 30, 2019 16:27
-
-
Save mislav/941a4edd3b63c9d9b07f7901b27e8b23 to your computer and use it in GitHub Desktop.
Download `bin/hub` for the current environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
latest-version() { | |
curl -fsi https://github.com/github/hub/releases/latest | awk -F/ '/^Location:/ {print $(NF)}' | |
} | |
HUB_VERSION="${1#v}" | |
if [ -z "$HUB_VERSION" ]; then | |
latest=$(latest-version) || true | |
[ -n "$latest" ] || latest="v2.12.8" | |
cat <<MSG >&2 | |
Error: You must specify a version of hub via the first argument. Example: | |
curl <script> | bash -s ${latest#v} | |
MSG | |
exit 1 | |
fi | |
ARCH="amd64" | |
OS="$(uname -s | tr '[:upper:]' '[:lower:]')" | |
[[ $OS != mingw* ]] || OS="windows" | |
download() { | |
if [ "$OS" = windows ]; then | |
zip="${1%.tgz}.zip" | |
curl -fsSLO "$zip" | |
unzip "$(basename "$zip")" bin/hub.exe | |
rm -f "$zip" | |
elif [ "$OS" = darwin ]; then | |
curl -fsSL "$1" | tar xz --strip-components=1 '*/bin/hub' | |
else | |
curl -fsSL "$1" | tar xz --strip-components=1 --wildcards '*/bin/hub' | |
fi | |
} | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment