|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | if [ "$#" -ne "4" ]; then |
4 | | - echo "Incorrect invocation: Should be download_xml.sh plugin_name plugin_version cloudsmith_user cloudsmith_level" |
| 4 | + echo "Incorrect invocation: Should be download_xml.sh cloudsmith_repository plugin_version cloudsmith_user cloudsmith_level" |
5 | 5 | echo "where:" |
6 | | - echo " plugin_name is the name of the plugin, i.e. testplugin_pi" |
| 6 | + echo " cloudsmith_repository is the name of the repository on cloudsmith the files are in, i.e. testplugin" |
7 | 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" |
| 8 | + echo " cloudsmith_user is the user name associated with the cloudsmith repository, i.e. jon-gough or opencpn" |
9 | 9 | echo " cloudsmith_level is the level of the repository and is one of: prod, beta, alpha" |
10 | 10 | echo "" |
11 | 11 | echo " Full command should look like:" |
12 | | - echo " download_xml.sh testplugin_pi 1.0.114.0 jon-gough alpha" |
| 12 | + echo " download_xml.sh testplugin_pi 1.0.114.0 jon-gough prod" |
| 13 | + echo " download_xml.sh weather-routing 1.13.8.0 opencpn prod" |
13 | 14 | exit |
14 | 15 | fi |
15 | 16 |
|
16 | | -REPO="https://cloudsmith.io/~$3/repos/" |
17 | | -echo "Issuing command: lynx -dump $REPO$1-$4/packages/?q=*$2*.xml | awk {'print $2'} |grep '.xml$' |grep $1-$2" |
18 | | -my_array=() |
| 17 | +NAME="$1" |
| 18 | +VERSION="$2" |
| 19 | +USER="$3" |
| 20 | +LEVEL="$4" |
| 21 | + |
| 22 | +REPO="https://cloudsmith.io/~${USER}/repos/" |
| 23 | +echo "Issuing command: wget -q -O - $REPO${NAME}-${LEVEL}/packages/?q=*${VERSION}*.xml" |
19 | 24 | echo "Show current files that match criteria" |
20 | | -ls metadata/$1-$2*xml -la |
| 25 | +ls metadata/${NAME}*-*${VERSION}*xml -la |
21 | 26 | echo "Deleting current files that match criteria" |
22 | | -rm metadata/$1-$2*xml |
| 27 | +rm metadata/${NAME}*-*${VERSION}*xml |
23 | 28 | echo "Finding files on remote cloudsmith repository" |
24 | | -while IFS= read -r line; do |
25 | | - my_array+=( "$line" ) |
26 | | -done < <( lynx -dump $REPO$1-$4/packages/?q=*$2*.xml | awk {'print $2'} |grep '.xml$' |grep $1-$2 ) |
27 | | - |
| 29 | +delimiter="href=\"" |
| 30 | +delimiter1=".xml" |
| 31 | +my_array=(); |
| 32 | +while read -r line; do |
| 33 | + if [[ "$line" =~ ^$delimiter && "$line" =~ $delimiter1.$ ]]; then |
| 34 | + start=`awk -v a="$line" -v b="$delimiter" 'BEGIN{print index(a,b)}'` |
| 35 | + start=$((start + ${#delimiter} - 1)) |
| 36 | + end=`awk -v a="$line" -v b="$delimiter1" 'BEGIN{print index(a,b)}'` |
| 37 | + end=$((end + 3 - start)) |
| 38 | + line=${line:$start:$end} |
| 39 | + my_array+=( $line ); |
| 40 | + fi |
| 41 | +done < <(wget -q -O - "${REPO}${NAME}-${LEVEL}/packages/?q=*${VERSION}*+tag:latest&page_size=50") |
28 | 42 | echo "Downloading files found that match criteria" |
29 | 43 | for URL in "${my_array[@]}" |
30 | 44 | do |
31 | | - echo $URL |
| 45 | + echo "URL: $URL" |
32 | 46 | wget --progress=bar:force:noscroll -c $URL -P metadata |
33 | 47 | done |
34 | 48 | echo "Files downloaded" |
35 | | -ls metadata/$1-$2*xml -la |
36 | | - |
| 49 | +ls -la metadata/$NAME*-*$VERSION*xml |
0 commit comments