2013-10-07 15:40:29 +02:00
|
|
|
nexusurl=maven.research-infrastructures.eu/nexus
|
2013-10-07 12:30:08 +02:00
|
|
|
group=org.gcube.distribution
|
|
|
|
artifact=smartgears-distribution
|
2013-10-07 17:30:38 +02:00
|
|
|
repo=gcube-release
|
|
|
|
folder=$PWD
|
2013-09-25 12:30:43 +02:00
|
|
|
|
|
|
|
function showhelp {
|
2013-10-07 17:30:38 +02:00
|
|
|
echo -e "\nusage: download [-v <version>] [-o <folder>] [-s|-h] \n"
|
2013-09-25 12:30:43 +02:00
|
|
|
echo " <version> = the version to download."
|
|
|
|
echo " = By default, this is the latest known version."
|
|
|
|
echo " s = download a snapshot version."
|
2013-10-07 17:30:38 +02:00
|
|
|
echo " <folder> = download to specific folder."
|
2013-09-25 12:30:43 +02:00
|
|
|
echo -e " h = shows this help.\n"
|
|
|
|
}
|
|
|
|
|
2013-10-07 17:30:38 +02:00
|
|
|
while getopts ":v:o:sh" opt; do
|
2013-09-25 12:30:43 +02:00
|
|
|
case $opt in
|
|
|
|
v) version=$OPTARG;;
|
2013-10-07 17:30:38 +02:00
|
|
|
o) folder=$OPTARG;;
|
2013-09-25 12:30:43 +02:00
|
|
|
s) repo=gcube-snapshots;;
|
|
|
|
h) showhelp
|
|
|
|
exit 0 ;;
|
|
|
|
:) echo -e "\nERROR:option -$OPTARG requires an argument." >&2 ;
|
|
|
|
showhelp;
|
|
|
|
echo -e "\naborting.\n"
|
|
|
|
exit 1;;
|
|
|
|
\?) echo -e "\nERROR:invalid option: -$OPTARG";
|
|
|
|
showhelp;
|
|
|
|
echo -e "\naborting.\n"
|
|
|
|
exit 1 >&2 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
#######find latest version in target repo. could use LATEST but would not know how to reflect version in file name
|
|
|
|
|
|
|
|
|
|
|
|
version_regexp=".*<baseVersion>\(.*\)</baseVersion>.*"
|
|
|
|
|
|
|
|
if [ -z "$version" ]; then
|
2013-10-07 17:30:38 +02:00
|
|
|
version=`curl -silent -L "$nexusurl/service/local/artifact/maven/resolve?r=$repo&g=$group&a=$artifact&v=LATEST&e=tar.gz" | grep "$version_regexp" | sed "s|$version_regexp|\1|"` #(first extract matching line, then extract matching group)
|
2013-09-25 12:30:43 +02:00
|
|
|
if [ -z "$version" ]; then
|
|
|
|
echo -e "\nERROR: cannot find a version to download in $repo." >&2
|
|
|
|
echo -e "\naborting.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-07 17:30:38 +02:00
|
|
|
echo -e "\ndownloading smartgears-distribution-$version.tar.gz to folder $folder ....\c"
|
2013-09-25 12:30:43 +02:00
|
|
|
|
|
|
|
|
2013-10-07 17:30:38 +02:00
|
|
|
http_code=`curl -s --create-dirs -o "$folder/smartgears-distribution-$version.tar.gz" -w "%{http_code}" -L "$nexusurl/service/local/artifact/maven/redirect?r=$repo&g=$group&a=$artifact&v=$version&e=tar.gz"`
|
2013-09-25 12:30:43 +02:00
|
|
|
|
|
|
|
if [ ! "$http_code" = "200" ]; then
|
|
|
|
echo -e "\n\nERROR: cannot download version $version from $repo." >&2
|
|
|
|
echo -e "\naborting.\n"
|
2013-10-07 12:30:08 +02:00
|
|
|
rm "smartgears-distribution-$version.tar.gz"
|
2013-09-25 12:30:43 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-10-07 17:30:38 +02:00
|
|
|
echo -e "done.\n"
|