gpipe 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env sh
  2. # IBM Confidential
  3. # OCO Source Materials
  4. # IBM Business Platform: Cognos Analytics on the Cloud
  5. # (C) Copyright IBM Corp. 2018
  6. #
  7. # The source code for this program is not published or otherwise divested of its trade secrets,
  8. # irrespective of what has been deposited with the U.S. Copyright Office.
  9. # This script provides access to the Globalization Pipeline
  10. set -e
  11. if [ -z "$GPIPE_JAR_REPOSITORY_URL" ]; then
  12. # fix this by moving to pipeline config
  13. GPIPE_JAR_REPOSITORY_URL="http://capipeline-nexus.canlab.ibm.com:8081/nexus/repository/master-mvn-dev"
  14. fi
  15. if [ -z "$GPIPE_GIT_REPOSITORY_URL" ]; then
  16. # fix this by moving to pipeline config
  17. GPIPE_GIT_REPOSITORY_URL="https://github.ibm.com/api/v3/repos/BusinessAnalytics/gp-helper"
  18. fi
  19. if [ -z "$GPIPE_JAR" ]; then
  20. GPIPE_JAR="${HOME}/gpipe.jar"
  21. fi
  22. if [ -z "$GPIPE_JAR_VERSION" ]; then
  23. GPIPE_JAR_VERSION="latest"
  24. fi
  25. GPSCRIPT=$0
  26. function displayUsage() {
  27. cat << EOF
  28. updateScript - updates the gpipe script in place. Requires \$GIT_TOKEN or
  29. \$GIT_API_TOKEN be set.
  30. updateJar - downloads the latest version of the gpipe jar file to the
  31. location indicated by \$GPIPE_JAR environment variable. Requires
  32. \$W3_USERNAME and \$W3_PASSWORD be set.
  33. Credentials may alternately be set in the netrc file for the hosts
  34. capipeline-nexus.canlab.ibm.com and github.ibm.com.
  35. EOF
  36. }
  37. function usage() {
  38. if [ -e $GPIPE_JAR ]; then
  39. java -cp ${GPIPE_JAR} com.ibm.g11n.pipeline.GPipe help
  40. fi
  41. displayUsage
  42. }
  43. function getGPScript() {
  44. if [ -z "$GIT_API_TOKEN" ]; then
  45. if [ -z "$GIT_TOKEN" ]; then
  46. CURL_CREDS="-n"
  47. else
  48. CURL_CREDS="-u user:$GIT_TOKEN"
  49. fi
  50. else
  51. CURL_CREDS="-u user:$GIT_API_TOKEN"
  52. fi
  53. curl --retry 5 --fail --silent --create-dirs $CURL_CREDS -o ${GPSCRIPT}.tags --show-error --location ${GPIPE_GIT_REPOSITORY_URL}/releases/latest
  54. TAG=$(grep tag_name ${GPSCRIPT}.tags | cut -d'"' -f4)
  55. rm -f ${GPSCRIPT}.tags
  56. echo "Downloading version $TAG of gpipe helper script to $GPSCRIPT"
  57. curl --retry 5 -o ${GPSCRIPT} $CURL_CREDS --fail --silent --create-dirs --show-error --location -H Accept:application/vnd.github.v4.raw ${GPIPE_GIT_REPOSITORY_URL}/contents/gpipe?ref=${TAG}
  58. exit 1
  59. }
  60. function getGPJar() {
  61. if [ ! -e $GPIPE_JAR ]; then
  62. if [[ -z "$W3_USERNAME" || -z "$W3_PASSWORD" ]]; then
  63. CURL_CREDS="-n"
  64. else
  65. CURL_CREDS="-u $W3_USERNAME:$W3_PASSWORD"
  66. fi
  67. if [ "$GPIPE_JAR_VERSION" == "latest" ]; then
  68. curl --retry 5 -f -s -S -L $CURL_CREDS -o ${GPIPE_JAR}.versions $GPIPE_JAR_REPOSITORY_URL/com/ibm/g11n/pipeline/gp-cli-with-filters/maven-metadata.xml
  69. GPIPE_JAR_VERSION=$(grep "<version>" ${GPIPE_JAR}.versions | sed -e 's/</ /g' -e 's/>/ /g' | awk '{ print $2 }' | sort -V | tail -1)
  70. rm -f ${GPIPE_JAR}.versions
  71. fi
  72. echo "Downloading version $GPIPE_JAR_VERSION of GPIPE jar with dependencies to $GPIPE_JAR"
  73. curl --retry 5 -f $CURL_CREDS -L -S --create-dirs --progress-bar -o $GPIPE_JAR $GPIPE_JAR_REPOSITORY_URL/com/ibm/g11n/pipeline/gp-cli-with-filters/${GPIPE_JAR_VERSION}/gp-cli-with-filters-${GPIPE_JAR_VERSION}.jar
  74. else
  75. echo "$GPIPE_JAR exists. Download aborted."
  76. fi
  77. }
  78. if [ "$1" == "" ]
  79. then
  80. usage
  81. exit 0
  82. fi
  83. while (( "$#" ))
  84. do
  85. case "$1" in
  86. help)
  87. usage;
  88. exit 0
  89. ;;
  90. updateScript)
  91. getGPScript;
  92. ;;
  93. updateJar)
  94. getGPJar;
  95. ;;
  96. *)
  97. java -cp ${GPIPE_JAR} com.ibm.g11n.pipeline.GPipe $@
  98. exit 0
  99. ;;
  100. esac
  101. shift
  102. done