Skip to content

Instantly share code, notes, and snippets.

@dbkegley
Forked from suicide/artifactory-get.sh
Last active April 26, 2017 18:07
Show Gist options
  • Save dbkegley/31cce5de99a23c71affe1e665daa45bc to your computer and use it in GitHub Desktop.
Save dbkegley/31cce5de99a23c71affe1e665daa45bc to your computer and use it in GitHub Desktop.
Downloads latest artifact version from artifactory
#!/bin/bash
# get specified artifact version
# downloads latest version of an artifact if no version is specified
set -e
usage(){
echo "Usage: $*" >&2
exit 64
}
repo=""
group=""
artifact=""
version=""
classifier=""
while getopts r:g:a:v:c: OPT; do
case "${OPT}" in
r) repo="${OPTARG}";;
g) group="${OPTARG}";;
a) artifact="${OPTARG}";;
v) version="${OPTARG}";;
c) classifier="${OPTARG}";;
esac
done
shift $(( $OPTIND - 1 ))
if [ -z "${repo}" ] || [ -z "${group}" ] || [ -z "${artifact}" ]; then
usage "-r REPOSITORY -g GROUPID -a ARTIFACTID [-v VERSION] [-c CLASSIFIER]"
fi
# Maven artifact location
ga=${group//./\/}/$artifact
repopath=$repo/$ga
# if no version, get latest
if [ -z "${version}" ]; then
version=`curl -s $repopath/maven-metadata.xml | grep latest | sed "s/.*<latest>\([^<]*\)<\/latest>.*/\1/"`
fi
jar=""
if [ -z "${classifier}" ]; then
jar=$artifact-$version.jar
else
jar=$artifact-$version-$classifier.jar
fi
echo "Getting $artifact version $version from location $repopath"
# Download
url=$repopath/$version/$jar
echo "Download url: $url"
curl -O $url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment