Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 2.19 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. # Argument = -h -v -i groupId:artifactId:version -c classifier -p packaging -r repository
  3.  
  4. #shopt -o -s xtrace
  5.  
  6. # Define Nexus Configuration
  7. NEXUS_BASE=http://repository.example.com:8081/nexus
  8. REST_PATH=/service/local
  9. ART_REDIR=/artifact/maven/redirect
  10.  
  11. usage()
  12. {
  13. cat <<EOF
  14.  
  15. usage: $0 options
  16.  
  17. This script will fetch an artifact from a Nexus server using the Nexus REST redirect service.
  18.  
  19. OPTIONS:
  20.    -h      Show this message
  21.    -v      Verbose
  22.    -i      GAV coordinate groupId:artifactId:version
  23.    -c      Artifact Classifier
  24.    -p      Artifact Packaging
  25.  
  26. EOF
  27. }
  28.  
  29. # Read in Complete Set of Coordinates from the Command Line
  30. GROUP_ID=
  31. ARTIFACT_ID=
  32. VERSION=
  33. CLASSIFIER=""
  34. PACKAGING=war
  35. REPO=
  36. VERBOSE=0
  37.  
  38. while getopts "hvi:c:p:" OPTION
  39. do
  40.      case $OPTION in
  41.          h)
  42.              usage
  43.              exit 1
  44.              ;;
  45.          i)
  46.              OIFS=$IFS
  47.              IFS=":"
  48.              GAV_COORD=( $OPTARG )
  49.              GROUP_ID=${GAV_COORD[0]}
  50.              ARTIFACT_ID=${GAV_COORD[1]}
  51.              VERSION=${GAV_COORD[2]}         
  52.              IFS=$OIFS
  53.              ;;
  54.          c)
  55.              CLASSIFIER=$OPTARG
  56.              ;;
  57.          p)
  58.              PACKAGING=$OPTARG
  59.              ;;
  60.          v)
  61.              VERBOSE=1
  62.              ;;
  63.          ?)
  64.              usage
  65.              exit
  66.              ;;
  67.      esac
  68. done
  69.  
  70. if [[ -z $GROUP_ID ]] || [[ -z $ARTIFACT_ID ]] || [[ -z $VERSION ]]
  71. then
  72.      echo "BAD ARGUMENTS: Either groupId, artifactId, or version was not supplied" >&2
  73.      usage
  74.      exit 1
  75. fi
  76.  
  77. # Define default values for optional components
  78.  
  79. # If the version requested is a SNAPSHOT use snapshots, otherwise use releases
  80. if [[ "$VERSION" =~ .*SNAPSHOT ]]
  81. then
  82.     : ${REPO:="snapshots"}
  83. else
  84.     : ${REPO:="releases"}
  85. fi
  86.  
  87. # Construct the base URL
  88. REDIRECT_URL=${NEXUS_BASE}${REST_PATH}${ART_REDIR}
  89.  
  90. # Generate the list of parameters
  91. PARAM_KEYS=( g a v r p c )
  92. PARAM_VALUES=( $GROUP_ID $ARTIFACT_ID $VERSION $REPO $PACKAGING $CLASSIFIER )
  93. PARAMS=""
  94. for index in ${!PARAM_KEYS[*]}
  95. do
  96.   if [[ ${PARAM_VALUES[$index]} != "" ]]
  97.   then
  98.     PARAMS="${PARAMS}${PARAM_KEYS[$index]}=${PARAM_VALUES[$index]}&"
  99.   fi
  100. done
  101.  
  102. REDIRECT_URL="${REDIRECT_URL}?${PARAMS}"
  103.  
  104. echo "Fetching Artifact from $REDIRECT_URL..." >&2
  105. curl -sS -L ${REDIRECT_URL}