diff --git a/download_xml_api.sh b/download_xml_api.sh new file mode 100644 index 0000000000..467ba5bfc9 --- /dev/null +++ b/download_xml_api.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +if [ "$#" -ne "4" ]; then + echo "Incorrect invocation: Should be download_xml_api.sh cloudsmith_repository plugin_version cloudsmith_user cloudsmith_level" + echo "where:" + echo " cloudsmith_repository is the name of the repository on cloudsmith the files are in, i.e. testplugin" + echo " plugin_version is the version number, i.e. 1.0.114.0" + echo " cloudsmith_user is the user name associated with the cloudsmith repository, i.e. jon-gough or opencpn" + echo " cloudsmith_level is the level of the repository and is one of: prod, beta, alpha" + echo "" + echo " Full command should look like:" + echo " download_xml_api.sh testplugin_pi 1.0.114.0 jon-gough prod" + echo " download_xml_api.sh weather-routing 1.13.8.0 opencpn prod" + exit +fi + +NAME="$1" +VERSION="$2" +USER="$3" +LEVEL="$4" + +REPO="https://api.cloudsmith.io/v1/packages" +echo "Issuing command: wget -q -O - $REPO/${USER}/${NAME}-${LEVEL}/?q=*${VERSION}*metadata" +echo "Show current files that match criteria" +ls metadata/${NAME}*-*${VERSION}*xml -la +echo "Deleting current files that match criteria" +rm metadata/${NAME}*-*${VERSION}*xml +echo "Finding files on remote cloudsmith repository" +delimiter="\"cdn_url\":" +delimiter1=".xml" +delimiter2="\"files\":[" +my__in_array=(); + +my_string=$(wget -q -O - "${REPO}/${USER}/${NAME}-${LEVEL}/?q=*${VERSION}*metadata+tag:latest&page_size=50") +my_string=$my_string$delimiter2 +while [[ $my_string ]]; do + my_in_array+=( "${my_string%%"$delimiter2"*}" ) + my_string=${my_string#*"$delimiter2"} +done + +my_out_array=(); +for line in "${my_in_array[@]}"; +do + if [[ "$line" =~ $delimiter && "$line" =~ $delimiter1 ]]; then + start=`awk -v a="$line" -v b="$delimiter" 'BEGIN{print index(a,b)}'` + start=$((start + ${#delimiter})) + end=`awk -v a="$line" -v b="$delimiter1" 'BEGIN{print index(a,b)}'` + end=$((end + 3 - start)) + line=${line:$start:$end} + my_out_array+=( $line ); + fi +done +echo "Downloading files found that match criteria" +for URL in "${my_out_array[@]}" +do + echo "URL: $URL" + echo "wget --progress=bar:force:noscroll -c $URL -P metadata" + wget --progress=bar:force:noscroll -c $URL -P metadata +done +echo "Files downloaded" +ls -la metadata/$NAME*-*$VERSION*xml +exit