Skip to content

Instantly share code, notes, and snippets.

@troykinsella
Last active October 12, 2018 18:41
Show Gist options
  • Save troykinsella/b0cf38006d6ff4afb5056129d14f0738 to your computer and use it in GitHub Desktop.
Save troykinsella/b0cf38006d6ff4afb5056129d14f0738 to your computer and use it in GitHub Desktop.
fetch_gh_release.sh
#!/usr/bin/env bash
set -e
GH_USER=${GH_USER:-$1}
GH_REPO=${GH_REPO:-$2}
ASSET=${ASSET:-$3}
VERSION=${VERSION:-${4:-latest}}
usage() {
echo "usage: $0 <username> <repository> <asset> [version]"
exit 1
}
test -z "$GH_USER" && usage
test -z "$GH_REPO" && usage
test -z "$ASSET" && usage
if [ "$VERSION" = "latest" ]; then
VERSION=$(wget -q -O - https://api.github.com/repos/$GH_USER/$GH_REPO/releases | \
grep tag_name | \
head -1 | \
awk '{print $2}' | \
sed 's/[",]//g')
echo "Resolved latest version: $VERSION"
fi
ASSET=$(echo $ASSET | sed "s/{VERSION}/$VERSION/g")
wget -q -O $ASSET https://github.com/$GH_USER/$GH_REPO/releases/download/$VERSION/$ASSET
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment