Last active
November 16, 2019 13:49
-
-
Save ppetko/04a75b7345e119a36aa6d6293f9504c8 to your computer and use it in GitHub Desktop.
Download Operators
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 | |
DATE=$(date +%Y-%m-%d-%H:%M:%S) | |
function log(){ | |
echo "$DATE INFO $@" | |
return 0 | |
} | |
function panic(){ | |
echo "$DATE ERROR $@" | |
exit 1 | |
} | |
if [ $# -lt 2 ]; then | |
panic "Usage: $0 NAMESPACE PACKAGE" | |
fi | |
if [ -z "${QUAY_AUTH_TOKEN}" ]; then | |
panic "You must set Quay auth token" | |
fi | |
PKG_NAMESPACE=$1 | |
PKG_NAME=$2 | |
RELEASE=$(curl -s -H "Authorization: ${QUAY_AUTH_TOKEN}" "https://quay.io/cnr/api/v1/packages?namespace=${PKG_NAMESPACE}" | jq '.[] | select(.name == "'$PKG_NAMESPACE'" + "/" + "'$PKG_NAME'") | .default' | tr -d '"') | |
DIGEST=$(curl -s -H "Authorization: ${QUAY_AUTH_TOKEN}" "https://quay.io/cnr/api/v1/packages/$PKG_NAMESPACE/$PKG_NAME/$RELEASE" | jq '.[].content.digest'| tr -d '"') | |
if [ -z "${RELEASE}" ] || [ -z "${DIGEST}" ]; then | |
panic "populate release and/or digest" | |
fi | |
log "Downloading ${PKG_NAMESPACE}/${PKG_NAME} ${RELEASE} release using ${DIGEST}" | |
FILENAME="${PKG_NAMESPACE}-${PKG_NAME}-${RELEASE}.tar.gz" | |
curl -s -H "Authorization: ${QUAY_AUTH_TOKEN}" \ | |
"https://quay.io/cnr/api/v1/packages/$PKG_NAMESPACE/$PKG_NAME/blobs/sha256/$DIGEST" -o "${FILENAME}" | |
log "Downloading file $FILENAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment