Skip to content

Commit fcf8317

Browse files
authored
Merge pull request #1304 from jongough/jg_update_master
Add download_xml_api.sh to access api.cloudsmith.io for retrievel of …
2 parents ce0d00e + 50ae299 commit fcf8317

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

download_xml_api.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
if [ "$#" -ne "4" ]; then
4+
echo "Incorrect invocation: Should be download_xml_api.sh cloudsmith_repository plugin_version cloudsmith_user cloudsmith_level"
5+
echo "where:"
6+
echo " cloudsmith_repository is the name of the repository on cloudsmith the files are in, i.e. testplugin"
7+
echo " plugin_version is the version number, i.e. 1.0.114.0"
8+
echo " cloudsmith_user is the user name associated with the cloudsmith repository, i.e. jon-gough or opencpn"
9+
echo " cloudsmith_level is the level of the repository and is one of: prod, beta, alpha"
10+
echo ""
11+
echo " Full command should look like:"
12+
echo " download_xml_api.sh testplugin_pi 1.0.114.0 jon-gough prod"
13+
echo " download_xml_api.sh weather-routing 1.13.8.0 opencpn prod"
14+
exit
15+
fi
16+
17+
NAME="$1"
18+
VERSION="$2"
19+
USER="$3"
20+
LEVEL="$4"
21+
22+
REPO="https://api.cloudsmith.io/v1/packages"
23+
echo "Issuing command: wget -q -O - $REPO/${USER}/${NAME}-${LEVEL}/?q=*${VERSION}*metadata"
24+
echo "Show current files that match criteria"
25+
ls metadata/${NAME}*-*${VERSION}*xml -la
26+
echo "Deleting current files that match criteria"
27+
rm metadata/${NAME}*-*${VERSION}*xml
28+
echo "Finding files on remote cloudsmith repository"
29+
delimiter="\"cdn_url\":"
30+
delimiter1=".xml"
31+
delimiter2="\"files\":["
32+
my__in_array=();
33+
34+
my_string=$(wget -q -O - "${REPO}/${USER}/${NAME}-${LEVEL}/?q=*${VERSION}*metadata+tag:latest&page_size=50")
35+
my_string=$my_string$delimiter2
36+
while [[ $my_string ]]; do
37+
my_in_array+=( "${my_string%%"$delimiter2"*}" )
38+
my_string=${my_string#*"$delimiter2"}
39+
done
40+
41+
my_out_array=();
42+
for line in "${my_in_array[@]}";
43+
do
44+
if [[ "$line" =~ $delimiter && "$line" =~ $delimiter1 ]]; then
45+
start=`awk -v a="$line" -v b="$delimiter" 'BEGIN{print index(a,b)}'`
46+
start=$((start + ${#delimiter}))
47+
end=`awk -v a="$line" -v b="$delimiter1" 'BEGIN{print index(a,b)}'`
48+
end=$((end + 3 - start))
49+
line=${line:$start:$end}
50+
my_out_array+=( $line );
51+
fi
52+
done
53+
echo "Downloading files found that match criteria"
54+
for URL in "${my_out_array[@]}"
55+
do
56+
echo "URL: $URL"
57+
echo "wget --progress=bar:force:noscroll -c $URL -P metadata"
58+
wget --progress=bar:force:noscroll -c $URL -P metadata
59+
done
60+
echo "Files downloaded"
61+
ls -la metadata/$NAME*-*$VERSION*xml
62+
exit

0 commit comments

Comments
 (0)