Created
May 18, 2019 11:10
-
-
Save da115115/1152fc54d017847d8cee02074a2b43df to your computer and use it in GitHub Desktop.
Extract the release tag (version) of the latest release of a given GitHub repository, potentially for specific OS, architecture and package type
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 | |
git_repo="containernetworking/plugins" | |
os="linux" | |
arch="amd64" | |
pack="tgz" | |
if [ -z "$1" -o "$1" = "-h" -o "$1" = "--help" ] | |
then | |
echo | |
echo "Usage: $0 <github-repo> [[[<os>] <arch>] <pack>]" | |
echo " - <github-repo>: GitHub repo, for instance containernetworking/plugins" | |
echo " - <os>: Operating System, for instance linux, windows, darwin" | |
echo " - <arch>: Architecture, for instance amd64, arm, arm64, ppc64le, s390" | |
echo " - <pack>: Type of package, for instance tgz, zip>" | |
echo | |
exit | |
fi | |
git_repo="$1" | |
if [ ! -z "$2" ] | |
then | |
os="$2" | |
fi | |
if [ ! -z "$3" ] | |
then | |
arch="$3" | |
fi | |
if [ ! -z "$4" ] | |
then | |
pack="$4" | |
fi | |
curl --silent "https://api.github.com/repos/${git_repo}/releases/latest" | grep "browser_download_url" | grep "${os}-${arch}" | grep "\.${pack}\"$" | sed -n -e "s|^.*/\([a-z0-9\-]*[0-9]\+.[0-9]\+.[0-9]\)/.*$|\1|p" | |
# Reporting | |
echo " - GitHub repo: ${git_repo} (https://github.com/${git_repo}/releases)" | |
echo " - OS: ${os}" | |
echo " - Architecture: ${arch}" | |
echo " - Package type: ${pack}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment