uploadToCentral.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #! /bin/bash
  2. set -euo pipefail
  3. ## Upload a deployment
  4. ## from the "org.jmonkeyengine" namespace in Sonatype's OSSRH staging area
  5. ## to Sonatype's Central Publisher Portal
  6. ## so the deployment can be tested and then published or dropped.
  7. ## IMPORTANT: The upload request must originate
  8. ## from the IP address used to stage the deployment to the staging area!
  9. # The required -p and -u flags on the command line
  10. # specify the password and username components of a "user token"
  11. # generated using the web interface at https://central.sonatype.com/account
  12. while getopts p:u: flag
  13. do
  14. case "${flag}" in
  15. p) centralPassword=${OPTARG};;
  16. u) centralUsername=${OPTARG};;
  17. esac
  18. done
  19. # Combine both components into a base64 "user token"
  20. # suitable for the Authorization header of a POST request:
  21. token=$(printf %s:%s "${centralUsername}" "${centralPassword}" | base64)
  22. # Send a POST request to upload the deployment:
  23. server='ossrh-staging-api.central.sonatype.com'
  24. endpoint='/manual/upload/defaultRepository/org.jmonkeyengine'
  25. url="https://${server}${endpoint}"
  26. statusCode=$(curl "${url}" \
  27. --no-progress-meter \
  28. --output postData1.txt \
  29. --write-out '%{response_code}' \
  30. --request POST \
  31. --header 'accept: */*' \
  32. --header "Authorization: Bearer ${token}" \
  33. --data '')
  34. echo "Status code = ${statusCode}"
  35. echo 'Received data:'
  36. cat postData1.txt
  37. echo '[EOF]'
  38. # Retry if the default repo isn't found (status=400).
  39. if [ "${statusCode}" == "400" ]; then
  40. echo "Will retry after 30 seconds."
  41. sleep 30
  42. statusCode2=$(curl "${url}" \
  43. --no-progress-meter \
  44. --output postData2.txt \
  45. --write-out '%{response_code}' \
  46. --request POST \
  47. --header 'accept: */*' \
  48. --header "Authorization: Bearer ${token}" \
  49. --data '')
  50. echo "Status code = ${statusCode2}"
  51. echo 'Received data:'
  52. cat postData2.txt
  53. echo '[EOF]'
  54. fi